Skip to content

benspaulding/eslint-plugin-django

Repository files navigation

eslint-plugin-django

Overview

This ESLint environment plugin provides globals for the Django JavaScript Catalog.

Most ESLint configurations use "no-undef": "error", which will cause ESLint to error if you internationalize your code and use Django as your backend, e.g.:

{# some template that loads your JS code #}
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>

… then call one of its functions in your front-end code:

const someText = gettext('My Text');

Installation

First add the plugin as a development dependency:

npm install --save-dev eslint-plugin-django

Then configure ESLint to use it:

{
  "plugins": ["django"],
  "env": {
    "browser": true,
    "node": true,
    "django/i18n": true
  }
}

Refer to the ESLint docs for configuring plugins and environments if you need more information.

Alternatives

If you don’t want to install this plugin you can list the necessary functions in the ESLint configuration globals key instead:

{
  "globals": {
    "gettext": "readonly",
    "ngettext": "readonly",
    "interpolate": "readonly",
    "get_format": "readonly",
    "gettext_noop": "readonly",
    "pgettext": "readonly",
    "npgettext": "readonly",
    "pluralidx": "readonly",
    "django": "readonly"
  }
}

About

An eslint environment plugin that configures globals added by the Django JavaScript Catalog

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published