@will-stone/eslint-config 11.0.2 → 11.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
1
  import { Linter } from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
+ /**
4
+ * This is a set of optional features that can be turned on.
5
+ */
3
6
  type Options = {
4
- readonly astro?: boolean;
5
- readonly jest?: boolean;
6
- readonly react?: boolean;
7
- readonly tailwind?: boolean;
8
- readonly typescript?: boolean | {
9
- /**
10
- * When this option is provided, type-aware rules will be enabled.
11
- * @see https://typescript-eslint.io/linting/typed-linting/
12
- */
13
- tsconfigPath?: string | readonly string[];
14
- };
15
- readonly vitest?: boolean;
7
+ astro?: boolean;
8
+ jest?: boolean;
9
+ react?: boolean;
10
+ tailwind?: {
11
+ config?: string;
12
+ cssFiles?: string[];
13
+ } | boolean;
14
+ typescript?: boolean;
15
+ vitest?: boolean;
16
16
  };
17
17
 
18
18
  /**
19
19
  * Construct an array of ESLint flat config items.
20
20
  */
21
- declare function factory(options?: Options): Linter.ConfigType[];
21
+ declare function config(options?: Options): Linter.ConfigType[];
22
22
 
23
- export { factory as default };
23
+ export { config as default };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import parserTypescript from "@typescript-eslint/parser";
3
3
  import parserAstro from "astro-eslint-parser";
4
4
  import pluginAstro from "eslint-plugin-astro";
5
- function astro() {
5
+ function astro(_options) {
6
6
  return [
7
7
  {
8
8
  files: ["**/*.astro"],
@@ -380,7 +380,7 @@ function ignores() {
380
380
  name: "will-stone/ignores"
381
381
  },
382
382
  {
383
- name: "will-stone/git-ignores",
383
+ name: "will-stone/git-ignore",
384
384
  ...gitignore({
385
385
  // Prevent throw if gitignore not found.
386
386
  strict: false
@@ -459,7 +459,7 @@ function imports() {
459
459
  // src/configs/jest.ts
460
460
  import pluginJest from "eslint-plugin-jest";
461
461
  import globals2 from "globals";
462
- function jest() {
462
+ function jest(_options) {
463
463
  return [
464
464
  {
465
465
  files: ["**/__mocks__/**/*", "**/*.{spec,test}.{js,cjs,mjs,jsx,ts,tsx}"],
@@ -604,7 +604,7 @@ import pluginJsxA11y from "eslint-plugin-jsx-a11y";
604
604
  import pluginReact from "eslint-plugin-react";
605
605
  import pluginReactHooks from "eslint-plugin-react-hooks";
606
606
  import globals4 from "globals";
607
- function react() {
607
+ function react(_options) {
608
608
  return [
609
609
  {
610
610
  files: ["**/*.{jsx,tsx}"],
@@ -902,7 +902,8 @@ function react() {
902
902
 
903
903
  // src/configs/tailwind.ts
904
904
  import pluginTailwind from "eslint-plugin-tailwindcss";
905
- function tailwind() {
905
+ function tailwind(rawOptions) {
906
+ const options = !rawOptions || rawOptions === true ? {} : rawOptions;
906
907
  return [
907
908
  {
908
909
  files: ["**/*.{jsx,tsx,astro}"],
@@ -916,6 +917,19 @@ function tailwind() {
916
917
  "tailwindcss/no-arbitrary-value": "off",
917
918
  "tailwindcss/no-contradicting-classname": "warn",
918
919
  "tailwindcss/no-custom-classname": "error"
920
+ },
921
+ settings: {
922
+ tailwindcss: {
923
+ config: options.config,
924
+ /**
925
+ * Default to no custom CSS files, due to performance issue with the
926
+ * plugin can be somewhat mitigated by setting this config to `[]` so
927
+ * that cssFiles do not need to be found automatically.
928
+ * @see https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/276
929
+ * @see https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/174
930
+ */
931
+ cssFiles: options.cssFiles || []
932
+ }
919
933
  }
920
934
  }
921
935
  ];
@@ -1321,7 +1335,7 @@ function unicorn() {
1321
1335
  // src/configs/vitest.ts
1322
1336
  import { fixupPluginRules as fixupPluginRules2 } from "@eslint/compat";
1323
1337
  import pluginVitest from "eslint-plugin-vitest";
1324
- function vitest() {
1338
+ function vitest(_options) {
1325
1339
  return [
1326
1340
  {
1327
1341
  files: ["**/*.{spec,test}.{js,cjs,mjs,jsx,ts,tsx}"],
@@ -1349,7 +1363,54 @@ function vitest() {
1349
1363
  ];
1350
1364
  }
1351
1365
 
1352
- // src/utils.ts
1366
+ // src/configs/index.ts
1367
+ var defaultConfigs = [
1368
+ { config: ignores, name: "Ignores" },
1369
+ { config: base, name: "Base" },
1370
+ { config: imports, name: "Imports" },
1371
+ { config: unicorn, name: "Unicorn" },
1372
+ { config: node, name: "Node" }
1373
+ ];
1374
+ var autoConfigs = [
1375
+ {
1376
+ config: astro,
1377
+ dep: "astro",
1378
+ name: "Astro.js",
1379
+ optionName: "astro"
1380
+ },
1381
+ {
1382
+ config: jest,
1383
+ dep: "jest",
1384
+ name: "Jest",
1385
+ optionName: "jest"
1386
+ },
1387
+ {
1388
+ config: react,
1389
+ dep: "react",
1390
+ name: "React",
1391
+ optionName: "react"
1392
+ },
1393
+ {
1394
+ config: tailwind,
1395
+ dep: "tailwindcss",
1396
+ name: "Tailwind",
1397
+ optionName: "tailwind"
1398
+ },
1399
+ {
1400
+ config: typescript,
1401
+ dep: "typescript",
1402
+ name: "Typescript",
1403
+ optionName: "typescript"
1404
+ },
1405
+ {
1406
+ config: vitest,
1407
+ dep: "vitest",
1408
+ name: "Vitest",
1409
+ optionName: "vitest"
1410
+ }
1411
+ ];
1412
+
1413
+ // src/utils/check-deps-exist.ts
1353
1414
  import { readFileSync } from "fs";
1354
1415
  import { globbySync } from "globby";
1355
1416
  function checkDepsExist(depNames) {
@@ -1359,6 +1420,9 @@ function checkDepsExist(depNames) {
1359
1420
  "!**/node_modules/**"
1360
1421
  ]);
1361
1422
  const hasPackageMap = {};
1423
+ for (const depName of depNames) {
1424
+ hasPackageMap[depName] = false;
1425
+ }
1362
1426
  let foundCount = 0;
1363
1427
  for (const packageJsonPath of allPackageJsonPaths) {
1364
1428
  const buffer = readFileSync(packageJsonPath);
@@ -1380,61 +1444,33 @@ function checkDepsExist(depNames) {
1380
1444
  return hasPackageMap;
1381
1445
  }
1382
1446
 
1383
- // src/factory.ts
1384
- function factory(options) {
1447
+ // src/index.ts
1448
+ function config(options) {
1385
1449
  const configs = [];
1386
- configs.push(ignores(), base(), imports(), unicorn(), node());
1387
- const packageExists = checkDepsExist([
1388
- "typescript",
1389
- "astro",
1390
- "react",
1391
- "tailwindcss",
1392
- "jest",
1393
- "vitest"
1394
- ]);
1395
- const isAtLeastOnePackageExists = Object.values(packageExists).some(Boolean);
1396
- if (isAtLeastOnePackageExists) {
1397
- console.log("Auto configured plugins:");
1398
- }
1399
- if (packageExists.typescript) {
1400
- console.log(" - TypeScript");
1401
- }
1402
- if (packageExists.typescript || options?.typescript || process.env.INSPECTOR) {
1403
- configs.push(typescript(options?.typescript));
1404
- }
1405
- if (packageExists.astro) {
1406
- console.log(" - Astro");
1407
- }
1408
- if (packageExists.astro || options?.astro || process.env.INSPECTOR) {
1409
- configs.push(astro());
1410
- }
1411
- if (packageExists.react) {
1412
- console.log(" - React");
1413
- }
1414
- if (packageExists.react || options?.react || process.env.INSPECTOR) {
1415
- configs.push(react());
1416
- }
1417
- if (packageExists.tailwindcss) {
1418
- console.log(" - Tailwind");
1419
- }
1420
- if (packageExists.tailwindcss || options?.tailwind || process.env.INSPECTOR) {
1421
- configs.push(tailwind());
1422
- }
1423
- if (packageExists.jest) {
1424
- console.log(" - Tailwind");
1425
- }
1426
- if (packageExists.jest || options?.jest || process.env.INSPECTOR) {
1427
- configs.push(jest());
1450
+ const autoConfigDeps = Object.values(autoConfigs).map(({ dep }) => dep);
1451
+ const existingAutoConfigDeps = checkDepsExist(autoConfigDeps);
1452
+ for (const defaultConfig of defaultConfigs) {
1453
+ configs.push(defaultConfig.config());
1428
1454
  }
1429
- if (packageExists.vitest) {
1430
- console.log(" - Vitest");
1455
+ const enabledAutoConfigs = autoConfigs.filter(({ dep, optionName }) => {
1456
+ return (
1457
+ // Is forced on.
1458
+ options?.[optionName] || // Is present and not forced off.
1459
+ existingAutoConfigDeps[dep] && options?.[optionName] !== false
1460
+ );
1461
+ });
1462
+ if (enabledAutoConfigs.length > 0) {
1463
+ console.log("Auto-configured plugins:");
1431
1464
  }
1432
- if (packageExists.vitest || options?.vitest || process.env.INSPECTOR) {
1433
- configs.push(vitest());
1465
+ for (const autoConfig of enabledAutoConfigs) {
1466
+ console.log(`- ${autoConfig.name}`);
1467
+ const autoConfigOptions = options?.[autoConfig.optionName];
1468
+ configs.push(autoConfig.config(autoConfigOptions));
1434
1469
  }
1435
1470
  const merged = configs.flat();
1436
1471
  return merged;
1437
1472
  }
1473
+ var src_default = config;
1438
1474
  export {
1439
- factory as default
1475
+ src_default as default
1440
1476
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@will-stone/eslint-config",
3
- "version": "11.0.2",
3
+ "version": "11.0.3",
4
4
  "description": "Will Stone's ESLint config",
5
5
  "keywords": [
6
6
  "eslint-config"
@@ -26,12 +26,13 @@
26
26
  ],
27
27
  "scripts": {
28
28
  "build": "tsup src/index.ts --format esm --clean --dts",
29
- "dev": "tsup src/index.ts --format esm --watch & INSPECTOR=true config-inspector",
29
+ "dev": "tsup src/index.ts --format esm --watch & config-inspector --config ./eslint-config-for-inspector.js",
30
30
  "lint": "npm run stub && eslint .",
31
31
  "prepare": "husky",
32
32
  "prepublishOnly": "npm run build",
33
33
  "release": "release-it",
34
34
  "stub": "tsup src/index.ts --format esm",
35
+ "test": "vitest",
35
36
  "typecheck": "tsc --noEmit"
36
37
  },
37
38
  "lint-staged": {
@@ -45,8 +46,8 @@
45
46
  "prettier": "@will-stone/prettier-config",
46
47
  "dependencies": {
47
48
  "@eslint/compat": "^1.1.1",
48
- "@typescript-eslint/eslint-plugin": "^8.0.1",
49
- "@typescript-eslint/parser": "^8.0.1",
49
+ "@typescript-eslint/eslint-plugin": "^8.1.0",
50
+ "@typescript-eslint/parser": "^8.1.0",
50
51
  "astro-eslint-parser": "^1.0.2",
51
52
  "confusing-browser-globals": "^1.0.11",
52
53
  "eslint-config-flat-gitignore": "^0.1.8",
@@ -72,14 +73,16 @@
72
73
  "@types/confusing-browser-globals": "^1.0.3",
73
74
  "@types/eslint": "^9.6.0",
74
75
  "@types/node": "^22.2.0",
75
- "@typescript-eslint/utils": "^8.0.1",
76
+ "@typescript-eslint/utils": "^8.1.0",
76
77
  "@will-stone/prettier-config": "^8.0.1",
77
78
  "husky": "^9.1.4",
78
79
  "lint-staged": "^15.2.8",
80
+ "memfs": "^4.11.1",
79
81
  "prettier": "^3.3.3",
80
82
  "release-it": "^17.6.0",
81
83
  "tsup": "^8.2.4",
82
- "typescript": "^5.5.4"
84
+ "typescript": "^5.5.4",
85
+ "vitest": "^2.0.5"
83
86
  },
84
87
  "peerDependencies": {
85
88
  "eslint": ">=9.9.0"