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
Schema validation modifies exported config object in .eslintrc.js #12592
Comments
|
This has nothing to do with babel or any other plugin. I'm on the mobile now but i think the problem can be reproduced via let errorConfig = ['error']; Where eslint will complain that default-case doesn't know of camelcase's options with default values. |
correction: let errorConfig = ['error', {}] |
I would expect the json schema to reject an empty object, and to require at least one key to be present. Is that the case here? |
Eslint barfs with
due to configuring ajv with Line 21 in 219aecb
camelcase will mutate into {ignoreDestructuring: false} .
I don't think anyone expects the configuration passed to My no-plugins example is coerced and doesn't make sense. I don't know why would you want to share the same options to two rules. BUT, now that I have shown you that the behavior is not related to plugins, but to eslint itself, the pattern of sharing configs "upstream" to the babel or typescript plugin is useful because many of their rules are supersets of the built-in ones and it allows you maintain the same configuration.
Real life scenario: babel has a `babel/camelcase` rule, and typescript has a `typescript/camelcase` one, both supersets of the built-in `camelcase` rule. And the recommendation goes like:
but if you maintain a
|
ah, gotcha. your use of the term "dereference" confused me since JS has no dereferencing and no pointers; objects are "reference values" :-) So specifically, you're saying that the validator should apply to the original config, not to the ajv-mutated one? |
yup |
This seems important since if unfixed, it leaves inaccurate error messages. |
Agreed. Reopened. |
I've edited the title to describe what I understand the issue to be. Please let me know if I've misunderstood. I would like to apologize for my previous comment, which might have come off as curt and rude. I was typing while multitasking and I should have waited until I could give my full attention and communicate in the way our valued community members deserve. I failed to do that, and for that I apologize. I have removed the original comment. |
# Conflicts: # configs/typescript-eslint-recommended.js
Just for some context, the Ajv docs make it clear that @epoberezkin we seem to be having an issue with the behavior of |
@nzakas my decision not to clone in Ajv was because in general case you cannot clone a JavaScript object. You can clone plain objects (e.g. the result of JSON.parse) and quite a few other things, but ajv can be used to validate all types of objects... Doing it in eslint would be easier because eslint can rely on some assumptions about what the object is - whether It seems that these two places need to be changed: eslint/lib/shared/config-validator.js Line 96 in 33efd71
eslint/lib/shared/config-validator.js Line 258 in 33efd71
where function compile(schema) {
const validate = ajv.compile(schema);
return function v(data) {
const d = clone(data);
const valid = validate(d);
v.errors = validate.errors;
return valid;
}
} That is needed as you seem to use ajv infamous api for errors directly... Or you could just return |
@nzakas @kaicataldo let me know what you think - happy to help if needed. |
Yeah, that’s what we are trying to do in #13034 Turns out to be tricky even with assumptions. |
* Fix: clone config data before validation (fixes #12592) * Chore: added test and cloning before validation * Chore: test fix * Chore: rules tests fixes * Update: cloning config using json parse and stringify * Update: changed test description * Chore: removed unnecessary tests * Update: changed clone logic * Update: using lodash.cloneDeepWith for cloning * Update: handling circular ref cases * Update: using JSON method for cloning logic * Update: moved clone logic to normalieObjectConfigData * Chore: added comments for cloning reason
…int#13034)" This reverts commit 7fb45cf.
Reopening this so we can find another solution. |
This was auto-closed when the revert commit was merged. Re-opening since it’s still outstanding. |
I'll tackle this as part of the new config system. |
Holy cow I didn't expect tweaking our default-case Any news on this? Anyone know a workaround to get this config working? 'default-case': ['error', { commentPattern: /^no-default-case$/i }] |
@slapbox this isn't related to the schema validation issue, 'default-case': ['error', { commentPattern: "^no-default-case$" }] It doesn't support specifying flags. If you want to allow uppercase in all letters, you can use this workaround: 'default-case': ['error', { commentPattern: "^[nN][oO]-[dD][eE][fF][aA][uU][lL][tT]-[cC][aA][sS][eE]$" }] |
Derp. This was the closest issue I could find at the end of the day with a burned out brain. Big thanks @mdjermanovic! |
In eslint.config.js files, it's possible for two rule configs to contain references to the same object. That object may be modified during validation, thus affecting all configs, and may create validation errors. This clones rule configs before validation to ensure that each rule is using unique references to manage its configs. Fixes #12592
* fix: Ensure shared references in rule configs are separated. In eslint.config.js files, it's possible for two rule configs to contain references to the same object. That object may be modified during validation, thus affecting all configs, and may create validation errors. This clones rule configs before validation to ensure that each rule is using unique references to manage its configs. Fixes #12592 * Update tests/lib/config/flat-config-array.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update tests/lib/config/flat-config-array.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/flat-config-schema.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/config/flat-config-schema.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Upgrade config-array and update tests --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
I expected no errors.
What actually happened? Please include the actual, raw output from ESLint.
This happens because of #12528 adding
ignoreImports
with default valuefailse
, and because the defaults ofcamelcase
are merged into the same object in.eslintrc.basic.js:rules.camelcase
, which is also the same reference in.eslintrc.babel.js:rules.@babel/camelcase
.Are you willing to submit a pull request to fix this bug?
Sure.
The text was updated successfully, but these errors were encountered: