UNPKG

1.17 kBJavaScriptView Raw
1const { realpathSync } = require("node:fs");
2const { sync: readPackage } = require("read-pkg-up");
3const presentRulesOnly = require("./tools/presentRulesOnly");
4
5const { packageJson } = readPackage({ cwd: realpathSync(process.cwd()) });
6const hasIn = (key, name) => {
7 for (const x in packageJson[key] || {}) {
8 if (x === name) return true;
9 }
10 return false;
11};
12const keys = ["dependencies", "devDependencies", "peerDependencies"];
13const hasInDeps = (name) => keys.some((k) => hasIn(k, name));
14
15module.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
40presentRulesOnly.showAbsence();