question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do we need to support custom messages for patterns in no-restricted-imports and no-restricted-modules?

See original GitHub issue

Follow-up issue to #8400.

Proposal would be to add support for custom error messages when users use patterns in no-restricted-imports or no-restricted-modules. Proposal is basically the same for both rules, so I’m going to save myself some time and only draw it out for no-restricted-modules.

What rule do you want to change?

no-restricted-modules (and no-restricted-imports, analogously)

Does this change cause the rule to produce more or fewer warnings?

Same number of warnings

How will the change be implemented? (New option, new default behavior, etc.)?

New option to create custom messages for pattern-based configurations

Please provide some example code that this change will affect:

Config strawman:

{
    "no-restricted-modules": ["error",
        { "patterns": ["import1/private/*"], "message": "Do not use any modules in import1/private" },
        { "patterns": ["import2/*", "!import2/good"], "message": "Do not use any modules in import2 except import2/good" }
    ]
}

Code:

const badImport1 = require("import1/private/foo");
const badImport2 = require("import2/bad");

What does the rule currently do for this code?

Report an error on each line using the generic message for this rule.

What will the rule do after it’s changed?

Report an error on each line using the generic message for this rule plus the message supplied in the configuration file.


I’m submitting this as a separate issue to see if this is something we definitely need to support in ESLint (either by strong community voice or by the team coming to consensus independently). I’m not championing this at the moment.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
platinumazurecommented, Mar 22, 2018

Closing due to lack of interest.

1reaction
jrbotroscommented, Jun 28, 2018

This would be really helpful to me as I’m looking to deprecate an entire directory worth of components in favor of a new set elsewhere. I could take a stab at this if you’d be interested!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Disallow specific imports (no-restricted-imports) - ESLint
Please note that you may not specify custom error messages for restricted patterns as a particular import may match more than one pattern....
Read more >
eslint no-restricted-imports - prevent an import from from path ...
What I'm trying to do is restrict imports from parent index files - as this is causing issues with cyclical dependencies (I am...
Read more >
ValidateJavaScript - Online Tool to Find & Fix JavaScript Errors
ValidateJavaScript is an online validating (or linting) tool that will automatically find basic errors and help prevent potentially destructive bugs in ...
Read more >
eslint-config-ash-nazg - npm
If you really don't want this, you can override by setting ... +babel.js : Wraps a module to support equivalent babel/eslint-parser rules ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found