Skip to content

fix: fix crash when message.fix is nullish - #19168

Merged
mdjermanovic merged 3 commits into
eslint:mainfrom
ntnyq:main
Dec 9, 2024
Merged

mdjermanovic merged 3 commits into
eslint:mainfrom
ntnyq:main

Conversation

@ntnyq

@ntnyq ntnyq commented Nov 25, 2024 •

Copy link
Copy Markdown
Contributor

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

No need for providing the template. So I skipped it.

What changes did you make? (Give an overview)

This PR adds a simple check in linter.source-code-fixer incasing message.fix equals to null or undefined which might cause the linter throw.

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

There is a reproduction repo https://github.com/pany-ang/issue-eslint-config.

Or you can just remove the check, run the tests added.

@ntnyq
ntnyq requested a review from a team as a code owner November 25, 2024 15:22
@eslint-github-bot eslint-github-bot Bot added the bug ESLint is working incorrectly label Nov 25, 2024
@github-actions github-actions Bot added the core Relates to ESLint's core APIs and features label Nov 25, 2024
@netlify

netlify Bot commented Nov 25, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit f21a9bb
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/6755aea307c1db0008a62aa7
😎 Deploy Preview https://deploy-preview-19168--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nzakas

nzakas commented Nov 25, 2024

Copy link
Copy Markdown
Member

Thanks for the PR. It's not clear from the changes or from you repo how to reproduce this error. Can you please provide some reproduction steps?

@mdjermanovic mdjermanovic changed the title fix: fix crash when message.fix is nil fix: fix crash when message.fix is nullish Nov 25, 2024
@mdjermanovic mdjermanovic added the needs info Not enough information has been provided to triage this issue label Dec 1, 2024
@nzakas

nzakas commented Dec 4, 2024

Copy link
Copy Markdown
Member

@ntnyq friendly ping. Can you answer my questions above? Thanks.

@ntnyq

ntnyq commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

@ntnyq friendly ping. Can you answer my questions above? Thanks.

Sorry for reply late.

I created a new repo with fewer code https://github.com/ntnyq-dev/repro-eslint-fix.

And added the repro steps in README.

@ntnyq

ntnyq commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

As I tested.

When call SourceCodeFixer.applyFixes, there is a message like this:

{
      ruleId: 'format/prettier',
      severity: 2,
      message: 'Parsing error: CssSyntaxError: Unclosed block',
      line: 6,
      column: 3,
      nodeType: null,
      endLine: 1,
      endColumn: NaN,
      fix: undefined
}

It cause the crash.

@nzakas

nzakas commented Dec 5, 2024

Copy link
Copy Markdown
Member

Thanks, I can reproduce the crash. For the record, here's what I see in the console:

$ npm run lint

> repro-eslint-fix@1.0.0 lint
> eslint . --fix


Oops! Something went wrong! :(

ESLint: 9.16.0

TypeError: Cannot read properties of undefined (reading 'range')
    at attemptFix (C:\Users\nzaka\projects\eslint\tmp\repro-eslint-fix\node_modules\eslint\lib\linter\source-code-fixer.js:88:27)
    at SourceCodeFixer.applyFixes (C:\Users\nzaka\projects\eslint\tmp\repro-eslint-fix\node_modules\eslint\lib\linter\source-code-fixer.js:123:17)
    at Linter.verifyAndFix (C:\Users\nzaka\projects\eslint\tmp\repro-eslint-fix\node_modules\eslint\lib\linter\linter.js:2329:43)
    at verifyText (C:\Users\nzaka\projects\eslint\tmp\repro-eslint-fix\node_modules\eslint\lib\eslint\eslint.js:329:48)
    at C:\Users\nzaka\projects\eslint\tmp\repro-eslint-fix\node_modules\eslint\lib\eslint\eslint.js:810:40

In the future, please be sure to open an issue first when reporting a bug so you can provide all of the info we need.

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to clean up the test names a bit, but otherwise looks good.

Comment thread tests/lib/linter/source-code-fixer.js Outdated
Comment thread tests/lib/linter/source-code-fixer.js Outdated
Comment thread tests/lib/linter/source-code-fixer.js Outdated
@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed needs info Not enough information has been provided to triage this issue labels Dec 5, 2024
@ntnyq

ntnyq commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

Got it and Resolved.

Thanks for your advice.

@ntnyq

ntnyq commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

Don't know why Browser Test failed in CI.

I tried run it in local and it went well.

@nzakas

nzakas commented Dec 5, 2024

Copy link
Copy Markdown
Member

Don't worry about the browser test. It's pretty flaky lately.

nzakas
nzakas previously approved these changes Dec 5, 2024

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would like another review before merging.

@mdjermanovic

Copy link
Copy Markdown
Member

I think this is rather a bug in the processor.

It gets a lint message without fix property:

{
    ruleId: 'format/prettier',
    severity: 2,
    message: 'Parsing error: CssSyntaxError: Missed semicolon',
    line: 4,
    column: 12,
    nodeType: null
}

but returns message with fix: undefined:

{
    ruleId: 'format/prettier',
    severity: 2,
    message: 'Parsing error: CssSyntaxError: Missed semicolon',
    line: 17,
    column: 2,
    nodeType: null,
    endLine: 1,
    endColumn: NaN,
    fix: undefined
}

Lint messages normally don't have the fix property when they're not autofixable.

@mdjermanovic

Copy link
Copy Markdown
Member

Now I see that both the docs and types say that the fix property can have undefined value, so although that can happen only when processors modify messages, seems we should support it.

Comment thread tests/lib/linter/source-code-fixer.js
Comment thread tests/lib/linter/source-code-fixer.js

@mdjermanovic mdjermanovic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic
mdjermanovic merged commit 67d683d into eslint:main Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly contributor pool core Relates to ESLint's core APIs and features

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants