avajs / eslint-plugin-ava

ESLint rules for AVA
https://avajs.dev
MIT License
229 stars 49 forks source link

Autofix rules #21

Open sindresorhus opened 8 years ago

sindresorhus commented 8 years ago

Would be useful to support autofixing for some of the rules. Not all are possible.

http://eslint.org/docs/developer-guide/working-with-rules#contextreport

Can't think of any way to reliably fix the other rules, but input welcome!

jfmengels commented 8 years ago

:+1: Great idea.

Not sure about no-identical-title though, as they won't really make things more readable in the source code (only when matching AVA's output to a test). Don't forget that the rule can also be triggered because there is no title.

sindresorhus commented 8 years ago

Not sure about no-identical-title though, as they won't really make things more readable in the source code (only when matching AVA's output to a test).

Appending a #n does make it clear it's testing the same thing just split up for readability, but I don't feel strongly about it, and is a pretty edge-case anyways.

jamestalmage commented 8 years ago

W/regard to the no-skip-* rules, I think auto fixing those is problematic. It will likely make the tests fail. If I am running xo --fix to clear up some whitespace / semicolon mistakes - I probably don't want you messing with my tests/assertions.

I don't think we should auto-fix anything that modifies code behavior (unless maybe the user sets some other CLI option or environment variable? FIX_AVA=true xo --fix.

One exception to the above. I think removing only is fine. Users should never check in .only tests, but .skip is acceptable in a number of situations (i.e. somebody has submitted a PR with a failing test but not the fix itself).

sindresorhus commented 8 years ago

But without it will make XO fail. So it will still fail.

jamestalmage commented 8 years ago

Does --fix only fix errors, or warnings too?

sindresorhus commented 8 years ago

Warnings too.

florianb commented 7 years ago

@sindresorhus: i would like to give it a try if it is still relevant.

sindresorhus commented 7 years ago

@florianb Sure. Go ahead. Seems like we couldn't agree on all of these yet, but you could start with autofixing for no-only-test :) There might also be other rules not mentioned here that could potentially have autofixing. Feel free to look into that too.

florianb commented 7 years ago

Great - i am sure a PR will stimulate discussions.. 😄

florianb commented 7 years ago

Hey everybody, i am stuck testing the fixResult.output since error.actual does not get printed. If i am not wrong this needs to be fixed in https://github.com/jfmengels/eslint-ava-rule-tester - i would be very happy to fix that if a contributor could check my assumption and approve that a PR for that would be welcome.

Thank you very much! 💝

sindresorhus commented 7 years ago

@florianb Just apply the fix mention in https://github.com/jfmengels/eslint-ava-rule-tester/issues/5 locally to your node_modules and you should be able to debug it for now.

florianb commented 7 years ago

@sindresorhus i guess this fix is not applicable since eslint forbids the modification of the AST. While it it would (probably) be possible to rename .only into something different, i can't remove it without causing the following exception:

Rule should not modify AST.

Actual:
[object Object]

Expected:
[object Object]

assertASTDidntChange (node_modules/eslint/lib/testers/rule-tester.js:406:24)
...

I opened a corresponding SO-question without helpful responses. I guess i could start a bounty to raise attention but i can't think of any solution overcoming this barrier.

I am really sorry that i just got stuck again. 😞

mightyiam commented 7 years ago

Keep it up, Florian. The light is ahead of the curve.

On Fri, Mar 31, 2017, 12:53 Florian Breisch notifications@github.com wrote:

@sindresorhus https://github.com/sindresorhus i guess this fix is not applicable since eslint forbids the modification of the AST. While it it would (probably) be possible to rename .only into something different, i can't remove it without causing the following exception:

Rule should not modify AST.

Actual: [object Object]

Expected: [object Object]

assertASTDidntChange (node_modules/eslint/lib/testers/rule-tester.js:406:24) ...

I opened a corresponding SO-question https://stackoverflow.com/questions/43043746/how-to-modify-the-javascript-ast-in-an-eslint-rule-fix without helpful responses. I guess i could start a bounty to raise attention but i can't think of any solution overcoming this barrier.

I am really sorry that i just got stuck again. 😞

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/avajs/eslint-plugin-ava/issues/21#issuecomment-290670396, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmyx8zhN7eb-uHslydazj9H6hF7W9umks5rrM0lgaJpZM4HkYpp .

sindresorhus commented 7 years ago

@florianb Can you submit a WIP PR so we can take a look and maybe help?

florianb commented 7 years ago

@sindresorhus - of course. Wait a minute.. 😄

florianb commented 7 years ago

@sindresorhus - created #173

florianb commented 6 years ago

Okaydo - heading on to implement the no-skip-test-fix.

florianb commented 6 years ago

🎺 I'm heading over to implement the fixer for no-skip-assert.

In thought of a fix for no-identical-title i'd propose adding with ${superhero()}-powers instead of numbers.

sindresorhus commented 6 years ago

In thought of a fix for no-identical-title i'd propose adding with ${superhero()}-powers instead of numbers.

Haha. Sounds funny in theory, but I think people will not appreciate our humor.

jfmengels commented 6 years ago

:trumpet: I'm heading over to implement the fixer for no-skip-assert.

Cool !

As for no-identical-title, joke aside, I am against having a fix for it. The title should IMO be a description of the expected behavior and conditions for that test case, and all of them grouped together should form a specification of the tested function(ality). It should be fixed by the developer so that the test has a useful title.

That said, these tests could have be autofixed:

sindresorhus commented 6 years ago

As for no-identical-title, joke aside, I am against having a fix for it. The title should IMO be a description of the expected behavior and conditions for that test case, and all of them grouped together should form a specification of the tested function(ality). It should be fixed by the developer so that the test has a useful title.

I agree.

florianb commented 6 years ago

Sure - so just to check if i got you all right 😅:

sindresorhus commented 6 years ago

Correct

sindresorhus commented 6 years ago

But I don't think we should do a fixer for no-todo-implementation. What if the user accidentally wrote a test body and then we just remove it. Better for them to just fix it manually.

jfmengels commented 6 years ago

For no-todo-implementation, I thought we could remove the todo modifier. Yeah we definitely don't want to remove the test body.

On Fri, Dec 8, 2017, 19:41 Sindre Sorhus notifications@github.com wrote:

But I don't think we should do no-todo-implementation. What if the user accidentally wrote a test body and then we just remove it. Better for them to just fix it manually.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/avajs/eslint-plugin-ava/issues/21#issuecomment-350339727, or mute the thread https://github.com/notifications/unsubscribe-auth/ADsK5Ftfe3rfgROJPe33AMJuAK7Cf1ajks5s-YLlgaJpZM4HkYpp .

sindresorhus commented 6 years ago

Oh ok, makes more sense. I still don't think it should have a fixer though.

florianb commented 6 years ago

Well - then thanks for extending the scope.. 😆

I'll ignore the no-todo-implementation for now.

mmkal commented 4 years ago

@sindresorhus piggy-backing on this issue: IMO no-only-test should not have an autofixer. See https://github.com/eslint/eslint/issues/7549#issuecomment-383002000 for why and https://github.com/eslint/eslint/issues/7549#issuecomment-383010918 for an explicit note that this kind of fix is not recommended by the eslint team.

It can be actively harmful to auto-fix no-only-test (and no-skip-test) - here's a scenario the current behaviour encourages:

By comparison, here's what happens with jest/no-disabled-tests

sindresorhus commented 4 years ago

@mmkal Yes, we plan to drop the auto-fixer for those rules. See: https://github.com/avajs/eslint-plugin-ava/issues/281#issuecomment-587137623