@shayanthenerd/eslint-config 0.13.1 → 0.15.0

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.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +192 -183
  3. package/dist/configs/base.mjs +13 -9
  4. package/dist/configs/css.mjs +2 -2
  5. package/dist/configs/cypress.mjs +2 -2
  6. package/dist/configs/html.mjs +2 -2
  7. package/dist/configs/importX.mjs +2 -2
  8. package/dist/configs/oxlintOverrides.mjs +16 -11
  9. package/dist/configs/perfectionist.mjs +2 -2
  10. package/dist/configs/playwright.mjs +2 -2
  11. package/dist/configs/restrictedExports.mjs +1 -1
  12. package/dist/configs/storybook.mjs +2 -2
  13. package/dist/configs/stylistic.mjs +2 -2
  14. package/dist/configs/tailwind.mjs +4 -4
  15. package/dist/configs/typescript.mjs +2 -2
  16. package/dist/configs/vitest.mjs +2 -2
  17. package/dist/configs/vue.mjs +2 -2
  18. package/dist/configs/vueComponentNames.mjs +1 -1
  19. package/dist/configs/vueServerComponents.mjs +1 -1
  20. package/dist/configs/zod.mjs +21 -0
  21. package/dist/{utils → helpers}/globs.mjs +1 -1
  22. package/dist/{utils → helpers}/ignores/defaultIgnorePatterns.mjs +1 -1
  23. package/dist/{utils → helpers}/ignores/getIgnorePatterns.mjs +1 -1
  24. package/dist/{utils → helpers}/ignores/resolveGitignorePatterns.mjs +1 -1
  25. package/dist/{utils → helpers}/isPackageDetected.mjs +5 -3
  26. package/dist/{utils → helpers}/options/defaultOptions.mjs +14 -7
  27. package/dist/{utils → helpers}/options/enableDetectedConfigs.mjs +2 -3
  28. package/dist/{utils → helpers}/options/mergeWithDefaults.mjs +4 -5
  29. package/dist/{utils → helpers}/vue/getRestrictedVueElements.mjs +1 -1
  30. package/dist/{utils → helpers}/vue/getRestrictedVueInputs.mjs +1 -1
  31. package/dist/index.mjs +6 -4
  32. package/dist/oxlint.config.jsonc +209 -201
  33. package/dist/prettier.config.mjs +1 -1
  34. package/dist/rules/css.mjs +1 -1
  35. package/dist/rules/html.mjs +3 -3
  36. package/dist/rules/importX.mjs +1 -1
  37. package/dist/rules/javascript.mjs +1 -2
  38. package/dist/rules/perfectionist.mjs +2 -2
  39. package/dist/rules/stylistic.mjs +22 -10
  40. package/dist/rules/tailwind.mjs +4 -4
  41. package/dist/rules/typescript.mjs +6 -3
  42. package/dist/rules/vitest.mjs +4 -0
  43. package/dist/rules/vue.mjs +6 -6
  44. package/dist/rules/vueAccessibility.mjs +1 -1
  45. package/dist/rules/zod.mjs +20 -0
  46. package/dist/types/configOptions/base.d.mts +8 -8
  47. package/dist/types/configOptions/nuxt.d.mts +3 -3
  48. package/dist/types/configOptions/stylistic.d.mts +0 -15
  49. package/dist/types/configOptions/test.d.mts +4 -4
  50. package/dist/types/configOptions/vue.d.mts +1 -1
  51. package/dist/types/eslint-schema.d.mts +769 -270
  52. package/dist/types/index.d.mts +43 -19
  53. package/package.json +139 -123
@@ -1,6 +1,6 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
  import { isEnabled } from "../utils/isEnabled.mjs";
3
- import { defaultOptions } from "../utils/options/defaultOptions.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
4
  import { getStylisticRules } from "../rules/stylistic.mjs";
5
5
  import { mergeConfigs } from "eslint-flat-config-utils";
6
6
  import eslintPluginStylistic from "@stylistic/eslint-plugin";
@@ -1,6 +1,6 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
  import { isEnabled } from "../utils/isEnabled.mjs";
3
- import { defaultOptions } from "../utils/options/defaultOptions.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
4
  import { getTailwindRules } from "../rules/tailwind.mjs";
5
5
  import path from "node:path";
6
6
  import { mergeConfigs } from "eslint-flat-config-utils";
@@ -25,8 +25,8 @@ function getTailwindConfig(options) {
25
25
  name: "shayanthenerd/tailwind",
26
26
  files: [
27
27
  globs.src,
28
- html ? globs.html : "",
29
- vue ? globs.vue : ""
28
+ vue ? globs.vue : "",
29
+ html ? globs.html : ""
30
30
  ].filter(Boolean),
31
31
  plugins: { "better-tailwindcss": eslintPluginTailwind },
32
32
  languageOptions: { parserOptions: { parser: isEnabled(html) ? eslintParserHTML : eslintParserVue } },
@@ -1,6 +1,6 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
  import { isEnabled } from "../utils/isEnabled.mjs";
3
- import { defaultOptions } from "../utils/options/defaultOptions.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
4
  import { getTypeScriptRules } from "../rules/typescript.mjs";
5
5
  import path from "node:path";
6
6
  import { mergeConfigs } from "eslint-flat-config-utils";
@@ -1,6 +1,6 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
  import { isEnabled } from "../utils/isEnabled.mjs";
3
- import { defaultOptions } from "../utils/options/defaultOptions.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
4
  import { getVitestRules } from "../rules/vitest.mjs";
5
5
  import { mergeConfigs } from "eslint-flat-config-utils";
6
6
  import eslintPluginVitest from "@vitest/eslint-plugin";
@@ -1,6 +1,6 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
  import { isEnabled } from "../utils/isEnabled.mjs";
3
- import { defaultOptions } from "../utils/options/defaultOptions.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
4
  import { getVueRules } from "../rules/vue.mjs";
5
5
  import { getVueAccessibilityRules } from "../rules/vueAccessibility.mjs";
6
6
  import { mergeConfigs } from "eslint-flat-config-utils";
@@ -1,4 +1,4 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
 
3
3
  //#region src/configs/vueComponentNames.ts
4
4
  function getVueComponentNamesConfig() {
@@ -1,4 +1,4 @@
1
- import { globs } from "../utils/globs.mjs";
1
+ import { globs } from "../helpers/globs.mjs";
2
2
 
3
3
  //#region src/configs/vueServerComponents.ts
4
4
  function getVueServerComponentsConfig() {
@@ -0,0 +1,21 @@
1
+ import { globs } from "../helpers/globs.mjs";
2
+ import { isEnabled } from "../utils/isEnabled.mjs";
3
+ import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
4
+ import { getZodRules } from "../rules/zod.mjs";
5
+ import { mergeConfigs } from "eslint-flat-config-utils";
6
+ import eslintPluginZodX from "eslint-plugin-zod-x";
7
+
8
+ //#region src/configs/zod.ts
9
+ function getZodConfig(options) {
10
+ const { zod, vue } = options.configs;
11
+ const { overrides } = isEnabled(zod) ? zod : defaultOptions.configs.zod;
12
+ return mergeConfigs({
13
+ name: "shayanthenerd/zod",
14
+ files: isEnabled(vue) ? [globs.src, globs.vue] : [globs.src],
15
+ plugins: { "zod-x": eslintPluginZodX },
16
+ rules: getZodRules()
17
+ }, overrides);
18
+ }
19
+
20
+ //#endregion
21
+ export { getZodConfig };
@@ -1,4 +1,4 @@
1
- //#region src/utils/globs.ts
1
+ //#region src/helpers/globs.ts
2
2
  const srcExtensions = "?([mc])[jt]s?(x)";
3
3
  const vueExtensions = `{vue,${srcExtensions}}`;
4
4
  const globs = {
@@ -1,4 +1,4 @@
1
- //#region src/utils/ignores/defaultIgnorePatterns.ts
1
+ //#region src/helpers/ignores/defaultIgnorePatterns.ts
2
2
  const defaultIgnorePatterns = [
3
3
  "**/*.min.*",
4
4
  "**/jspm_packages",
@@ -1,7 +1,7 @@
1
1
  import { defaultIgnorePatterns } from "./defaultIgnorePatterns.mjs";
2
2
  import { resolveGitignorePatterns } from "./resolveGitignorePatterns.mjs";
3
3
 
4
- //#region src/utils/ignores/getIgnorePatterns.ts
4
+ //#region src/helpers/ignores/getIgnorePatterns.ts
5
5
  function getIgnorePatterns({ patterns, gitignore }) {
6
6
  if (gitignore) {
7
7
  const gitignorePatterns = resolveGitignorePatterns(gitignore);
@@ -3,7 +3,7 @@ import { includeIgnoreFile } from "@eslint/compat";
3
3
  import fs from "node:fs";
4
4
  import { styleText } from "node:util";
5
5
 
6
- //#region src/utils/ignores/resolveGitignorePatterns.ts
6
+ //#region src/helpers/ignores/resolveGitignorePatterns.ts
7
7
  const warningMessage = styleText("yellow", "⚠ Warning:");
8
8
  const fallbackMessage = `Falling back to default ignore patterns. You can suppress this warning by setting ${styleText("bgBlack", " gitignore: false ")} in the config.`;
9
9
  function resolveGitignorePatterns(gitignorePath) {
@@ -3,17 +3,19 @@ import path from "node:path";
3
3
  import { styleText } from "node:util";
4
4
  import { isPackageExists } from "local-pkg";
5
5
 
6
- //#region src/utils/isPackageDetected.ts
6
+ //#region src/helpers/isPackageDetected.ts
7
7
  const detectedPackages = [];
8
8
  function logDetectedPackages() {
9
- if (detectedPackages.length > 0) console.info(styleText("green", "✔"), "Automatic dependency detection enabled ESLint configurations for", detectedPackages.map((packageName) => styleText("blue", packageName)).join(", "));
9
+ if (detectedPackages.length > 0) {
10
+ detectedPackages.sort();
11
+ console.info(styleText("green", "✔"), "Automatic dependency detection enabled ESLint configurations for", detectedPackages.map((packageName) => styleText("blue", packageName)).join(", "));
12
+ }
10
13
  }
11
14
  function isPackageDetected(packageName, options = defaultOptions) {
12
15
  const { packageDir = defaultOptions.packageDir, autoDetectDeps = defaultOptions.autoDetectDeps } = options;
13
16
  if (!autoDetectDeps) return false;
14
17
  const isPackageInstalled = isPackageExists(packageName, { paths: [path.resolve(packageDir)] });
15
18
  if (isPackageInstalled) detectedPackages.push(packageName);
16
- detectedPackages.sort();
17
19
  return isPackageInstalled;
18
20
  }
19
21
 
@@ -1,4 +1,4 @@
1
- //#region src/utils/options/defaultOptions.ts
1
+ //#region src/helpers/options/defaultOptions.ts
2
2
  const defaultOptions = {
3
3
  autoDetectDeps: true,
4
4
  gitignore: ".gitignore",
@@ -14,19 +14,26 @@ const defaultOptions = {
14
14
  reportUnusedDisableDirectives: "warn"
15
15
  },
16
16
  globals: {
17
- node: true,
17
+ worker: true,
18
18
  commonjs: false,
19
+ bun: true,
20
+ deno: true,
21
+ node: true,
22
+ nodeBuiltin: true,
19
23
  browser: true,
20
- worker: true,
21
- serviceworker: false,
22
- webextension: false,
24
+ sharedWorker: true,
25
+ serviceworker: true,
26
+ webextension: true,
27
+ audioWorklet: true,
28
+ vitest: false,
29
+ vue: true,
23
30
  custom: {}
24
31
  },
25
32
  settings: {},
26
33
  rules: {}
27
34
  },
28
35
  configs: {
29
- oxlint: "./.oxlintrc.json",
36
+ oxlint: ".oxlintrc.json",
30
37
  base: {
31
38
  maxDepth: 3,
32
39
  maxNestedCallbacks: 3,
@@ -41,7 +48,6 @@ const defaultOptions = {
41
48
  quotes: "single",
42
49
  jsxQuotes: "prefer-double",
43
50
  arrowParens: "always",
44
- useTabs: true,
45
51
  indent: 2,
46
52
  maxConsecutiveEmptyLines: 1,
47
53
  maxLineLength: 120,
@@ -80,6 +86,7 @@ const defaultOptions = {
80
86
  sortType: "line-length",
81
87
  overrides: {}
82
88
  },
89
+ zod: { overrides: {} },
83
90
  vue: {
84
91
  accessibility: {
85
92
  imageComponents: ["NuxtImg"],
@@ -1,7 +1,6 @@
1
- import { defaultOptions } from "./defaultOptions.mjs";
2
1
  import { isPackageDetected, logDetectedPackages } from "../isPackageDetected.mjs";
3
2
 
4
- //#region src/utils/options/enableDetectedConfigs.ts
3
+ //#region src/helpers/options/enableDetectedConfigs.ts
5
4
  function enableDetectedConfigs(options) {
6
5
  options.configs ??= {};
7
6
  options.configs.test ??= {};
@@ -14,11 +13,11 @@ function enableDetectedConfigs(options) {
14
13
  options.configs.vue ??= isPackageDetected("vue", options);
15
14
  options.configs.nuxt ??= isPackageDetected("nuxt", options);
16
15
  options.configs.typescript ??= isPackageDetected("typescript", options);
16
+ options.configs.zod ??= isPackageDetected("zod", options);
17
17
  options.configs.test.vitest ??= isPackageDetected("vitest", options);
18
18
  options.configs.test.cypress ??= isPackageDetected("cypress", options);
19
19
  options.configs.test.storybook ??= isPackageDetected("storybook", options);
20
20
  options.configs.test.playwright ??= isPackageDetected("@playwright/test", options);
21
- options.configs.oxlint ??= isPackageDetected("oxlint", options) ? defaultOptions.configs.oxlint : false;
22
21
  options.tsConfig ??= options.configs.typescript ? {
23
22
  rootDir: ".",
24
23
  filename: "tsconfig.json"
@@ -1,17 +1,16 @@
1
1
  import { defaultOptions } from "./defaultOptions.mjs";
2
- import { isEmptyString } from "../isEmptyString.mjs";
2
+ import { isEmptyString } from "../../utils/isEmptyString.mjs";
3
3
  import { enableDetectedConfigs } from "./enableDetectedConfigs.mjs";
4
4
  import { createDefu } from "defu";
5
5
 
6
- //#region src/utils/options/mergeWithDefaults.ts
6
+ //#region src/helpers/options/mergeWithDefaults.ts
7
7
  const mergeOptions = createDefu((object, key, value) => {
8
- const stringKey = key.toString();
9
8
  if ([
10
9
  "allowedRelativeFontUnits",
11
- "macrosOrder",
12
10
  "blocksOrder",
11
+ "macrosOrder",
13
12
  "attributesOrder"
14
- ].includes(stringKey)) {
13
+ ].includes(key.toString())) {
15
14
  object[key] = value;
16
15
  return true;
17
16
  }
@@ -1,4 +1,4 @@
1
- //#region src/utils/vue/getRestrictedVueElements.ts
1
+ //#region src/helpers/vue/getRestrictedVueElements.ts
2
2
  const alternativeComponentPairs = Object.entries({
3
3
  kbd: "Kbd",
4
4
  form: "Form",
@@ -1,4 +1,4 @@
1
- //#region src/utils/vue/getRestrictedVueInputs.ts
1
+ //#region src/helpers/vue/getRestrictedVueInputs.ts
2
2
  const alternativeComponentPairs = Object.entries({
3
3
  range: "Slider",
4
4
  date: "Calendar",
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { isEnabled } from "./utils/isEnabled.mjs";
2
- import { defaultOptions } from "./utils/options/defaultOptions.mjs";
2
+ import { defaultOptions } from "./helpers/options/defaultOptions.mjs";
3
3
  import { getCSSConfig } from "./configs/css.mjs";
4
4
  import { getVueConfig } from "./configs/vue.mjs";
5
+ import { getZodConfig } from "./configs/zod.mjs";
5
6
  import { getBaseConfig } from "./configs/base.mjs";
6
7
  import { getHTMLConfig } from "./configs/html.mjs";
7
8
  import { getVitestConfig } from "./configs/vitest.mjs";
@@ -15,8 +16,8 @@ import { getTypeScriptConfig } from "./configs/typescript.mjs";
15
16
  import { getPerfectionistConfig } from "./configs/perfectionist.mjs";
16
17
  import { getRestrictedExports } from "./configs/restrictedExports.mjs";
17
18
  import { getOXLintOverridesConfig } from "./configs/oxlintOverrides.mjs";
18
- import { getIgnorePatterns } from "./utils/ignores/getIgnorePatterns.mjs";
19
- import { mergeWithDefaults } from "./utils/options/mergeWithDefaults.mjs";
19
+ import { getIgnorePatterns } from "./helpers/ignores/getIgnorePatterns.mjs";
20
+ import { mergeWithDefaults } from "./helpers/options/mergeWithDefaults.mjs";
20
21
  import { getVueComponentNamesConfig } from "./configs/vueComponentNames.mjs";
21
22
  import { getVueServerComponentsConfig } from "./configs/vueServerComponents.mjs";
22
23
  import eslintPluginOXLint from "eslint-plugin-oxlint";
@@ -34,7 +35,7 @@ import path from "node:path";
34
35
  */
35
36
  function defineConfig(options = {}, ...configs) {
36
37
  const mergedOptions = mergeWithDefaults(options);
37
- const { gitignore, global: { rules, ignores, settings, linterOptions }, configs: { vue, css, nuxt, html, oxlint, importX, tailwind, stylistic, typescript, perfectionist, base: { preferNamedExports }, test: { vitest, cypress, storybook, playwright } } } = mergedOptions;
38
+ const { gitignore, global: { rules, ignores, settings, linterOptions }, configs: { css, zod, vue, html, nuxt, oxlint, importX, tailwind, stylistic, typescript, perfectionist, base: { preferNamedExports }, test: { vitest, cypress, storybook, playwright } } } = mergedOptions;
38
39
  const ignorePatterns = getIgnorePatterns({
39
40
  gitignore,
40
41
  patterns: ignores
@@ -57,6 +58,7 @@ function defineConfig(options = {}, ...configs) {
57
58
  preferNamedExports && getRestrictedExports(),
58
59
  isEnabled(stylistic) && getStylisticConfig(mergedOptions),
59
60
  isEnabled(perfectionist) && getPerfectionistConfig(mergedOptions),
61
+ isEnabled(zod) && getZodConfig(mergedOptions),
60
62
  isEnabled(tailwind) && getTailwindConfig(mergedOptions),
61
63
  isEnabled(vue) && getVueConfig(mergedOptions),
62
64
  isEnabled(vue) && getVueComponentNamesConfig(),