testing-library / eslint-plugin-testing-library

ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library
https://npm.im/eslint-plugin-testing-library
MIT License
992 stars 142 forks source link

Make 'await-async-queries' rule auto-fixable #914

Open neriyarden opened 4 months ago

neriyarden commented 4 months ago

What rule do you want to change?

await-async-queries

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings

How will the change be implemented?

When the eslint is run with the --fix flag, an await will be inserted before the async query

For example:

findByText('text') 
=> await findByText('text')

Example code

findByText('text') 
after fix => await findByText('text')

const promise = () => findByText('text')
promise()
after fix => await promise()

How does the current rule affect the code?

The error has to be manually fixed

How will the new rule affect the code?

Auto-fix will enhance dev experience and productivity

Anything else?

I would like to develop this myself :)

I will need some help on how to test my fixer. Is there a kind of test that tests the auto-fix of rules? If not, is it possible to install and run the plugin in this repo itself? Any other suggestions?

Do you want to submit a pull request to change the rule?

Yes

Belco90 commented 4 months ago

Thanks for reporting. This issue can be considered part of #202.

For testing your fixer, you can use just ESLint tests. For invalid cases, it allows checking what's the expected output after the fixer is executed. Take await-async-events tests as an example: you can see the invalid cases have an output property with the expected code that should generate. I'd start by adding such output to all existing invalid cases from await-async-queries. The implementation of the fixer should be quite similar to the await-async-events` one.