jupyterlab/eslint-plugin-jinja

Name: eslint-plugin-jinja

Owner: JupyterLab

Description: This plugin treats Jinja template expressions as Javascript literals and ignores template statements and comments

Forked from: alexkuz/eslint-plugin-jinja

Created: 2017-12-08 13:54:45.0

Updated: 2017-12-25 11:50:52.0

Pushed: 2017-12-08 13:58:54.0

Homepage: null

Size: 8

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

npm version

eslint-plugin-jinja

This plugin treats Jinja template expressions and statements as valid Javascript expressions, so that ESLint can check javascript code, ignoring any Jinja expression found.

As a note, it is possible that this best effort conversion yeilds false negatives or positives because it is impossible to know the right way to insert placeholders.

Example

Plugin will convert (internally) this code:

unction() {
'use strict';

{# plain jinja variables are converted into strings
  (preferred quotes are getting from .eslintrc file) #}

var a = 'this is' + {{ some_variable }};

{# if it is already in string, it is wrapped with spaces #}

var b = 'this is {{ other_variable }}';
var c = 'and this is {{ another_one['field']}}';

{# if-else statements are converted into ( ..., ... ) expression #}

var d = {% if something %} 'this is something' {% else %} null {% endif %};

{# any other statements become comments #}

{% for i in [1, 2, 3] %}
  console.log(a, b, c, d);
{% endfor %}
();

into this:

nction() {
'use strict';

/* plain jinja variables are converted into strings
  (preferred quotes are getting from .eslintrc file) */

var a = 'this is' + '  some_variable  ';

/* if it is already in string, it is wrapped with spaces */

var b = 'this is    other_variable   ';
var c = 'and this is    another_one[ field ]  ';

/* if-else statements are converted into ( ..., ... ) expression */

var d = (/*if something */ 'this is something' ,/*else */ null /*endif */);

/* any other statements become comments */

/* for i in [1, 2, 3] */
  console.log(a, b, c, d);
/* endfor */
();

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.