I want to use eslint api in my node js script. I found this: https://eslint.org/docs/developer-guide/nodejs-api. So I am trying to create CLIEngine, load config and lint something using API.
When I am trying to lint some code using API I am getting error: Definition for rule <ruleName> was not found.
.
You can watch code in this repo: https://github.com/sharikovvladislav/eslint-try-api-with-plugins
Here is whole my code:
const CLIEngine = require('eslint').CLIEngine;
const Linter = require('eslint').Linter;
const path = require('path');
const cli = new CLIEngine({
configPath: path.resolve(process.cwd(), '.eslintrc.json')
});
const linter = new Linter();
const result = linter.verifyAndFix('var foo', cli.getConfigForFile("script.js"));
console.log(result);
In result I get something like this:
~/tmp/test-eslint-with-plugins node script.js
{ fixed: false,
messages:
[ { ruleId: 'node/no-extraneous-require',
message:
'Definition for rule \'node/no-extraneous-require\' was not found.',
line: 1,
column: 1,
endLine: 1,
endColumn: 2,
severity: 2,
nodeType: null }
// ....
]
}
I have this in my package dependency:
"eslint": "^6.1.0",
"eslint-plugin-node": "^9.1.0"
This is my eslintrc:
{
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"rules": {
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error"
}
}
So I specified some plugins and rules. Looks like everything is correct.
I tried to debug a bit and I realised that CLI is created (looks like) normally. Also, config file parsed correctly. I can see this in config properties:
cli.getConfigForFile("script.js").plugins
>> ["node"]
Object.keys(cli.getConfigForFile("script.js").rules).filter(key => key.startsWith('node'))
>> ["node/exports-style", "node/file-extension-in-import", "node/prefer-global/buffer", "node/prefer-global/console", "node/prefer-global/process", "node/prefer-global/url-search-params", "node/prefer-global/url", "node/prefer-promises/dns", "node/prefer-promises/fs", "node/no-deprecated-api", "node/no-extraneous-require", "node/no-missing-require", "node/no-unpublished-bin", "node/no-unpublished-require", "node/no-unsupported-features/es-builtins", "node/no-unsupported-features/es-syntax", "node/no-unsupported-features/node-builtins", "node/process-exit-as-throw", "node/shebang", "node/no-extraneous-import", "node/no-missing-import", "node/no-unpublished-import"]
Why do I get Definition for rule \'node/no-extraneous-require\' was not found.
error (and other errors like this)? What I am missing?
from Why eslint plugins are not applied when I am trying to use eslint nodejs api?
No comments:
Post a Comment