New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: Adding support for custom environments (fixes #1130) #2024
Conversation
|
||
Plugins can also provide custom environments. Custom environments can declare `globals`, turn `ecmaFeatures` on and off, | ||
and configure both core rules as well as rules included in the plugin. To provide custom environment, include `environment` | ||
property in your exported object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about enabling other plugins?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Environments can't specify plugins, only globals
, ecmaFeatures
, and rules
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you can't include plugins
section, the thing that was bothering me, was that you can specify rules from another plugins. There's no validation currently anywhere in the code, to verify that rules inside environments don't include rules from some other plugin. I guess even if that happens, you are going to get a message about incorrect configuration of the rule, so not the end of the world.
OK, I had a chance to go over the code in eslint.js to see how hard would it be to add support for inline config for environments from plugins, and it looks like there's some major re-factoring required to do that. All of the code that deals with config should be moved out from eslint.js, and there's a lot of it there. I don't really know when I'll have time to get to it, so for now I'll close this pull request and will reopen it when I will refactor all of the code. |
oh, man.. I was hoping we'd get something like this in here for something like adding an "angular-mocks" environment so I don't have to have this in all my tests:
I could just have
|
We will. Eventually:-) Just don't really have time or energy to refactor the whole eslint.js file right now. |
I understand :) I haven't looked at the code yet, but it sounds like a lot of work. |
Fixes #1130
This adds support for custom environments provided by plugins. All the same limitations as with custom rules apply here (See #2022). I also think that unit tests are probably lacking a bit right now. It should probably include at least a unit-test for changing rules from custom environment, however, it's pretty hard to test that, since when
reset
is true, rule configuration will be discarded, and when it's false, all of the rules from the default config are being pulled in.