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.

no-restricted-imports allow patterns to have custom message in config

See original GitHub issue

The version of ESLint you are using. v6.8.0

The problem you want to solve.

Currently the no-restricted-imports rule config allows us to configure custom message for paths. Proposal is to extend the capability to patterns as well.

"no-restricted-imports": [	
  "error",
  {
	"patterns": [
		"@lodash/*"
	]
}]

Will give us the below linting error when we do "import get from "lodash/get" "@lodash/* restricted by a pattern"

The error is not informative, something like this will be helpful"@lodash/* restricted by a pattern, {{ customMessage }}", so that we can give additional information why we did such pattern restriction.

Your take on the correct solution to problem.

A change in rule config schema for accepting custom message for pattern and modify the eslint output to print the custom message along with the actual output "@lodash/* restricted by a pattern, {{ customMessage }}".

Are you willing to submit a pull request to implement this change?

Yes

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Jun 11, 2020

I think we already have an accepted issue for this enhancement: #11843

1reaction
niyazhussaincommented, Jun 11, 2020

@kaicataldo updated the info

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for "message" with "patterns" in `no-restricted-imports`
I can't customize the error message for the restricted pattern import. What will the rule do after it's changed? It should allow me...
Read more >
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 >
Lint rule "no-restricted-imports" throw error when patterns ...
Configuration for rule "no-restricted-imports" is invalid: Value {"patterns":[{"group":["lodash/"],"message":"Message"}]} should be string.
Read more >
Disallow specific imports (no-restricted-imports) - ESLint
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 >
Creating a Custom ESLint Rule with TDD - DEV Community ‍ ‍
My custom rule makes sure that a developer will not be able to import a namespace (“import * as ...”) from modules, with...
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