eslint-plugin-rulesdir
eslint-plugin-rulesdir copied to clipboard
initialization doesn't work in VS Code
OS: win 7 VS Code Version: 1.27.2
Using Microsoft/vscode-eslint extension.
throws:
[Error - 5:35:09 PM] Error: To use eslint-plugin-rulesdir, you must load it beforehand and set the `RULES_DIR` property on the module to a string.
at Object.get rules [as rules] (\node_modules\eslint-plugin-rulesdir\index.js:24:13)
at Rules.importPlugin (\node_modules\eslint\lib\rules.js:97:20)
at Plugins.define (\node_modules\eslint\lib\config\plugins.js:55:21)
at Plugins.load (\node_modules\eslint\lib\config\plugins.js:143:18)
at Array.forEach (<anonymous>)
at Plugins.loadAll (\node_modules\eslint\lib\config\plugins.js:166:21)
at loadFromDisk (\node_modules\eslint\lib\config\config-file.js:501:35)
at Object.load (\node_modules\eslint\lib\config\config-file.js:559:20)
at Config.getLocalConfigHierarchy (\node_modules\eslint\lib\config.js:227:44)
at Config.getConfigHierarchy (\node_modules\eslint\lib\config.js:179:43)
root .eslintrc.js
:
const rulesDirPlugin = require("eslint-plugin-rulesdir");
rulesDirPlugin.RULES_DIR = "eslint-rules";
module.exports = {
"parser": "babel-eslint",
"plugins": [
"rulesdir"
],
"rules": {
"rulesdir/spaced-comment-line": [ "warn", "always" ]
}
};
In Atom, this setup works fine.
To be honest, this is probably the extension's problem, but wanted to ensure it's not eslint-plugin-rulesdir
's problem before opening an issue over there.
Looking at the source code, there's not much to be broken here. It seems somewhere along to way the eslint-plugin-rulesdir
plugin is re-required. Not sure by whom.
Could this be solved by allowing to supply RULES_DIR
some other way, e.g. as a package.json
option or .eslint-plugin-rulesdir.json
config? AFAIK, eslint doesn't allow pre-initialization of plugins and the plugin doesn't even know what .eslintrc
file it belongs to. Other ideas?
Thanks for creating an issue. I think I've heard about people having problems with this in the past (also see: https://github.com/eslint/eslint/issues/10229), although I'm not sure what the cause was. Is it possible that there are two separate versions of eslint-plugin-rulesdir
present?
If you want to specify plugin info in a file, you could also use something like eslint-plugin-local-rules
.
I've run a search across my whole drive and there's only a single eslint-plugin-rulesdir
package, so the issue must be in how vscode/eslint handles it.
Either way, thanks for the eslint-plugin-local-rules
suggestion --- that one works great and isn't such a bother to migrate to.
I'll leave this issue open so it's easier for other people to find.