From fe7725b137c5623d54c94d0fc594cb52d7429a80 Mon Sep 17 00:00:00 2001 From: electrovir Date: Sun, 15 Dec 2024 01:54:27 +0000 Subject: [PATCH] [patch] fix messed up line endings without trailing commas GitHub: fixes #41 --- README.md | 42 +- configs/c8.config.json | 19 - configs/dep-cruiser.config.cts | 6 + configs/typedoc.config.ts | 17 + package-lock.json | 805 +++++++++++------- package.json | 14 +- src/augments/array.ts | 3 +- src/augments/doc.ts | 11 +- src/index.ts | 3 +- src/preprocessing.ts | 20 +- src/printer/comment-triggers.ts | 7 +- src/printer/comments.ts | 21 +- .../insert-new-lines-into-arguments.ts | 157 ---- src/printer/insert-new-lines.ts | 44 +- src/printer/multiline-array-printer.ts | 6 +- src/printer/supported-node-types.ts | 1 - src/printer/trailing-comma.ts | 1 + .../prettier-options.example.ts | 2 +- src/test/babel-ts.test.ts | 2 +- src/test/json.test.ts | 1 - src/test/run-tests.mock.ts | 12 +- ...ript-tests.ts => typescript-tests.mock.ts} | 44 +- src/test/typescript.test.ts | 2 +- todo.md | 2 +- 24 files changed, 666 insertions(+), 576 deletions(-) delete mode 100644 configs/c8.config.json create mode 100644 configs/typedoc.config.ts delete mode 100644 src/printer/insert-new-lines-into-arguments.ts rename src/test/{typescript-tests.ts => typescript-tests.mock.ts} (97%) diff --git a/README.md b/README.md index 9a80612..aa8e10f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add this config to your prettierrc file: ```TypeScript -module.exports = { +export default { plugins: [ 'prettier-plugin-multiline-arrays', ], @@ -26,18 +26,18 @@ The order of your plugins array is very important, so if you have other plugins This plugin provides two new options for your Prettier config: -- **`multilineArraysWrapThreshold`**: This should be set to a single number which controls when arrays wrap. If an array has _more_ elements than the number specified here, it will be forced to wrap. This option defaults to `-1`, which indicates that no automatic wrapping will take place. Example JSON: `"multilineArraysWrapThreshold": 3,`. To override this option for an individual array, precede the array with a comment like so: `// prettier-multiline-arrays-next-threshold: 4`. -- **`multilineArraysLinePattern`**: This should be set to a string which contains a space separated list of numbers. These numbers allow fine grained control over how many elements appear in each line. The pattern will repeat if an array has more elements than the pattern. See the `Examples` section for how this works. This defaults to just `1`, which indicates all array lines have just a single element. Example: `"multilineArraysLinePattern": "2 1"`, which means the first line will have 2 elements, the second will have 1, the third will have 2, the fourth will have 1, and so on. If set, _this option overrides Prettier's default wrapping; multiple elements on one line will not be wrapped even if they don't fit within the column count._ To override this option for an array, precede the array with a comment like so: `// prettier-multiline-arrays-next-line-pattern: 2 1`. +- **`multilineArraysWrapThreshold`**: This should be set to a single number which controls when arrays wrap. If an array has _more_ elements than the number specified here, it will be forced to wrap. This option defaults to `-1`, which indicates that no automatic wrapping will take place. Example JSON: `"multilineArraysWrapThreshold": 3,`. To override this option for an individual array, precede the array with a comment like so: `// prettier-multiline-arrays-next-threshold: 4`. +- **`multilineArraysLinePattern`**: This should be set to a string which contains a space separated list of numbers. These numbers allow fine grained control over how many elements appear in each line. The pattern will repeat if an array has more elements than the pattern. See the `Examples` section for how this works. This defaults to just `1`, which indicates all array lines have just a single element. Example: `"multilineArraysLinePattern": "2 1"`, which means the first line will have 2 elements, the second will have 1, the third will have 2, the fourth will have 1, and so on. If set, _this option overrides Prettier's default wrapping; multiple elements on one line will not be wrapped even if they don't fit within the column count._ To override this option for an array, precede the array with a comment like so: `// prettier-multiline-arrays-next-line-pattern: 2 1`. ## Comment overrides -- Add a comment starting with `prettier-multiline-arrays-next-threshold:` followed by a single number to control `multilineArraysWrapThreshold` for an array on the next line. -- Add a comment starting with `prettier-multiline-arrays-next-line-pattern:` followed by a pattern of numbers to control `multilineArraysLinePattern` for an array on the next line. +- Add a comment starting with `prettier-multiline-arrays-next-threshold:` followed by a single number to control `multilineArraysWrapThreshold` for an array on the next line. +- Add a comment starting with `prettier-multiline-arrays-next-line-pattern:` followed by a pattern of numbers to control `multilineArraysLinePattern` for an array on the next line. To set a comment override for all arrays in a file following the comment, change `next` to `set`. Like so: -- `prettier-multiline-arrays-set-threshold: 5` -- `prettier-multiline-arrays-set-line-pattern: 2 1 3` +- `prettier-multiline-arrays-set-threshold: 5` +- `prettier-multiline-arrays-set-line-pattern: 2 1 3` To later undo a `set` comment, use `prettier-multiline-arrays-reset`, which resets the options to whatever you have set in prettierrc, or the default values. @@ -52,7 +52,7 @@ The precedence of forcing wrapping goes as follows: ## Examples -- Not formatted: +- Not formatted: @@ -65,27 +65,7 @@ The precedence of forcing wrapping goes as follows: 'a', 'b', 'c', 'd', 'e'] // note the leading new line which forces a wrap ``` -- Removing the `prettier-ignore` comments leads to formatting like this (with the default options): - - - - ```TypeScript - export const myArray = [ - 'a', - 'b', - 'c', - ]; // note the trailing comma which forces a wrap - - export const myCustomArray = [ - 'a', - 'b', - 'c', - 'd', - 'e', - ]; // note the leading new line which forces a wrap - ``` - -- Use comment overrides to affect wrapping: +- Use comment overrides to affect wrapping: @@ -126,5 +106,5 @@ Tested to be compatible with the following plugins. It is likely compatible with ### Debugging -- Set the `MULTILINE_DEBUG` environment variable to something truthy before formatting to get extra debug output when formatting. -- To debug in browser dev tools, run `npm run test:debug` and open Chrome's dev tools. +- Set the `MULTILINE_DEBUG` environment variable to something truthy before formatting to get extra debug output when formatting. +- To debug in browser dev tools, run `npm run test:debug` and open Chrome's dev tools. diff --git a/configs/c8.config.json b/configs/c8.config.json deleted file mode 100644 index 0b49257..0000000 --- a/configs/c8.config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "100": true, - "all": true, - "checkCoverage": true, - "clean": true, - "exclude": [ - "**/*.test.ts", - "**/*.example.ts" - ], - "include": [ - "src/**/*.ts" - ], - "perFile": true, - "reporter": [ - "html", - "istanbul-smart-text-reporter" - ], - "skipFull": true -} diff --git a/configs/dep-cruiser.config.cts b/configs/dep-cruiser.config.cts index 16ebc10..f5fedfa 100644 --- a/configs/dep-cruiser.config.cts +++ b/configs/dep-cruiser.config.cts @@ -7,6 +7,12 @@ const baseConfig = defineConfig({ 'no-orphans': { from: [ 'src/index.ts', + '.example.ts', + ], + }, + 'no-duplicate-dep-types': { + to: [ + 'prettier', ], }, }, diff --git a/configs/typedoc.config.ts b/configs/typedoc.config.ts new file mode 100644 index 0000000..3c7805a --- /dev/null +++ b/configs/typedoc.config.ts @@ -0,0 +1,17 @@ +import {baseTypedocConfig} from '@virmator/docs/configs/typedoc.config.base'; +import {join, resolve} from 'path'; +import type {TypeDocOptions} from 'typedoc'; + +const repoRoot = resolve(import.meta.dirname, '..'); +const indexTsFile = join(repoRoot, 'src', 'index.ts'); + +export const typeDocConfig: Partial = { + ...baseTypedocConfig, + out: join(repoRoot, 'docs-dist'), + entryPoints: [ + indexTsFile, + ], + intentionallyNotExported: [], + requiredToBeDocumented: [], + emit: 'none', +}; diff --git a/package-lock.json b/package-lock.json index f6ecbc3..d1c3a55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "prettier-plugin-multiline-arrays", - "version": "3.0.6", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "prettier-plugin-multiline-arrays", - "version": "3.0.6", + "version": "4.0.0", "license": "(MIT or CC0 1.0)", "dependencies": { "@augment-vir/common": "^31.1.1", @@ -21,7 +21,9 @@ "@stylistic/eslint-plugin-ts": "^2.12.0", "@types/esprima": "^4.0.6", "@types/estree": "^1.0.6", + "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^8.18.0", + "c8": "^10.1.2", "cross-env": "^7.0.3", "cspell": "^8.16.1", "dependency-cruiser": "^16.8.0", @@ -35,12 +37,13 @@ "eslint-plugin-require-extensions": "^0.1.3", "eslint-plugin-sonarjs": "^3.0.1", "eslint-plugin-unicorn": "^56.0.1", + "istanbul-smart-text-reporter": "^1.1.5", "markdown-code-example-inserter": "^3.0.3", "npm-check-updates": "^17.1.11", - "prettier": "^3.4.2", + "prettier": "3.3.3", "prettier-plugin-interpolated-html-tags": "^2.0.0", "prettier-plugin-jsdoc": "^1.3.0", - "prettier-plugin-multiline-arrays": "./", + "prettier-plugin-multiline-arrays": "^3.0.6", "prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-packagejson": "^2.5.6", "prettier-plugin-sort-json": "^4.0.0", @@ -1965,6 +1968,13 @@ "node": ">=6.9.0" } }, + "node_modules/@bcoe/v8-coverage": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", + "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", + "dev": true, + "license": "MIT" + }, "node_modules/@cspell/cspell-bundled-dicts": { "version": "8.16.1", "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-8.16.1.tgz", @@ -3012,13 +3022,13 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", - "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.19.1.tgz", + "integrity": "sha512-fo6Mtm5mWyKjA/Chy1BYTdn5mGJoDNjC7C64ug20ADsRDGrA85bN3uK3MaKbeRkRuuIEAR5N33Jr1pbm411/PA==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/object-schema": "^2.1.4", + "@eslint/object-schema": "^2.1.5", "debug": "^4.3.1", "minimatch": "^3.1.2" }, @@ -3026,36 +3036,15 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/@eslint/config-array/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/@eslint/config-array/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/@eslint/core": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.7.0.tgz", - "integrity": "sha512-xp5Jirz5DyPYlPiKat8jaq0EmYvDXKKpzTbxXMpT9eqlRJkRKIz9AGMdlvYjih+im+QlhWrpvVjl8IPC/lHlUw==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.1.tgz", + "integrity": "sha512-GuUdqkyyzQI5RMIWkHhvTWLCyLo1jNK3vzkSyaExH5kHPDHcuL2VOpHjmMY+y3+NC69qAKToBqldTBgYeLSr9Q==", "dev": true, "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -3084,68 +3073,10 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/@eslint/eslintrc/node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/@eslint/eslintrc/node_modules/ignore": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", - "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4" - } - }, - "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@eslint/eslintrc/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/@eslint/js": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.14.0.tgz", - "integrity": "sha512-pFoEtFWCPyDOl+C6Ift+wC7Ro89otjigCf5vcuWqWgqNSQbRrpjSvdeE6ofLz4dHmyxD5f7gIdGT4+p36L6Twg==", + "version": "9.17.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.17.0.tgz", + "integrity": "sha512-Sxc4hqcs1kTu0iID3kcZDW3JHq2a77HO9P8CP6YEA/FpH3Ll8UXE2r/86Rz9YJLKme39S9vU5OWNjC6Xl0Cr3w==", "dev": true, "license": "MIT", "engines": { @@ -3278,6 +3209,16 @@ "node": ">=12" } }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.8", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz", @@ -3467,6 +3408,17 @@ "lit-html": "^2.0.0 || ^3.0.0" } }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@pkgr/core": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", @@ -3510,9 +3462,9 @@ "license": "MIT" }, "node_modules/@stylistic/eslint-plugin": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-2.12.0.tgz", - "integrity": "sha512-IvD2WXbOoSp0zNpyYbjdSyEjZtut78RYfj2WIlbChE7HFuposTK5X1hc5+4AyqYcjLXYdD5oo/sJtqMGFNRb1w==", + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-2.12.1.tgz", + "integrity": "sha512-fubZKIHSPuo07FgRTn6S4Nl0uXPRPYVNpyZzIDGfp7Fny6JjNus6kReLD7NI380JXi4HtUTSOZ34LBuNPO1XLQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3530,9 +3482,9 @@ } }, "node_modules/@stylistic/eslint-plugin-ts": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-2.12.0.tgz", - "integrity": "sha512-JqoHGQCeW0dC3LN/7+ZRwTOCs3kBum2b4k7ovx+0RXeaDIINs5F+/Mp/NvTCPqDzUlBkd1HOaviKyaEWpKA7Yw==", + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-2.12.1.tgz", + "integrity": "sha512-Xx1NIioeW6LLlOfq5L/dLSrUXvi6q80UXDNbn/rXjKCzFT4a8wKwtp1q25kssdr1JEXI9a6tOHwFsh4Em+MoGg==", "dev": true, "license": "MIT", "dependencies": { @@ -3547,19 +3499,6 @@ "eslint": ">=8.40.0" } }, - "node_modules/@stylistic/eslint-plugin/node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/@taplo/core": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@taplo/core/-/core-0.1.1.tgz", @@ -3836,9 +3775,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.10.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz", - "integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==", + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3950,16 +3889,6 @@ "typescript": ">=4.8.4 <5.8.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", - "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4" - } - }, "node_modules/@typescript-eslint/parser": { "version": "8.18.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.18.0.tgz", @@ -4068,6 +3997,16 @@ "typescript": ">=4.8.4 <5.8.0" } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -4393,6 +4332,19 @@ "node": ">=18.0.0" } }, + "node_modules/@web/dev-server-core/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/@web/parse5-utils": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@web/parse5-utils/-/parse5-utils-2.1.0.tgz", @@ -4445,6 +4397,19 @@ "node": ">=18.0.0" } }, + "node_modules/@web/test-runner-core/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -4516,16 +4481,16 @@ } }, "node_modules/ajv": { - "version": "8.17.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", - "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" }, "funding": { "type": "github", @@ -4804,13 +4769,14 @@ "license": "MIT" }, "node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, "node_modules/braces": { @@ -4888,6 +4854,40 @@ "node": ">= 0.8" } }, + "node_modules/c8": { + "version": "10.1.2", + "resolved": "https://registry.npmjs.org/c8/-/c8-10.1.2.tgz", + "integrity": "sha512-Qr6rj76eSshu5CgRYvktW0uM0CFY0yi4Fd5D0duDXO6sYinyopmftUiJVuzBQxQcwQLor7JWDVRP+dUfCmzgJw==", + "dev": true, + "license": "ISC", + "dependencies": { + "@bcoe/v8-coverage": "^0.2.3", + "@istanbuljs/schema": "^0.1.3", + "find-up": "^5.0.0", + "foreground-child": "^3.1.1", + "istanbul-lib-coverage": "^3.2.0", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.1.6", + "test-exclude": "^7.0.1", + "v8-to-istanbul": "^9.0.0", + "yargs": "^17.7.2", + "yargs-parser": "^21.1.1" + }, + "bin": { + "c8": "bin/c8.js" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "monocart-coverage-reports": "^2" + }, + "peerDependenciesMeta": { + "monocart-coverage-reports": { + "optional": true + } + } + }, "node_modules/cache-content-type": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", @@ -5903,19 +5903,40 @@ "node": "^18.17||>=20" } }, - "node_modules/dependency-cruiser/node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "node_modules/dependency-cruiser/node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "engines": { - "node": ">=12" + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" }, "funding": { - "url": "https://github.com/sponsors/jonschlinkert" + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/dependency-cruiser/node_modules/ignore": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-6.0.2.tgz", + "integrity": "sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" } }, + "node_modules/dependency-cruiser/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, "node_modules/dependency-graph": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/dependency-graph/-/dependency-graph-0.11.0.tgz", @@ -6329,27 +6350,27 @@ } }, "node_modules/eslint": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.14.0.tgz", - "integrity": "sha512-c2FHsVBr87lnUtjP4Yhvk4yEhKrQavGafRA/Se1ouse8PfbfC/Qh9Mxa00yWsZRlqeUB9raXip0aiiUZkgnr9g==", + "version": "9.17.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.17.0.tgz", + "integrity": "sha512-evtlNcpJg+cZLcnVKwsai8fExnqjGPicK7gnUtlNuzu+Fv9bI0aLpND5T44VLQtoMEnI57LoXO9XAkIXwohKrA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", - "@eslint/config-array": "^0.18.0", - "@eslint/core": "^0.7.0", - "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.14.0", - "@eslint/plugin-kit": "^0.2.0", + "@eslint/config-array": "^0.19.0", + "@eslint/core": "^0.9.0", + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "9.17.0", + "@eslint/plugin-kit": "^0.2.3", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.4.0", + "@humanwhocodes/retry": "^0.4.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", + "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0", @@ -6368,8 +6389,7 @@ "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", - "optionator": "^0.9.3", - "text-table": "^0.2.0" + "optionator": "^0.9.3" }, "bin": { "eslint": "bin/eslint.js" @@ -6403,9 +6423,9 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "50.6.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.6.0.tgz", - "integrity": "sha512-tCNp4fR79Le3dYTPB0dKEv7yFyvGkUCa+Z3yuTrrNGGOxBlXo9Pn0PEgroOZikUQOGjxoGMVKNjrOHcYEdfszg==", + "version": "50.6.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.6.1.tgz", + "integrity": "sha512-UWyaYi6iURdSfdVVqvfOs2vdCVz0J40O/z/HTsv2sFjdjmdlUI/qlKLOTmwbPQ2tAfQnE5F9vqx+B+poF71DBQ==", "dev": true, "license": "BSD-3-Clause", "dependencies": { @@ -6561,6 +6581,16 @@ "eslint": "^8.0.0 || ^9.0.0" } }, + "node_modules/eslint-plugin-sonarjs/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, "node_modules/eslint-plugin-sonarjs/node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -6738,23 +6768,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, "node_modules/eslint/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -6771,17 +6784,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/eslint/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "node_modules/eslint/node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -6826,49 +6828,6 @@ "node": ">=16" } }, - "node_modules/eslint/node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dev": true, - "license": "ISC", - "dependencies": { - "is-glob": "^4.0.3" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/eslint/node_modules/ignore": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", - "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4" - } - }, - "node_modules/eslint/node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "license": "MIT" - }, - "node_modules/eslint/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/eslint/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -7074,6 +7033,19 @@ "node": ">=8.6.0" } }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -7105,6 +7077,21 @@ "reusify": "^1.0.4" } }, + "node_modules/fdir": { + "version": "6.4.2", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.2.tgz", + "integrity": "sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/file-entry-cache": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-9.1.0.tgz", @@ -7434,16 +7421,42 @@ } }, "node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, "license": "ISC", "dependencies": { - "is-glob": "^4.0.1" + "is-glob": "^4.0.3" }, "engines": { - "node": ">= 6" + "node": ">=10.13.0" + } + }, + "node_modules/glob/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", + "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/global-directory": { @@ -7513,16 +7526,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globby/node_modules/ignore": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", - "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4" - } - }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", @@ -7815,9 +7818,9 @@ } }, "node_modules/ignore": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-6.0.2.tgz", - "integrity": "sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, "license": "MIT", "engines": { @@ -8579,6 +8582,17 @@ "node": ">=8" } }, + "node_modules/istanbul-smart-text-reporter": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/istanbul-smart-text-reporter/-/istanbul-smart-text-reporter-1.1.5.tgz", + "integrity": "sha512-vwMgnu+JWaD7EonOJioKmG6wjo2tu2EPH7qkOb4EFRd3TOFlEmAgtXkN0ulFU185UKasERji3t6L/mHFj+bnbQ==", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1" + } + }, "node_modules/jackspeak": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.2.tgz", @@ -8653,9 +8667,9 @@ "license": "MIT" }, "node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true, "license": "MIT" }, @@ -9718,6 +9732,19 @@ "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -9775,19 +9802,16 @@ } }, "node_modules/minimatch": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", - "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^1.1.7" }, "engines": { - "node": "20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": "*" } }, "node_modules/minimist": { @@ -10339,13 +10363,13 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", "dev": true, "license": "MIT", "engines": { - "node": ">=8.6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" @@ -10382,9 +10406,9 @@ } }, "node_modules/prettier": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", - "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, "license": "MIT", "bin": { @@ -10495,8 +10519,59 @@ } }, "node_modules/prettier-plugin-multiline-arrays": { - "resolved": "", - "link": true + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/prettier-plugin-multiline-arrays/-/prettier-plugin-multiline-arrays-3.0.6.tgz", + "integrity": "sha512-FrWVa7MoDQo9b5XoLPrqIDClb0k+O8wOIsIr1DutRXhcerLY8PfIe/yYeTVD/vpRISkSXCBEYmj5Voe0wb5dEQ==", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^28.1.0", + "proxy-vir": "^1.0.0" + }, + "peerDependencies": { + "prettier": ">=3.0.0" + } + }, + "node_modules/prettier-plugin-multiline-arrays/node_modules/@augment-vir/common": { + "version": "28.2.4", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-28.2.4.tgz", + "integrity": "sha512-5Ib0OX7YlxAuFrG+MAoTsz6RlKMcbdMdoNGcEEKH/ezc/ZKMy/IHZ9Z/ZcCHYopZ4ocGXzVY4KUOiJ8+CXXvTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^3.0.0", + "run-time-assertions": "^1.5.1", + "type-fest": "^4.20.1" + } + }, + "node_modules/prettier-plugin-multiline-arrays/node_modules/proxy-vir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/proxy-vir/-/proxy-vir-1.0.0.tgz", + "integrity": "sha512-WV1gkBxUOwLSz0Bn09tisIqLK7leAqtFm/474t3L0hQKJw7/gdrkGcWw0/OT1PhSy+TDS6swfq7Niuoq3XJhkQ==", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^23.3.4" + } + }, + "node_modules/prettier-plugin-multiline-arrays/node_modules/proxy-vir/node_modules/@augment-vir/common": { + "version": "23.4.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-23.4.0.tgz", + "integrity": "sha512-QIrJ1doD00TNbOzeVrk9KgPTzRlIjayxERnhtbQjK/AFPj5yElcB03GbnGdQZPzws/R+5gfMM5cZiH7QyBP+Kg==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^2.1.1", + "run-time-assertions": "^1.0.0", + "type-fest": "^4.10.2" + } + }, + "node_modules/prettier-plugin-multiline-arrays/node_modules/proxy-vir/node_modules/browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==", + "dev": true, + "license": "MIT" }, "node_modules/prettier-plugin-organize-imports": { "version": "4.1.0", @@ -11282,6 +11357,38 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/run-time-assertions": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/run-time-assertions/-/run-time-assertions-1.5.2.tgz", + "integrity": "sha512-ccfwvjGuNU14cSSXLlmPRiqEgMfA7w3J2TViO79zMnzXGvE6FJ0dxnhIQGwe5r/vwySOJ4sqZksexo9wyAlA8g==", + "deprecated": "Use @augment-vir/assert instead.", + "dev": true, + "license": "(MIT or CC0 1.0)", + "dependencies": { + "@augment-vir/common": "^29.3.0", + "expect-type": "~0.15.0", + "type-fest": "^4.22.0" + } + }, + "node_modules/run-time-assertions/node_modules/@augment-vir/common": { + "version": "29.3.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-29.3.0.tgz", + "integrity": "sha512-k3OX35/576thmGUzQUBcCKGarb7ONBfiu07+iV2vxmjl7VoB1rOB0vu8WqgB1ceJq2EMLDPXY18hHpJ9WeTHXQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "browser-or-node": "^3.0.0", + "run-time-assertions": "^1.5.1", + "type-fest": "^4.21.0" + } + }, + "node_modules/run-time-assertions/node_modules/expect-type": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-0.15.0.tgz", + "integrity": "sha512-yWnriYB4e8G54M5/fAFj7rCIBiKs1HAACaY13kCz6Ku0dezjS9aMcfcdVK2X8Tv2tEV1BPz/wKfQ7WA4S/d8aA==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/rxjs": { "version": "7.8.1", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", @@ -12140,12 +12247,107 @@ "node": ">=22" } }, - "node_modules/text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "node_modules/test-exclude": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.1.tgz", + "integrity": "sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==", "dev": true, - "license": "MIT" + "license": "ISC", + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^10.4.1", + "minimatch": "^9.0.4" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/test-exclude/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/test-exclude/node_modules/glob": { + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/test-exclude/node_modules/jackspeak": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", + "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, + "node_modules/test-exclude/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/test-exclude/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/test-exclude/node_modules/path-scurry": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } }, "node_modules/through": { "version": "2.3.8", @@ -12168,34 +12370,6 @@ "node": ">=12.0.0" } }, - "node_modules/tinyglobby/node_modules/fdir": { - "version": "6.4.2", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.2.tgz", - "integrity": "sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "picomatch": "^3 || ^4" - }, - "peerDependenciesMeta": { - "picomatch": { - "optional": true - } - } - }, - "node_modules/tinyglobby/node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -13029,6 +13203,16 @@ "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x" } }, + "node_modules/typedoc/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, "node_modules/typedoc/node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -13316,6 +13500,21 @@ "node": ">=22" } }, + "node_modules/v8-to-istanbul": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", + "integrity": "sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==", + "dev": true, + "license": "ISC", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.12", + "@types/istanbul-lib-coverage": "^2.0.1", + "convert-source-map": "^2.0.0" + }, + "engines": { + "node": ">=10.12.0" + } + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index 332662f..ca2ec46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier-plugin-multiline-arrays", - "version": "3.0.6", + "version": "4.0.0", "description": "Prettier plugin to force all arrays to be multiline.", "keywords": [ "array", @@ -29,13 +29,14 @@ "types": "dist/index.d.ts", "scripts": { "compile": "virmator compile", + "docs": "virmator docs", "format": "virmator format", "lint": "virmator lint fix", "publish": "virmator publish npm run test:all", "test": "npm run compile && test-as-package virmator test node", - "test:all": "npm run compile && concurrently --colors --kill-others-on-fail -c auto --names tests,spelling,format,docs,deps,lint \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\" \"npm run test:lint\"", - "test:coverage": "npm run test coverage", + "test:all": "npm run compile && concurrently --colors --kill-others-on-fail -c auto --names tests,spelling,format,deps,lint \"npm test\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:deps\" \"npm run test:lint\"", "test:deps": "virmator deps check", + "test:docs": "virmator docs check", "test:format": "virmator format check", "test:lint": "virmator lint", "test:spelling": "virmator spellcheck", @@ -54,7 +55,9 @@ "@stylistic/eslint-plugin-ts": "^2.12.0", "@types/esprima": "^4.0.6", "@types/estree": "^1.0.6", + "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^8.18.0", + "c8": "^10.1.2", "cross-env": "^7.0.3", "cspell": "^8.16.1", "dependency-cruiser": "^16.8.0", @@ -68,12 +71,13 @@ "eslint-plugin-require-extensions": "^0.1.3", "eslint-plugin-sonarjs": "^3.0.1", "eslint-plugin-unicorn": "^56.0.1", + "istanbul-smart-text-reporter": "^1.1.5", "markdown-code-example-inserter": "^3.0.3", "npm-check-updates": "^17.1.11", - "prettier": "^3.4.2", + "prettier": "3.3.3", "prettier-plugin-interpolated-html-tags": "^2.0.0", "prettier-plugin-jsdoc": "^1.3.0", - "prettier-plugin-multiline-arrays": "./", + "prettier-plugin-multiline-arrays": "^3.0.6", "prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-packagejson": "^2.5.6", "prettier-plugin-sort-json": "^4.0.0", diff --git a/src/augments/array.ts b/src/augments/array.ts index f283ea8..8f1531c 100644 --- a/src/augments/array.ts +++ b/src/augments/array.ts @@ -24,7 +24,8 @@ export function extractTextBetweenRanges( extractedText += '\n'; for (let lineIndex = range.start.line + 1; lineIndex < range.end.line; lineIndex++) { - extractedText += input[lineIndex]; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + extractedText += input[lineIndex]!; extractedText += '\n'; } diff --git a/src/augments/doc.ts b/src/augments/doc.ts index e7de548..d64a90f 100644 --- a/src/augments/doc.ts +++ b/src/augments/doc.ts @@ -1,3 +1,4 @@ +import {stringify} from '@augment-vir/common'; import {Doc, doc} from 'prettier'; type NestedStringArray = (string | NestedStringArray)[]; @@ -9,16 +10,18 @@ const childProperties = [ 'parts', ] as const; -export function stringifyDoc(input: Doc, recursive = false): NestedStringArray { +export function stringifyDoc(input: Doc | null | undefined, recursive = false): NestedStringArray { if (typeof input === 'string' || !input) { - return [input]; + return [stringify(input)]; } else if (Array.isArray(input)) { return input.map((entry) => stringifyDoc(entry, recursive)); } else if (recursive) { const children = childProperties.reduce((accum: NestedStringArray, currentProperty) => { if (currentProperty in input) { - accum.push(`${currentProperty}:`); - accum.push(stringifyDoc((input as any)[currentProperty], recursive)); + accum.push( + `${currentProperty}:`, + stringifyDoc((input as any)[currentProperty], recursive), + ); } return accum; }, []); diff --git a/src/index.ts b/src/index.ts index 64c4054..66f6548 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,8 +9,8 @@ import { StringSupportOption, SupportOption, } from 'prettier'; -import {parsers as tsParsers} from 'prettier/plugins/typescript'; import {parsers as babelParsers} from 'prettier/plugins/babel'; +import {parsers as tsParsers} from 'prettier/plugins/typescript'; import {MultilineArrayOptions, defaultMultilineArrayOptions, optionHelp} from './options.js'; import {wrapParser} from './preprocessing.js'; import {multilineArrayPrinter} from './printer/multiline-array-printer.js'; @@ -62,6 +62,7 @@ export const defaultOptions: Partial & Required { @@ -74,13 +77,14 @@ export function wrapParser(originalParser: Parser, parserName: string) { const pluginsWithRelevantParsers = findPluginsByParserName(parserName, pluginsFromOptions); pluginsWithRelevantParsers.forEach((plugin) => { const currentParser = plugin.parsers?.[parserName]; - if (currentParser && - (plugin as {name?: string | undefined} | undefined)?.name?.includes( - 'prettier-plugin-sort-json', - ) - ) { - parserProxy.proxyModifier.addOverrideTarget(currentParser); - } + if ( + currentParser && + (plugin as {name?: string | undefined} | undefined)?.name?.includes( + 'prettier-plugin-sort-json', + ) + ) { + parserProxy.proxyModifier.addOverrideTarget(currentParser); + } }); const pluginsWithPreprocessor = pluginsWithRelevantParsers.filter( diff --git a/src/printer/comment-triggers.ts b/src/printer/comment-triggers.ts index ffc6535..8ed1cbc 100644 --- a/src/printer/comment-triggers.ts +++ b/src/printer/comment-triggers.ts @@ -100,7 +100,7 @@ function setCommentTriggers(rootNode: Node, debug: boolean): CommentTriggers { starterTriggers, ); - internalCommentTriggers.resets = internalCommentTriggers.resets.sort(); + internalCommentTriggers.resets.sort(); setResets(internalCommentTriggers); @@ -136,11 +136,6 @@ function setResets(internalCommentTriggers: InternalCommentTriggers): void { currentLineNumberStats.lineEnd = endLineNumber; }); } - const setWrapThresholdLineNumbers = getObjectTypedKeys( - internalCommentTriggers.setWrapThresholds, - ); - if (setWrapThresholdLineNumbers.length) { - } } function getWrapThreshold(commentText: string | undefined, nextOnly: boolean): number | undefined { diff --git a/src/printer/comments.ts b/src/printer/comments.ts index 7c424f7..835eb12 100644 --- a/src/printer/comments.ts +++ b/src/printer/comments.ts @@ -14,20 +14,13 @@ const commentTypes = [ ] as const; function isMaybeComment(input: any): input is Comment { - if (!input || typeof input !== 'object') { - return false; - } - if (!('type' in input)) { - return false; - } - if (!commentTypes.includes(input.type)) { - return false; - } - if (!('value' in input)) { - return false; - } - - return true; + return !( + !input || + typeof input !== 'object' || + !('type' in input) || + !commentTypes.includes(input.type) || + !('value' in input) + ); } export function extractComments(node: any): Comment[] { diff --git a/src/printer/insert-new-lines-into-arguments.ts b/src/printer/insert-new-lines-into-arguments.ts deleted file mode 100644 index c931c35..0000000 --- a/src/printer/insert-new-lines-into-arguments.ts +++ /dev/null @@ -1,157 +0,0 @@ -import {Doc, doc} from 'prettier'; -import {isDocCommand, stringifyDoc} from '../augments/doc.js'; -import {walkDoc} from './child-docs.js'; - -const nestingSyntaxOpen = '[{(`'; -const nestingSyntaxClose = ']})`'; - -const found = 'Found "(" but'; - -export function insertLinesIntoArguments( - inputDoc: Doc, - forceWrap: boolean, - lineCounts: number[], - wrapThreshold: number, - includesTrailingComma: boolean, - debug: boolean, -): Doc { - walkDoc(inputDoc, debug, (currentDoc, parentDocs, childIndex): boolean => { - const currentParent = parentDocs[0]; - const parentDoc = currentParent?.parent; - if (typeof currentDoc === 'string' && currentDoc.trim() === '(') { - const undoMutations: (() => void)[] = []; - let arrayChildCount = 0; - - if (!Array.isArray(parentDoc)) { - if (debug) { - console.error({brokenParent: parentDoc, currentDoc}); - } - throw new Error(`${found} parentDoc is not an array.`); - } - - if (debug) { - console.info({currentDoc, parentDoc}); - console.info(JSON.stringify(stringifyDoc(parentDoc, true), null, 4)); - } - - if (childIndex == undefined) { - throw new Error(`${found} childIndex is undefined`); - } - - const openingSiblingIndex = childIndex + 1; - // sibling to the '(' - const openingSibling = parentDoc[openingSiblingIndex]; - let findingSiblingChildren: doc.builders.Doc; - let codePath = ''; - if (isDocCommand(openingSibling)) { - // case 1. sibling is indent - if (isDocCommand(openingSibling) && openingSibling.type === 'indent') { - findingSiblingChildren = openingSibling.contents; - codePath = 'indent'; - } - // case 2. sibling is concat - else if (Array.isArray(openingSibling)) { - findingSiblingChildren = openingSibling; - codePath = 'concat'; - } - // case 3. sibling is group - else if (openingSibling.type === 'group') { - const originalBreakValue = openingSibling.break; - openingSibling.break = true; - undoMutations.push(() => { - openingSibling.break = originalBreakValue; - }); - findingSiblingChildren = openingSibling.contents; - codePath = 'group'; - } else { - throw new Error( - `${found} and sibling was doc command but didn't match expected types.`, - ); - } - } - // case 4. sibling is an array - else if (Array.isArray(openingSibling)) { - findingSiblingChildren = openingSibling; - codePath = 'array'; - } else if (openingSibling === '' && parentDoc[openingSiblingIndex + 1] === ')') { - // this is for just an empty call, like the parentheses here: () => {} - return false; - } else { - throw new Error(`${found} its sibling was not of an expected type`); - } - - if (!Array.isArray(findingSiblingChildren)) { - throw new TypeError(`${found} its sibling's children were not in an array.`); - } - const foundSiblingChildren = findingSiblingChildren; - - foundSiblingChildren.forEach((child, index) => { - if (isDocCommand(child) && child.type === 'line') { - foundSiblingChildren[index] = doc.builders.hardlineWithoutBreakParent; - undoMutations.push(() => { - foundSiblingChildren[index] = child; - }); - } else if ( - child && - typeof child === 'string' && - child !== ',' && - !nestingSyntaxClose.includes(child) - ) { - arrayChildCount++; - } else if (Array.isArray(child)) { - arrayChildCount++; - } - }); - - foundSiblingChildren.splice(0, 0, doc.builders.breakParent); - undoMutations.push(() => { - foundSiblingChildren.splice(0, 1); - }); - - if (arrayChildCount <= wrapThreshold && !lineCounts.length && !forceWrap) { - undoMutations.reverse().forEach((undoMutation) => { - undoMutation(); - }); - } else { - // foundSiblingChildren.push(',', doc.builders.hardline); - // parentDoc.forEach((docEntry, index) => { - // if (isDocCommand(docEntry)) { - // if (docEntry.type === 'line') { - // parentDoc[index] = doc.builders.hardlineWithoutBreakParent; - // } else if (docEntry.type === 'if-break') { - // parentDoc[index] = docEntry.breakContents; - // } - // } - // }); - // parentDoc.splice(openingSiblingIndex, 0, doc.builders.hardlineWithoutBreakParent); - // parentDoc.splice( - // 0, - // 0, - // doc.builders.breakParent, - // doc.builders.hardlineWithoutBreakParent, - // ); - // const grandparentDoc = parentDocs[1]?.parent; - // if (!grandparentDoc || typeof grandparentDoc === 'string') { - // throw new Error( - // `Invalid grandparentDoc value, these could not have had children.`, - // ); - // } - // walkDoc(grandparentDoc, debug, (grandparentInnerDoc) => { - // if (Array.isArray(grandparentInnerDoc)) { - // grandparentInnerDoc.splice(0, 0, doc.builders.breakParent); - // return false; - // } - // return true; - // }); - } - - // don't walk any deeper - return false; - } else if (debug) { - console.info({ignoring: currentDoc}); - } - - return true; - }); - return inputDoc; -} diff --git a/src/printer/insert-new-lines.ts b/src/printer/insert-new-lines.ts index b1ee946..635ae60 100644 --- a/src/printer/insert-new-lines.ts +++ b/src/printer/insert-new-lines.ts @@ -1,6 +1,6 @@ import {getObjectTypedKeys, stringify, Values, type AnyObject} from '@augment-vir/common'; import {AstPath, Doc, doc, ParserOptions} from 'prettier'; -import {isDocCommand, stringifyDoc} from '../augments/doc.js'; +import {isDocCommand} from '../augments/doc.js'; import {MultilineArrayOptions} from '../options.js'; import {walkDoc} from './child-docs.js'; import { @@ -30,10 +30,10 @@ function insertLinesIntoArray( if (typeof currentDoc === 'string' && currentDoc.trim() === '[') { const undoMutations: (() => void)[] = []; - let finalLineBreakExists = false; + let finalLineBreakExists = false as boolean; function undoAllMutations() { - undoMutations.reverse().forEach((undoMutation) => { + undoMutations.toReversed().forEach((undoMutation) => { undoMutation(); }); } @@ -47,7 +47,7 @@ function insertLinesIntoArray( if (debug) { console.info({currentDoc, parentDoc}); - console.info(JSON.stringify(stringifyDoc(parentDoc, true), null, 4)); + console.info(stringify(parentDoc)); } if (childIndex !== 0) { throw new Error(`${found} not at index 0 in its parent`); @@ -70,7 +70,9 @@ function insertLinesIntoArray( return false; } if (!isDocCommand(bracketSibling) || bracketSibling.type !== 'indent') { - throw new Error(`${found} its sibling was not an indent Doc.: ${bracketSibling}`); + throw new Error( + `${found} its sibling was not an indent Doc.: ${stringify(bracketSibling)}`, + ); } const indentContents = bracketSibling.contents; if (debug) { @@ -81,7 +83,7 @@ function insertLinesIntoArray( } if (indentContents.length < 2) { if (debug) { - console.error(JSON.stringify(stringifyDoc(indentContents, true), null, 4)); + console.error(stringify(indentContents)); } throw new Error(`${found} indent contents did not have at least 2 children`); } @@ -149,7 +151,7 @@ function insertLinesIntoArray( let arrayChildCount = 0; - let forceFinalLineBreakExists = false; + let forceFinalLineBreakExists = false as boolean; if (!finalLineBreakExists) { walkDoc( @@ -215,7 +217,8 @@ function insertLinesIntoArray( closingSibling && typeof closingSibling === 'object' && !Array.isArray(closingSibling) && - closingSibling.type === 'line' + closingSibling.type === 'line' && + !closingSibling.soft ) { if (debug) { console.info( @@ -402,9 +405,21 @@ function insertLinesIntoArray( } const closingBracketIndex: number = parentDoc.indexOf(']'); - parentDoc.splice(closingBracketIndex, 0, doc.builders.hardlineWithoutBreakParent); + const preBracketChild = parentDoc[closingBracketIndex - 1]; + if (isDocCommand(preBracketChild) && preBracketChild.type === 'line') { + parentDoc.splice(closingBracketIndex - 1, 1); + undoMutations.push(() => { + parentDoc.splice(closingBracketIndex - 1, 0, preBracketChild); + }); + } + + parentDoc.splice( + closingBracketIndex - 1, + 0, + doc.builders.hardlineWithoutBreakParent, + ); undoMutations.push(() => { - parentDoc.splice(closingBracketIndex, 1); + parentDoc.splice(closingBracketIndex - 1, 1); }); } @@ -419,6 +434,7 @@ function insertLinesIntoArray( ]), ); undoMutations.push(() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion indentContents[1] = oldIndentContentChild!; }); } else { @@ -447,6 +463,10 @@ function insertLinesIntoArray( return true; }); + if (debug) { + console.info('final doc:', stringify(inputDoc)); + } + // return what is input because we perform mutations on it return inputDoc; } @@ -460,7 +480,9 @@ function getLatestSetValue( .reduce( (closestKey, currentKey): keyof T => { if (Number(currentKey) < currentLine) { - const currentData = triggers[currentKey]; + const currentData = triggers[currentKey] as + | CommentTriggerWithEnding[keyof T] + | undefined; if (currentData && currentData.lineEnd > currentLine) { return currentKey; diff --git a/src/printer/multiline-array-printer.ts b/src/printer/multiline-array-printer.ts index 2fb20d1..1745637 100644 --- a/src/printer/multiline-array-printer.ts +++ b/src/printer/multiline-array-printer.ts @@ -1,3 +1,4 @@ +import type {AnyFunction} from '@augment-vir/common'; import {Node} from 'estree'; import {AstPath, ParserOptions, Printer} from 'prettier'; import {MultilineArrayOptions, envDebugKey, fillInOptions} from '../options.js'; @@ -50,7 +51,7 @@ function wrapInOriginalPrinterCall( printerProp = (printerProp as any)[subProperty]; } try { - return (printerProp as Function | undefined)?.apply(thisParent, args); + return (printerProp as AnyFunction | undefined)?.apply(thisParent, args); } catch (error) { const newError = new Error( `Failed to wrap JS printer call for property "${property}" ${ @@ -84,8 +85,7 @@ const handleComments: Printer['handleComments'] = { /** This is a proxy because the original printer is only set at run time. */ export const multilineArrayPrinter = new Proxy>({} as Printer, { get: (target, property: keyof Printer) => { - // the avoidAstMutation property is not defined in the types - // @ts-expect-error + // @ts-expect-error: the avoidAstMutation property is not defined in the types if (property === 'experimentalFeatures') { return { avoidAstMutation: true, diff --git a/src/printer/supported-node-types.ts b/src/printer/supported-node-types.ts index d9278a6..9db1f86 100644 --- a/src/printer/supported-node-types.ts +++ b/src/printer/supported-node-types.ts @@ -16,4 +16,3 @@ string[] => input)([ export function isArrayLikeNode(node: Node): node is ArrayLikeNode { return arrayLikeNodeTypes.includes(node.type); } - diff --git a/src/printer/trailing-comma.ts b/src/printer/trailing-comma.ts index ceb261f..e72fcc7 100644 --- a/src/printer/trailing-comma.ts +++ b/src/printer/trailing-comma.ts @@ -5,6 +5,7 @@ export function containsTrailingComma( nodeLocation: BaseNode['loc'], children: (BaseNode | null)[], originalLines: string[], + // eslint-disable-next-line @typescript-eslint/no-unused-vars debug: boolean, ): boolean { const lastElement = children[children.length - 1]; diff --git a/src/readme-examples/prettier-options.example.ts b/src/readme-examples/prettier-options.example.ts index b7b5ae1..7b0ca95 100644 --- a/src/readme-examples/prettier-options.example.ts +++ b/src/readme-examples/prettier-options.example.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [ 'prettier-plugin-multiline-arrays', ], diff --git a/src/test/babel-ts.test.ts b/src/test/babel-ts.test.ts index 50e0204..7387f36 100644 --- a/src/test/babel-ts.test.ts +++ b/src/test/babel-ts.test.ts @@ -1,6 +1,6 @@ import {describe} from '@augment-vir/test'; import {runTests} from './run-tests.mock.js'; -import {typescriptTests} from './typescript-tests.js'; +import {typescriptTests} from './typescript-tests.mock.js'; describe('babel-ts multiline array formatting', () => { runTests('.ts', typescriptTests, 'babel-ts'); diff --git a/src/test/json.test.ts b/src/test/json.test.ts index 28110b3..224b6f6 100644 --- a/src/test/json.test.ts +++ b/src/test/json.test.ts @@ -5,7 +5,6 @@ import {MultilineArrayTest, runTests} from './run-tests.mock.js'; const jsonTests: MultilineArrayTest[] = [ { it: 'formats ending array correctly', - skip: true, code: ` { "files": [], diff --git a/src/test/run-tests.mock.ts b/src/test/run-tests.mock.ts index 3f67fa7..b0e63a2 100644 --- a/src/test/run-tests.mock.ts +++ b/src/test/run-tests.mock.ts @@ -40,10 +40,14 @@ let forced = false; let allPassed = true; function removeIndent(input: string): string { - return input - .replace(/^\s*\n\s*/, '') - .replace(/\n {12}/g, '\n') - .replace(/\n\s+$/, '\n'); + return ( + input + .replace(/^\s*\n\s*/, '') + .replace(/\n {12}/g, '\n') + // this is only used for tests + // eslint-disable-next-line sonarjs/slow-regex + .replace(/\n\s+$/, '\n') + ); } export function runTests(extension: string, tests: MultilineArrayTest[], parser: string) { diff --git a/src/test/typescript-tests.ts b/src/test/typescript-tests.mock.ts similarity index 97% rename from src/test/typescript-tests.ts rename to src/test/typescript-tests.mock.ts index bf097da..a8d09a7 100644 --- a/src/test/typescript-tests.ts +++ b/src/test/typescript-tests.mock.ts @@ -931,8 +931,20 @@ export const typescriptTests: MultilineArrayTest[] = [ `, }, { - it: 'does not add an extra new line when commas are turned off', - skip: true, + it: 'handles as const with trailing commas', + code: ` + function derp() { + return [ + { + operation: 'update', + content: 'text', + } as const, + ]; + } + `, + }, + { + it: 'handles as const without trailing commas', code: ` function derp() { return [ @@ -947,9 +959,35 @@ export const typescriptTests: MultilineArrayTest[] = [ trailingComma: 'none', }, }, + { + it: 'handles array ending with trailing commas', + code: ` + const derp = { + files: [], + references: [ + {path: './tsconfig.app.json'}, + {path: './tsconfig.node.json'}, + ], + }; + `, + }, + { + it: 'handles array ending without trailing commas', + code: ` + const derp = { + files: [], + references: [ + {path: './tsconfig.app.json'}, + {path: './tsconfig.node.json'} + ] + }; + `, + options: { + trailingComma: 'none', + }, + }, { it: 'formats a map correctly without commas', - skip: true, code: ` const array = [ 1, diff --git a/src/test/typescript.test.ts b/src/test/typescript.test.ts index 1c7d27c..f9f656a 100644 --- a/src/test/typescript.test.ts +++ b/src/test/typescript.test.ts @@ -1,6 +1,6 @@ import {describe} from '@augment-vir/test'; import {runTests} from './run-tests.mock.js'; -import {typescriptTests} from './typescript-tests.js'; +import {typescriptTests} from './typescript-tests.mock.js'; describe('typescript multiline array formatting', () => { runTests('.ts', typescriptTests, 'typescript'); diff --git a/todo.md b/todo.md index e315555..b752241 100644 --- a/todo.md +++ b/todo.md @@ -1 +1 @@ -- make sure README link to prettier config is valid +- make sure README link to prettier config is valid