@aiou/eslint-config 2.2.0 → 3.0.1

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.mjs CHANGED
@@ -10,7 +10,6 @@ import pluginN from 'eslint-plugin-n';
10
10
  import pluginPromise from 'eslint-plugin-promise';
11
11
  import globals from 'globals';
12
12
  import pluginJsonc from 'eslint-plugin-jsonc';
13
- import jsoncParser from 'jsonc-eslint-parser';
14
13
  import pluginMarkdown from '@eslint/markdown';
15
14
  import pluginNext from '@next/eslint-plugin-next';
16
15
  import pluginProgress from '@aiou/eslint-plugin-progress';
@@ -20,12 +19,12 @@ import pluginReactRefresh from 'eslint-plugin-react-refresh';
20
19
  import { configs } from 'eslint-plugin-regexp';
21
20
  import pluginStylistic from '@stylistic/eslint-plugin';
22
21
  import { createRequire } from 'node:module';
22
+ import pluginToml from 'eslint-plugin-toml';
23
23
  import pluginTypeScript from '@typescript-eslint/eslint-plugin';
24
24
  import tsParser from '@typescript-eslint/parser';
25
25
  import pluginETC from 'eslint-plugin-etc';
26
26
  import pluginUnicorn from 'eslint-plugin-unicorn';
27
- import pluginYaml from 'eslint-plugin-yml';
28
- import yamlParser from 'yaml-eslint-parser';
27
+ import pluginYml from 'eslint-plugin-yml';
29
28
 
30
29
  const comments = () => {
31
30
  const config = [
@@ -506,23 +505,11 @@ const javascript = () => {
506
505
 
507
506
  const jsonc = () => {
508
507
  const config = [
509
- {
510
- files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
511
- ignores: [GLOB_CLAUDE_JSON],
512
- name: "jsonc/setup",
513
- languageOptions: {
514
- parser: jsoncParser
515
- },
516
- plugins: {
517
- jsonc: pluginJsonc
518
- }
519
- },
508
+ ...pluginJsonc.configs["recommended-with-jsonc"],
520
509
  {
521
510
  files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
522
511
  ignores: [GLOB_CLAUDE_JSON],
523
512
  rules: {
524
- ...pluginJsonc.configs["recommended-with-jsonc"].rules,
525
- // refs: https://ota-meshi.github.io/eslint-plugin-jsonc/rules/indent.html
526
513
  "jsonc/array-bracket-newline": [
527
514
  "error",
528
515
  {
@@ -601,8 +588,6 @@ const jsonc = () => {
601
588
  },
602
589
  {
603
590
  pathPattern: "^exports.*$",
604
- // According to webpack, default condition should be last item
605
- // Typescript bugs: types should be first one
606
591
  order: ["types", "import", "require", "node", "browser", "default"]
607
592
  },
608
593
  {
@@ -616,7 +601,6 @@ const jsonc = () => {
616
601
  ]
617
602
  }
618
603
  },
619
- // refs: https://github.com/sxzz/eslint-config/blob/main/src/configs/sort.ts
620
604
  {
621
605
  files: ["**/tsconfig.json", "**/tsconfig.*.json"],
622
606
  rules: {
@@ -743,14 +727,10 @@ const jsonc = () => {
743
727
 
744
728
  const markdown = () => {
745
729
  const config = [
746
- ...pluginMarkdown.configs.processor.map((config2) => ({
747
- ...config2
748
- })),
730
+ ...pluginMarkdown.configs.processor,
749
731
  {
750
- // Code blocks in markdown file
751
732
  files: [`${GLOB_MARKDOWN}/*.${GLOB_SCRIPT_EXT}`],
752
733
  rules: {
753
- // https://eslint-react.xyz/docs/migration
754
734
  "react/no-missing-component-display-name": "off",
755
735
  "@typescript-eslint/no-redeclare": "off",
756
736
  "@typescript-eslint/no-unused-vars": "off",
@@ -768,7 +748,6 @@ const markdown = () => {
768
748
  "no-undef": "off",
769
749
  "no-unused-expressions": "off",
770
750
  "no-unused-vars": "off",
771
- // Off imports
772
751
  "import/no-extraneous-dependencies": "off",
773
752
  "import/no-default-export": "off",
774
753
  "import/no-anonymous-default-export": "off",
@@ -788,7 +767,6 @@ const next = () => {
788
767
  "@next/next": pluginNext
789
768
  },
790
769
  rules: {
791
- // Enable rules for next project
792
770
  ...pluginNext.configs.recommended.rules
793
771
  }
794
772
  }
@@ -824,7 +802,6 @@ function renameRules(rules, map) {
824
802
  }
825
803
 
826
804
  const react = () => {
827
- const plugins = pluginReact.configs.all.plugins;
828
805
  const config = [
829
806
  {
830
807
  files: [GLOB_JSX, GLOB_TSX],
@@ -837,34 +814,29 @@ const react = () => {
837
814
  sourceType: "module"
838
815
  },
839
816
  settings: {
840
- react: {
841
- // 'detect' will throw warn on monorepo
817
+ "react-x": {
842
818
  version: "18.0"
843
819
  }
844
820
  },
845
821
  plugins: {
846
- react: plugins["@eslint-react"],
847
- "react-dom": plugins["@eslint-react/dom"],
822
+ react: pluginReact,
823
+ "react-dom": pluginReact,
848
824
  "react-hooks": pluginReactHooks,
849
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
850
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
825
+ "react-hooks-extra": pluginReact,
826
+ "react-naming-convention": pluginReact,
851
827
  "react-refresh": pluginReactRefresh,
852
- "react-web-api": plugins["@eslint-react/web-api"]
828
+ "react-web-api": pluginReact
853
829
  },
854
830
  rules: {
855
- ...renameRules(plugins["@eslint-react"].configs["recommended-typescript"].rules, { "react-x": "react" }),
856
- ...renameRules(plugins["@eslint-react/dom"].configs.recommended.rules, { "@eslint-react": "react-dom" }),
857
- ...renameRules(pluginReactHooks.configs.recommended.rules, { "@eslint-react": "react-hooks" }),
858
- ...renameRules(plugins["@eslint-react/hooks-extra"].configs.recommended.rules, { "@eslint-react": "react-hooks-extra" }),
859
- ...renameRules(plugins["@eslint-react/naming-convention"].configs.recommended.rules, { "@eslint-react": "react-naming-convention" }),
860
- ...renameRules(plugins["@eslint-react/web-api"].configs.recommended.rules, { "@eslint-react": "react-web-api" }),
861
- "react/no-prop-types": "error",
831
+ ...renameRules(pluginReact.configs["recommended-typescript"].rules, { "@eslint-react": "react" }),
832
+ ...renameRules(pluginReact.configs["dom"].rules, { "@eslint-react": "react-dom" }),
833
+ ...renameRules(pluginReact.configs["x"].rules, { "@eslint-react": "react-hooks-extra" }),
834
+ ...renameRules(pluginReact.configs["x"].rules, { "@eslint-react": "react-naming-convention" }),
835
+ ...renameRules(pluginReact.configs["web-api"].rules, { "@eslint-react": "react-web-api" }),
836
+ ...pluginReactHooks.configs.flat.recommended.rules,
862
837
  "react/no-nested-component-definitions": "warn",
863
838
  "react-dom/no-unknown-property": "off",
864
- "react/avoid-shorthand-boolean": ["error"],
865
- // https://github.com/ArnaudBarre/eslint-plugin-react-refresh
866
- "react-refresh/only-export-components": "warn",
867
- "react-hooks-extra/no-direct-set-state-in-use-effect": "off"
839
+ "react-refresh/only-export-components": "warn"
868
840
  }
869
841
  },
870
842
  {
@@ -885,9 +857,6 @@ const react = () => {
885
857
  `**/*{-entry,entry.}*.${GLOB_SCRIPT_EXT}`,
886
858
  GLOB_TEST_SCRIPT,
887
859
  GLOB_TEST_DIRS,
888
- // With next.js pages will export getStaticProps funcs
889
- // There are some bad cases for not all files are route files
890
- // RECOMMEND: pages/routes should only contain page files
891
860
  GLOB_PAGES_DIRS
892
861
  ],
893
862
  ignores: [
@@ -913,8 +882,7 @@ const ssrReact = () => {
913
882
  sourceType: "module"
914
883
  },
915
884
  settings: {
916
- react: {
917
- // 'detect' will throw warn on monorepo
885
+ "react-x": {
918
886
  version: "18.0"
919
887
  }
920
888
  },
@@ -936,7 +904,7 @@ const ssrReact = () => {
936
904
  selector: "Identifier[name='window']:not(UnaryExpression[operator='typeof'] > Identifier)",
937
905
  message: `Direct window access not allowed. Use 'typeof window !== "undefined"' check first`
938
906
  },
939
- // Document 对象
907
+ // Document
940
908
  {
941
909
  selector: "MemberExpression[object.name='document']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='document'])",
942
910
  message: `Use 'typeof document !== "undefined" && document.xxx' for safe DOM access`
@@ -945,27 +913,26 @@ const ssrReact = () => {
945
913
  selector: "Identifier[name='document']:not(UnaryExpression[operator='typeof'] > Identifier)",
946
914
  message: `Direct document access not allowed. Use 'typeof document !== "undefined"' check first`
947
915
  },
948
- // Navigator 对象
916
+ // Navigator
949
917
  {
950
918
  selector: "MemberExpression[object.name='navigator']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='navigator'])",
951
919
  message: `Use 'typeof navigator !== "undefined" && navigator.xxx' for safe DOM access`
952
920
  },
953
- // Location 对象
921
+ // Location
954
922
  {
955
923
  selector: "MemberExpression[object.name='location']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='location'])",
956
924
  message: `Use 'typeof location !== "undefined" && location.xxx' for safe DOM access`
957
925
  },
958
- // History 对象
926
+ // History
959
927
  {
960
928
  selector: "MemberExpression[object.name='history']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='history'])",
961
929
  message: `Use 'typeof history !== "undefined" && history.xxx' for safe DOM access`
962
930
  },
963
- // Storage 对象们
931
+ // Storage
964
932
  {
965
933
  selector: "MemberExpression[object.name='localStorage']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='localStorage'])",
966
934
  message: `Use 'typeof localStorage !== "undefined" && localStorage.xxx' for safe DOM access`
967
935
  },
968
- // Fork from enum
969
936
  {
970
937
  selector: "TSEnumDeclaration",
971
938
  message: "Don't declare enums"
@@ -976,7 +943,6 @@ const ssrReact = () => {
976
943
  {
977
944
  files: [
978
945
  `**/*config*.${GLOB_SCRIPT_EXT}`,
979
- // Client entry files not need to be SSR friendly
980
946
  `**/*{client-entry,entry.client}*.${GLOB_SCRIPT_EXT}`,
981
947
  GLOB_TEST_SCRIPT,
982
948
  GLOB_TEST_DIRS
@@ -1001,7 +967,7 @@ const ssrReact = () => {
1001
967
  const regexp = () => {
1002
968
  const config = [
1003
969
  {
1004
- ...configs["flat/recommended"]
970
+ ...configs.recommended
1005
971
  }
1006
972
  ];
1007
973
  return config;
@@ -1009,16 +975,19 @@ const regexp = () => {
1009
975
 
1010
976
  const stylistic = () => {
1011
977
  const config = pluginStylistic.configs.customize({
1012
- flat: true,
1013
978
  indent: 2,
1014
979
  jsx: true,
1015
980
  quotes: "single",
1016
981
  semi: false
1017
982
  });
1018
983
  const off = {};
1019
- Object.keys(config.rules ?? {}).forEach((key) => {
1020
- off[key.replace("@stylistic/", "")] = "off";
1021
- });
984
+ for (const key of Object.keys(config.rules ?? {})) {
985
+ const bare = key.replace("@stylistic/", "");
986
+ if (bare === "function-call-spacing") {
987
+ continue;
988
+ }
989
+ off[bare] = "off";
990
+ }
1022
991
  const configs = [
1023
992
  {
1024
993
  files: [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX],
@@ -1031,7 +1000,6 @@ const stylistic = () => {
1031
1000
  "@stylistic/quotes": ["error", "single", { avoidEscape: true }],
1032
1001
  "@stylistic/quote-props": ["error", "as-needed"],
1033
1002
  "@stylistic/array-bracket-spacing": ["error", "never"],
1034
- // https://eslint.org/docs/latest/rules/brace-style#1tbs
1035
1003
  "@stylistic/brace-style": ["error", "1tbs"],
1036
1004
  "@stylistic/block-spacing": ["error", "always"],
1037
1005
  "@stylistic/comma-spacing": ["error", { before: false, after: true }],
@@ -1085,8 +1053,7 @@ const stylistic = () => {
1085
1053
  "@stylistic/operator-linebreak": ["error", "before"],
1086
1054
  "@stylistic/member-delimiter-style": ["error", { multiline: { delimiter: "none" } }],
1087
1055
  "@stylistic/type-annotation-spacing": ["error", {}],
1088
- // no-spaced-func alert -- https://eslint.org/docs/latest/rules/no-spaced-func
1089
- "@stylistic/func-call-spacing": ["error", "never"],
1056
+ "@stylistic/function-call-spacing": ["error", "never"],
1090
1057
  "@stylistic/semi": ["error", "never"],
1091
1058
  "@stylistic/space-before-blocks": ["error", "always"],
1092
1059
  "@stylistic/space-before-function-paren": [
@@ -1106,8 +1073,6 @@ const stylistic = () => {
1106
1073
  { exceptAfterSingleLine: true }
1107
1074
  ],
1108
1075
  "@stylistic/jsx-quotes": ["error", "prefer-double"],
1109
- // React
1110
- // Enforce new line when declare jsx element e.g. const element = (\newline<div
1111
1076
  "@stylistic/jsx-wrap-multilines": [
1112
1077
  "warn",
1113
1078
  {
@@ -1121,15 +1086,10 @@ const stylistic = () => {
1121
1086
  }
1122
1087
  ],
1123
1088
  "@stylistic/jsx-closing-tag-location": "error",
1124
- // Enforce disallow </ div>
1125
1089
  "@stylistic/jsx-tag-spacing": ["error", { closingSlash: "never", beforeSelfClosing: "always", afterOpening: "never", beforeClosing: "allow" }],
1126
1090
  "@stylistic/jsx-max-props-per-line": ["warn", { maximum: 1, when: "multiline" }],
1127
- // indentLogicalExpressions will fix && element
1128
- "@stylistic/jsx-indent": ["warn", 2, { indentLogicalExpressions: true }],
1129
1091
  "@stylistic/jsx-indent-props": ["warn", 2],
1130
- // < and > should be on the same line(y-axis) if jsx is multiline
1131
1092
  "@stylistic/jsx-closing-bracket-location": ["warn", "tag-aligned"],
1132
- // Enforce new line when multiline props jsx
1133
1093
  "@stylistic/jsx-first-prop-new-line": ["warn", "multiline-multiprop"],
1134
1094
  "@stylistic/jsx-one-expression-per-line": "off"
1135
1095
  }
@@ -1153,6 +1113,35 @@ const tailwindcss = () => {
1153
1113
  return config;
1154
1114
  };
1155
1115
 
1116
+ const toml = () => {
1117
+ const config = [
1118
+ ...pluginToml.configs.recommended,
1119
+ {
1120
+ rules: {
1121
+ "toml/comma-style": "error",
1122
+ "toml/keys-order": "error",
1123
+ "toml/no-space-dots": "error",
1124
+ "toml/no-unreadable-number-separator": "error",
1125
+ "toml/precision-of-fractional-seconds": "error",
1126
+ "toml/precision-of-integer": "error",
1127
+ "toml/tables-order": "error",
1128
+ "toml/array-bracket-newline": "error",
1129
+ "toml/array-bracket-spacing": "error",
1130
+ "toml/array-element-newline": "error",
1131
+ "toml/indent": ["error", 4],
1132
+ "toml/inline-table-curly-spacing": "error",
1133
+ "toml/key-spacing": "error",
1134
+ "toml/padding-line-between-pairs": "error",
1135
+ "toml/padding-line-between-tables": "error",
1136
+ "toml/quoted-keys": "error",
1137
+ "toml/spaced-comment": "error",
1138
+ "toml/table-bracket-spacing": "error"
1139
+ }
1140
+ }
1141
+ ];
1142
+ return config;
1143
+ };
1144
+
1156
1145
  const typescript = () => {
1157
1146
  const config = [
1158
1147
  {
@@ -1286,6 +1275,7 @@ const unicorn = () => {
1286
1275
  unicorn: pluginUnicorn
1287
1276
  },
1288
1277
  rules: {
1278
+ ...pluginUnicorn.configs.recommended.rules,
1289
1279
  "unicorn/consistent-empty-array-spread": "error",
1290
1280
  "unicorn/error-message": "error",
1291
1281
  "unicorn/escape-case": "error",
@@ -1309,17 +1299,10 @@ const unicorn = () => {
1309
1299
 
1310
1300
  const yml = () => {
1311
1301
  const config = [
1302
+ ...pluginYml.configs.standard,
1312
1303
  {
1313
1304
  files: [GLOB_YAML],
1314
- languageOptions: {
1315
- parser: yamlParser
1316
- },
1317
- plugins: {
1318
- yml: pluginYaml
1319
- },
1320
1305
  rules: {
1321
- ...pluginYaml.configs.standard.rules,
1322
- // yml
1323
1306
  "spaced-comment": "off",
1324
1307
  "yml/quotes": ["error", { prefer: "double", avoidEscape: false }],
1325
1308
  "yml/no-empty-document": "off"
@@ -1328,12 +1311,6 @@ const yml = () => {
1328
1311
  {
1329
1312
  files: [GLOB_WORKFLOW_YAML],
1330
1313
  rules: {
1331
- /**
1332
- * on:
1333
- * push:
1334
- * pull_request:
1335
- * branches: []
1336
- */
1337
1314
  "yml/no-empty-mapping-value": "off"
1338
1315
  }
1339
1316
  }
@@ -1355,7 +1332,8 @@ const presetTypescript = [
1355
1332
  const presetLangsExtensions = [
1356
1333
  ...yml(),
1357
1334
  ...markdown(),
1358
- ...jsonc()
1335
+ ...jsonc(),
1336
+ ...toml()
1359
1337
  ];
1360
1338
  const presetDefault = [
1361
1339
  ...presetTypescript,
@@ -0,0 +1,2 @@
1
+ import type { Config } from '../type';
2
+ export declare const toml: () => Config[];
package/dts/globs.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare const GLOB_PAGES_COMPONENTS_DIRS = "**/{pages,routes}/components/
6
6
  export declare const GLOB_DTS = "**/*.d.ts";
7
7
  export declare const GLOB_TS = "**/*.?([cm])ts";
8
8
  export declare const GLOB_TSX = "**/*.?([cm])tsx";
9
+ export declare const GLOB_TOML = "**/*.toml";
9
10
  export declare const GLOB_JS = "**/*.?([cm])js";
10
11
  export declare const GLOB_JSX = "**/*.?([cm])jsx";
11
12
  export declare const GLOB_JSON = "**/*.json";
package/dts/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { type Arrayable, type Awaitable, FlatConfigComposer } from 'eslint-flat-config-utils';
1
+ import { FlatConfigComposer } from 'eslint-flat-config-utils';
2
2
  import type { Linter } from 'eslint';
3
+ import type { Arrayable, Awaitable } from 'eslint-flat-config-utils';
3
4
  import type { Config } from './type';
4
5
  import type { ConfigNames } from './typegen';
5
6
  export declare const all: Config[];