@ntnyq/eslint-config 3.3.1 → 3.4.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.
package/dist/index.js CHANGED
@@ -4,9 +4,6 @@ import { FlatConfigComposer } from "eslint-flat-config-utils";
4
4
  // src/configs/vue.ts
5
5
  import { mergeProcessors as mergeProcessors2 } from "eslint-merge-processors";
6
6
 
7
- // src/eslint/utils.ts
8
- import { config } from "typescript-eslint";
9
-
10
7
  // src/eslint/parsers.ts
11
8
  import tseslint from "typescript-eslint";
12
9
  import * as parserVue from "vue-eslint-parser";
@@ -94,6 +91,7 @@ var GLOB_YAML = "**/*.y?(a)ml";
94
91
  var GLOB_TOML = "**/*.toml";
95
92
  var GLOB_HTML = "**/*.htm?(l)";
96
93
  var GLOB_ASTRO = "**/*.astro";
94
+ var GLOB_ASTRO_TS = "**/*.astro/*.ts";
97
95
  var GLOB_SVELTE = "**/*.svelte";
98
96
  var GLOB_MARKDOWN = "**/*.md";
99
97
  var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
@@ -164,126 +162,6 @@ var GLOB_EXCLUDE = [
164
162
  "**/.yarnrc"
165
163
  ];
166
164
 
167
- // src/configs/typescript.ts
168
- import process from "node:process";
169
- var typescriptCore = (options = {}) => {
170
- const isTypeAware = !!options.tsconfigPath;
171
- const configs2 = config({
172
- name: "ntnyq/ts/core",
173
- extends: [...configs.recommended],
174
- files: [GLOB_TS, GLOB_TSX],
175
- languageOptions: {
176
- parser: parserTypeScript,
177
- parserOptions: {
178
- sourceType: "module",
179
- ...isTypeAware ? {
180
- projectService: {
181
- defaultProject: options.tsconfigPath
182
- },
183
- tsconfigRootDir: process.cwd()
184
- } : {}
185
- }
186
- },
187
- rules: {
188
- // Disabled in favor of ts rules
189
- "no-redeclare": "off",
190
- "no-use-before-define": "off",
191
- "no-unused-vars": "off",
192
- "@typescript-eslint/no-redeclare": [
193
- "error",
194
- {
195
- builtinGlobals: false,
196
- ignoreDeclarationMerge: true
197
- }
198
- ],
199
- "@typescript-eslint/no-use-before-define": [
200
- "error",
201
- {
202
- functions: false,
203
- classes: false,
204
- variables: true,
205
- allowNamedExports: false,
206
- enums: true,
207
- typedefs: false,
208
- ignoreTypeReferences: false
209
- }
210
- ],
211
- "@typescript-eslint/no-unused-vars": [
212
- "error",
213
- {
214
- // Args after the last used will be reported
215
- args: "after-used",
216
- argsIgnorePattern: "^_",
217
- caughtErrors: "all",
218
- caughtErrorsIgnorePattern: "^_",
219
- destructuredArrayIgnorePattern: "^_",
220
- varsIgnorePattern: "^_",
221
- ignoreRestSiblings: true
222
- }
223
- ],
224
- "@typescript-eslint/no-unused-expressions": [
225
- "error",
226
- {
227
- allowShortCircuit: true,
228
- allowTernary: true,
229
- allowTaggedTemplates: true
230
- }
231
- ],
232
- "@typescript-eslint/consistent-type-imports": [
233
- "error",
234
- {
235
- prefer: "type-imports",
236
- fixStyle: "separate-type-imports",
237
- disallowTypeAnnotations: false
238
- }
239
- ],
240
- "@typescript-eslint/no-empty-object-type": [
241
- "error",
242
- {
243
- allowInterfaces: "always",
244
- allowObjectTypes: "always"
245
- }
246
- ],
247
- "@typescript-eslint/consistent-type-assertions": [
248
- "error",
249
- {
250
- assertionStyle: "as",
251
- objectLiteralTypeAssertions: "allow-as-parameter"
252
- }
253
- ],
254
- "@typescript-eslint/prefer-as-const": "warn",
255
- "@typescript-eslint/no-namespace": "off",
256
- "@typescript-eslint/ban-ts-comment": "off",
257
- "@typescript-eslint/no-explicit-any": "off",
258
- "@typescript-eslint/no-empty-function": "off",
259
- "@typescript-eslint/naming-convention": "off",
260
- "@typescript-eslint/no-non-null-assertion": "off",
261
- "@typescript-eslint/triple-slash-reference": "off",
262
- "@typescript-eslint/explicit-member-accessibility": "off",
263
- "@typescript-eslint/explicit-function-return-type": "off",
264
- "@typescript-eslint/explicit-module-boundary-types": "off",
265
- "@typescript-eslint/consistent-indexed-object-style": "off",
266
- // Overrides rules
267
- ...options.overrides
268
- }
269
- });
270
- return configs2;
271
- };
272
- var typescript = (options = {}) => [
273
- ...typescriptCore(options),
274
- {
275
- name: "ntnyq/ts/types",
276
- files: [GLOB_DTS, "**/types/**/*.ts"],
277
- rules: {
278
- "no-use-before-define": "off",
279
- "no-restricted-syntax": "off",
280
- "import/no-duplicates": "off",
281
- "import/newline-after-import": "off",
282
- "@typescript-eslint/no-use-before-define": "off"
283
- }
284
- }
285
- ];
286
-
287
165
  // src/configs/vue.ts
288
166
  var vue2Rules = {
289
167
  ...default3.configs.base.rules,
@@ -481,11 +359,6 @@ var vue = (options = {}) => {
481
359
  const isVue3 = options.vueVersion !== 2;
482
360
  const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
483
361
  return [
484
- ...config({
485
- name: "ntnyq/vue/ts",
486
- files: [GLOB_VUE],
487
- extends: typescriptCore()
488
- }),
489
362
  {
490
363
  name: "ntnyq/vue/setup",
491
364
  plugins: {
@@ -497,7 +370,7 @@ var vue = (options = {}) => {
497
370
  sourceType: "module",
498
371
  ecmaVersion: "latest",
499
372
  extraFileExtensions: [".vue"],
500
- parser: "@typescript-eslint/parser",
373
+ parser: parserTypeScript,
501
374
  ecmaFeatures: {
502
375
  jsx: true
503
376
  }
@@ -1151,9 +1024,9 @@ var ntnyq = (options = {}) => [
1151
1024
 
1152
1025
  // src/configs/regexp.ts
1153
1026
  var regexp = (options = {}) => {
1154
- const config2 = pluginRegexp.configs["flat/recommended"];
1027
+ const config = pluginRegexp.configs["flat/recommended"];
1155
1028
  const rules = {
1156
- ...config2.rules
1029
+ ...config.rules
1157
1030
  };
1158
1031
  if (options.level === "warn") {
1159
1032
  for (const key in rules) {
@@ -1164,7 +1037,7 @@ var regexp = (options = {}) => {
1164
1037
  }
1165
1038
  return [
1166
1039
  {
1167
- ...config2,
1040
+ ...config,
1168
1041
  name: "ntnyq/regexp",
1169
1042
  rules: {
1170
1043
  ...rules,
@@ -1243,12 +1116,12 @@ var DEFAULT_PRETTIER_OPTIONS = {
1243
1116
 
1244
1117
  // src/utils/env.ts
1245
1118
  import { resolve } from "node:path";
1246
- import process2 from "node:process";
1119
+ import process from "node:process";
1247
1120
  import { isPackageExists } from "local-pkg";
1248
1121
  var hasTypeScript = isPackageExists("typescript");
1249
1122
  var hasVitest = isPackageExists("vitest");
1250
1123
  var hasVue = isPackageExists("vue") || isPackageExists("nuxt") || isPackageExists("vitepress") || isPackageExists("@slidev/cli") || isPackageExists("vue", {
1251
- paths: [resolve(process2.cwd(), "playground")]
1124
+ paths: [resolve(process.cwd(), "playground")]
1252
1125
  });
1253
1126
  var hasUnoCSS = isPackageExists("unocss") || isPackageExists("@unocss/postcss") || isPackageExists("@unocss/webpack") || isPackageExists("@unocss/nuxt");
1254
1127
 
@@ -1589,9 +1462,9 @@ var comments = (options = {}) => [
1589
1462
  var markdown = (options = {}) => {
1590
1463
  if (!Array.isArray(default7.configs?.processor)) return [];
1591
1464
  return [
1592
- ...default7.configs.processor.map((config2) => ({
1593
- ...config2,
1594
- name: `ntnyq/${config2.name}`
1465
+ ...default7.configs.processor.map((config) => ({
1466
+ ...config,
1467
+ name: `ntnyq/${config.name}`
1595
1468
  })),
1596
1469
  {
1597
1470
  name: "ntnyq/markdown/disabled/code-blocks",
@@ -1957,6 +1830,198 @@ var jsx = () => [
1957
1830
  }
1958
1831
  ];
1959
1832
 
1833
+ // src/configs/typescript.ts
1834
+ import process2 from "node:process";
1835
+ var typeAwareRules = {
1836
+ "dot-notation": "off",
1837
+ "require-await": "off",
1838
+ "no-implied-eval": "off",
1839
+ "no-throw-literal": "off",
1840
+ // too strict
1841
+ "@typescript-eslint/strict-boolean-expressions": "off",
1842
+ "@typescript-eslint/require-await": "error",
1843
+ "@typescript-eslint/unbound-method": "error",
1844
+ "@typescript-eslint/no-unsafe-call": "error",
1845
+ "@typescript-eslint/await-thenable": "error",
1846
+ "@typescript-eslint/no-for-in-array": "error",
1847
+ "@typescript-eslint/no-implied-eval": "error",
1848
+ "@typescript-eslint/only-throw-error": "error",
1849
+ "@typescript-eslint/no-unsafe-return": "error",
1850
+ "@typescript-eslint/no-unsafe-argument": "error",
1851
+ "@typescript-eslint/no-misused-promises": "error",
1852
+ "@typescript-eslint/no-unsafe-assignment": "error",
1853
+ "@typescript-eslint/no-floating-promises": "error",
1854
+ "@typescript-eslint/promise-function-async": "error",
1855
+ "@typescript-eslint/restrict-plus-operands": "error",
1856
+ "@typescript-eslint/triple-slash-reference": "error",
1857
+ "@typescript-eslint/no-unsafe-member-access": "error",
1858
+ "@typescript-eslint/switch-exhaustiveness-check": "error",
1859
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
1860
+ "@typescript-eslint/restrict-template-expressions": "error",
1861
+ "@typescript-eslint/no-redundant-type-constituents": "error",
1862
+ "@typescript-eslint/no-duplicate-type-constituents": "error",
1863
+ "@typescript-eslint/return-await": ["error", "in-try-catch"],
1864
+ "@typescript-eslint/dot-notation": ["error", { allowKeywords: true }]
1865
+ };
1866
+ var recommendedRules = configs.recommended.reduce((rules, config) => {
1867
+ return { ...rules, ...config.rules || {} };
1868
+ }, {});
1869
+ var typescript = (options = {}) => {
1870
+ const enableTypeAwareLint = !!options?.tsconfigPath;
1871
+ const {
1872
+ filesTypeAware = [GLOB_TS, GLOB_TSX],
1873
+ ignoresTypeAware = [GLOB_ASTRO, `${GLOB_MARKDOWN}/**`],
1874
+ overridesTypeAwareRules = {},
1875
+ parserOptions = {}
1876
+ } = options;
1877
+ function createParserConfig(enableTypeAware = false, files = [], ignores2 = []) {
1878
+ const parserConfig = {
1879
+ name: `ntnyq/ts/${enableTypeAware ? "parser-type-aware" : "parser"}`,
1880
+ files,
1881
+ ignores: [...ignores2],
1882
+ languageOptions: {
1883
+ parser: parserTypeScript,
1884
+ parserOptions: {
1885
+ // extraFileExtensions: [''],
1886
+ sourceType: "module",
1887
+ ...enableTypeAware ? {
1888
+ projectService: {
1889
+ allowDefaultProject: ["./*.js"],
1890
+ defaultProject: options.tsconfigPath
1891
+ },
1892
+ tsconfigRootDir: process2.cwd()
1893
+ } : {},
1894
+ ...parserOptions
1895
+ }
1896
+ }
1897
+ };
1898
+ return parserConfig;
1899
+ }
1900
+ return [
1901
+ {
1902
+ name: "ntnyq/ts/setup",
1903
+ plugins: {
1904
+ "@typescript-eslint": plugin,
1905
+ antfu: default8
1906
+ }
1907
+ },
1908
+ ...enableTypeAwareLint ? [
1909
+ createParserConfig(false, [GLOB_TS, GLOB_TSX]),
1910
+ createParserConfig(true, filesTypeAware, ignoresTypeAware)
1911
+ ] : [createParserConfig(false, [GLOB_TS, GLOB_TSX])],
1912
+ {
1913
+ name: "ntnyq/ts/rules",
1914
+ files: [GLOB_TS, GLOB_TSX],
1915
+ rules: {
1916
+ ...recommendedRules,
1917
+ // Disabled in favor of ts rules
1918
+ "no-redeclare": "off",
1919
+ "no-use-before-define": "off",
1920
+ "no-unused-vars": "off",
1921
+ "@typescript-eslint/no-redeclare": [
1922
+ "error",
1923
+ {
1924
+ builtinGlobals: false,
1925
+ ignoreDeclarationMerge: true
1926
+ }
1927
+ ],
1928
+ "@typescript-eslint/no-use-before-define": [
1929
+ "error",
1930
+ {
1931
+ functions: false,
1932
+ classes: false,
1933
+ variables: true,
1934
+ allowNamedExports: false,
1935
+ enums: true,
1936
+ typedefs: false,
1937
+ ignoreTypeReferences: false
1938
+ }
1939
+ ],
1940
+ "@typescript-eslint/no-unused-vars": [
1941
+ "error",
1942
+ {
1943
+ // Args after the last used will be reported
1944
+ args: "after-used",
1945
+ argsIgnorePattern: "^_",
1946
+ caughtErrors: "all",
1947
+ caughtErrorsIgnorePattern: "^_",
1948
+ destructuredArrayIgnorePattern: "^_",
1949
+ varsIgnorePattern: "^_",
1950
+ ignoreRestSiblings: true
1951
+ }
1952
+ ],
1953
+ "@typescript-eslint/no-unused-expressions": [
1954
+ "error",
1955
+ {
1956
+ allowShortCircuit: true,
1957
+ allowTernary: true,
1958
+ allowTaggedTemplates: true
1959
+ }
1960
+ ],
1961
+ "@typescript-eslint/consistent-type-imports": [
1962
+ "error",
1963
+ {
1964
+ prefer: "type-imports",
1965
+ fixStyle: "separate-type-imports",
1966
+ disallowTypeAnnotations: false
1967
+ }
1968
+ ],
1969
+ "@typescript-eslint/no-empty-object-type": [
1970
+ "error",
1971
+ {
1972
+ allowInterfaces: "always",
1973
+ allowObjectTypes: "always"
1974
+ }
1975
+ ],
1976
+ "@typescript-eslint/consistent-type-assertions": [
1977
+ "error",
1978
+ {
1979
+ assertionStyle: "as",
1980
+ objectLiteralTypeAssertions: "allow-as-parameter"
1981
+ }
1982
+ ],
1983
+ "@typescript-eslint/prefer-as-const": "warn",
1984
+ "@typescript-eslint/no-namespace": "off",
1985
+ "@typescript-eslint/ban-ts-comment": "off",
1986
+ "@typescript-eslint/no-explicit-any": "off",
1987
+ "@typescript-eslint/no-empty-function": "off",
1988
+ "@typescript-eslint/naming-convention": "off",
1989
+ "@typescript-eslint/no-non-null-assertion": "off",
1990
+ "@typescript-eslint/triple-slash-reference": "off",
1991
+ "@typescript-eslint/explicit-member-accessibility": "off",
1992
+ "@typescript-eslint/explicit-function-return-type": "off",
1993
+ "@typescript-eslint/explicit-module-boundary-types": "off",
1994
+ "@typescript-eslint/consistent-indexed-object-style": "off",
1995
+ // Overrides rules
1996
+ ...options.overrides
1997
+ }
1998
+ },
1999
+ ...enableTypeAwareLint ? [
2000
+ {
2001
+ name: "ntnyq/ts/rules/type-aware",
2002
+ files: [...filesTypeAware],
2003
+ ignores: [...ignoresTypeAware],
2004
+ rules: {
2005
+ ...typeAwareRules,
2006
+ // Overrides type aware rules
2007
+ ...overridesTypeAwareRules
2008
+ }
2009
+ }
2010
+ ] : [],
2011
+ {
2012
+ name: "ntnyq/ts/types",
2013
+ files: [GLOB_DTS, "**/types/**/*.ts"],
2014
+ rules: {
2015
+ "no-use-before-define": "off",
2016
+ "no-restricted-syntax": "off",
2017
+ "import/no-duplicates": "off",
2018
+ "import/newline-after-import": "off",
2019
+ "@typescript-eslint/no-use-before-define": "off"
2020
+ }
2021
+ }
2022
+ ];
2023
+ };
2024
+
1960
2025
  // src/configs/githubAction.ts
1961
2026
  var githubAction = (options = {}) => [
1962
2027
  {
@@ -2089,7 +2154,7 @@ var unusedImports = (options = {}) => [
2089
2154
  ];
2090
2155
 
2091
2156
  // src/core.ts
2092
- function defineESLintConfig(options = {}, userConfigs = []) {
2157
+ async function defineESLintConfig(options = {}, ...userConfigs) {
2093
2158
  const configs2 = [];
2094
2159
  if (options.gitignore ?? true) {
2095
2160
  configs2.push(
@@ -2104,9 +2169,18 @@ function defineESLintConfig(options = {}, userConfigs = []) {
2104
2169
  ...node({
2105
2170
  overrides: getOverrides(options, "node")
2106
2171
  }),
2172
+ ...command({
2173
+ ...resolveSubOptions(options, "command")
2174
+ }),
2107
2175
  ...imports({
2108
2176
  overrides: getOverrides(options, "imports")
2109
2177
  }),
2178
+ ...jsdoc({
2179
+ overrides: getOverrides(options, "jsdoc")
2180
+ }),
2181
+ ...comments({
2182
+ overrides: getOverrides(options, "comments")
2183
+ }),
2110
2184
  ...javascript({
2111
2185
  ...resolveSubOptions(options, "javascript"),
2112
2186
  overrides: getOverrides(options, "javascript")
@@ -2135,20 +2209,6 @@ function defineESLintConfig(options = {}, userConfigs = []) {
2135
2209
  })
2136
2210
  );
2137
2211
  }
2138
- if (options.jsdoc ?? true) {
2139
- configs2.push(
2140
- ...jsdoc({
2141
- overrides: getOverrides(options, "jsdoc")
2142
- })
2143
- );
2144
- }
2145
- if (options.comments ?? true) {
2146
- configs2.push(
2147
- ...comments({
2148
- overrides: getOverrides(options, "comments")
2149
- })
2150
- );
2151
- }
2152
2212
  if (options.typescript ?? hasTypeScript) {
2153
2213
  configs2.push(
2154
2214
  ...typescript({
@@ -2217,13 +2277,6 @@ function defineESLintConfig(options = {}, userConfigs = []) {
2217
2277
  })
2218
2278
  );
2219
2279
  }
2220
- if (options.command ?? true) {
2221
- configs2.push(
2222
- ...command({
2223
- ...resolveSubOptions(options, "command")
2224
- })
2225
- );
2226
- }
2227
2280
  if (options.antfu ?? true) {
2228
2281
  configs2.push(
2229
2282
  ...antfu({
@@ -2251,9 +2304,9 @@ function defineESLintConfig(options = {}, userConfigs = []) {
2251
2304
  overrides: getOverrides(options, "prettier")
2252
2305
  }) : [];
2253
2306
  const composer = new FlatConfigComposer();
2254
- composer.append(
2307
+ await composer.append(
2255
2308
  ...configs2,
2256
- ...toArray(userConfigs),
2309
+ ...userConfigs,
2257
2310
  ...configSpecials,
2258
2311
  ...configPrettier
2259
2312
  );
@@ -2263,6 +2316,7 @@ export {
2263
2316
  DEFAULT_PRETTIER_OPTIONS,
2264
2317
  GLOB_ALL_SRC,
2265
2318
  GLOB_ASTRO,
2319
+ GLOB_ASTRO_TS,
2266
2320
  GLOB_CSS,
2267
2321
  GLOB_DIST,
2268
2322
  GLOB_DTS,
@@ -2295,7 +2349,6 @@ export {
2295
2349
  antfu,
2296
2350
  command,
2297
2351
  comments,
2298
- config as createTypeScriptConfig,
2299
2352
  defineESLintConfig,
2300
2353
  format,
2301
2354
  getOverrides,
@@ -2360,7 +2413,6 @@ export {
2360
2413
  toml,
2361
2414
  typescript,
2362
2415
  configs as typescriptConfigs,
2363
- typescriptCore,
2364
2416
  unicorn,
2365
2417
  unocss,
2366
2418
  unusedImports,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/eslint-config",
3
3
  "type": "module",
4
- "version": "3.3.1",
4
+ "version": "3.4.0",
5
5
  "packageManager": "pnpm@9.14.2",
6
6
  "description": "An opinionated ESLint config preset of ntnyq",
7
7
  "keywords": [