From 59f7669c7dd39936fb6b94e08c3c015ff01f6600 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Apr 2023 11:06:53 +0800 Subject: [PATCH 01/16] Upgrade Prettier to v3 --- package.json | 2 +- packages/babel-plugin-jest-hoist/package.json | 3 +-- packages/jest-snapshot/package.json | 2 +- scripts/build.mjs | 10 ++++++---- scripts/bundleTs.mjs | 4 ++-- yarn.lock | 18 +++++++++++++----- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 98c93623dd8d..c4206d07182b 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "node-notifier": "^10.0.0", "p-limit": "^3.1.0", "pkg-dir": "^5.0.0", - "prettier": "^2.1.1", + "prettier": "3.0.0-alpha.11", "promise": "^8.0.2", "read-pkg": "^5.2.0", "resolve": "^1.20.0", diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index 3698c80ff7a9..fb15696e98e6 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -31,9 +31,8 @@ "@babel/preset-typescript": "^7.0.0", "@types/babel__template": "^7.0.2", "@types/node": "*", - "@types/prettier": "^2.1.5", "babel-plugin-tester": "^11.0.2", - "prettier": "^2.1.1" + "prettier": "3.0.0-alpha.11" }, "publishConfig": { "access": "public" diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index b5b1af95738f..de848e69fcce 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -50,7 +50,7 @@ "@types/semver": "^7.1.0", "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", - "prettier": "^2.1.1", + "prettier": "3.0.0-alpha.11", "tsd-lite": "^0.7.0" }, "engines": { diff --git a/scripts/build.mjs b/scripts/build.mjs index 50dc12493c66..935370eb772d 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -42,7 +42,7 @@ const IGNORE_PATTERN = '**/__{tests,mocks}__/**'; const INLINE_REQUIRE_EXCLUDE_LIST = /packages\/expect|(jest-(circus|diff|get-type|jasmine2|matcher-utils|message-util|regex-util|snapshot))|pretty-format\//; -const prettierConfig = prettier.resolveConfig.sync( +const prettierConfig = await prettier.resolveConfig( fileURLToPath(import.meta.url), ); prettierConfig.trailingComma = 'none'; @@ -76,7 +76,7 @@ function buildNodePackage({packageDir, pkg}) { process.stdout.write(`${OK}\n`); } -function buildFile(file, silent) { +async function buildFile(file, silent) { const destPath = getBuildPath(file, BUILD_DIR); if (micromatch.isMatch(file, IGNORE_PATTERN)) { @@ -131,7 +131,7 @@ function buildFile(file, silent) { } const transformed = babel.transformFileSync(file, options).code; - const prettyCode = prettier.format(transformed, prettierConfig); + const prettyCode = await prettier.format(transformed, prettierConfig); fs.writeFileSync(destPath, prettyCode); @@ -150,7 +150,9 @@ function buildFile(file, silent) { const files = process.argv.slice(2); if (files.length) { - files.forEach(file => buildFile(file)); + for (const file of files) { + await buildFile(file); + } } else { const packages = getPackages(); process.stdout.write(chalk.inverse(' Building packages \n')); diff --git a/scripts/bundleTs.mjs b/scripts/bundleTs.mjs index 34789d6c0528..526814312ac0 100644 --- a/scripts/bundleTs.mjs +++ b/scripts/bundleTs.mjs @@ -20,7 +20,7 @@ import prettier from 'prettier'; import rimraf from 'rimraf'; import {getPackages} from './buildUtils.mjs'; -const prettierConfig = prettier.resolveConfig.sync( +const prettierConfig = await prettier.resolveConfig( fileURLToPath(import.meta.url).replace(/\.js$/, '.d.ts'), ); @@ -194,7 +194,7 @@ await Promise.all( ...definitionFile.split(copyrightSnippet), ].join('\n'); - const formattedContent = prettier.format(definitionFile, { + const formattedContent = await prettier.format(definitionFile, { ...prettierConfig, filepath, }); diff --git a/yarn.lock b/yarn.lock index 38d678d30b07..8d5f129c7b43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2886,7 +2886,7 @@ __metadata: node-notifier: ^10.0.0 p-limit: ^3.1.0 pkg-dir: ^5.0.0 - prettier: ^2.1.1 + prettier: 3.0.0-alpha.11 promise: ^8.0.2 read-pkg: ^5.2.0 resolve: ^1.20.0 @@ -6317,9 +6317,8 @@ __metadata: "@types/babel__template": ^7.0.2 "@types/babel__traverse": ^7.0.6 "@types/node": "*" - "@types/prettier": ^2.1.5 babel-plugin-tester: ^11.0.2 - prettier: ^2.1.1 + prettier: 3.0.0-alpha.11 languageName: unknown linkType: soft @@ -13201,7 +13200,7 @@ __metadata: jest-message-util: "workspace:^" jest-util: "workspace:^" natural-compare: ^1.4.0 - prettier: ^2.1.1 + prettier: 3.0.0-alpha.11 pretty-format: "workspace:^" semver: ^7.3.5 tsd-lite: ^0.7.0 @@ -17194,7 +17193,16 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.1.1, prettier@npm:^2.8.3": +"prettier@npm:3.0.0-alpha.11": + version: 3.0.0-alpha.11 + resolution: "prettier@npm:3.0.0-alpha.11" + bin: + prettier: bin/prettier.cjs + checksum: ce0a252201cc3758825a0e03d895bd88c876daf6cc9aab1365ef3164075807535146ad3d338582f652337d23914480fac309d84b3558f9576b6d2bd8bdbed57b + languageName: node + linkType: hard + +"prettier@npm:^2.8.3": version: 2.8.7 resolution: "prettier@npm:2.8.7" bin: From 926d3b01e0160d3eed66b4af88ed812b5234bede Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Apr 2023 11:16:53 +0800 Subject: [PATCH 02/16] Fix build script --- scripts/build.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 935370eb772d..55b6faac3db2 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -24,7 +24,7 @@ import chalk from 'chalk'; import glob from 'glob'; import fs from 'graceful-fs'; import micromatch from 'micromatch'; -import prettier from 'prettier'; +import * as prettier from 'prettier'; import transformOptions from '../babel.config.js'; import { OK, From 5d97b956482214e235bc43f92f231cb4703c7199 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Apr 2023 11:30:18 +0800 Subject: [PATCH 03/16] Fix build script --- scripts/build.mjs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 55b6faac3db2..aead3c9531d0 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -60,13 +60,15 @@ function getBuildPath(file, buildFolder) { return path.resolve(pkgBuildPath, relativeToSrcPath).replace(/\.ts$/, '.js'); } -function buildNodePackage({packageDir, pkg}) { +async function buildNodePackage({packageDir, pkg}) { const srcDir = path.resolve(packageDir, SRC_DIR); const files = glob.sync('**/*', {absolute: true, cwd: srcDir, nodir: true}); process.stdout.write(adjustToTerminalWidth(`${pkg.name}\n`)); - files.forEach(file => buildFile(file, true)); + for (const file of files) { + await buildFile(file); + } assert.ok( fs.existsSync(path.resolve(packageDir, pkg.main)), @@ -156,5 +158,7 @@ if (files.length) { } else { const packages = getPackages(); process.stdout.write(chalk.inverse(' Building packages \n')); - packages.forEach(buildNodePackage); + for (const pkg of packages) { + await buildNodePackage(pkg); + } } From 8c3a3a1f199a96610c6a0ebbdd89c9fc82d877aa Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 5 Jul 2023 15:34:30 +0200 Subject: [PATCH 04/16] stable --- package.json | 2 +- packages/babel-plugin-jest-hoist/package.json | 2 +- packages/jest-snapshot/package.json | 2 +- yarn.lock | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 2c65f52cee50..9ae002532b6a 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "node-notifier": "^10.0.0", "p-limit": "^3.1.0", "pkg-dir": "^5.0.0", - "prettier": "3.0.0-alpha.11", + "prettier": "3.0.0", "promise": "^8.0.2", "read-pkg": "^5.2.0", "resolve": "^1.20.0", diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index fb15696e98e6..d9a626ff302c 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -32,7 +32,7 @@ "@types/babel__template": "^7.0.2", "@types/node": "*", "babel-plugin-tester": "^11.0.2", - "prettier": "3.0.0-alpha.11" + "prettier": "3.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index 043cfe2af3aa..8fbb75488fae 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -50,7 +50,7 @@ "@types/semver": "^7.1.0", "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", - "prettier": "3.0.0-alpha.11", + "prettier": "3.0.0", "tsd-lite": "^0.7.0" }, "engines": { diff --git a/yarn.lock b/yarn.lock index 129d28c52541..a2c7c9f28521 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2900,7 +2900,7 @@ __metadata: node-notifier: ^10.0.0 p-limit: ^3.1.0 pkg-dir: ^5.0.0 - prettier: 3.0.0-alpha.11 + prettier: 3.0.0 promise: ^8.0.2 read-pkg: ^5.2.0 resolve: ^1.20.0 @@ -6302,7 +6302,7 @@ __metadata: "@types/babel__traverse": ^7.0.6 "@types/node": "*" babel-plugin-tester: ^11.0.2 - prettier: 3.0.0-alpha.11 + prettier: 3.0.0 languageName: unknown linkType: soft @@ -12999,7 +12999,7 @@ __metadata: jest-message-util: "workspace:^" jest-util: "workspace:^" natural-compare: ^1.4.0 - prettier: 3.0.0-alpha.11 + prettier: 3.0.0 pretty-format: "workspace:^" semver: ^7.5.3 tsd-lite: ^0.7.0 @@ -16915,12 +16915,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.0.0-alpha.11": - version: 3.0.0-alpha.11 - resolution: "prettier@npm:3.0.0-alpha.11" +"prettier@npm:3.0.0": + version: 3.0.0 + resolution: "prettier@npm:3.0.0" bin: prettier: bin/prettier.cjs - checksum: ce0a252201cc3758825a0e03d895bd88c876daf6cc9aab1365ef3164075807535146ad3d338582f652337d23914480fac309d84b3558f9576b6d2bd8bdbed57b + checksum: 6a832876a1552dc58330d2467874e5a0b46b9ccbfc5d3531eb69d15684743e7f83dc9fbd202db6270446deba9c82b79d24383d09924c462b457136a759425e33 languageName: node linkType: hard From 1043a468c7d908b01250a574bbbbcd53388c7aca Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 7 Jul 2023 16:08:22 +0200 Subject: [PATCH 05/16] do not bump version in packages --- package.json | 2 +- packages/babel-plugin-jest-hoist/package.json | 3 ++- packages/jest-snapshot/package.json | 2 +- yarn.lock | 26 +++++++++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 9ae002532b6a..e63a9f3320d0 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "node-notifier": "^10.0.0", "p-limit": "^3.1.0", "pkg-dir": "^5.0.0", - "prettier": "3.0.0", + "prettier": "^3.0.0", "promise": "^8.0.2", "read-pkg": "^5.2.0", "resolve": "^1.20.0", diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index d9a626ff302c..3698c80ff7a9 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -31,8 +31,9 @@ "@babel/preset-typescript": "^7.0.0", "@types/babel__template": "^7.0.2", "@types/node": "*", + "@types/prettier": "^2.1.5", "babel-plugin-tester": "^11.0.2", - "prettier": "3.0.0" + "prettier": "^2.1.1" }, "publishConfig": { "access": "public" diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index cba139cca27e..010459dbd2bc 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -50,7 +50,7 @@ "@types/semver": "^7.1.0", "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", - "prettier": "3.0.0", + "prettier": "^2.1.1", "tsd-lite": "^0.7.0" }, "engines": { diff --git a/yarn.lock b/yarn.lock index a2c7c9f28521..d0b87c0a49ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2900,7 +2900,7 @@ __metadata: node-notifier: ^10.0.0 p-limit: ^3.1.0 pkg-dir: ^5.0.0 - prettier: 3.0.0 + prettier: ^3.0.0 promise: ^8.0.2 read-pkg: ^5.2.0 resolve: ^1.20.0 @@ -6301,8 +6301,9 @@ __metadata: "@types/babel__template": ^7.0.2 "@types/babel__traverse": ^7.0.6 "@types/node": "*" + "@types/prettier": ^2.1.5 babel-plugin-tester: ^11.0.2 - prettier: 3.0.0 + prettier: ^2.1.1 languageName: unknown linkType: soft @@ -12999,7 +13000,7 @@ __metadata: jest-message-util: "workspace:^" jest-util: "workspace:^" natural-compare: ^1.4.0 - prettier: 3.0.0 + prettier: ^2.1.1 pretty-format: "workspace:^" semver: ^7.5.3 tsd-lite: ^0.7.0 @@ -16915,12 +16916,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.0.0": - version: 3.0.0 - resolution: "prettier@npm:3.0.0" +"prettier@npm:^2.1.1": + version: 2.8.8 + resolution: "prettier@npm:2.8.8" bin: - prettier: bin/prettier.cjs - checksum: 6a832876a1552dc58330d2467874e5a0b46b9ccbfc5d3531eb69d15684743e7f83dc9fbd202db6270446deba9c82b79d24383d09924c462b457136a759425e33 + prettier: bin-prettier.js + checksum: b49e409431bf129dd89238d64299ba80717b57ff5a6d1c1a8b1a28b590d998a34e083fa13573bc732bb8d2305becb4c9a4407f8486c81fa7d55100eb08263cf8 languageName: node linkType: hard @@ -16933,6 +16934,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.0.0": + version: 3.0.0 + resolution: "prettier@npm:3.0.0" + bin: + prettier: bin/prettier.cjs + checksum: 6a832876a1552dc58330d2467874e5a0b46b9ccbfc5d3531eb69d15684743e7f83dc9fbd202db6270446deba9c82b79d24383d09924c462b457136a759425e33 + languageName: node + linkType: hard + "pretty-bytes@npm:^5.3.0": version: 5.6.0 resolution: "pretty-bytes@npm:5.6.0" From b307fb0c2333ac67c79b38733c1bac80e0c194c9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 7 Jul 2023 16:09:46 +0200 Subject: [PATCH 06/16] remove default config --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index e63a9f3320d0..2f40749ae7c9 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,6 @@ "bracketSpacing": false, "proseWrap": "never", "singleQuote": true, - "trailingComma": "all", "arrowParens": "avoid", "overrides": [ { From 613b4c659695ef792f053d29b99472809aba9f0f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 7 Jul 2023 16:11:29 +0200 Subject: [PATCH 07/16] format files in parallel --- scripts/build.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index aead3c9531d0..0b508e2eb3af 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -66,9 +66,7 @@ async function buildNodePackage({packageDir, pkg}) { process.stdout.write(adjustToTerminalWidth(`${pkg.name}\n`)); - for (const file of files) { - await buildFile(file); - } + await Promise.all(files.map(file => buildFile(file))); assert.ok( fs.existsSync(path.resolve(packageDir, pkg.main)), From 3b7638a715610339c496eaa426fc735faab62743 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 8 Jul 2023 11:04:12 +0200 Subject: [PATCH 08/16] update eslint-plugin-prettier --- package.json | 2 +- yarn.lock | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 2f40749ae7c9..6f960ea109c1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-jsdoc": "^46.0.0", "eslint-plugin-local": "link:./.eslintplugin", "eslint-plugin-markdown": "^3.0.0", - "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-prettier": "^5.0.0-alpha.2", "execa": "^5.0.0", "find-process": "^1.4.1", "glob": "^8.0.0", diff --git a/yarn.lock b/yarn.lock index d0b87c0a49ab..14b15a21d2e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2873,7 +2873,7 @@ __metadata: eslint-plugin-jsdoc: ^46.0.0 eslint-plugin-local: "link:./.eslintplugin" eslint-plugin-markdown: ^3.0.0 - eslint-plugin-prettier: ^4.0.0 + eslint-plugin-prettier: ^5.0.0-alpha.2 execa: ^5.0.0 find-process: ^1.4.1 glob: ^8.0.0 @@ -9259,18 +9259,22 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-prettier@npm:^4.0.0": - version: 4.2.1 - resolution: "eslint-plugin-prettier@npm:4.2.1" +"eslint-plugin-prettier@npm:^5.0.0-alpha.2": + version: 5.0.0-alpha.2 + resolution: "eslint-plugin-prettier@npm:5.0.0-alpha.2" dependencies: prettier-linter-helpers: ^1.0.0 + synckit: ^0.8.5 peerDependencies: - eslint: ">=7.28.0" - prettier: ">=2.0.0" + "@types/eslint": ">=8.0.0" + eslint: ">=8.0.0" + prettier: ">=3.0.0" peerDependenciesMeta: + "@types/eslint": + optional: true eslint-config-prettier: optional: true - checksum: b9e839d2334ad8ec7a5589c5cb0f219bded260839a857d7a486997f9870e95106aa59b8756ff3f37202085ebab658de382b0267cae44c3a7f0eb0bcc03a4f6d6 + checksum: 612798739d498244e16031b1c8cf4617db9c0526b134afea2e8b6960fcab6bcde403e2e60e3647854ebefc2374ce5ce6453cba89649a5bdf66ab9045beb4d666 languageName: node linkType: hard From 257e7a6df6a70f5f69fcb069f630755f598ac7b9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 8 Jul 2023 11:18:30 +0200 Subject: [PATCH 09/16] run eslint --fix --- .../__tests__/typescript.test.ts | 2 +- packages/expect/src/asymmetricMatchers.ts | 5 ++++- packages/expect/src/types.ts | 9 ++++---- .../jest-core/src/__tests__/watch.test.js | 2 +- .../lib/__tests__/logDebugMessages.test.ts | 2 +- packages/jest-core/src/watch.ts | 4 ++-- packages/jest-each/src/table/array.ts | 19 ++++++++++------- packages/jest-expect/src/types.ts | 4 +++- .../src/__tests__/reporter.test.ts | 2 +- packages/jest-mock/src/index.ts | 3 +-- packages/jest-types/src/Global.ts | 21 ++++++++++++++----- .../src/base/__tests__/BaseWorkerPool.test.ts | 20 +++++++++--------- 12 files changed, 56 insertions(+), 37 deletions(-) diff --git a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts index bc27a66d5bcf..64d7cec8c0ad 100644 --- a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts +++ b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts @@ -11,7 +11,7 @@ import {color} from '../entry'; import type {Color} from '../types'; -jest.mock('some-module', () => ({} as Partial<{}>), {virtual: true}); +jest.mock('some-module', () => ({}) as Partial<{}>, {virtual: true}); jest.mock('../entry', () => { const color: Color = 'blue'; diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index 1eb9c52fa66d..2ce48f4e53f1 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -69,7 +69,10 @@ export abstract class AsymmetricMatcher { $$typeof = Symbol.for('jest.asymmetricMatcher'); - constructor(protected sample: T, protected inverse = false) {} + constructor( + protected sample: T, + protected inverse = false, + ) {} protected getMatcherContext(): MatcherContext { return { diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 96e858dad93d..476f5cf80596 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -22,7 +22,8 @@ export type ExpectationResult = SyncExpectationResult | AsyncExpectationResult; export type MatcherFunctionWithContext< Context extends MatcherContext = MatcherContext, - Expected extends Array = [] /** TODO should be: extends Array = [] */, + Expected extends + Array = [] /** TODO should be: extends Array = [] */, > = ( this: Context, actual: unknown, @@ -99,9 +100,9 @@ export interface BaseExpect { } export type Expect = { - (actual: T): Matchers & - Inverse> & - PromiseMatchers; + ( + actual: T, + ): Matchers & Inverse> & PromiseMatchers; } & BaseExpect & AsymmetricMatchers & Inverse>; diff --git a/packages/jest-core/src/__tests__/watch.test.js b/packages/jest-core/src/__tests__/watch.test.js index 7f412e1561a3..20137d6bd2e2 100644 --- a/packages/jest-core/src/__tests__/watch.test.js +++ b/packages/jest-core/src/__tests__/watch.test.js @@ -630,7 +630,7 @@ describe('Watch mode flows', () => { }); it.each` - ok | option + ok | option ${'✔︎'} | ${'bail'} ${'✖︎'} | ${'changedFilesWithAncestor'} ${'✔︎'} | ${'changedSince'} diff --git a/packages/jest-core/src/lib/__tests__/logDebugMessages.test.ts b/packages/jest-core/src/lib/__tests__/logDebugMessages.test.ts index fa4c4910ad66..1b08341df2c7 100644 --- a/packages/jest-core/src/lib/__tests__/logDebugMessages.test.ts +++ b/packages/jest-core/src/lib/__tests__/logDebugMessages.test.ts @@ -18,7 +18,7 @@ const getOutputStream = (resolve: (message: string) => void) => write(message: string) { resolve(message); }, - } as NodeJS.WriteStream); + }) as NodeJS.WriteStream; it('prints the jest version', async () => { expect.assertions(1); diff --git a/packages/jest-core/src/watch.ts b/packages/jest-core/src/watch.ts index 5671e2b5be2b..60c39fd1744c 100644 --- a/packages/jest-core/src/watch.ts +++ b/packages/jest-core/src/watch.ts @@ -496,8 +496,8 @@ const checkForConflicts = ( .join(' and '); error = ` Watch plugins ${plugins} both attempted to register key ${chalk.bold.red( - `<${key}>`, - )}. + `<${key}>`, + )}. Please change the key configuration for one of the conflicting plugins to avoid overlap.`.trim(); } diff --git a/packages/jest-each/src/table/array.ts b/packages/jest-each/src/table/array.ts index 4a90b8a76d37..740a5a0abecd 100644 --- a/packages/jest-each/src/table/array.ts +++ b/packages/jest-each/src/table/array.ts @@ -60,16 +60,19 @@ const formatTitle = ( rowIndex: number, ): string => row - .reduce((formattedTitle, value) => { - const [placeholder] = getMatchingPlaceholders(formattedTitle); - const normalisedValue = normalisePlaceholderValue(value); - if (!placeholder) return formattedTitle; + .reduce( + (formattedTitle, value) => { + const [placeholder] = getMatchingPlaceholders(formattedTitle); + const normalisedValue = normalisePlaceholderValue(value); + if (!placeholder) return formattedTitle; - if (placeholder === PRETTY_PLACEHOLDER) - return interpolatePrettyPlaceholder(formattedTitle, normalisedValue); + if (placeholder === PRETTY_PLACEHOLDER) + return interpolatePrettyPlaceholder(formattedTitle, normalisedValue); - return util.format(formattedTitle, normalisedValue); - }, interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex)) + return util.format(formattedTitle, normalisedValue); + }, + interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex), + ) .replace(new RegExp(JEST_EACH_PLACEHOLDER_ESCAPE, 'g'), PLACEHOLDER_PREFIX); const normalisePlaceholderValue = (value: unknown) => diff --git a/packages/jest-expect/src/types.ts b/packages/jest-expect/src/types.ts index 35cd086ee94d..7cceee6d01b1 100644 --- a/packages/jest-expect/src/types.ts +++ b/packages/jest-expect/src/types.ts @@ -13,7 +13,9 @@ import type { } from 'jest-snapshot'; export type JestExpect = { - (actual: T): JestMatchers & + ( + actual: T, + ): JestMatchers & Inverse> & PromiseMatchers; // Duplicated due to https://github.com/microsoft/rushstack/issues/1709 diff --git a/packages/jest-jasmine2/src/__tests__/reporter.test.ts b/packages/jest-jasmine2/src/__tests__/reporter.test.ts index c5d2c29cd998..652bed3482af 100644 --- a/packages/jest-jasmine2/src/__tests__/reporter.test.ts +++ b/packages/jest-jasmine2/src/__tests__/reporter.test.ts @@ -24,7 +24,7 @@ describe('Jasmine2Reporter', () => { description: 'description', failedExpectations: [], fullName: name, - } as any as SpecResult); + }) as any as SpecResult; reporter.suiteStarted({description: 'parent'} as SuiteResult); reporter.suiteStarted({description: 'child'} as SuiteResult); reporter.specDone(makeSpec('spec 1')); diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 8989c5320bf3..25fbe03f69ff 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -743,8 +743,7 @@ export class ModuleMocker { } return finalReturnValue; - }, - metadata.length || 0); + }, metadata.length || 0); const f = this._createMockFunction(metadata, mockConstructor) as Mock; f._isMockFunction = true; diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index ea15a036913c..2fae1a2ffadc 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -57,35 +57,46 @@ export type EachTestFn = ( interface Each { // when the table is an array of object literals - >(table: ReadonlyArray): ( + >( + table: ReadonlyArray, + ): ( name: string | NameLike, fn: (arg: T, done: DoneFn) => ReturnType, timeout?: number, ) => void; // when the table is an array of tuples - ]>(table: ReadonlyArray): ( + ]>( + table: ReadonlyArray, + ): ( name: string | NameLike, fn: (...args: T) => ReturnType, timeout?: number, ) => void; // when the table is an array of arrays - >(table: ReadonlyArray): ( + >( + table: ReadonlyArray, + ): ( name: string | NameLike, fn: (...args: T) => ReturnType, timeout?: number, ) => void; // when the table is a tuple or array - (table: ReadonlyArray): ( + ( + table: ReadonlyArray, + ): ( name: string | NameLike, fn: (arg: T, done: DoneFn) => ReturnType, timeout?: number, ) => void; // when the table is a template literal - (strings: TemplateStringsArray, ...expressions: Array): ( + ( + strings: TemplateStringsArray, + ...expressions: Array + ): ( name: string | NameLike, fn: (arg: Record, done: DoneFn) => ReturnType, timeout?: number, diff --git a/packages/jest-worker/src/base/__tests__/BaseWorkerPool.test.ts b/packages/jest-worker/src/base/__tests__/BaseWorkerPool.test.ts index b5b83482d5fb..2b85ac18cc98 100644 --- a/packages/jest-worker/src/base/__tests__/BaseWorkerPool.test.ts +++ b/packages/jest-worker/src/base/__tests__/BaseWorkerPool.test.ts @@ -34,12 +34,12 @@ describe('BaseWorkerPool', () => { ({ forceExit: jest.fn(), getStderr: () => - ({once() {}, pipe() {}} as unknown as NodeJS.ReadStream), + ({once() {}, pipe() {}}) as unknown as NodeJS.ReadStream, getStdout: () => - ({once() {}, pipe() {}} as unknown as NodeJS.ReadStream), + ({once() {}, pipe() {}}) as unknown as NodeJS.ReadStream, send: jest.fn(), waitForExit: () => Promise.resolve(), - } as unknown as WorkerInterface), + }) as unknown as WorkerInterface, ); }); @@ -138,15 +138,15 @@ describe('BaseWorkerPool', () => { pipe(errStream: NodeJS.WritableStream) { err.push(errStream); }, - } as unknown as NodeJS.ReadableStream), + }) as unknown as NodeJS.ReadableStream, getStdout: () => ({ once() {}, pipe(outStream: NodeJS.WritableStream) { out.push(outStream); }, - } as unknown as NodeJS.ReadableStream), - } as WorkerInterface), + }) as unknown as NodeJS.ReadableStream, + }) as WorkerInterface, ); const farm = new MockWorkerPool('/tmp/baz.js', { @@ -181,7 +181,7 @@ describe('BaseWorkerPool', () => { getStderr: () => null, getStdout: () => null, send: () => null, - } as unknown as WorkerInterface), + }) as unknown as WorkerInterface, ); const farm = new MockWorkerPool('/tmp/baz.js', { @@ -225,7 +225,7 @@ describe('BaseWorkerPool', () => { getStdout: () => null, send: jest.fn(), waitForExit: () => Promise.resolve(), - } as unknown as WorkerInterface), + }) as unknown as WorkerInterface, ); const pool = new MockWorkerPool('/tmp/baz.js', { @@ -253,7 +253,7 @@ describe('BaseWorkerPool', () => { send: jest.fn(), waitForExit: () => new Promise(resolve => (worker0Exited = resolve)), - } as unknown as WorkerInterface), + }) as unknown as WorkerInterface, ).mockImplementation( () => ({ @@ -262,7 +262,7 @@ describe('BaseWorkerPool', () => { getStdout: () => null, send: jest.fn(), waitForExit: () => Promise.resolve(), - } as unknown as WorkerInterface), + }) as unknown as WorkerInterface, ); const pool = new MockWorkerPool('/tmp/baz.js', { From 5dcd2ebaf8580df31efb6155d71c7b70e52057ad Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 8 Jul 2023 11:19:04 +0200 Subject: [PATCH 10/16] Revert "remove default config" This reverts commit b307fb0c2333ac67c79b38733c1bac80e0c194c9. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6f960ea109c1..a01e5ad81981 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "bracketSpacing": false, "proseWrap": "never", "singleQuote": true, + "trailingComma": "all", "arrowParens": "avoid", "overrides": [ { From 5d96cfb0251e7b2dda3467f2ae7941c6b5fbb046 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 10 Jul 2023 08:57:08 +0200 Subject: [PATCH 11/16] set prettier path --- jest.config.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jest.config.mjs b/jest.config.mjs index 0044e3a87119..6a5795c6202d 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -8,6 +8,10 @@ import {createRequire} from 'module'; const require = createRequire(import.meta.url); +const jestSnapshotIndex = require.resolve('jest-snapshot'); +const requireFromSnapshot = createRequire(jestSnapshotIndex); +const prettierPath = requireFromSnapshot.resolve('prettier'); + /** @type {import('jest').Config} */ export default { collectCoverageFrom: [ @@ -31,6 +35,7 @@ export default { 'website/.*', 'e2e/runtime-internal-module-registry/__mocks__', ], + prettierPath, projects: ['', '/examples/*/'], snapshotFormat: { printBasicPrototype: true, From 9a21eb327aef109bebaf0bb4fbd29935a93820c0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 10 Jul 2023 09:02:22 +0200 Subject: [PATCH 12/16] dedupe --- yarn.lock | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/yarn.lock b/yarn.lock index 14b15a21d2e9..25990c735269 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16920,7 +16920,7 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.1.1": +"prettier@npm:^2.1.1, prettier@npm:^2.8.3": version: 2.8.8 resolution: "prettier@npm:2.8.8" bin: @@ -16929,15 +16929,6 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.8.3": - version: 2.8.7 - resolution: "prettier@npm:2.8.7" - bin: - prettier: bin-prettier.js - checksum: fdc8f2616f099f5f0d685907f4449a70595a0fc1d081a88919604375989e0d5e9168d6121d8cc6861f21990b31665828e00472544d785d5940ea08a17660c3a6 - languageName: node - linkType: hard - "prettier@npm:^3.0.0": version: 3.0.0 resolution: "prettier@npm:3.0.0" From 730209cd09eda4655c0789febc700b610cccf2a9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 10 Jul 2023 09:08:15 +0200 Subject: [PATCH 13/16] patch away prettier's types --- .../prettier-npm-3.0.0-7ffbcce680.patch | 1452 +++++++++++++++++ package.json | 2 +- yarn.lock | 11 +- 3 files changed, 1463 insertions(+), 2 deletions(-) create mode 100644 .yarn/patches/prettier-npm-3.0.0-7ffbcce680.patch diff --git a/.yarn/patches/prettier-npm-3.0.0-7ffbcce680.patch b/.yarn/patches/prettier-npm-3.0.0-7ffbcce680.patch new file mode 100644 index 000000000000..545184ae1bcc --- /dev/null +++ b/.yarn/patches/prettier-npm-3.0.0-7ffbcce680.patch @@ -0,0 +1,1452 @@ +diff --git a/doc.d.ts b/doc.d.ts +deleted file mode 100644 +index 84aff5462d22233be5f6a0f262d22803d846cb1b..0000000000000000000000000000000000000000 +--- a/doc.d.ts ++++ /dev/null +@@ -1,240 +0,0 @@ +-// https://github.com/prettier/prettier/blob/next/src/document/public.js +-export namespace builders { +- type DocCommand = +- | Align +- | BreakParent +- | Cursor +- | Fill +- | Group +- | IfBreak +- | Indent +- | IndentIfBreak +- | Label +- | Line +- | LineSuffix +- | LineSuffixBoundary +- | Trim; +- type Doc = string | Doc[] | DocCommand; +- +- interface Align { +- type: "align"; +- contents: Doc; +- n: number | string | { type: "root" }; +- } +- +- interface BreakParent { +- type: "break-parent"; +- } +- +- interface Cursor { +- type: "cursor"; +- placeholder: symbol; +- } +- +- interface Fill { +- type: "fill"; +- parts: Doc[]; +- } +- +- interface Group { +- type: "group"; +- contents: Doc; +- break: boolean; +- expandedStates: Doc[]; +- } +- +- interface HardlineWithoutBreakParent extends Line { +- hard: true; +- } +- +- interface IfBreak { +- type: "if-break"; +- breakContents: Doc; +- flatContents: Doc; +- } +- +- interface Indent { +- type: "indent"; +- contents: Doc; +- } +- +- interface IndentIfBreak { +- type: "indent-if-break"; +- } +- +- interface Label { +- type: "label"; +- } +- +- interface Line { +- type: "line"; +- soft?: boolean | undefined; +- hard?: boolean | undefined; +- literal?: boolean | undefined; +- } +- +- interface LineSuffix { +- type: "line-suffix"; +- contents: Doc; +- } +- +- interface LineSuffixBoundary { +- type: "line-suffix-boundary"; +- } +- +- interface LiterallineWithoutBreakParent extends Line { +- hard: true; +- literal: true; +- } +- +- type LiteralLine = [LiterallineWithoutBreakParent, BreakParent]; +- +- interface Softline extends Line { +- soft: true; +- } +- +- type Hardline = [HardlineWithoutBreakParent, BreakParent]; +- +- interface Trim { +- type: "trim"; +- } +- +- interface GroupOptions { +- shouldBreak?: boolean | undefined; +- id?: symbol | undefined; +- } +- +- function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc; +- +- /** @see [align](https://github.com/prettier/prettier/blob/main/commands.md#align) */ +- function align(widthOrString: Align["n"], doc: Doc): Align; +- +- /** @see [breakParent](https://github.com/prettier/prettier/blob/main/commands.md#breakparent) */ +- const breakParent: BreakParent; +- +- /** @see [conditionalGroup](https://github.com/prettier/prettier/blob/main/commands.md#conditionalgroup) */ +- function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group; +- +- /** @see [dedent](https://github.com/prettier/prettier/blob/main/commands.md#dedent) */ +- function dedent(doc: Doc): Align; +- +- /** @see [dedentToRoot](https://github.com/prettier/prettier/blob/main/commands.md#dedenttoroot) */ +- function dedentToRoot(doc: Doc): Align; +- +- /** @see [fill](https://github.com/prettier/prettier/blob/main/commands.md#fill) */ +- function fill(docs: Doc[]): Fill; +- +- /** @see [group](https://github.com/prettier/prettier/blob/main/commands.md#group) */ +- function group(doc: Doc, opts?: GroupOptions): Group; +- +- /** @see [hardline](https://github.com/prettier/prettier/blob/main/commands.md#hardline) */ +- const hardline: Hardline; +- +- /** @see [hardlineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */ +- const hardlineWithoutBreakParent: HardlineWithoutBreakParent; +- +- /** @see [ifBreak](https://github.com/prettier/prettier/blob/main/commands.md#ifbreak) */ +- function ifBreak( +- ifBreak: Doc, +- noBreak?: Doc, +- options?: { groupId?: symbol | undefined } +- ): IfBreak; +- +- /** @see [indent](https://github.com/prettier/prettier/blob/main/commands.md#indent) */ +- function indent(doc: Doc): Indent; +- +- /** @see [indentIfBreak](https://github.com/prettier/prettier/blob/main/commands.md#indentifbreak) */ +- function indentIfBreak( +- doc: Doc, +- opts: { groupId: symbol; negate?: boolean | undefined } +- ): IndentIfBreak; +- +- /** @see [join](https://github.com/prettier/prettier/blob/main/commands.md#join) */ +- function join(sep: Doc, docs: Doc[]): Doc[]; +- +- /** @see [label](https://github.com/prettier/prettier/blob/main/commands.md#label) */ +- function label(label: any | undefined, contents: Doc): Doc; +- +- /** @see [line](https://github.com/prettier/prettier/blob/main/commands.md#line) */ +- const line: Line; +- +- /** @see [lineSuffix](https://github.com/prettier/prettier/blob/main/commands.md#linesuffix) */ +- function lineSuffix(suffix: Doc): LineSuffix; +- +- /** @see [lineSuffixBoundary](https://github.com/prettier/prettier/blob/main/commands.md#linesuffixboundary) */ +- const lineSuffixBoundary: LineSuffixBoundary; +- +- /** @see [literalline](https://github.com/prettier/prettier/blob/main/commands.md#literalline) */ +- const literalline: LiteralLine; +- +- /** @see [literallineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */ +- const literallineWithoutBreakParent: LiterallineWithoutBreakParent; +- +- /** @see [markAsRoot](https://github.com/prettier/prettier/blob/main/commands.md#markasroot) */ +- function markAsRoot(doc: Doc): Align; +- +- /** @see [softline](https://github.com/prettier/prettier/blob/main/commands.md#softline) */ +- const softline: Softline; +- +- /** @see [trim](https://github.com/prettier/prettier/blob/main/commands.md#trim) */ +- const trim: Trim; +- +- /** @see [cursor](https://github.com/prettier/prettier/blob/main/commands.md#cursor) */ +- const cursor: Cursor; +-} +- +-export namespace printer { +- function printDocToString( +- doc: builders.Doc, +- options: Options +- ): { +- formatted: string; +- cursorNodeStart?: number | undefined; +- cursorNodeText?: string | undefined; +- }; +- interface Options { +- /** +- * Specify the line length that the printer will wrap on. +- * @default 80 +- */ +- printWidth: number; +- /** +- * Specify the number of spaces per indentation-level. +- * @default 2 +- */ +- tabWidth: number; +- /** +- * Indent lines with tabs instead of spaces +- * @default false +- */ +- useTabs?: boolean; +- parentParser?: string | undefined; +- __embeddedInHtml?: boolean | undefined; +- } +-} +- +-export namespace utils { +- function willBreak(doc: builders.Doc): boolean; +- function traverseDoc( +- doc: builders.Doc, +- onEnter?: (doc: builders.Doc) => void | boolean, +- onExit?: (doc: builders.Doc) => void, +- shouldTraverseConditionalGroups?: boolean +- ): void; +- function findInDoc( +- doc: builders.Doc, +- callback: (doc: builders.Doc) => T, +- defaultValue: T +- ): T; +- function mapDoc( +- doc: builders.Doc, +- callback: (doc: builders.Doc) => T +- ): T; +- function removeLines(doc: builders.Doc): builders.Doc; +- function stripTrailingHardline(doc: builders.Doc): builders.Doc; +- function replaceEndOfLine( +- doc: builders.Doc, +- replacement?: builders.Doc +- ): builders.Doc; +- function canBreak(doc: builders.Doc): boolean; +-} +diff --git a/index.d.ts b/index.d.ts +deleted file mode 100644 +index f2f5e910124ea1333cfadcab54f839987577ed4e..0000000000000000000000000000000000000000 +--- a/index.d.ts ++++ /dev/null +@@ -1,915 +0,0 @@ +-// Copied from `@types/prettier` +-// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/5bb07fc4b087cb7ee91084afa6fe750551a7bbb1/types/prettier/index.d.ts +- +-// Minimum TypeScript Version: 4.2 +- +-// Add `export {}` here to shut off automatic exporting from index.d.ts. There +-// are quite a few utility types here that don't need to be shipped with the +-// exported module. +-export {}; +- +-import { builders, printer, utils } from "./doc.js"; +- +-export namespace doc { +- export { builders, printer, utils }; +-} +- +-// This utility is here to handle the case where you have an explicit union +-// between string literals and the generic string type. It would normally +-// resolve out to just the string type, but this generic LiteralUnion maintains +-// the intellisense of the original union. +-// +-// It comes from this issue: microsoft/TypeScript#29729: +-// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227 +-export type LiteralUnion = +- | T +- | (Pick & { _?: never | undefined }); +- +-export type AST = any; +-export type Doc = doc.builders.Doc; +- +-// The type of elements that make up the given array T. +-type ArrayElement = T extends Array ? E : never; +- +-// A union of the properties of the given object that are arrays. +-type ArrayProperties = { +- [K in keyof T]: NonNullable extends any[] ? K : never; +-}[keyof T]; +- +-// A union of the properties of the given array T that can be used to index it. +-// If the array is a tuple, then that's going to be the explicit indices of the +-// array, otherwise it's going to just be number. +-type IndexProperties = IsTuple extends true +- ? Exclude["length"], T["length"]> +- : number; +- +-// Effectively performing T[P], except that it's telling TypeScript that it's +-// safe to do this for tuples, arrays, or objects. +-type IndexValue = T extends any[] +- ? P extends number +- ? T[P] +- : never +- : P extends keyof T +- ? T[P] +- : never; +- +-// Determines if an object T is an array like string[] (in which case this +-// evaluates to false) or a tuple like [string] (in which case this evaluates to +-// true). +-// eslint-disable-next-line @typescript-eslint/no-unused-vars +-type IsTuple = T extends [] +- ? true +- : T extends [infer First, ...infer Remain] +- ? IsTuple +- : false; +- +-type CallProperties = T extends any[] ? IndexProperties : keyof T; +-type IterProperties = T extends any[] +- ? IndexProperties +- : ArrayProperties; +- +-type CallCallback = (path: AstPath, index: number, value: any) => U; +-type EachCallback = ( +- path: AstPath>, +- index: number, +- value: any +-) => void; +-type MapCallback = ( +- path: AstPath>, +- index: number, +- value: any +-) => U; +- +-// https://github.com/prettier/prettier/blob/next/src/common/ast-path.js +-export class AstPath { +- constructor(value: T); +- +- get key(): string | null; +- get index(): number | null; +- get node(): T; +- get parent(): T | null; +- get grandparent(): T | null; +- get isInArray(): boolean; +- get siblings(): T[] | null; +- get next(): T | null; +- get previous(): T | null; +- get isFirst(): boolean; +- get isLast(): boolean; +- get isRoot(): boolean; +- get root(): T; +- get ancestors(): T[]; +- +- stack: T[]; +- +- callParent(callback: (path: this) => U, count?: number): U; +- +- /** +- * @deprecated Please use `AstPath#key` or `AstPath#index` +- */ +- getName(): PropertyKey | null; +- +- /** +- * @deprecated Please use `AstPath#node` or `AstPath#siblings` +- */ +- getValue(): T; +- +- getNode(count?: number): T | null; +- +- getParentNode(count?: number): T | null; +- +- match( +- ...predicates: Array< +- (node: any, name: string | null, number: number | null) => boolean +- > +- ): boolean; +- +- // For each of the tree walk functions (call, each, and map) this provides 5 +- // strict type signatures, along with a fallback at the end if you end up +- // calling more than 5 properties deep. This helps a lot with typing because +- // for the majority of cases you're calling fewer than 5 properties, so the +- // tree walk functions have a clearer understanding of what you're doing. +- // +- // Note that resolving these types is somewhat complicated, and it wasn't +- // even supported until TypeScript 4.2 (before it would just say that the +- // type instantiation was excessively deep and possibly infinite). +- +- call(callback: CallCallback): U; +- call>( +- callback: CallCallback, U>, +- prop1: P1 +- ): U; +- call>( +- callback: CallCallback, P2>, U>, +- prop1: P1, +- prop2: P2 +- ): U; +- call< +- U, +- P1 extends keyof T, +- P2 extends CallProperties, +- P3 extends CallProperties> +- >( +- callback: CallCallback< +- IndexValue, P2>, P3>, +- U +- >, +- prop1: P1, +- prop2: P2, +- prop3: P3 +- ): U; +- call< +- U, +- P1 extends keyof T, +- P2 extends CallProperties, +- P3 extends CallProperties>, +- P4 extends CallProperties, P3>> +- >( +- callback: CallCallback< +- IndexValue, P2>, P3>, P4>, +- U +- >, +- prop1: P1, +- prop2: P2, +- prop3: P3, +- prop4: P4 +- ): U; +- call( +- callback: CallCallback, +- prop1: P, +- prop2: P, +- prop3: P, +- prop4: P, +- ...props: P[] +- ): U; +- +- each(callback: EachCallback): void; +- each>( +- callback: EachCallback>, +- prop1: P1 +- ): void; +- each>( +- callback: EachCallback, P2>>, +- prop1: P1, +- prop2: P2 +- ): void; +- each< +- P1 extends keyof T, +- P2 extends IterProperties, +- P3 extends IterProperties> +- >( +- callback: EachCallback, P2>, P3>>, +- prop1: P1, +- prop2: P2, +- prop3: P3 +- ): void; +- each< +- P1 extends keyof T, +- P2 extends IterProperties, +- P3 extends IterProperties>, +- P4 extends IterProperties, P3>> +- >( +- callback: EachCallback< +- IndexValue, P2>, P3>, P4> +- >, +- prop1: P1, +- prop2: P2, +- prop3: P3, +- prop4: P4 +- ): void; +- each( +- callback: EachCallback, +- prop1: PropertyKey, +- prop2: PropertyKey, +- prop3: PropertyKey, +- prop4: PropertyKey, +- ...props: PropertyKey[] +- ): void; +- +- map(callback: MapCallback): U[]; +- map>( +- callback: MapCallback, U>, +- prop1: P1 +- ): U[]; +- map>( +- callback: MapCallback, P2>, U>, +- prop1: P1, +- prop2: P2 +- ): U[]; +- map< +- U, +- P1 extends keyof T, +- P2 extends IterProperties, +- P3 extends IterProperties> +- >( +- callback: MapCallback, P2>, P3>, U>, +- prop1: P1, +- prop2: P2, +- prop3: P3 +- ): U[]; +- map< +- U, +- P1 extends keyof T, +- P2 extends IterProperties, +- P3 extends IterProperties>, +- P4 extends IterProperties, P3>> +- >( +- callback: MapCallback< +- IndexValue, P2>, P3>, P4>, +- U +- >, +- prop1: P1, +- prop2: P2, +- prop3: P3, +- prop4: P4 +- ): U[]; +- map( +- callback: MapCallback, +- prop1: PropertyKey, +- prop2: PropertyKey, +- prop3: PropertyKey, +- prop4: PropertyKey, +- ...props: PropertyKey[] +- ): U[]; +-} +- +-/** @deprecated `FastPath` was renamed to `AstPath` */ +-export type FastPath = AstPath; +- +-export type BuiltInParser = (text: string, options?: any) => AST; +-export type BuiltInParserName = +- | "acorn" +- | "angular" +- | "babel-flow" +- | "babel-ts" +- | "babel" +- | "css" +- | "espree" +- | "flow" +- | "glimmer" +- | "graphql" +- | "html" +- | "json-stringify" +- | "json" +- | "json5" +- | "less" +- | "lwc" +- | "markdown" +- | "mdx" +- | "meriyah" +- | "scss" +- | "typescript" +- | "vue" +- | "yaml"; +-export type BuiltInParsers = Record; +- +-export type CustomParser = ( +- text: string, +- options: Options +-) => AST | Promise; +- +-/** +- * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettierrc.mjs`, `prettier.config.js`, `prettier.config.cjs`, `prettier.config.mjs` +- */ +-export interface Config extends Options { +- overrides?: Array<{ +- files: string | string[]; +- excludeFiles?: string | string[]; +- options?: Options; +- }>; +-} +- +-export interface Options extends Partial {} +- +-export interface RequiredOptions extends doc.printer.Options { +- /** +- * Print semicolons at the ends of statements. +- * @default true +- */ +- semi: boolean; +- /** +- * Use single quotes instead of double quotes. +- * @default false +- */ +- singleQuote: boolean; +- /** +- * Use single quotes in JSX. +- * @default false +- */ +- jsxSingleQuote: boolean; +- /** +- * Print trailing commas wherever possible. +- * @default "all" +- */ +- trailingComma: "none" | "es5" | "all"; +- /** +- * Print spaces between brackets in object literals. +- * @default true +- */ +- bracketSpacing: boolean; +- /** +- * Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being +- * alone on the next line (does not apply to self closing elements). +- * @default false +- */ +- bracketSameLine: boolean; +- /** +- * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line. +- * @default false +- * @deprecated use bracketSameLine instead +- */ +- jsxBracketSameLine: boolean; +- /** +- * Format only a segment of a file. +- * @default 0 +- */ +- rangeStart: number; +- /** +- * Format only a segment of a file. +- * @default Number.POSITIVE_INFINITY +- */ +- rangeEnd: number; +- /** +- * Specify which parser to use. +- */ +- parser: LiteralUnion | CustomParser; +- /** +- * Specify the input filepath. This will be used to do parser inference. +- */ +- filepath: string; +- /** +- * Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file. +- * This is very useful when gradually transitioning large, unformatted codebases to prettier. +- * @default false +- */ +- requirePragma: boolean; +- /** +- * Prettier can insert a special @format marker at the top of files specifying that +- * the file has been formatted with prettier. This works well when used in tandem with +- * the --require-pragma option. If there is already a docblock at the top of +- * the file then this option will add a newline to it with the @format marker. +- * @default false +- */ +- insertPragma: boolean; +- /** +- * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer. +- * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out. +- * @default "preserve" +- */ +- proseWrap: "always" | "never" | "preserve"; +- /** +- * Include parentheses around a sole arrow function parameter. +- * @default "always" +- */ +- arrowParens: "avoid" | "always"; +- /** +- * Provide ability to support new languages to prettier. +- */ +- plugins: Array; +- /** +- * How to handle whitespaces in HTML. +- * @default "css" +- */ +- htmlWhitespaceSensitivity: "css" | "strict" | "ignore"; +- /** +- * Which end of line characters to apply. +- * @default "lf" +- */ +- endOfLine: "auto" | "lf" | "crlf" | "cr"; +- /** +- * Change when properties in objects are quoted. +- * @default "as-needed" +- */ +- quoteProps: "as-needed" | "consistent" | "preserve"; +- /** +- * Whether or not to indent the code inside