Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Support for rules from eslint plugins #16

Closed
lostm1nd opened this issue Nov 3, 2014 · 9 comments
Closed

Support for rules from eslint plugins #16

lostm1nd opened this issue Nov 3, 2014 · 9 comments
Assignees

Comments

@lostm1nd
Copy link

lostm1nd commented Nov 3, 2014

Hello,
I am having an issue with loading rules from external eslint plugins. I am trying to load get the linter working with "eslint-plugin-openui5" but get an error that the definition for the rule is not found.
This is how we the plugin is loaded:

"plugins": [
"eslint-plugin-openui5"
],
"rules": {
"openui5/line-endings": 2,
}

I would really appreciate some help in fixing this problem.
Thanks

@jfaissolle jfaissolle self-assigned this Nov 4, 2014
@jfaissolle
Copy link
Member

I first need an answer to eslint/eslint#1450

@killercup
Copy link
Contributor

+1

Any progress so far? It's blocking me using any eslint plugins since linter-eslint crashes trying to read my .eslintrc

@jfaissolle
Copy link
Member

I am sorry to say that I did not make any progress recently. For now, I have no idea of how to do it properly because of how plugins are loaded. I must think about it a bit more.

@killercup
Copy link
Contributor

I can imagine the difficulties: The plugins (incl. versions) are defined in a project (directory) and can't be known beforehand, so you'd have to install them when reading a project's .eslintrc and even store them per-project. That's not easy and probably a bad solution anyway.

Is there a chance you might parsing the .eslintrc a bit more robust, e.g. by stripping/ignoring all unknown rules. This is not a good solution for eslint itself but for an editor plugin, it might ensure future compatibility (and prevent crashes on unknown plugins).

That being said, there are currently only a handful of eslint plugins. You might want to decide to include a few of them in linter-eslint (I would certainly welcome it).

@jfaissolle
Copy link
Member

The problem is that the config (.eslintrc) loading and merging is delegated to the eslint API to ensure a consistent behaviour with the command line. So at the moment I see the following options:

  • add all existing plugins like you propose (easy but not future-proof)
  • ask the eslint team for a change in their API to avoid error when plugin is not found (difficult to obtain)
  • use something like https://www.npmjs.org/package/app-module-path to add additional module directories to the node module path (dangerous, can be a bad behaviour for an atom plugin)
  • use the previous solution but in an external process to avoid polluting atom

@killercup
Copy link
Contributor

Sounds like the best option for now would be option 2, i.e. adding a silent error option to eslint.

From a quick code search, it looks like this else branch is all that needs to change for missing rule errors to be silent.


Wait—you wrote that "loading and merging is delegated to the eslint API". But that just means that you retrieve the config from eslint, to then pass that config object to linter.verify. I added a breakpoint to this line, got the config and was able to modify it before passing it on to linter.verify:

# Line 43
config = engine.getConfigForFile(origPath)
config.plugins = _.omit(config.rules, (val, key) -> _.contains(key, '/'))

result = linter.verify @editor.getText(), config
# ...

If I'm not mistaken, this is all you need to remove plugin-based rules.

@jfaissolle
Copy link
Member

You are right. I think this is the best option at the moment. Would you mind submitting a PR ?

@killercup
Copy link
Contributor

Sure thing: #18

killercup added a commit to killercup/linter-eslint that referenced this issue Nov 20, 2014
See AtomLinter#16 for more discussion.
killercup added a commit to killercup/linter-eslint that referenced this issue Nov 20, 2014
See AtomLinter#16 for more discussion.
@jfaissolle
Copy link
Member

Should not break anymore but real plugin support would be cool.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants