@cuiqg/eslint-config 2.2.0 → 2.2.2

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 (2) hide show
  1. package/dist/index.js +45 -9
  2. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -11,6 +11,12 @@ async function interopDefault(m) {
11
11
  const resolved = await m;
12
12
  return resolved.default || m;
13
13
  }
14
+ function renameRules(rules, map) {
15
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
16
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
17
+ return [key, value];
18
+ }));
19
+ }
14
20
 
15
21
  //#endregion
16
22
  //#region src/configs/comments.js
@@ -35,6 +41,8 @@ const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
35
41
  const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
36
42
  const GLOB_JS = "**/*.?([cm])js";
37
43
  const GLOB_JSX = "**/*.?([cm])jsx";
44
+ const GLOB_TS = "**/*.?([cm])ts";
45
+ const GLOB_TSX = "**/*.?([cm])tsx";
38
46
  const GLOB_STYLE = "**/*.{c,le,sc}ss";
39
47
  const GLOB_CSS = "**/*.css";
40
48
  const GLOB_POSTCSS = "**/*.{p,post}css";
@@ -43,11 +51,13 @@ const GLOB_SCSS = "**/*.scss";
43
51
  const GLOB_JSON = "**/*.json";
44
52
  const GLOB_JSON5 = "**/*.json5";
45
53
  const GLOB_JSONC = "**/*.jsonc";
54
+ const GLOB_MARKDOWN = "**/*.md";
46
55
  const GLOB_VUE = "**/*.vue";
47
56
  const GLOB_YAML = "**/*.y?(a)ml";
57
+ const GLOB_TOML = "**/*.toml";
48
58
  const GLOB_XML = "**/*.xml";
59
+ const GLOB_SVG = "**/*.svg";
49
60
  const GLOB_HTML = "**/*.htm?(l)";
50
- const GLOB_TOML = "**/*.toml";
51
61
  const GLOB_EXCLUDE = [
52
62
  "**/node_modules",
53
63
  "**/dist",
@@ -169,7 +179,7 @@ function isInEditor() {
169
179
  return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
170
180
  }
171
181
  function isInGitHooksOrLintStaged() {
172
- return !!(process.env.HUSKY || process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
182
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
173
183
  }
174
184
 
175
185
  //#endregion
@@ -841,6 +851,29 @@ const toml = async () => {
841
851
  }];
842
852
  };
843
853
 
854
+ //#endregion
855
+ //#region src/configs/typescript.js
856
+ /**
857
+ * TypeScript
858
+ *
859
+ * @see https://typescript-eslint.io/
860
+ * @returns {import('eslint').Linter.FlatConfig[]}
861
+ */
862
+ async function typescript() {
863
+ const files = [GLOB_TS, GLOB_TSX];
864
+ const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
865
+ return [{
866
+ files,
867
+ languageOptions: {
868
+ parser: parserTs,
869
+ parserOptions: { sourceType: "module" }
870
+ },
871
+ name: "cuiqg/typescript",
872
+ plugins: { "ts": pluginTs },
873
+ rules: { ...renameRules(pluginTs.configs["flat/recommended"].rules, { "@typescript-eslint": "ts" }) }
874
+ }];
875
+ }
876
+
844
877
  //#endregion
845
878
  //#region src/configs/unicorn.js
846
879
  /**
@@ -897,6 +930,7 @@ const unocss = async () => {
897
930
  */
898
931
  const unplugin = async () => {
899
932
  const resolved = resolve(process.cwd(), `./.eslintrc-auto-import.json`);
933
+ let globals$1 = {};
900
934
  if (fs.existsSync(resolved) && fs.statSync(resolved).isFile) {
901
935
  const cwd = dirname(resolved);
902
936
  const { config } = await loadConfig({
@@ -909,11 +943,12 @@ const unplugin = async () => {
909
943
  }],
910
944
  cwd
911
945
  });
912
- return [{
913
- name: "cuiqg/unplugin/auto-import",
914
- languageOptions: { globals: { ...config } }
915
- }];
916
- } else return [];
946
+ globals$1 = { ...config };
947
+ }
948
+ return [{
949
+ name: "cuiqg/unplugin/auto-import",
950
+ languageOptions: { globals: globals$1 }
951
+ }];
917
952
  };
918
953
 
919
954
  //#endregion
@@ -1112,7 +1147,7 @@ const defaultPluginRenaming = {
1112
1147
  "yml": "yaml"
1113
1148
  };
1114
1149
  function cuiqg(options = {}, ...userConfigs) {
1115
- const { prettier: enablePrettier = false, gitignore: enableGitignore = true, unocss: enableUnocss = hasUnocss, vue: enableVue = hasVue, stylistic: enableStylistic = true, jsdoc: enableJsdoc = false, pnpm: enablePnpm = false } = options;
1150
+ const { prettier: enablePrettier = false, gitignore: enableGitignore = true, unocss: enableUnocss = hasUnocss, vue: enableVue = hasVue, stylistic: enableStylistic = true, typescript: enableTypescript = hasTypescript, jsdoc: enableJsdoc = false, pnpm: enablePnpm = false } = options;
1116
1151
  const configs = [
1117
1152
  unplugin(),
1118
1153
  ignores(),
@@ -1136,6 +1171,7 @@ function cuiqg(options = {}, ...userConfigs) {
1136
1171
  if (enablePrettier) configs.push(prettier());
1137
1172
  if (enableJsdoc) configs.push(jsdoc());
1138
1173
  if (enablePnpm) configs.push(pnpm());
1174
+ if (enableTypescript) configs.push(typescript());
1139
1175
  let composer = new FlatConfigComposer(...configs, ...userConfigs);
1140
1176
  composer = composer.renamePlugins(defaultPluginRenaming);
1141
1177
  return composer;
@@ -1146,4 +1182,4 @@ function cuiqg(options = {}, ...userConfigs) {
1146
1182
  var src_default = cuiqg;
1147
1183
 
1148
1184
  //#endregion
1149
- export { GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TOML, GLOB_VUE, GLOB_XML, GLOB_YAML, comments, cuiqg, src_default as default, defaultPluginRenaming, disables, gitignore, hasTypescript, hasUnocss, hasVue, ignores, imports, interopDefault, isInEditor, isInGitHooksOrLintStaged, javascript, jsdoc, jsonc, macros, node, pnpm, prettier, sortJsconfig, sortPackageJson, stylistic, toml, unicorn, unocss, unplugin, vue, yaml };
1185
+ export { GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, comments, cuiqg, src_default as default, defaultPluginRenaming, disables, gitignore, hasTypescript, hasUnocss, hasVue, ignores, imports, interopDefault, isInEditor, isInGitHooksOrLintStaged, javascript, jsdoc, jsonc, macros, node, pnpm, prettier, renameRules, sortJsconfig, sortPackageJson, stylistic, toml, typescript, unicorn, unocss, unplugin, vue, yaml };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuiqg/eslint-config",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "ESLint config preset for @cuiqg",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -31,6 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@stylistic/eslint-plugin": "^4.4.0",
34
+ "@typescript-eslint/eslint-plugin": "^8.33.1",
35
+ "@typescript-eslint/parser": "^8.33.1",
34
36
  "@unocss/eslint-plugin": "^66.1.2",
35
37
  "eslint-config-flat-gitignore": "^2.1.0",
36
38
  "eslint-flat-config-utils": "^2.1.0",