eslint-plugin-package-json icon indicating copy to clipboard operation
eslint-plugin-package-json copied to clipboard

🚀 Feature: sort-collections: alphabetically sorting with co-located hooks for `scripts`

Open lo1tuma opened this issue 1 year ago • 3 comments

Bug Report Checklist

  • [X] I have tried restarting my IDE and the issue persists.
  • [X] I have pulled the latest main branch 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

lo1tuma avatar Sep 09 '24 15:09 lo1tuma

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!

JoshuaKGoldberg avatar Sep 12 '24 12:09 JoshuaKGoldberg

@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 avatar Sep 12 '24 15:09 JoshuaKGoldberg

@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.

allcontributors[bot] avatar Sep 12 '24 15:09 allcontributors[bot]

:tada: This is included in version v0.17.0 :tada:

The release is available on:

Cheers! 📦🚀

github-actions[bot] avatar Nov 30 '24 14:11 github-actions[bot]