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

no-restricted-imports with custom messages is throwing a validation error #11717

Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation

Comments

@yvele
Copy link

yvele commented May 14, 2019

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 #8400

@yvele yvele added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 14, 2019
@yvele yvele changed the title no-restricted-imports example no-restricted-imports with custom messages is throwing a validation error May 14, 2019
@yvele
Copy link
Author

yvele commented May 14, 2019

Looks like the ONLY syntax from the examples that works is

"no-restricted-imports": ["error", "import1", "import2"]

@g-plane
Copy link
Member

g-plane commented May 14, 2019

Hi @yvele , thanks for this issue.

It seems that documentation has something wrong.

You can try this:

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

@g-plane g-plane added documentation Relates to ESLint's documentation and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 14, 2019
@yvele
Copy link
Author

yvele commented May 14, 2019

@g-plane I've copy/pasted your config and it's not working either

Configuration for rule "no-restricted-imports" is invalid:
Value [{"paths":[{"name":"import-foo","message":"Please use import-bar instead."}]}] should be string.
Value [{"paths":[{"name":"import-foo","message":"Please use import-bar instead."}]}] should be object.
Value [{"paths":[{"name":"import-foo","message":"Please use import-bar instead."}]}] should match some schema in anyOf.
Value [{"paths":[{"name":"import-foo","message":"Please use import-bar instead."}]}] should be object.
Value [[{"paths":[{"name":"import-foo","message":"Please use import-bar instead."}]}]] should match some schema in anyOf.

@platinumazure
Copy link
Member

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!

@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Jun 14, 2019
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@kumarashwin
Copy link

Having the same issue. Tried all the different methods mentioned here to no avail.

@platinumazure
Copy link
Member

@kumarashwin Please open a new issue and please fill in the information the new issue template asks for (including the configuration you're using). Thanks!

@mdjermanovic
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.