Skip to content

add --fix to no-identical-tests. #13

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

Merged

Conversation

aladdin-add
Copy link
Contributor

@aladdin-add aladdin-add commented Jul 1, 2017

this is WIP, as the trailing commas have not been handled.

it simply remove the identical tests, so may cause incorrect indent. any suggestions? @not-an-aardvark

@aladdin-add aladdin-add changed the title [WIP]add --fix to no-identical-tests. add --fix to no-identical-tests. Jul 2, 2017
@not-an-aardvark
Copy link
Contributor

Thanks for working on these issues! Sorry about the delay, I'm planning to review your PRs in the next day or two.

it simply remove the identical tests, so may cause incorrect indent. any suggestions?

I think that's fine and we don't have to worry about it here -- if the indent rule is enabled, the indentation will be automatically fixed.

{ code: 'foo', errors: ['bar'] },
]
});
`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test where there is no trailing comma?

valid: [
  { code: 'foo' }
]

const end = sourceCode.getTokenAfter(test);
return fixer.replaceTextRange(
// should remove test's trailing comma
[start.range[1], end.range[end.value === ',' ? 1 : 0]]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will handle whitespace differently depending on whether there is a comma. If there is no comma, then all the whitespace up to the next test will be removed. If there is a comma, the whitespace up to the next test will be preserved.

Maybe it would be better to be consistent about handling whitespace.

@aladdin-add
Copy link
Contributor Author

ping @not-an-aardvark

Copy link
Contributor

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

I just have one nitpick, but feel free to merge it afterwards.

fix (fixer) {
const start = sourceCode.getTokenBefore(test);
const end = sourceCode.getTokenAfter(test);
return fixer.replaceTextRange(
Copy link
Contributor

@not-an-aardvark not-an-aardvark Jul 9, 2017

Choose a reason for hiding this comment

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

Nitpick: This can be fixer.removeRange instead of fixer.replaceTextRange.

Actually, maybe that would be a good rule to add to this plugin. 😄

@aladdin-add aladdin-add merged commit ca607c4 into eslint-community:master Jul 9, 2017
@aladdin-add aladdin-add deleted the no-identical-tests-fixer branch July 9, 2017 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants