From 15c96f85c4517375fe234d04c53cbd13be050eb3 Mon Sep 17 00:00:00 2001 From: aarondill Date: Wed, 1 Feb 2023 23:29:58 -0600 Subject: [PATCH 01/11] fix: add quiet flag to update-snapshot script This fix returns the output of update-snapshot to the closest to the previous output as is possible. The new increased output takes from the focus of the script. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0c37a0f..9ed1f16d 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "sort-package-json": "node cli.js package.json --check", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", - "update-snapshot": "ava -u && node cli.js package.json" + "update-snapshot": "ava -u && node cli.js package.json --quiet" }, "commitlint": { "extends": [ From f29a2f3226057b5d7c1e9ab54771610049178c7c Mon Sep 17 00:00:00 2001 From: Aaron Dill <117116764+aarondill@users.noreply.github.com> Date: Wed, 1 Feb 2023 23:48:18 -0600 Subject: [PATCH 02/11] refactor: use long option for ava update-snapshots Co-authored-by: fisker Cheung --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ed1f16d..26efba0b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "sort-package-json": "node cli.js package.json --check", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", - "update-snapshot": "ava -u && node cli.js package.json --quiet" + "update-snapshots": "ava --update-snapshots && node cli.js package.json --quiet" }, "commitlint": { "extends": [ From dc8f40ee23a0711433bb53739197435ba27f2c81 Mon Sep 17 00:00:00 2001 From: aarondill Date: Wed, 1 Feb 2023 23:53:46 -0600 Subject: [PATCH 03/11] refactor: quote pacakge.json in scripts --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 26efba0b..8ddc79cf 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,10 @@ "lint": "eslint .", "prepare": "husky install", "semantic-release": "semantic-release", - "sort-package-json": "node cli.js package.json --check", + "sort-package-json": "node cli.js \"package.json\" --check", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", - "update-snapshots": "ava --update-snapshots && node cli.js package.json --quiet" + "update-snapshots": "ava --update-snapshots && node cli.js \"package.json\" --quiet" }, "commitlint": { "extends": [ From 3131ff1eb944df7a9b7ab0b7ddee8503c8b0c0cb Mon Sep 17 00:00:00 2001 From: aarondill Date: Wed, 1 Feb 2023 23:57:22 -0600 Subject: [PATCH 04/11] fix: change sort-package-json script to actually sort --- .github/workflows/pr.yml | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ebb3e401..fb42941a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -8,14 +8,14 @@ jobs: fail-fast: false matrix: os: - - "ubuntu-latest" + - 'ubuntu-latest' # - "macos-latest" # - "windows-latest" node_version: - - "18" - - "16" - - "14" - - "12" + - '18' + - '16' + - '14' + - '12' name: Node.js ${{ matrix.node_version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: @@ -39,7 +39,7 @@ jobs: run: npm run lint - name: Check package.json - run: npm run sort-package-json + run: npm run sort-package-json -- check - name: Run Tests run: npm run test-coverage diff --git a/package.json b/package.json index 8ddc79cf..4c38d9b9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint": "eslint .", "prepare": "husky install", "semantic-release": "semantic-release", - "sort-package-json": "node cli.js \"package.json\" --check", + "sort-package-json": "node cli.js \"package.json\"", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", "update-snapshots": "ava --update-snapshots && node cli.js \"package.json\" --quiet" From ec3a79950815790343ba7b408903b3f2de67e3fd Mon Sep 17 00:00:00 2001 From: aarondill Date: Wed, 1 Feb 2023 23:58:19 -0600 Subject: [PATCH 05/11] fix: fix argument passed to npm run sort-package-json --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fb42941a..c24850ce 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -39,7 +39,7 @@ jobs: run: npm run lint - name: Check package.json - run: npm run sort-package-json -- check + run: npm run sort-package-json -- --check - name: Run Tests run: npm run test-coverage From 0423ea37244d179ef312d5d8a3013a582d74206c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:08:56 +0800 Subject: [PATCH 06/11] style: run Prettier on everything --- .github/workflows/pr.yml | 2 +- .prettierignore | 2 ++ README.md | 4 ++-- package.json | 5 +++-- tsconfig.json | 28 ++++++++++++++-------------- tslint.json | 10 +++++----- 6 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 .prettierignore diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c24850ce..0e889694 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -34,7 +34,7 @@ jobs: - name: Install Dependencies run: npm ci - - name: Run ESLint + - name: Run ESLint and Prettier if: matrix.node_version == '18' run: npm run lint diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..725c5753 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +.nyc_output/ +tests/snapshots/ \ No newline at end of file diff --git a/README.md b/README.md index 2d6e460f..225dc958 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ If an array, sort keys in ordering of `options.sortOrder`. ```js const sorted = sortPackageJson(packageJsonObject, { - sortOrder: ['version'] + sortOrder: ['version'], }) console.log(Object.keys(sorted)) @@ -173,7 +173,7 @@ If a function, sort fields by [Array#sort(options.sortOrder)](https://developer. const sorted = sortPackageJson(packageJsonObject, { sortOrder(left, right) { return left.localeCompare(right) - } + }, }) console.log(Object.keys(sorted)) diff --git a/package.json b/package.json index 4c38d9b9..7cd9e1c4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "reporter.js" ], "scripts": { - "lint": "eslint .", + "fix": "eslint . --fix && prettier . \"!**/*.js\" --write", + "lint": "eslint . && prettier . \"!**/*.js\" --check", "prepare": "husky install", "semantic-release": "semantic-release", "sort-package-json": "node cli.js \"package.json\"", @@ -45,7 +46,7 @@ "*.js": [ "eslint --fix" ], - "*.ts": [ + "**/*.{ts,md,json,md,yml}": [ "prettier --write" ], "package.json": [ diff --git a/tsconfig.json b/tsconfig.json index 7cc436f7..5e9d07a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,16 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": ["es6"], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "noEmit": true, + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noEmit": true, - // If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index". - // If the library is global (cannot be imported via `import` or `require`), leave this out. - "baseUrl": ".", - "paths": { "sort-package-json": ["."] } - } -} \ No newline at end of file + // If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index". + // If the library is global (cannot be imported via `import` or `require`), leave this out. + "baseUrl": ".", + "paths": { "sort-package-json": ["."] } + } +} diff --git a/tslint.json b/tslint.json index 29fa58a9..8cd631ee 100644 --- a/tslint.json +++ b/tslint.json @@ -1,6 +1,6 @@ { - "extends": "dtslint/dtslint.json", // Or "dtslint/dt.json" if on DefinitelyTyped - "rules": { - "semicolon": false - } -} \ No newline at end of file + "extends": "dtslint/dtslint.json", // Or "dtslint/dt.json" if on DefinitelyTyped + "rules": { + "semicolon": false + } +} From 5cf1a25667150124cf374dd33f5d327ff881ec9f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:11:54 +0800 Subject: [PATCH 07/11] style: quotes in comments --- .github/workflows/pr.yml | 4 ++-- .prettierignore | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0e889694..3a011c5f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -9,8 +9,8 @@ jobs: matrix: os: - 'ubuntu-latest' - # - "macos-latest" - # - "windows-latest" + # - 'macos-latest' + # - 'windows-latest' node_version: - '18' - '16' diff --git a/.prettierignore b/.prettierignore index 725c5753..23abab46 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,2 @@ .nyc_output/ -tests/snapshots/ \ No newline at end of file +tests/snapshots/ From 51fe85275c6cd095e875ce0ec747c788e59e4464 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:14:08 +0800 Subject: [PATCH 08/11] chore: tweak --- .github/workflows/pr.yml | 5 +---- package.json | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3a011c5f..af500694 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -34,12 +34,9 @@ jobs: - name: Install Dependencies run: npm ci - - name: Run ESLint and Prettier + - name: Lint if: matrix.node_version == '18' run: npm run lint - - name: Check package.json - run: npm run sort-package-json -- --check - - name: Run Tests run: npm run test-coverage diff --git a/package.json b/package.json index 7cd9e1c4..e8cd94bd 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,10 @@ "reporter.js" ], "scripts": { - "fix": "eslint . --fix && prettier . \"!**/*.js\" --write", - "lint": "eslint . && prettier . \"!**/*.js\" --check", + "fix": "eslint . --fix && prettier . \"!**/*.js\" --write && node cli.js \"package.json\"", + "lint": "eslint . && prettier . \"!**/*.js\" --check && node cli.js \"package.json\" --check", "prepare": "husky install", "semantic-release": "semantic-release", - "sort-package-json": "node cli.js \"package.json\"", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", "update-snapshots": "ava --update-snapshots && node cli.js \"package.json\" --quiet" From 464cf1cf95f121cd7e8dc736c1fd4eff3bf8b604 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:18:20 +0800 Subject: [PATCH 09/11] refactor: remove sort from `update-snapshots` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8cd94bd..5faf0720 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "semantic-release": "semantic-release", "test": "ava && dtslint --localTs node_modules/typescript/lib", "test-coverage": "nyc ava", - "update-snapshots": "ava --update-snapshots && node cli.js \"package.json\" --quiet" + "update-snapshots": "ava --update-snapshots" }, "commitlint": { "extends": [ From 4019beba86d575ac74a7c5a9dffba42ea5a1d48a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:27:02 +0800 Subject: [PATCH 10/11] test: see how `package.json` works in lint-staged --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5faf0720..ae506125 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "type": "module", "exports": "./index.js", "types": "index.d.ts", - "bin": "cli.js", + "bin": "cli.js------------", "files": [ "index.js", "index.d.ts", From 6285a9c454ac955479a764ae81a57a4f7d3a09d9 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 2 Feb 2023 14:29:29 +0800 Subject: [PATCH 11/11] chore: lint-stage runs prettier on everything --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ae506125..fe9952e0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "type": "module", "exports": "./index.js", "types": "index.d.ts", - "bin": "cli.js------------", + "bin": "cli.js", "files": [ "index.js", "index.d.ts", @@ -42,14 +42,14 @@ ] }, "lint-staged": { + "package.json": [ + "node cli.js" + ], "*.js": [ "eslint --fix" ], - "**/*.{ts,md,json,md,yml}": [ - "prettier --write" - ], - "package.json": [ - "node cli.js" + "**/*,!*.js": [ + "prettier --write --ignore-unkown" ] }, "prettier": {