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 with custom messages is throwing a validation error

See original GitHub issue

Node 10.15.3 and latest ESLint version.

When configuring the rule with a custom message exactly how it is done in the example page https://eslint.org/docs/rules/no-restricted-imports

"no-restricted-imports": ["error", [{
  "name": "import-foo",
  "message": "Please use import-bar instead."
}]]

I get an ESLint rule validation error

Error: /Users/me/project/my-rules.js:
Configuration for rule "no-restricted-imports" is invalid:
Value [{"name":"import-foo","message":"Please use import-bar instead."}] should be string.
Value [{"name":"import-foo","message":"Please use import-bar instead."}] should be object.
Value [{"name":"import-foo","message":"Please use import-bar instead."}] should match some schema in anyOf.
Value [{"name":"import-foo","message":"Please use import-bar instead."}] should be object.
Value [[{"name":"import-foo","message":"Please use import-bar instead."}]] should match some schema in anyOf.

I don’t think the documentation is wrong because the rule should accept custom messages as stated here https://github.com/eslint/eslint/issues/8400

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, May 14, 2019

I think the issue is that the severity and options should all be a flat array:

{
    "no-restricted-imports": [
        "error",
        {
            "name": "import-foo",
            "message": "Please use import-bar instead."
        }
    ]
}

@yvele Could you please give that a try? And if it works, please advise (or submit a PR) where the documentation needs to be corrected… Thanks!

0reactions
mdjermanoviccommented, Dec 4, 2019

Example from the original post is indeed wrong in the documentation, it should be as in this comment

It seems that the other examples are correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
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 >
Error 'bad value for restricted picklist field' appears when a ...
This error can occur when you deploy a picklist field from sandbox and the values are not selected on the record types. This...
Read more >
Resolve validation errors - Azure DevOps Services
Fix errors reported upon importing a process to support customization of tracking work in Azure DevOps Services.
Read more >
Import format quotas and validation - Amazon DynamoDB
There are three categories of import errors: API validation errors, ... does not exist, the import will fail and log the error message...
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