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

Replace context.sourceCode with context.getSourceCode() in no-war… #17325

Closed
wants to merge 1 commit into from

Conversation

CamillaTeodoro
Copy link

…ning-comments.js

For the rule no-warning-comments the variable sourceCode was undefined and resulting in the following error:

$ yarn lint           

yarn run v1.9.4
$ getk run lint-es '**/*.{js,jsx,ts,tsx}' --ignore-path .gitignore

Oops! Something went wrong! :(

ESLint: 8.43.0

TypeError: Cannot read properties of undefined (reading 'getAllComments')
Occurred while linting /Users/shermam/Projects/format-location/.eslintrc.js:1
Rule: "unicorn/expiring-todo-comments"
    at Object.Program (/Users/shermam/Projects/format-location/node_modules/eslint/lib/rules/no-warning-comments.js:193:45)
    at Program (/Users/shermam/Projects/format-location/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:511:10)
    at /Users/shermam/Projects/format-location/node_modules/eslint-plugin-unicorn/rules/utils/rule.js:39:18
    at ruleErrorHandler (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1050:28)
    at /Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
    at /Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1085:32
    at Array.forEach (<anonymous>)
    at runRules (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1080:15)
    at Linter._verifyWithoutProcessors (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1330:31)
    at Linter._verifyWithoutProcessors (/Users/shermam/Projects/format-location/node_modules/eslint-plugin-eslint-comments/lib/utils/patch.js:166:36)
    at Linter._verifyWithConfigArray (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1706:21)
    at Linter.verify (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1412:65)
    at Linter.verifyAndFix (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1967:29)
    at verifyText (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli-engine/cli-engine.js:245:48)
    at CLIEngine.executeOnFiles (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli-engine/cli-engine.js:825:28)
    at ESLint.lintFiles (/Users/shermam/Projects/format-location/node_modules/eslint/lib/eslint/eslint.js:551:23)
    at Object.execute (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli.js:391:36)
    at async main (/Users/shermam/Projects/format-location/node_modules/eslint/bin/eslint.js:135:24)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This change set updates the code to use context.getSourceCode() instead of context.sourceCode which is no longer defined.

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
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Is there anything you'd like reviewers to focus on?

…ning-comments.js

For the rule `no-warning-comments` the variable `sourceCode` was undefined and resulting in the following error:

```
$ yarn lint           

yarn run v1.9.4
$ getk run lint-es '**/*.{js,jsx,ts,tsx}' --ignore-path .gitignore

Oops! Something went wrong! :(

ESLint: 8.43.0

TypeError: Cannot read properties of undefined (reading 'getAllComments')
Occurred while linting /Users/shermam/Projects/format-location/.eslintrc.js:1
Rule: "unicorn/expiring-todo-comments"
    at Object.Program (/Users/shermam/Projects/format-location/node_modules/eslint/lib/rules/no-warning-comments.js:193:45)
    at Program (/Users/shermam/Projects/format-location/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:511:10)
    at /Users/shermam/Projects/format-location/node_modules/eslint-plugin-unicorn/rules/utils/rule.js:39:18
    at ruleErrorHandler (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1050:28)
    at /Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
    at /Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1085:32
    at Array.forEach (<anonymous>)
    at runRules (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1080:15)
    at Linter._verifyWithoutProcessors (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1330:31)
    at Linter._verifyWithoutProcessors (/Users/shermam/Projects/format-location/node_modules/eslint-plugin-eslint-comments/lib/utils/patch.js:166:36)
    at Linter._verifyWithConfigArray (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1706:21)
    at Linter.verify (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1412:65)
    at Linter.verifyAndFix (/Users/shermam/Projects/format-location/node_modules/eslint/lib/linter/linter.js:1967:29)
    at verifyText (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli-engine/cli-engine.js:245:48)
    at CLIEngine.executeOnFiles (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli-engine/cli-engine.js:825:28)
    at ESLint.lintFiles (/Users/shermam/Projects/format-location/node_modules/eslint/lib/eslint/eslint.js:551:23)
    at Object.execute (/Users/shermam/Projects/format-location/node_modules/eslint/lib/cli.js:391:36)
    at async main (/Users/shermam/Projects/format-location/node_modules/eslint/bin/eslint.js:135:24)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

This change set updates the code to use `context.getSourceCode()` instead of `context.sourceCode` which is no longer defined.
@CamillaTeodoro CamillaTeodoro requested a review from a team as a code owner June 30, 2023 14:01
@linux-foundation-easycla
Copy link

CLA Not Signed

@eslint-github-bot
Copy link

Hi @CamillaTeodoro!, thanks for the Pull Request

The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by running git commit --amend, editing your commit message, and then running git push -f to update this pull request.

Read more about contributing to ESLint here

@netlify
Copy link

netlify bot commented Jun 30, 2023

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit c53c3a7
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/649ee045837cde0008958ca6

@mdjermanovic
Copy link
Member

Hi @CamillaTeodoro!

Thanks for the PR but we can't accept this change because the current code is correct and this is actually a problem in eslint-plugin-unicorn's rule unicorn/expiring-todo-comments. Updating eslint-plugin-unicorn to the latest version should fix the error you're getting, as described in #17167.

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 28, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 28, 2023
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
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

2 participants