Eslint-plugin-import: eslint-module-utils moduleVisitor makeOptionsSchema does not limit number of options in options array

Created on 9 Sep 2020  路  2Comments  路  Source: benmosher/eslint-plugin-import

I was helping someone out in ESLint's help channel who had their import/no-unresolved rule configured incorrectly.

They were using this configuration:

{
    "import/no-unresolved": [2, {"amd": true}, { "ignore": ["external"] }]
}

The complaint was that the "ignore" option was being ignored.

According to my understanding of the rule (i.e., 30 seconds of reading the documentation), this is incorrect because the options should be combined, like this:

{
    "import/no-unresolved": ["error", { "amd": true, "ignore": ["external"] }]
}

I took a look at the code and I think the issue is that the generated schema is interpreted by ESLint as an open-ended array. So in the first example, { "amd": true } was interpreted as the options object, but { "ignore": ["external"] } was ignored.


Since this is a utility, it might be a better experience if the function could export a full JSON schema, with an array for severity and for the option object, as well as the array schema having "additionalItems": false. This would allow the above example to fail schema validation and provide a slightly better user experience.

With all of that said, I understand that (1) this is a corner case, (2) not a lot of people will run into this, and (3) the potential breaking change on the eslint-module-utils package might not be worth the benefit here. If that's the case, feel free to close this. I just wanted to report it in case it's something you want to fix. :smile:

help wanted semver-major

Most helpful comment

Oops, I opened this with my work account by accident 馃槅

I can't prioritize this right now, but if I get time, I can look into creating a PR. If someone else creates a PR first, awesome.

All 2 comments

Thanks for the report. I agree it's a corner case, and I agree that additionalItems: false should be there.

What would probably be most helpful is a PR to do this - even if i decided it was semver-major and let it sit there until the next major version :-)

Oops, I opened this with my work account by accident 馃槅

I can't prioritize this right now, but if I get time, I can look into creating a PR. If someone else creates a PR first, awesome.

Was this page helpful?
0 / 5 - 0 ratings