Skip to content
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

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

Closed
platinumazure opened this issue Jan 15, 2018 · 7 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Comments

@platinumazure
Copy link
Member

platinumazure commented Jan 15, 2018

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.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jan 15, 2018
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jan 15, 2018
@yvele
Copy link

yvele commented Jan 15, 2018

My team need a custom message no-restricted-module.

Sometimes we need to blacklist npm modules and it would like awesome to show a custom message explaining what module should be used instead.

@platinumazure
Copy link
Member Author

Hi @yvele, thanks for replying.

To be clear, you can currently use custom messages for require paths- it's only for patterns where you can't yet use a custom message.

@yvele
Copy link

yvele commented Jan 15, 2018

@platinumazure Ho yeah right! The name is enough for us, we don't need custom message for patterns.. (if you want I can delete my ambiguous messages)

@platinumazure
Copy link
Member Author

No worries, I appreciate your feedback anyway, no need to delete. Thanks!

@platinumazure
Copy link
Member Author

Closing due to lack of interest.

@jrbotros
Copy link

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!

@wzalazar
Copy link

I think is useful can set a custom message, for example in my case I want to avoid the relative path to favor use absolute path at least that file is inside the same directory.

with this rule,

/* eslint no-restricted-imports: ["error", { "patterns": ["../*"] } ] */

is enough, but I don't show any message how to fix this issue and it brings bad experience

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 19, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants