diff --git a/README.md b/README.md index c64072c..32c5676 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Keys in `engines` are ordered alphabetically. ### Files -Keys in `files` are ordered alphabetically, followed by `README.md` and `LICENSE` if they exist in the array. +Keys in `files` are ordered alphabetically (keeping the negations below), followed by `README.md` and `LICENSE` if they exist in the array. ### Scripts @@ -99,9 +99,14 @@ Top-level keys are sorted according to a style commonly seen in the packages of 'bundledDependencies', 'optionalDependencies', 'peerDependencies', + 'peerDependenciesMeta', 'dependencies', 'devDependencies', - 'resolutions' + 'resolutions', + + // types + 'types', + 'typings' ] ``` diff --git a/lib/rules/files.js b/lib/rules/files.js index 20eedbe..76e0264 100644 --- a/lib/rules/files.js +++ b/lib/rules/files.js @@ -35,7 +35,12 @@ const process = (props) => { return true; }) - .sort((a, b) => (a.value > b.value ? 1 : a.value < b.value ? -1 : 0)); + .sort((a, b) => { + const aValue = a.value.startsWith('!') ? a.value.substring(1) : a.value; + const bValue = b.value.startsWith('!') ? b.value.substring(1) : b.value; + + return aValue.localeCompare(bValue); + }); if (readme) { elements.push(readme); diff --git a/lib/rules/sort.js b/lib/rules/sort.js index 7caf6fe..03c32cc 100644 --- a/lib/rules/sort.js +++ b/lib/rules/sort.js @@ -47,6 +47,7 @@ const primary = [ 'bundledDependencies', 'optionalDependencies', 'peerDependencies', + 'peerDependenciesMeta', 'dependencies', 'devDependencies', 'resolutions' diff --git a/package.json b/package.json index 7ba5145..cf27b0a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": "Max Milton ", "main": "lib/index.js", "engines": { - "node": ">= 8.0.0" + "node": ">=10.13.0" }, "scripts": { "lint": "eslint lib test", @@ -28,18 +28,26 @@ "prettier": "^2.0.0" }, "devDependencies": { - "ava": "3.9.0", - "eslint-config-shellscape": "2.1.0", - "eslint-plugin-prettier": "3.1.4", - "execa": "4.0.2", - "nyc": "15.1.0", - "prettier": "2.0.5" + "@commitlint/cli": "^11.0.0", + "@commitlint/config-conventional": "^11.0.0", + "ava": "^3.13.0", + "eslint-config-shellscape": "^2.1.0", + "execa": "^4.0.3", + "lint-staged": "^10.4.0", + "nyc": "^15.1.0", + "pre-commit": "^1.2.2", + "prettier": "^2.1.2" }, "ava": { "files": [ "!**/fixtures/**" ] }, + "lint-staged": { + "*.js": [ + "eslint --fix" + ] + }, "nyc": { "include": [ "lib/*.js" diff --git a/test/files.js b/test/files.js index e6649ae..678f2d9 100644 --- a/test/files.js +++ b/test/files.js @@ -16,3 +16,33 @@ test('default', (t) => { t.snapshot(output); }); + +test('negations', (t) => { + const options = { + filepath: 'package.json', + parser: 'json-stringify', + plugins: ['.'] + }; + const fixture = { + files: [ + '/lit-html.js', + '/lit-html.js.map', + '/lit-html.d.ts', + '/lit-html.d.ts.map', + '/directives/', + '/parts.js', + '/parts.js.map', + '/parts.d.ts', + '/parts.d.ts.map', + '/src/', + '!/src/test/', + '/development/', + '!/development/test/' + ] + }; + + const input = JSON.stringify(fixture, null, 2); + const output = prettier.format(input, options); + + t.snapshot(output); +}); diff --git a/test/snapshots/files.js.md b/test/snapshots/files.js.md index 747e38d..c312ae0 100644 --- a/test/snapshots/files.js.md +++ b/test/snapshots/files.js.md @@ -16,3 +16,26 @@ Generated by [AVA](https://ava.li). ]␊ }␊ ` + +## negations + +> Snapshot 1 + + `{␊ + "files": [␊ + "/development/",␊ + "!/development/test/",␊ + "/directives/",␊ + "/lit-html.d.ts",␊ + "/lit-html.d.ts.map",␊ + "/lit-html.js",␊ + "/lit-html.js.map",␊ + "/parts.d.ts",␊ + "/parts.d.ts.map",␊ + "/parts.js",␊ + "/parts.js.map",␊ + "/src/",␊ + "!/src/test/"␊ + ]␊ + }␊ + ` diff --git a/test/snapshots/files.js.snap b/test/snapshots/files.js.snap index 776ef7c..46c8059 100644 Binary files a/test/snapshots/files.js.snap and b/test/snapshots/files.js.snap differ