Skip to content

Conversation

cotonne
Copy link

@cotonne cotonne commented Oct 6, 2018

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[X ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version: "eslint": "^5.6.1"
  • Node Version: v8.10.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?

Please show your full configuration:

Configuration File eslintrc.json ```js { ... "plugins": [ ["import"], [{ "node": "node"}], { "promise": "promise" }], ] } ```

What did you do? Please include the actual source code causing the issue.
Provided an invalid json config file.
cf. configuration (generated with a fuzzer PyJFuzz)

What did you expect to happen?
A meaningful message should be displayed.

What actually happened? Please include the actual, raw output from ESLint.
Big exception:

TypeError: normalizedName.charAt is not a function
    at Object.normalizePackageName (xxx/node_modules/eslint/lib/util/naming.js:37:24)

What changes did you make? (Give an overview)
When a non-string parameter is provided to the configuration parameter "plugins",
an exception is thrown

Is there anything you'd like reviewers to focus on?

@jsf-clabot
Copy link

jsf-clabot commented Oct 6, 2018

CLA assistant check
All committers have signed the CLA.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Oct 6, 2018
@cotonne cotonne force-pushed the issue10927 branch 3 times, most recently from 204f6f0 to fe1c838 Compare October 6, 2018 09:12
@aladdin-add aladdin-add added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Oct 6, 2018
@aladdin-add
Copy link
Member

aladdin-add commented Oct 6, 2018

thanks for the PR! 😄
I agreed it should output more friendly error message, but eslint is using schema validator ( ajv). I believe it's better to use it(like some other options). thoughts?

the config is here:

plugins: { type: "array" },

@aladdin-add aladdin-add added enhancement This change enhances an existing feature of ESLint and removed bug ESLint is working incorrectly labels Oct 6, 2018
When an invalid config type for "plugins" is provided in
eslintrc.json, like an array or an object, a stacktrace is
dumped.

The stacktrace has been replaced by a meaningful message
using ajv.
@cotonne
Copy link
Author

cotonne commented Oct 7, 2018

I fix the stacktrace by using the validation with ajv.

However, i duplicate a call to validator.validateConfigSchema into loadFromDisk (lib/config/config-file.js)

validateConfigSchema must be called before plugins.loadAll. Actually, the call is made by the function validator.validate.

I'm surprised by the fact that config is used before being validated.
Does it make sense to remove the call of validator.validateConfigSchema from the function validate?

@cotonne
Copy link
Author

cotonne commented Nov 2, 2018

Any comment on this fix?
Feel free to give me some feedbacks 😸

@nzakas nzakas changed the title Fix: replace stacktrace by a clear message when invalid plugins are provided (fixes #10927) Update: replace stacktrace by a clear message when invalid plugins are provided (fixes #10927) Dec 7, 2018
@nzakas
Copy link
Member

nzakas commented Dec 7, 2018

@cotonne sorry, we lost track of this.

Just to be clear: your concern here is if someone defines the plugins array with values other than strings, correct? In that case, you get an explosion at an unrelated point.

I agree that it would be nice to give a more useful error message to the user, though there must be a way to do that without validating twice.

@nzakas
Copy link
Member

nzakas commented Dec 7, 2018

After digging into this a bit, it looks like the best path forward might be to split up the validation steps in config-file.js such that the schema is validated first (as in this PR), and then we have a new method (something like, validateConfigContents() that is basically validate() without the config schema validation).

@not-an-aardvark @mysticatea thoughts on this?

@cotonne
Copy link
Author

cotonne commented Dec 7, 2018

@nzakas Yes, i duplicate the call mainly because it will break a lot of tests.
Clearly, this is a bad approach. I know that it is not the best method but I don't know enough eslint to propose a better way and what can be the impact.
I would appreciate to have some help with this issue.

@nzakas
Copy link
Member

nzakas commented Dec 14, 2018

@cotonne it seems like the team liked my last comment, so here's what I would suggest:

  • Create a validateConfigContents() method that is the same as validate() except that it does not do validateConfigSchema() first.
  • Export validateConfigContents() from config-validator.
  • Keep your call to validateConfigSchema() where it is, and change the following call to validate() to instead call validateConfigContents().

Does that make sense?

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 7, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants