[no-restricted-imports] Allow configuring severity at the path level so both errors and warnings are possible
See original GitHub issueThe 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 the no-restricted-imports
but this is the current rule I’m running into the roadblock with.
In JSON configuration
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "somepackage",
"message": "I want to make this one an error"
},
{
"name": "otherpackage",
"message": "But this should only be a warning"
},
],
}
],
Your take on the correct solution to problem.
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "somepackage",
"message": "I want to make this one an error"
},
{
"name": "otherpackage",
"message": "But this should only be a warning. By providing a severity here it overrides the severity set above",
"severity": "warn"
},
],
}
],
Are you willing to submit a pull request to implement this change? No
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
no-restricted-imports - ESLint - Pluggable JavaScript Linter
This rule allows you to specify imports that you don't want to use in your application. It applies to static imports only, not...
Read more >Emitting Multiple Error Levels with the Same ESlint Rule
This rule allows users to specify imports that are not allowed in their applications, flagging them at either the “error” level or the...
Read more >Improve your code with lint checks - Android Developers
All lint methods that override the given severity level of an issue— enable , disable / ignore , informational , warning , error...
Read more >Settings Reference for Python - Visual Studio Code
Allows a user to override the severity levels for individual diagnostics. For each rule, the available severity levels are error (red squiggle), warning...
Read more >How to use no-restricted-imports to prevent any import file that ...
To do so, I've used the following rules: { 'no-restricted-imports': ['error', { patterns: [{ group: ['_*'], message: 'Import files starting ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Now you can use this module as a custom rule with –rulesdir. For example, the above code can be placed in
my-rules/no-restricted-imports-clone.js
, and then the two rules would be configured like this:ESLint would be run with
--rulesdir my-rules
.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:
https://github.com/eslint/eslint/blob/4cab165bf4e6e5e9f42a59a37a8ff2548c0af87d/package.json#L102
The plugin is in https://github.com/eslint/eslint/tree/master/tools/internal-rules
Looks like configuring it as a plugin (following this guide) worked.