-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[no-restricted-imports] Allow configuring severity at the path level so both errors and warnings are possible #14061
Comments
Hi @dshook, thanks for the issue! This request looks similar to #13831. Supporting this would require a lot of changes in ESLint's design, for maybe only a few rules where it would be useful. As a workaround, you can make a clone of the rule and then configure the two rules separately (e.g., the original rule as |
Thanks for the quick reply! Just to be clear, when you say clone you mean using one of the other packages (like eslint-rule-extender or eslint-rule-composer mentioned in the other issue) right? I can't just put another instance of the |
Yes, it should be two different rules, seemingly unrelated to each other. eslint-rule-extender or eslint-rule-composer are actually not necessary if we just want to clone a rule without any modifications. New rule can just "re-export" the existing one, so this would be all the code of the new rule: const eslint = require("eslint");
module.exports = new eslint.Linter().getRules().get("no-restricted-imports"); Now you can use this module as a custom rule with --rulesdir. For example, the above code can be placed in rules: {
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "somepackage",
"message": "I want to make this one an error"
}
],
}
],
"no-restricted-imports-clone": [
"warn",
{
"paths": [
{
"name": "otherpackage",
"message": "But this should only be a warning"
},
],
}
]
}, ESLint would be run with Another option is to make a plugin. For an example of a plugin that doesn't have to be published, you can see our internal rules used for this project only: Line 102 in 4cab165
The plugin is in https://github.com/eslint/eslint/tree/master/tools/internal-rules |
I'm getting a |
Looks like configuring it as a plugin (following this guide) worked. |
Resolved, so closing. |
I am having the same issue, that we want |
The version of ESLint you are using.
6.8.0
The problem you want to solve.
I want to be able to configure the
no-restricted-imports
rule to have some paths be errors and others only be warnings. After looking at the docs, the source for the rule, and much searching I couldn't find any way to configure it to do that. I believe this is a broader configuration issue than just theno-restricted-imports
but this is the current rule I'm running into the roadblock with.In JSON configuration
Your take on the correct solution to problem.
Are you willing to submit a pull request to implement this change?
No
The text was updated successfully, but these errors were encountered: