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

Closed
yvele opened this issue May 14, 2019 · 8 comments · May be fixed by nl253/BlogUI#3, neo355/octicons#1, neo355/octicons#7, yowainwright/learn-redux#7 or O330oei/Fontscipt-#5

Comments

@yvele
Copy link

@yvele 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 triage 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

This comment has been minimized.

Copy link
Author

@yvele yvele commented May 14, 2019

Looks like the ONLY syntax from the examples that works is

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

This comment has been minimized.

Copy link
Member

@g-plane 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 and removed bug triage labels May 14, 2019
@yvele

This comment has been minimized.

Copy link
Author

@yvele 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

This comment has been minimized.

Copy link
Member

@platinumazure platinumazure commented 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!

@eslint eslint bot closed this Jun 14, 2019
@eslint eslint bot added the auto closed label Jun 14, 2019
@eslint

This comment has been minimized.

Copy link
Contributor

@eslint eslint bot commented Jun 14, 2019

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

This comment has been minimized.

Copy link

@kumarashwin kumarashwin commented Aug 14, 2019

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

@platinumazure

This comment has been minimized.

Copy link
Member

@platinumazure platinumazure commented Aug 14, 2019

@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

This comment has been minimized.

Copy link
Member

@mdjermanovic mdjermanovic commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.