Skip to content
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

SourceCode not optimize for RuleTester changes #13293

Closed
SuperOleg39 opened this issue May 13, 2020 · 3 comments
Closed

SourceCode not optimize for RuleTester changes #13293

SuperOleg39 opened this issue May 13, 2020 · 3 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly

Comments

@SuperOleg39
Copy link
Contributor

Tell us about your environment

  • ESLint Version: 7

What parser (default, Babel-ESLint, etc.) are you using?

  1. babel-eslint
  2. @typescript-eslint/parser

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

We using RuleTester for custom rule, and have this code inside rule:

// context: Rule.RuleContext
const sourceCode = context.getSourceCode();
const comments = sourceCode.getComments(nodeSource).leading;

After updating to Eslint 7, have a error, because source-code.js use deprecated by rule-tester.js node properties.

What did you expect to happen?

My tests passes succesfull

What actually happened? Please include the actual, raw output from ESLint.

Use token.range[0] instead of token.start
    Occurred while linting <input>:3

      68 |       const chunkName = last(propName.split('/'));
      69 |       const sourceCode = context.getSourceCode();
    > 70 |       const comments = sourceCode.getComments(nodeSource).leading;
         |                                   ^
      71 | 
      72 |       if (!comments || comments.length === 0) {
      73 |         return context.report({

      at Object.get (node_modules/eslint/lib/rule-tester/rule-tester.js:223:23)
      at SourceCode.getComments (node_modules/eslint/lib/source-code/source-code.js:352:50)
      at checkImport (packages/eslint/src/config/rules/bundle-chunk-name.ts:70:35)
      at ImportExpression (packages/eslint/src/config/rules/bundle-chunk-name.ts:134:16)
      at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/linter/safe-emitter.js:45:58)
          at Array.forEach (<anonymous>)
      at Object.emit (node_modules/eslint/lib/linter/safe-emitter.js:45:38)
      at NodeEventGenerator.applySelector (node_modules/eslint/lib/linter/node-event-generator.js:254:26)
      at NodeEventGenerator.applySelectors (node_modules/eslint/lib/linter/node-event-generator.js:283:22)
      at NodeEventGenerator.enterNode (node_modules/eslint/lib/linter/node-event-generator.js:297:14)

Are you willing to submit a pull request to fix this bug?

Yes

@SuperOleg39 SuperOleg39 added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 13, 2020
SuperOleg39 pushed a commit to SuperOleg39/eslint that referenced this issue May 13, 2020
@SuperOleg39
Copy link
Contributor Author

SuperOleg39 commented May 13, 2020

also, SourceCode unit tests failed in my branch with fix, and i see a difference between start, end and range

https://github.com/eslint/eslint/blob/master/lib/source-code/source-code.js#L352

console.log(currentToken.start, currentToken.end, currentToken.range) // the same - 0, 42, [ 0, 42]
console.log(node.parent.start, node.parent.end, node.parent.range) // different - 0, 101, [ 43, 54 ]

find same information in this comment

@SuperOleg39
Copy link
Contributor Author

Difference between range and start, end - it is adaptation to Esprima behaviour

@kaicataldo
Copy link
Member

As mentioned here, SourceCode#getComments() is deprecated and we recommend using SourceCode#getCommentsBefore(), SourceCode#getCommentsAfter(), and SourceCode#getCommentsInside() instead.

@kaicataldo kaicataldo added works as intended The behavior described in this issue is working correctly and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 13, 2020
devtools-bot pushed a commit to ChromeDevTools/devtools-frontend that referenced this issue Nov 16, 2020
The upgrade to ESLint 7.0.0 broke our custom rule tests. It seems
we were affected by eslint/eslint#13293
after all.

R=jacktfranklin@chromium.org

Change-Id: I3dcf8b7e15f1bc6a26c2fa069f24241e87f07627
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2538840
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 16, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion works as intended The behavior described in this issue is working correctly
Projects
None yet
Development

No branches or pull requests

2 participants