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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/rules/semi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

output: 'a\n++b',
errors: [
{
line: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/rules/space-infix-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?

`,
errors: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-tester/src/utils/SourceCodeFixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

remainingMessages.push(problem);
return false;
}
Expand Down