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
feat!: Set default schema: []
, drop support for function-style rules
#17792
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
Thank you for picking this work up! I see you still have a few items on your todo list. My original draft PR may be helpful to reference: #16614 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, should we avoid deleting pages to avoid breaking links, and just add a placeholder page linking to the replacement page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I've added back and updated this document in d14e2b5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we also could do a redirect like this: eslint/eslint.org#499
Discussion here: #17840 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we also could do a redirect like this: eslint/eslint.org#499
Discussion here: #17840 (comment)
Maybe, but this is a slightly different situation so I'm not sure.
For configuration-files-new
, its content is moved to configuration-files
, so redirecting makes the most sense.
For custom-rules-deprecated
, its content is not moved to custom-rules
but deleted, so info that it no longer applies in ESLint 9+ might be more helpful.
lib/rule-tester/rule-tester.js
Outdated
); | ||
} | ||
} | ||
|
||
/** | ||
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to delete emitMissingSchemaWarning
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I kept that for now to see if the tests for it will fail as expected after the schema default change (wip).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 24144d4
@@ -32,18 +32,6 @@ describe("rules", () => { | |||
assert.ok(rules.get(ruleId)); | |||
}); | |||
|
|||
it("should return the rule as an object with a create() method if the rule was defined as a function", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my draft implementation, I updated this test to check that it throws: https://github.com/eslint/eslint/pull/16614/files#diff-0c938400b183b70017038162a127cef7bc753f98c6e2ccc97800bce0a0effcc8 But maybe you omitted this because it's tested in several other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schema: []
, drop support for function-style rulesschema: []
, drop support for function-style rules
This is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for picking up this work.
* At this point, `schema` can only be an object or `null`. | ||
*/ | ||
if (schema && Object.keys(schema).length === 0) { | ||
throw new Error(`\`schema: {}\` is a no-op${metaSchemaDescription}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disallowing schema: {}
is most important since it's the most common, accidental, no-op schema.
I'm fine with this one check for now, but just want to ask if any other obvious/common no-op schemas come to mind? In the RFC, I mentioned schema: { type: "array" }
as another no-op schema we could disallow, with the intention being to leave the door open to any others that we judge worth checking for. Obviously, we can only add update the banned no-op list during major versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a related discussion in ajv repo? it could benefit all the dependents (not just eslint) - if it could be supported by ajv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a brief search and didn't immediately find a relevant discussion in in ajv. But I have included a lot more context in this issue discussing a potential lint rule:
Overall, we should probably just allow any schema in ESLint except extremely common and obvious mistakes like {}
, and consider linting to detect further possible problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newer versions of Ajv have some built-in validations, but there were backwards compatibility issues when we tried to switch to Ajv 7+ (#13911). However, I believe schema: { type: "array" }
would be considered valid by Ajv. It's just useless in ESLint because we're always passing arrays to these validations.
I agree that for now RuleTester should only check for the common and obvious mistake schema: {}
.
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
Looks like there are some merge conflicts here. |
I'll rebase when we merge a few more PRs that target the same files. This shouldn't be merged until we release |
ea58146
to
a92d4ab
Compare
Merge conflicts are fixed now. |
This is ready now. @nzakas would you like to take a look before merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please be sure to update the migration guide with info about this change.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[x] Add something to the core
[ ] Other, please explain:
Fixes #14709
Implements RFC Require schemas and object-style rules
This includes changes in the
@eslint/eslintrc
package: eslint/eslintrc#139What changes did you make? (Give an overview)
Drop support for function-style rules:
Linter
, I added the following check right before running the rule'screate()
method:if (!rule || typeof rule !== "object" || typeof rule.create !== "function")
then throw an error.This is to show a message that is more descriptive than
TypeError: rule.create is not a function
.custom-rules-deprecated
dost, just left a link tocustom-rules
, and added a note that the function style is no longer supported.Schema changes:
GetRuleOptionsSchema
(flat config, eslintrc, and the one used by RuleTester) to work as follows:schema
property is ignored.meta.schema
:schema: []
.schema: undefined
is treated the same as omitted.false
. If any other value is specified (null
,true
, number...), this function throws an error.schema: false
, this function returnsnull
, meaning that options validation is disabled for the rule. The same as omitted (or falsy) before this change.schema: {}
.no-constructor-return
rule, from{}
(no-op) to[]
(disallow passing options).custom-rules
docs with the schema changes.Is there anything you'd like reviewers to focus on?
typeof rule
must be"object"
.