eslint-plugin-package-json
eslint-plugin-package-json copied to clipboard
🚀 Feature: sort-collections: alphabetically sorting with co-located hooks for `scripts`
Bug Report Checklist
- [X] I have tried restarting my IDE and the issue persists.
- [X] I have pulled the latest
mainbranch of the repository. - [X] I have searched for related issues and found none that matched my issue.
Overview
npm run-scripts support pre and post hooks. For readability I prefer them to be co-located next to their script they belong to,
e.g.
{
"scripts": {
"precompress": "",
"compress": "",
"postcompress": ""
}
}
while pre comes before and post after the actual script.
So this should be valid:
{
"scripts": {
"build": "",
"precompress": "",
"compress": "",
"postcompress": ""
}
}
and this one invalid:
{
"scripts": {
"precompress": "",
"compress": "",
"postcompress": "",
"build": ""
}
}
Additional Info
No response
Agreed, this would be a nice feature and matches the common convention. https://github.com/keithamus/sort-package-json/blob/92de3ef894435e402d76ae1e8444c4683a46ea2c/defaultRules.md#scripts is an example of this already being used in the wild:
Keys are sorted alphabetically except for pre/post scripts. Those are placed before and after their corresponding base npm script.
Since we're still on a 0.x version of the plugin I think we can turn it on for everyone by default. Thanks for filing!
@all-contributors please add @lo1tuma for ideas.
🤖 Beep boop! This comment was added automatically by all-contributors-auto-action. Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed. ...and of course, thank you for contributing! 💙
@JoshuaKGoldberg
I've put up a pull request to add @lo1tuma! :tada:
I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.