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
Fix: ecmaVersion defaults to 5 and allows "latest" in RuleTester #14710
Conversation
@nzakas, @aladdin-add this is related to #14622. |
I'm 👍 to this - I found the easiest way to get it is to add a wrapper to const espree = require("espree");
espree.parse = function(){
// TODO: change its defaults
}
module.exports = espree; then we can replace all the |
Another alternative is to also check Lines 440 to 456 in 353ddf9
Linter would get This will work with RuleTester because RuleTester sets the absolute path of the original parser as parser name for the wrapper object. |
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!
}); | ||
} | ||
} | ||
|
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 can be removed when eslint has the same defaults with espree?
@mdjermanovic I've pushed a commit aladdin-add@f701736, it avoids the duplicate Linter's espree-specific normalizations. thoughts? |
Yes, now I think something like that would be better than duplicating, which is error-prone by itself, and RuleTester, unlike Linter, doesn't have the final For example, if we add the following test case here, it fails on this branch but works well with aladdin-add@f701736: {
code: "/*eslint-env es6*/ let x;",
errors: [{ messageId: "ecmaVersionMessage", data: { type: "number", ecmaVersion: "6" } }]
} @nzakas thoughts about this? |
We decided to revert 831f6b3 for now, and also keep We'll revisit I'll keep this open for the case there's some code that might be useful for a |
Should we close this now? |
Yes, closing in favor of #14720 |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an 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:
I noticed that this test is failing in #14653:
eslint/tests/lib/rule-tester/rule-tester.js
Lines 632 to 641 in 353ddf9
The test is unrelated to the PR. It's failing because:
ecmaVersion: 5
This reveals some problems:
ecmaVersion: "latest"
context.parserOptions
will getecmaVersion: 5
in runtime, butecmaVersion: undefined
when run through RuleTester.What changes did you make? (Give an overview)
Updated RuleTester to perform normalizations from #14622
Is there anything you'd like reviewers to focus on?
/*eslint-env*/
comments in the code becauseparserOptions
in configurations have precedence overparserOptions
in environments. For example, a test withcode: "/*eslint-env es6*/ let x;"
will produce a parsing error after this change.