Skip to content

Commit 6a4e2c5

Browse files
committed
chore: upgrade to Prettier v3
1 parent 4dc7caa commit 6a4e2c5

File tree

4 files changed

+44
-89
lines changed

4 files changed

+44
-89
lines changed

package-lock.json

+21-73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"eslint-plugin-jest": "^27.2.1",
7575
"eslint-plugin-jest-formatting": "^3.1.0",
7676
"eslint-plugin-node": "^11.1.0",
77-
"eslint-plugin-prettier": "^4.2.1",
7877
"eslint-plugin-promise": "^6.1.1",
7978
"eslint-remote-tester": "^3.0.0",
8079
"eslint-remote-tester-repositories": "^1.0.1",
@@ -83,7 +82,7 @@
8382
"jest": "^28.1.3",
8483
"lint-staged": "^13.2.1",
8584
"npm-run-all": "^4.1.5",
86-
"prettier": "2.8.7",
85+
"prettier": "^3.3.3",
8786
"semantic-release": "^19.0.5",
8887
"ts-node": "^10.9.1",
8988
"typescript": "^5.0.4"

tools/generate-configs/index.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { LinterConfig, writeConfig } from './utils';
1111
const RULE_NAME_PREFIX = 'testing-library/';
1212

1313
const getRecommendedRulesForTestingFramework = (
14-
framework: SupportedTestingFramework
14+
framework: SupportedTestingFramework,
1515
): Record<string, TSESLint.Linter.RuleEntry> =>
1616
Object.entries(rules)
1717
.filter(
@@ -20,7 +20,7 @@ const getRecommendedRulesForTestingFramework = (
2020
{
2121
meta: { docs },
2222
},
23-
]) => Boolean(docs.recommendedConfig[framework])
23+
]) => Boolean(docs.recommendedConfig[framework]),
2424
)
2525
.reduce((allRules, [ruleName, { meta }]) => {
2626
const name = `${RULE_NAME_PREFIX}${ruleName}`;
@@ -32,11 +32,16 @@ const getRecommendedRulesForTestingFramework = (
3232
};
3333
}, {});
3434

35-
SUPPORTED_TESTING_FRAMEWORKS.forEach((framework) => {
36-
const specificFrameworkConfig: LinterConfig = {
37-
plugins: ['testing-library'],
38-
rules: getRecommendedRulesForTestingFramework(framework),
39-
};
35+
(async () => {
36+
for (const framework of SUPPORTED_TESTING_FRAMEWORKS) {
37+
const specificFrameworkConfig: LinterConfig = {
38+
plugins: ['testing-library'],
39+
rules: getRecommendedRulesForTestingFramework(framework),
40+
};
4041

41-
writeConfig(specificFrameworkConfig, framework);
42+
await writeConfig(specificFrameworkConfig, framework);
43+
}
44+
})().catch((error) => {
45+
console.error(error);
46+
process.exitCode = 1;
4247
});

tools/generate-configs/utils.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { writeFileSync } from 'fs';
1+
import { writeFile } from 'fs/promises';
22
import { resolve } from 'path';
33

44
import { type TSESLint } from '@typescript-eslint/utils';
55
import { format, resolveConfig } from 'prettier';
66

7-
const prettierConfig = resolveConfig.sync(__dirname);
7+
const prettierConfig = resolveConfig(__dirname);
88

99
export type LinterConfig = TSESLint.Linter.Config;
1010

@@ -20,14 +20,17 @@ const addAutoGeneratedComment = (code: string) =>
2020
/**
2121
* Helper function writes configuration.
2222
*/
23-
export const writeConfig = (config: LinterConfig, configName: string): void => {
23+
export const writeConfig = async (
24+
config: LinterConfig,
25+
configName: string,
26+
): Promise<void> => {
2427
// note: we use `export =` because ESLint will import these configs via a commonjs import
2528
const code = `export = ${JSON.stringify(config)};`;
26-
const configStr = format(addAutoGeneratedComment(code), {
29+
const configStr = await format(addAutoGeneratedComment(code), {
2730
parser: 'typescript',
28-
...prettierConfig,
31+
...(await prettierConfig),
2932
});
3033
const filePath = resolve(__dirname, `../../lib/configs/${configName}.ts`);
3134

32-
writeFileSync(filePath, configStr);
35+
await writeFile(filePath, configStr);
3336
};

0 commit comments

Comments
 (0)