Skip to content

fix(rule-tester): fixes on the same line are not fixed properly #8252

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

Conversation

StyleShit
Copy link
Contributor

@StyleShit StyleShit commented Jan 14, 2024

Closes #8251

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @StyleShit!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jan 14, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit f25d901
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65a41f6d6b33c90009bbc24f
😎 Deploy Preview https://deploy-preview-8252--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

@@ -1069,7 +1069,7 @@ class PanCamera extends FreeCamera {
},
{
code: 'a;\n++b;',
output: 'a\n++b;',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug in the tests. See other tests above.

@@ -1022,7 +1022,7 @@ ruleTester.run('space-infix-ops', rule, {
type Test=|string|(((() => void)))|string;
`,
output: `
type Test = |string | (((() => void))) | string;
type Test = | string | (((() => void))) | string;
Copy link
Contributor Author

@StyleShit StyleShit Jan 14, 2024

Choose a reason for hiding this comment

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

This should be the real fix. See this playground.

The test currently fails because it's being fixed to:

type Test =  | string | (((() => void))) | string;

(notice there are 2 spaces after the =)
The reason is probably because there are 2 fixes that add spaces before and after the relevant characters (= & |), which then results in 2 spaces.

Not sure how to approach this. I have 2 options in mind:

  1. Trimming the spaces after each fix somehow (probably a bad idea)
  2. Re-running the rule tester on the same line after each fix (is that what happens in real life? not sure if/how to do it though)

WDYT?

@@ -63,7 +63,7 @@ export function applyFixes(
const end = fix.range[1];

// Remain it as a problem if it's overlapped or it's a negative range
if (lastPos >= start || start > end) {
if (lastPos > start || start > end) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual fix that causes all of this mess 😅

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/eslint/eslint/blob/1f3744278433006042b8d5f4e9e1e488b2bbb011/lib/linter/source-code-fixer.js#L92

As per the comment at the top of the file - this code is directly forked from eslint core.

If it's broken here then this only changes tests run using our rule tester. Code run through eslint will have the old logic.

So either you've found a bug upstream or tests are running correctly, but correctly, but differently to how you expect.

If it's the former - the fix needs to land upstream before we land it here.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

Above comment #8252 (comment)

@bradzacher bradzacher closed this Jan 14, 2024
@bradzacher
Copy link
Member

Closing for now as per above.
We can reopen if it lands upstream.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: RuleTester doesn't fix properly when there are multiple fixes on the same line
2 participants