Rewrite code on file save
HerringtonDarkholme opened this issue · comments
Discussed in ast-grep/ast-grep#829
Originally posted by AlexeyDuybo January 1, 2024
Hi, is it possible to rewrite the code, according with the "fix" option in the rules, when saving the file? I use vscode extension but it doesnt rewrite the files on save
Here is some eslint-related information as an entry point for our investigation
![image](https://private-user-images.githubusercontent.com/79413249/304625060-203945c4-6a2e-44a3-a16c-a023e1b13678.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NTAwMTcsIm5iZiI6MTcyNDQ0OTcxNywicGF0aCI6Ii83OTQxMzI0OS8zMDQ2MjUwNjAtMjAzOTQ1YzQtNmEyZS00NGEzLWExNmMtYTAyM2UxYjEzNjc4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDIxNDgzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTllZDVjNDk3ZGJjMmU5ZTM2ZjY5YTg0YTA1Njk0NjQ4YTA4NTkzZGEwN2NjOTVhZWQ4YWIxZWU1NWI2OWY0MDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ff2unngpCpGqPOUyvnHc8de5Jkk4TEyDsl4RAlrf0jg)
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
In addition, we should try to avoid ast-grep as the default formatter, the most commonly used method of ast-grep should be used as a supplement to the formatter rather than being a formatter. Maybe our goal is to let eslint, prettier etc can work together when saving
![image](https://private-user-images.githubusercontent.com/79413249/304632566-f9cbebc9-b43b-48b0-8f38-7468bda0ccaf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NTAwMTcsIm5iZiI6MTcyNDQ0OTcxNywicGF0aCI6Ii83OTQxMzI0OS8zMDQ2MzI1NjYtZjljYmViYzktYjQzYi00OGIwLThmMzgtNzQ2OGJkYTBjY2FmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDIxNDgzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJjNmFmOTFlMjM1MzM0YTJmZWRhMTA4NGEyYzk0YjhlOWUzMjJlNTgwMDMyMzVhYTEwNzViNGIwMjc2ZGQ2ODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.a949yJYCb7aaNr64HpSn1GU1JBgbgLSRFUrWQmDEgmI)