1 | const { realpathSync } = require("node:fs");
|
2 | const { sync: readPackage } = require("read-pkg-up");
|
3 | const presentRulesOnly = require("./tools/presentRulesOnly");
|
4 |
|
5 | const { packageJson } = readPackage({ cwd: realpathSync(process.cwd()) });
|
6 | const hasIn = (key, name) => {
|
7 | for (const x in packageJson[key] || {}) {
|
8 | if (x === name) return true;
|
9 | }
|
10 | return false;
|
11 | };
|
12 | const keys = ["dependencies", "devDependencies", "peerDependencies"];
|
13 | const hasInDeps = (name) => keys.some((k) => hasIn(k, name));
|
14 |
|
15 | module.exports = {
|
16 | extends: ["./", hasInDeps("react") && "./react"].filter(Boolean),
|
17 | overrides: [
|
18 | hasInDeps("jest") && {
|
19 | files: [
|
20 | "*.{test,spec}.{js,ts,jsx,tsx}",
|
21 | "**/__tests__/**/*.{js,ts,jsx,tsx}",
|
22 | ],
|
23 | extends: "./jest",
|
24 | },
|
25 | hasInDeps("typescript") && {
|
26 | files: ["*.{ts,tsx}"],
|
27 | extends: "./typescript-without-type",
|
28 | },
|
29 | hasInDeps("jest") &&
|
30 | hasInDeps("typescript") && {
|
31 | files: [
|
32 | "*.{test,spec}.{js,ts,jsx,tsx}",
|
33 | "**/__tests__/**/*.{js,ts,jsx,tsx}",
|
34 | ],
|
35 | extends: "./jest-and-typescript",
|
36 | },
|
37 | ].filter(Boolean),
|
38 | };
|
39 |
|
40 | presentRulesOnly.showAbsence();
|