Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import environment exported by eslint plugin?

I see that in https://github.com/Gillespie59/eslint-plugin-angular/blob/master/environments.js subsection mocks eslint-plugin-angular declares the inject global variable.

How do I import these environment settings from my application? I tried "extends": "angular" but eslint still complains:

7:14  error  'inject' is not defined  no-undef

I tried adding:

"env": {
    "angular/mocks": true
}

to the config, but then I got

Environment key "angular/mocks" is unknown
like image 875
Gili Avatar asked Feb 03 '17 17:02

Gili


People also ask

How to use ESLint plugin?

To use the rule in ESLint, you would use the unprefixed plugin name, followed by a slash, followed by the rule name. So if this plugin were named eslint-plugin-myplugin , then in your configuration you'd refer to the rule by the name myplugin/dollar-sign . Example: "rules": {"myplugin/dollar-sign": 2} .

What does ESLint plugin Import do?

This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.


1 Answers

You are getting this error because ESLint can only use environments exposed by plugins and not configs. You have to register eslint-plugin-angular as plugin in your config file:

"plugins": ["angular"],
"env": {
  "angular/mocks": true
}

If that still doesn't work, you should run ESLint with --debug flag to see if your config is correctly loaded and environment is applied. You can also run ESLint with --print-config flag followed by a path to some file in your repository to see all of the rules and global variables that ESLint will use when linting that file.

like image 105
Ilya Volodin Avatar answered Sep 20 '22 19:09

Ilya Volodin