Open fisker opened 3 months ago
The ESLint ecosystem has mostly agreed that formatting should be left to dedicated formatting tools like Prettier. Thus, I think package.json sorting is best done as a Prettier plugin, which is exactly what prettier-plugin-packagejson does. (It simply calls sort-package-json
under the hood.)
I opened https://github.com/eslint/json/issues/37 but maybe this should be done outside @eslint/json
plugin. Sorting keys via prettier-plugin-packagejson has been working well for me for a few years. The problem with this plugin is that it goes outside of the scope of Prettier:
What Prettier is not concerned about Prettier only prints code. It does not transform it. This is to limit the scope of Prettier. Let’s focus on the printing and do it really well! Here are a few examples of things that are out of scope for Prettier:
- ...
- Sorting/moving imports, object keys, class members, JSX keys, CSS properties or anything else. Apart from being a transform rather than just printing (as mentioned above), sorting is potentially unsafe because of side effects (for imports, as an example) and makes it difficult to verify the most important correctness goal.
Sorting package.json
keys is similar to sorting imports. It’s not just formatting so it’s a concern of ESLint. The question is whether to sort as part of @eslint/json
or as a separate sort-package-json
plugin.
We also use the Prettier plugin. I agree that this should not go into ESLint, as people have been moving away from using ESLint for formatting.
ESLint starting to support other languages. Should we consider?