Skip to content

Commit

Permalink
feat: change order-properties order default to sort-package-json (#122)
Browse files Browse the repository at this point in the history
## PR Checklist

-   [x] Addresses an existing open issue: fixes #58
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Applies the change, along with a notice in the docs.

**This is a breaking change**. But since this package is still 0.x,
there's nothing necessary to do with semver.
  • Loading branch information
JoshuaKGoldberg committed Jan 20, 2024
1 parent ebdd7aa commit 246261d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
34 changes: 2 additions & 32 deletions docs/rules/order-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,9 @@ interface {
}
```

Default: `legacy`
Default: `"sort-package-json"`

```json
[
"name",
"version",
"private",
"publishConfig",
"description",
"main",
"browser",
"files",
"bin",
"directories",
"man",
"scripts",
"repository",
"keywords",
"author",
"license",
"bugs",
"homepage",
"config",
"dependencies",
"devDependencies",
"peerDependencies",
"optionalDependencies",
"bundledDependencies",
"engines",
"os",
"cpu"
]
```
> ⚠️ The default value for `order` changed from `"legacy"` to `"sort-package-json"` in v0.6.0.
This rule is **autofixable**; run `eslint` with the `--fix` option to sort top-level properties in place.
Any properties not present in the array of ordered properties will be left in their original positions.
6 changes: 5 additions & 1 deletion src/rules/order-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export default createRule<Options>({
"Program:exit"() {
const { ast, text } = context.sourceCode;

const options = context.options[0] ?? { order: "legacy" };
const options = {
order: "sort-package-json",
...context.options[0],
} satisfies Options[0];

const requiredOrder =
options.order === "legacy"
? standardOrderLegacy
Expand Down
8 changes: 4 additions & 4 deletions src/tests/rules/order-properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ ruleTester.run("order-properties", rule, {
"name": "invalid-top-level-property-order",
"version": "1.0.0",
"description": "npm made me this way",
"main": "index.js",
"scripts": {
"test": "tape"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fake/github.git"
},
"main": "index.js",
"scripts": {
"test": "tape"
}
}
`,
Expand Down

0 comments on commit 246261d

Please sign in to comment.