-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Change Request: Remove deprecated context pass-through SourceCode methods #17520
Comments
Sounds good to me. We could add deprecation warnings in RuleTester in v8.x, and then remove these methods in v9.0.0? |
We don't actually have a way to do that because the |
RuleTester already wraps eslint/lib/rule-tester/rule-tester.js Lines 561 to 571 in 926a286
Perhaps we could insert an object with methods that shadow deprecated ones: linter.defineRule(ruleName, Object.assign({}, rule, {
// Create a wrapper rule that freezes the `context` properties.
create(context) {
freezeDeeply(context.options);
freezeDeeply(context.settings);
freezeDeeply(context.parserOptions);
const newContext = Object.freeze(
Object.create(
context,
Object.fromEntries(Object.keys(DEPRECATED_SOURCECODE_PASSTHROUGHS).map(name => [
name,
{
value(...args) {
// emit deprecation warning here
// call the original method
return context[name].call(this, ...args);
},
enumerable: true
}
]))
)
);
return (typeof rule === "function" ? rule : rule.create)(newContext);
}
})); |
Oh nice! I didn't realize we were doing that already (yet another part of the codebase I'm not familiar with). Then we can definitely do that. |
In looking at this, I discovered that the tests for |
Emits deprecation warnings when using methods on `context` that are deprecated. Refs #17520
It's intentional per #16063 (comment). I think these warnings can also be implemented just in |
In that case, the PR is ready! 🎉 |
* feat: Emit deprecation warnings in RuleTester Emits deprecation warnings when using methods on `context` that are deprecated. Refs #17520 * Revert flat-rule-tester * Fix linting error
Looks like #17527 closed this out? |
The remaining task is to remove these methods in v9. |
* feat: Emit deprecation warnings in RuleTester Emits deprecation warnings when using methods on `context` that are deprecated. Refs #17520 * Revert flat-rule-tester * Fix linting error
Working on this. |
2023-11-30 tsc-meeting note: This one will be ready along with the language plugins issue because it's all in the same PR |
* feat!: Remove deprecated context methods fixes #17520 * Fix broken tests * Remove BASE_TRAVERSAL_CONTEXT * Remove deprecated methods from RuleTester * Removed more methods/properties * Fix lint errors * Update docs/src/extend/custom-rules.md Co-authored-by: 唯然 <weiran.zsd@outlook.com> * Update docs/src/extend/custom-rules.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update docs/src/extend/custom-rules.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update docs/src/extend/custom-rules.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Remove unneeded deprecated notices * Restore parserServices tests --------- Co-authored-by: 唯然 <weiran.zsd@outlook.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
ESLint version
HEAD
What problem do you want to solve?
We have a bunch of deprecated methods on
context
that pass through toSourceCode
:getComments()
getSource
getAllComments
getNodeByRangeIndex
getComments
getCommentsBefore
getCommentsAfter
getCommentsInside
getJSDocComment
getFirstToken
getFirstTokens
getLastToken
getLastTokens
getTokenAfter
getTokenBefore
getTokenByRangeStart
getTokens
getTokensAfter
getTokensBefore
getTokensBetween
What do you think is the correct solution?
I think it's time to remove these methods to clean up the codebase.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: