@shayanthenerd/eslint-config 0.26.7 → 0.27.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.
@@ -12,6 +12,7 @@ function getBaseConfig(options) {
12
12
  name: "shayanthenerd/base",
13
13
  files: [
14
14
  globs.src,
15
+ globs.jsxLike,
15
16
  isEnabled(vue) ? globs.vue : "",
16
17
  isEnabled(astro) ? globs.astro : ""
17
18
  ].filter(isTruthy),
@@ -10,6 +10,7 @@ function getBaselineConfig(options) {
10
10
  name: "shayanthenerd/baseline",
11
11
  files: [
12
12
  globs.src,
13
+ globs.jsxLike,
13
14
  isEnabled(vue) ? globs.vue : "",
14
15
  isEnabled(astro) ? globs.astro : ""
15
16
  ].filter(isTruthy),
@@ -13,6 +13,7 @@ function getImportXConfig(options) {
13
13
  name: "shayanthenerd/import-x",
14
14
  files: [
15
15
  globs.src,
16
+ globs.jsxLike,
16
17
  isEnabled(vue) ? globs.vue : "",
17
18
  isEnabled(astro) ? globs.astro : ""
18
19
  ].filter(isTruthy),
@@ -10,7 +10,7 @@ function getNextConfig(options) {
10
10
  const { overrides } = isEnabled(next) ? next : defaultOptions.configs.next;
11
11
  return mergeConfigs({
12
12
  name: "shayanthenerd/next",
13
- files: [globs.src],
13
+ files: [globs.src, globs.jsxLike],
14
14
  plugins: { next: eslintPluginNext },
15
15
  settings: { next: { rootDir: packageDir } },
16
16
  rules: getNextRules()
@@ -15,6 +15,7 @@ function getNodeConfig(options) {
15
15
  name: "shayanthenerd/node",
16
16
  files: [
17
17
  globs.src,
18
+ globs.jsxLike,
18
19
  isEnabled(vue) ? globs.vue : "",
19
20
  isEnabled(astro) ? globs.astro : ""
20
21
  ].filter(isTruthy),
@@ -13,6 +13,7 @@ function getPerfectionistConfig(options) {
13
13
  name: "shayanthenerd/perfectionist",
14
14
  files: [
15
15
  globs.src,
16
+ globs.jsxLike,
16
17
  isEnabled(vue) ? globs.vue : "",
17
18
  isEnabled(astro) ? globs.astro : ""
18
19
  ].filter(isTruthy),
@@ -13,6 +13,7 @@ function getPromiseConfig(options) {
13
13
  name: "shayanthenerd/promise",
14
14
  files: [
15
15
  globs.src,
16
+ globs.jsxLike,
16
17
  isEnabled(vue) ? globs.vue : "",
17
18
  isEnabled(astro) ? globs.astro : ""
18
19
  ].filter(isTruthy),
@@ -13,7 +13,7 @@ function getReactConfig(options) {
13
13
  const { overrides, accessibility } = isEnabled(react) ? react : defaultOptions.configs.react;
14
14
  return mergeConfigs({
15
15
  name: "shayanthenerd/react",
16
- files: [globs.src],
16
+ files: [globs.src, globs.jsxLike],
17
17
  plugins: {
18
18
  "@eslint-react": eslintPluginReact,
19
19
  "@html-eslint/react": eslintPluginHtmlReact,
@@ -13,6 +13,7 @@ function getStylisticConfig(options) {
13
13
  name: "shayanthenerd/stylistic",
14
14
  files: [
15
15
  globs.src,
16
+ globs.jsxLike,
16
17
  isEnabled(vue) ? globs.vue : "",
17
18
  isEnabled(astro) ? globs.astro : ""
18
19
  ].filter(isTruthy),
@@ -58,6 +58,7 @@ function getTailwindConfig(options) {
58
58
  name: "shayanthenerd/tailwind",
59
59
  files: [
60
60
  globs.src,
61
+ globs.jsxLike,
61
62
  isEnabled(vue) ? globs.vue : "",
62
63
  isEnabled(html) ? globs.html : "",
63
64
  isEnabled(astro) ? globs.astro : ""
@@ -15,6 +15,7 @@ function getTypeScriptConfig(options) {
15
15
  name: "shayanthenerd/typescript",
16
16
  files: [
17
17
  globs.src,
18
+ globs.jsxLike,
18
19
  isEnabled(vue) ? globs.vue : "",
19
20
  isEnabled(astro) ? globs.astro : ""
20
21
  ].filter(isTruthy),
@@ -13,6 +13,7 @@ function getUnicornConfig(options) {
13
13
  name: "shayanthenerd/unicorn",
14
14
  files: [
15
15
  globs.src,
16
+ globs.jsxLike,
16
17
  isEnabled(vue) ? globs.vue : "",
17
18
  isEnabled(astro) ? globs.astro : ""
18
19
  ].filter(isTruthy),
@@ -0,0 +1,14 @@
1
+ import { globs } from "../helpers/globs.mjs";
2
+ //#region src/configs/vueMiddlewares.ts
3
+ function getVueMiddlewaresConfig() {
4
+ return {
5
+ name: "shayanthenerd/vue/middlewares",
6
+ files: [globs.vueMiddlewares],
7
+ rules: {
8
+ "consistent-return": "off",
9
+ "@typescript-eslint/consistent-return": "off"
10
+ }
11
+ };
12
+ }
13
+ //#endregion
14
+ export { getVueMiddlewaresConfig };
@@ -14,6 +14,7 @@ function getZodConfig(options) {
14
14
  name: `shayanthenerd/${mini ? "zod-mini" : "zod"}`,
15
15
  files: [
16
16
  globs.src,
17
+ globs.jsxLike,
17
18
  isEnabled(vue) ? globs.vue : "",
18
19
  isEnabled(astro) ? globs.astro : ""
19
20
  ].filter(isTruthy),
@@ -1,17 +1,20 @@
1
1
  //#region src/helpers/globs.ts
2
- const srcExtensions = "?([mc])[jt]s?(x)";
3
- const vueExtensions = `{vue,${srcExtensions}}`;
2
+ const srcExtensions = "?([mc])[jt]s";
3
+ const jsxLikeExtensions = "[jt]sx";
4
+ const vueExtensions = `{vue,${srcExtensions},${jsxLikeExtensions}}`;
4
5
  const globs = {
5
6
  src: `**/*.${srcExtensions}`,
7
+ jsxLike: `**/*.${jsxLikeExtensions}`,
6
8
  packageJson: "**/package.json",
7
9
  markdown: "**/*.md",
8
10
  html: "**/*.html",
9
11
  css: "**/*.css",
10
12
  astro: "**/*.astro",
11
13
  vue: `**/*.${vueExtensions}`,
14
+ vueMiddlewares: `**/middleware?(s)/**/*.${srcExtensions}`,
12
15
  vueServerComponents: `**/*.server.${vueExtensions}`,
13
16
  vueAppErrorLayoutsPages: `**/{{app,error},{layouts,pages}/**/*}.${vueExtensions}`,
14
- storybook: `**/*.(story|stories).${srcExtensions}`,
17
+ storybook: `**/*.(story|stories).{${srcExtensions},${jsxLikeExtensions}}`,
15
18
  test: `**/{__tests__/*,*.{test,spec,cy,bench?(mark)}.${srcExtensions}`,
16
19
  coverage: "**/coverage/**"
17
20
  };
@@ -18,7 +18,8 @@ const mergeOptions = createDefu((object, key, value) => {
18
18
  return isEmptyString(value) || isValueTrue && !isDefaultValueFalse;
19
19
  });
20
20
  function mergeWithDefaults(options) {
21
- return mergeOptions(enableDetectedConfigs(options), defaultOptions);
21
+ const optionsWithDetectedConfigs = enableDetectedConfigs(options);
22
+ return mergeOptions(optionsWithDetectedConfigs, defaultOptions);
22
23
  }
23
24
  //#endregion
24
25
  export { mergeWithDefaults };
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { Options } from "./types/index.mjs";
2
2
  import { Linter } from "eslint";
3
3
 
4
4
  //#region src/index.d.ts
5
- /** Valid argument combinations for the `defineConfig` function. */
5
+ /** Valid argument combinations for `defineConfig`. */
6
6
  type DefineConfigArguments = [] | [options: Options] | [configs: Linter.Config[]] | [options: Options, configs: Linter.Config[]];
7
7
  /**
8
8
  * Define your ESLint configuration based on the provided options and/or custom Flat Config Objects.
package/dist/index.mjs CHANGED
@@ -23,6 +23,7 @@ import { getPlaywrightConfig } from "./configs/playwright.mjs";
23
23
  import { getTypeScriptConfig } from "./configs/typescript.mjs";
24
24
  import { getPackageJsonConfig } from "./configs/packageJson.mjs";
25
25
  import { getPerfectionistConfig } from "./configs/perfectionist.mjs";
26
+ import { getVueMiddlewaresConfig } from "./configs/vueMiddlewares.mjs";
26
27
  import { getIgnorePatterns } from "./helpers/ignores/getIgnorePatterns.mjs";
27
28
  import { mergeWithDefaults } from "./helpers/options/mergeWithDefaults.mjs";
28
29
  import { getVueComponentNamesConfig } from "./configs/vueComponentNames.mjs";
@@ -105,6 +106,7 @@ function defineConfig(...args) {
105
106
  isEnabled(react) && getReactConfig(mergedOptions),
106
107
  isEnabled(next) && getNextConfig(mergedOptions),
107
108
  isEnabled(vue) && getVueConfig(mergedOptions),
109
+ isEnabled(vue) && getVueMiddlewaresConfig(),
108
110
  isEnabled(vue) && getVueComponentNamesConfig(),
109
111
  isEnabled(vue) && isEnabled(nuxt) && getVueServerComponentsConfig(),
110
112
  isEnabled(storybook) && getStorybookConfig(mergedOptions),
@@ -1,6 +1,105 @@
1
1
  import { isEnabled } from "../utils/isEnabled.mjs";
2
2
  import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
3
3
  //#region src/rules/perfectionist.ts
4
+ const literalCustomGroups = [
5
+ {
6
+ groupName: "template-literal",
7
+ selector: "literal",
8
+ elementNamePattern: "^`.*`$"
9
+ },
10
+ {
11
+ groupName: "bigint-literal",
12
+ selector: "literal",
13
+ elementNamePattern: "^-?\\d[\\d_]*n$"
14
+ },
15
+ {
16
+ groupName: "string-literal",
17
+ selector: "literal",
18
+ elementNamePattern: "^(?:'.*'|\".*\")$"
19
+ },
20
+ {
21
+ groupName: "boolean-literal",
22
+ selector: "literal",
23
+ elementNamePattern: "^(?:true|false)$"
24
+ },
25
+ {
26
+ groupName: "number-literal",
27
+ selector: "literal",
28
+ elementNamePattern: "^-?(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:[eE][+-]?\\d[\\d_]*)?$"
29
+ }
30
+ ];
31
+ const booleanKeywordCustomGroup = {
32
+ groupName: "boolean-keyword",
33
+ selector: "keyword",
34
+ elementNamePattern: "^boolean$"
35
+ };
36
+ const sharedTypeLikeGroups = [
37
+ "boolean-literal",
38
+ "number-literal",
39
+ "bigint-literal",
40
+ "string-literal",
41
+ "template-literal",
42
+ "literal",
43
+ "keyword",
44
+ "named",
45
+ "operator",
46
+ "tuple",
47
+ "object",
48
+ "union",
49
+ "intersection",
50
+ "conditional",
51
+ "function",
52
+ "import",
53
+ "unknown",
54
+ "nullish"
55
+ ];
56
+ const typeConstituentSortOptions = {
57
+ customGroups: [booleanKeywordCustomGroup, ...literalCustomGroups],
58
+ groups: ["boolean-keyword", ...sharedTypeLikeGroups]
59
+ };
60
+ const sortArrayIncludesOptions = {
61
+ customGroups: literalCustomGroups,
62
+ groups: sharedTypeLikeGroups
63
+ };
64
+ const sortImportsCustomGroups = [{
65
+ groupName: "component",
66
+ elementNamePattern: ["\\.(vue|[jt]sx)$"],
67
+ modifiers: ["value"]
68
+ }, {
69
+ groupName: "image",
70
+ elementNamePattern: ["\\.(ico|svg|gif|png|jpe?g|webp|avif|heic)$"]
71
+ }];
72
+ const sortImportsGroups = [
73
+ ["style", "side-effect-style"],
74
+ { newlinesBetween: 0 },
75
+ "side-effect",
76
+ "image",
77
+ "component",
78
+ "type-external",
79
+ { newlinesBetween: 0 },
80
+ "type-builtin",
81
+ { newlinesBetween: 0 },
82
+ ["type-tsconfig-path", "type-subpath"],
83
+ { newlinesBetween: 0 },
84
+ [
85
+ "type-internal",
86
+ "type-index",
87
+ "type-parent",
88
+ "type-sibling"
89
+ ],
90
+ "external",
91
+ { newlinesBetween: 0 },
92
+ "builtin",
93
+ ["tsconfig-path", "subpath"],
94
+ { newlinesBetween: 0 },
95
+ [
96
+ "internal",
97
+ "index",
98
+ "parent",
99
+ "sibling"
100
+ ],
101
+ ["import", "unknown"]
102
+ ];
4
103
  function getPerfectionistRules(options) {
5
104
  const { env, tsConfig, configs: { stylistic, perfectionist } } = options;
6
105
  const { maxLineLength } = isEnabled(stylistic) ? stylistic : defaultOptions.configs.stylistic;
@@ -8,9 +107,9 @@ function getPerfectionistRules(options) {
8
107
  return {
9
108
  "perfectionist/sort-maps": "warn",
10
109
  "perfectionist/sort-exports": "warn",
11
- "perfectionist/sort-union-types": "warn",
12
- "perfectionist/sort-array-includes": "warn",
13
- "perfectionist/sort-intersection-types": "warn",
110
+ "perfectionist/sort-union-types": ["warn", typeConstituentSortOptions],
111
+ "perfectionist/sort-array-includes": ["warn", sortArrayIncludesOptions],
112
+ "perfectionist/sort-intersection-types": ["warn", typeConstituentSortOptions],
14
113
  "perfectionist/sort-named-imports": "warn",
15
114
  "perfectionist/sort-named-exports": "warn",
16
115
  "perfectionist/sort-imports": ["warn", {
@@ -25,45 +124,8 @@ function getPerfectionistRules(options) {
25
124
  specialCharacters: "trim",
26
125
  type: sortType,
27
126
  maxLineLength,
28
- customGroups: [{
29
- groupName: "vue-sfc",
30
- elementNamePattern: ["\\.(vue|[jt]sx)$"],
31
- modifiers: ["value"]
32
- }, {
33
- groupName: "image",
34
- elementNamePattern: ["\\.(ico|svg|gif|png|jpe?g|webp|avif|heic)$"]
35
- }],
36
- groups: [
37
- ["style", "side-effect-style"],
38
- { newlinesBetween: 0 },
39
- "side-effect",
40
- "image",
41
- "vue-sfc",
42
- "type-external",
43
- { newlinesBetween: 0 },
44
- "type-builtin",
45
- { newlinesBetween: 0 },
46
- ["type-tsconfig-path", "type-subpath"],
47
- { newlinesBetween: 0 },
48
- [
49
- "type-internal",
50
- "type-index",
51
- "type-parent",
52
- "type-sibling"
53
- ],
54
- "external",
55
- { newlinesBetween: 0 },
56
- "builtin",
57
- ["tsconfig-path", "subpath"],
58
- { newlinesBetween: 0 },
59
- [
60
- "internal",
61
- "index",
62
- "parent",
63
- "sibling"
64
- ],
65
- ["import", "unknown"]
66
- ]
127
+ customGroups: sortImportsCustomGroups,
128
+ groups: sortImportsGroups
67
129
  }]
68
130
  };
69
131
  }