Schema JSON validation fails with ESLint 4.2.0 #8908
Comments
@gajus @epoberezkin would love u guys feedback on this. thanks |
It seems related to #8864 Eslint currently does not correctly support references when schema is defined as array of schemas (see docs change in the referenced PR) I will double check how it was working before, but I believe it was not working correctly anyway. The schema in the rule should be updated to be a schema object (to be able to use references). |
@jseminck are you passing some options to the rule or is it just enabled? |
I am running the I did a bit of digging and saw that this doesn't crash: valid: [{
code: [
'<App foo={42} {...bar} baz={ { 4: 2 } }>',
'{foo} { { bar: baz } }',
'</App>'
].join('\n'),
options: [{
when: 'never',
spacing: {objectLiterals: 'always'},
attributes: true
}] But this does;
Edit: But the following warning is always displayed. It's only displayed once even for all of the test cases, so I assume it's being logged when the rule is evaluated:
|
As far as I know, we cannot use |
@jseminck here is the example showing that with is-my-json-valid it was never working correctly: https://runkit.com/esp/596268082d308c00122b7d86. Both options should fail validation ("whatever" is not an allowed value) yet they pass. It seems that when is-my-json-valid cannot resolve $ref it quietly passes validation. This is the same example with Ajv: https://runkit.com/esp/59626adc6f924f00124f5fed But in any case, the schema in eslint-plugin-react should be either changed to use the full JSON Schema format or to be refactored to not use $ref, otherwise it will not work correctly (as the examples show). |
@mysticatea Ajv is supposed to ignore missing $ref, will release a fix. |
I'll make a PR to The only thing I still fail to understand completely is why the {
type: 'array',
items: [
obj
],
} But why don't the |
@jseminck That is correct, as the result of this transformation all the JSON pointers to the same sub-schemas change. So instead of |
Aha. That makes sense! Thanks for explanation. |
Fixed in Ajv 5.2.2: https://runkit.com/esp/59626adc6f924f00124f5fed No changes in eslint are required. |
@epoberezkin so with v5.2.2 of ajv installed, should I still be seeing "can't resolve reference" warnings? Specifically, I'm trying |
Yes, it's a warning that the reference in the schema is invalid. It passes validation though, same as it did before. |
The schema in eslint-plugin-react still needs to be fixed. |
To clarify, does this warning appear for all users of |
It should have been unusable if the configuration was set in such a way that it crashes during schema validation (triggering the bug that has now been fixed in I'm guessing most users did not have such a "complicated configuration"? Although the issue on Also the bug would only occur when upgrading I created PR for |
I think this can be closed now, right? |
Cool thanks guys for your help. Special thanks to @epoberezkin for his help. |
@jseminck Was a PR created for eslint-plugin-react to address this issue? I can't seem to find it. |
Required for eslint 4.2+. See: eslint/eslint#8908
@jeffrey-l-turner yannickcr/eslint-plugin-react#1292. Currently unreleased. |
So should I no longer be seeing this issue given the package versions listed below?
|
You should be seeing the message, until the issue is resolve in the plugin(s). The fix prevented schema validation failing, but the warning should be still logged as those unresolved references are ignored. |
yannickcr/eslint-plugin-react#1292 Is merged but we are awaiting a release |
FYI, it seems that eslint-plugin-sort-class-members is affected too. |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
N/A
What did you do? Please include the actual source code causing the issue.
It seems that ESLint has upgraded its JSON validator for 4.2.0: #8852
Note: It's only a guess that the above change has caused the problems, but it's not fully confirmed.
This is causing issues for a rule in
eslint-plugin-react
:. It seems that the following schema validation is causing problems: https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-curly-spacing.js#L34The produced error:
The issue can be reproduced by cloning the
eslint-plugin-react
repo and runningnpm run test
.What did you expect to happen?
No errors.
What actually happened? Please include the actual, raw output from ESLint.
See above.
The text was updated successfully, but these errors were encountered: