@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.cjs CHANGED
@@ -12,7 +12,6 @@ var pluginN = require('eslint-plugin-n');
12
12
  var pluginPromise = require('eslint-plugin-promise');
13
13
  var globals = require('globals');
14
14
  var pluginJsonc = require('eslint-plugin-jsonc');
15
- var jsoncParser = require('jsonc-eslint-parser');
16
15
  var pluginMarkdown = require('@eslint/markdown');
17
16
  var pluginNext = require('@next/eslint-plugin-next');
18
17
  var pluginProgress = require('@aiou/eslint-plugin-progress');
@@ -22,12 +21,12 @@ var pluginReactRefresh = require('eslint-plugin-react-refresh');
22
21
  var eslintPluginRegexp = require('eslint-plugin-regexp');
23
22
  var pluginStylistic = require('@stylistic/eslint-plugin');
24
23
  var node_module = require('node:module');
24
+ var pluginToml = require('eslint-plugin-toml');
25
25
  var pluginTypeScript = require('@typescript-eslint/eslint-plugin');
26
26
  var tsParser = require('@typescript-eslint/parser');
27
27
  var pluginETC = require('eslint-plugin-etc');
28
28
  var pluginUnicorn = require('eslint-plugin-unicorn');
29
- var pluginYaml = require('eslint-plugin-yml');
30
- var yamlParser = require('yaml-eslint-parser');
29
+ var pluginYml = require('eslint-plugin-yml');
31
30
 
32
31
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
33
32
 
@@ -41,7 +40,6 @@ var pluginN__default = /*#__PURE__*/_interopDefault(pluginN);
41
40
  var pluginPromise__default = /*#__PURE__*/_interopDefault(pluginPromise);
42
41
  var globals__default = /*#__PURE__*/_interopDefault(globals);
43
42
  var pluginJsonc__default = /*#__PURE__*/_interopDefault(pluginJsonc);
44
- var jsoncParser__default = /*#__PURE__*/_interopDefault(jsoncParser);
45
43
  var pluginMarkdown__default = /*#__PURE__*/_interopDefault(pluginMarkdown);
46
44
  var pluginNext__default = /*#__PURE__*/_interopDefault(pluginNext);
47
45
  var pluginProgress__default = /*#__PURE__*/_interopDefault(pluginProgress);
@@ -49,12 +47,12 @@ var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
49
47
  var pluginReactHooks__default = /*#__PURE__*/_interopDefault(pluginReactHooks);
50
48
  var pluginReactRefresh__default = /*#__PURE__*/_interopDefault(pluginReactRefresh);
51
49
  var pluginStylistic__default = /*#__PURE__*/_interopDefault(pluginStylistic);
50
+ var pluginToml__default = /*#__PURE__*/_interopDefault(pluginToml);
52
51
  var pluginTypeScript__default = /*#__PURE__*/_interopDefault(pluginTypeScript);
53
52
  var tsParser__default = /*#__PURE__*/_interopDefault(tsParser);
54
53
  var pluginETC__default = /*#__PURE__*/_interopDefault(pluginETC);
55
54
  var pluginUnicorn__default = /*#__PURE__*/_interopDefault(pluginUnicorn);
56
- var pluginYaml__default = /*#__PURE__*/_interopDefault(pluginYaml);
57
- var yamlParser__default = /*#__PURE__*/_interopDefault(yamlParser);
55
+ var pluginYml__default = /*#__PURE__*/_interopDefault(pluginYml);
58
56
 
59
57
  const comments = () => {
60
58
  const config = [
@@ -535,23 +533,11 @@ const javascript = () => {
535
533
 
536
534
  const jsonc = () => {
537
535
  const config = [
538
- {
539
- files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
540
- ignores: [GLOB_CLAUDE_JSON],
541
- name: "jsonc/setup",
542
- languageOptions: {
543
- parser: jsoncParser__default.default
544
- },
545
- plugins: {
546
- jsonc: pluginJsonc__default.default
547
- }
548
- },
536
+ ...pluginJsonc__default.default.configs["recommended-with-jsonc"],
549
537
  {
550
538
  files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
551
539
  ignores: [GLOB_CLAUDE_JSON],
552
540
  rules: {
553
- ...pluginJsonc__default.default.configs["recommended-with-jsonc"].rules,
554
- // refs: https://ota-meshi.github.io/eslint-plugin-jsonc/rules/indent.html
555
541
  "jsonc/array-bracket-newline": [
556
542
  "error",
557
543
  {
@@ -630,8 +616,6 @@ const jsonc = () => {
630
616
  },
631
617
  {
632
618
  pathPattern: "^exports.*$",
633
- // According to webpack, default condition should be last item
634
- // Typescript bugs: types should be first one
635
619
  order: ["types", "import", "require", "node", "browser", "default"]
636
620
  },
637
621
  {
@@ -645,7 +629,6 @@ const jsonc = () => {
645
629
  ]
646
630
  }
647
631
  },
648
- // refs: https://github.com/sxzz/eslint-config/blob/main/src/configs/sort.ts
649
632
  {
650
633
  files: ["**/tsconfig.json", "**/tsconfig.*.json"],
651
634
  rules: {
@@ -772,14 +755,10 @@ const jsonc = () => {
772
755
 
773
756
  const markdown = () => {
774
757
  const config = [
775
- ...pluginMarkdown__default.default.configs.processor.map((config2) => ({
776
- ...config2
777
- })),
758
+ ...pluginMarkdown__default.default.configs.processor,
778
759
  {
779
- // Code blocks in markdown file
780
760
  files: [`${GLOB_MARKDOWN}/*.${GLOB_SCRIPT_EXT}`],
781
761
  rules: {
782
- // https://eslint-react.xyz/docs/migration
783
762
  "react/no-missing-component-display-name": "off",
784
763
  "@typescript-eslint/no-redeclare": "off",
785
764
  "@typescript-eslint/no-unused-vars": "off",
@@ -797,7 +776,6 @@ const markdown = () => {
797
776
  "no-undef": "off",
798
777
  "no-unused-expressions": "off",
799
778
  "no-unused-vars": "off",
800
- // Off imports
801
779
  "import/no-extraneous-dependencies": "off",
802
780
  "import/no-default-export": "off",
803
781
  "import/no-anonymous-default-export": "off",
@@ -817,7 +795,6 @@ const next = () => {
817
795
  "@next/next": pluginNext__default.default
818
796
  },
819
797
  rules: {
820
- // Enable rules for next project
821
798
  ...pluginNext__default.default.configs.recommended.rules
822
799
  }
823
800
  }
@@ -853,7 +830,6 @@ function renameRules(rules, map) {
853
830
  }
854
831
 
855
832
  const react = () => {
856
- const plugins = pluginReact__default.default.configs.all.plugins;
857
833
  const config = [
858
834
  {
859
835
  files: [GLOB_JSX, GLOB_TSX],
@@ -866,34 +842,29 @@ const react = () => {
866
842
  sourceType: "module"
867
843
  },
868
844
  settings: {
869
- react: {
870
- // 'detect' will throw warn on monorepo
845
+ "react-x": {
871
846
  version: "18.0"
872
847
  }
873
848
  },
874
849
  plugins: {
875
- react: plugins["@eslint-react"],
876
- "react-dom": plugins["@eslint-react/dom"],
850
+ react: pluginReact__default.default,
851
+ "react-dom": pluginReact__default.default,
877
852
  "react-hooks": pluginReactHooks__default.default,
878
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
879
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
853
+ "react-hooks-extra": pluginReact__default.default,
854
+ "react-naming-convention": pluginReact__default.default,
880
855
  "react-refresh": pluginReactRefresh__default.default,
881
- "react-web-api": plugins["@eslint-react/web-api"]
856
+ "react-web-api": pluginReact__default.default
882
857
  },
883
858
  rules: {
884
- ...renameRules(plugins["@eslint-react"].configs["recommended-typescript"].rules, { "react-x": "react" }),
885
- ...renameRules(plugins["@eslint-react/dom"].configs.recommended.rules, { "@eslint-react": "react-dom" }),
886
- ...renameRules(pluginReactHooks__default.default.configs.recommended.rules, { "@eslint-react": "react-hooks" }),
887
- ...renameRules(plugins["@eslint-react/hooks-extra"].configs.recommended.rules, { "@eslint-react": "react-hooks-extra" }),
888
- ...renameRules(plugins["@eslint-react/naming-convention"].configs.recommended.rules, { "@eslint-react": "react-naming-convention" }),
889
- ...renameRules(plugins["@eslint-react/web-api"].configs.recommended.rules, { "@eslint-react": "react-web-api" }),
890
- "react/no-prop-types": "error",
859
+ ...renameRules(pluginReact__default.default.configs["recommended-typescript"].rules, { "@eslint-react": "react" }),
860
+ ...renameRules(pluginReact__default.default.configs["dom"].rules, { "@eslint-react": "react-dom" }),
861
+ ...renameRules(pluginReact__default.default.configs["x"].rules, { "@eslint-react": "react-hooks-extra" }),
862
+ ...renameRules(pluginReact__default.default.configs["x"].rules, { "@eslint-react": "react-naming-convention" }),
863
+ ...renameRules(pluginReact__default.default.configs["web-api"].rules, { "@eslint-react": "react-web-api" }),
864
+ ...pluginReactHooks__default.default.configs.flat.recommended.rules,
891
865
  "react/no-nested-component-definitions": "warn",
892
866
  "react-dom/no-unknown-property": "off",
893
- "react/avoid-shorthand-boolean": ["error"],
894
- // https://github.com/ArnaudBarre/eslint-plugin-react-refresh
895
- "react-refresh/only-export-components": "warn",
896
- "react-hooks-extra/no-direct-set-state-in-use-effect": "off"
867
+ "react-refresh/only-export-components": "warn"
897
868
  }
898
869
  },
899
870
  {
@@ -914,9 +885,6 @@ const react = () => {
914
885
  `**/*{-entry,entry.}*.${GLOB_SCRIPT_EXT}`,
915
886
  GLOB_TEST_SCRIPT,
916
887
  GLOB_TEST_DIRS,
917
- // With next.js pages will export getStaticProps funcs
918
- // There are some bad cases for not all files are route files
919
- // RECOMMEND: pages/routes should only contain page files
920
888
  GLOB_PAGES_DIRS
921
889
  ],
922
890
  ignores: [
@@ -942,8 +910,7 @@ const ssrReact = () => {
942
910
  sourceType: "module"
943
911
  },
944
912
  settings: {
945
- react: {
946
- // 'detect' will throw warn on monorepo
913
+ "react-x": {
947
914
  version: "18.0"
948
915
  }
949
916
  },
@@ -965,7 +932,7 @@ const ssrReact = () => {
965
932
  selector: "Identifier[name='window']:not(UnaryExpression[operator='typeof'] > Identifier)",
966
933
  message: `Direct window access not allowed. Use 'typeof window !== "undefined"' check first`
967
934
  },
968
- // Document 对象
935
+ // Document
969
936
  {
970
937
  selector: "MemberExpression[object.name='document']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='document'])",
971
938
  message: `Use 'typeof document !== "undefined" && document.xxx' for safe DOM access`
@@ -974,27 +941,26 @@ const ssrReact = () => {
974
941
  selector: "Identifier[name='document']:not(UnaryExpression[operator='typeof'] > Identifier)",
975
942
  message: `Direct document access not allowed. Use 'typeof document !== "undefined"' check first`
976
943
  },
977
- // Navigator 对象
944
+ // Navigator
978
945
  {
979
946
  selector: "MemberExpression[object.name='navigator']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='navigator'])",
980
947
  message: `Use 'typeof navigator !== "undefined" && navigator.xxx' for safe DOM access`
981
948
  },
982
- // Location 对象
949
+ // Location
983
950
  {
984
951
  selector: "MemberExpression[object.name='location']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='location'])",
985
952
  message: `Use 'typeof location !== "undefined" && location.xxx' for safe DOM access`
986
953
  },
987
- // History 对象
954
+ // History
988
955
  {
989
956
  selector: "MemberExpression[object.name='history']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='history'])",
990
957
  message: `Use 'typeof history !== "undefined" && history.xxx' for safe DOM access`
991
958
  },
992
- // Storage 对象们
959
+ // Storage
993
960
  {
994
961
  selector: "MemberExpression[object.name='localStorage']:not(LogicalExpression[right=MemberExpression] > MemberExpression[object.name='localStorage'])",
995
962
  message: `Use 'typeof localStorage !== "undefined" && localStorage.xxx' for safe DOM access`
996
963
  },
997
- // Fork from enum
998
964
  {
999
965
  selector: "TSEnumDeclaration",
1000
966
  message: "Don't declare enums"
@@ -1005,7 +971,6 @@ const ssrReact = () => {
1005
971
  {
1006
972
  files: [
1007
973
  `**/*config*.${GLOB_SCRIPT_EXT}`,
1008
- // Client entry files not need to be SSR friendly
1009
974
  `**/*{client-entry,entry.client}*.${GLOB_SCRIPT_EXT}`,
1010
975
  GLOB_TEST_SCRIPT,
1011
976
  GLOB_TEST_DIRS
@@ -1030,7 +995,7 @@ const ssrReact = () => {
1030
995
  const regexp = () => {
1031
996
  const config = [
1032
997
  {
1033
- ...eslintPluginRegexp.configs["flat/recommended"]
998
+ ...eslintPluginRegexp.configs.recommended
1034
999
  }
1035
1000
  ];
1036
1001
  return config;
@@ -1038,16 +1003,19 @@ const regexp = () => {
1038
1003
 
1039
1004
  const stylistic = () => {
1040
1005
  const config = pluginStylistic__default.default.configs.customize({
1041
- flat: true,
1042
1006
  indent: 2,
1043
1007
  jsx: true,
1044
1008
  quotes: "single",
1045
1009
  semi: false
1046
1010
  });
1047
1011
  const off = {};
1048
- Object.keys(config.rules ?? {}).forEach((key) => {
1049
- off[key.replace("@stylistic/", "")] = "off";
1050
- });
1012
+ for (const key of Object.keys(config.rules ?? {})) {
1013
+ const bare = key.replace("@stylistic/", "");
1014
+ if (bare === "function-call-spacing") {
1015
+ continue;
1016
+ }
1017
+ off[bare] = "off";
1018
+ }
1051
1019
  const configs = [
1052
1020
  {
1053
1021
  files: [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX],
@@ -1060,7 +1028,6 @@ const stylistic = () => {
1060
1028
  "@stylistic/quotes": ["error", "single", { avoidEscape: true }],
1061
1029
  "@stylistic/quote-props": ["error", "as-needed"],
1062
1030
  "@stylistic/array-bracket-spacing": ["error", "never"],
1063
- // https://eslint.org/docs/latest/rules/brace-style#1tbs
1064
1031
  "@stylistic/brace-style": ["error", "1tbs"],
1065
1032
  "@stylistic/block-spacing": ["error", "always"],
1066
1033
  "@stylistic/comma-spacing": ["error", { before: false, after: true }],
@@ -1114,8 +1081,7 @@ const stylistic = () => {
1114
1081
  "@stylistic/operator-linebreak": ["error", "before"],
1115
1082
  "@stylistic/member-delimiter-style": ["error", { multiline: { delimiter: "none" } }],
1116
1083
  "@stylistic/type-annotation-spacing": ["error", {}],
1117
- // no-spaced-func alert -- https://eslint.org/docs/latest/rules/no-spaced-func
1118
- "@stylistic/func-call-spacing": ["error", "never"],
1084
+ "@stylistic/function-call-spacing": ["error", "never"],
1119
1085
  "@stylistic/semi": ["error", "never"],
1120
1086
  "@stylistic/space-before-blocks": ["error", "always"],
1121
1087
  "@stylistic/space-before-function-paren": [
@@ -1135,8 +1101,6 @@ const stylistic = () => {
1135
1101
  { exceptAfterSingleLine: true }
1136
1102
  ],
1137
1103
  "@stylistic/jsx-quotes": ["error", "prefer-double"],
1138
- // React
1139
- // Enforce new line when declare jsx element e.g. const element = (\newline<div
1140
1104
  "@stylistic/jsx-wrap-multilines": [
1141
1105
  "warn",
1142
1106
  {
@@ -1150,15 +1114,10 @@ const stylistic = () => {
1150
1114
  }
1151
1115
  ],
1152
1116
  "@stylistic/jsx-closing-tag-location": "error",
1153
- // Enforce disallow </ div>
1154
1117
  "@stylistic/jsx-tag-spacing": ["error", { closingSlash: "never", beforeSelfClosing: "always", afterOpening: "never", beforeClosing: "allow" }],
1155
1118
  "@stylistic/jsx-max-props-per-line": ["warn", { maximum: 1, when: "multiline" }],
1156
- // indentLogicalExpressions will fix && element
1157
- "@stylistic/jsx-indent": ["warn", 2, { indentLogicalExpressions: true }],
1158
1119
  "@stylistic/jsx-indent-props": ["warn", 2],
1159
- // < and > should be on the same line(y-axis) if jsx is multiline
1160
1120
  "@stylistic/jsx-closing-bracket-location": ["warn", "tag-aligned"],
1161
- // Enforce new line when multiline props jsx
1162
1121
  "@stylistic/jsx-first-prop-new-line": ["warn", "multiline-multiprop"],
1163
1122
  "@stylistic/jsx-one-expression-per-line": "off"
1164
1123
  }
@@ -1182,6 +1141,35 @@ const tailwindcss = () => {
1182
1141
  return config;
1183
1142
  };
1184
1143
 
1144
+ const toml = () => {
1145
+ const config = [
1146
+ ...pluginToml__default.default.configs.recommended,
1147
+ {
1148
+ rules: {
1149
+ "toml/comma-style": "error",
1150
+ "toml/keys-order": "error",
1151
+ "toml/no-space-dots": "error",
1152
+ "toml/no-unreadable-number-separator": "error",
1153
+ "toml/precision-of-fractional-seconds": "error",
1154
+ "toml/precision-of-integer": "error",
1155
+ "toml/tables-order": "error",
1156
+ "toml/array-bracket-newline": "error",
1157
+ "toml/array-bracket-spacing": "error",
1158
+ "toml/array-element-newline": "error",
1159
+ "toml/indent": ["error", 4],
1160
+ "toml/inline-table-curly-spacing": "error",
1161
+ "toml/key-spacing": "error",
1162
+ "toml/padding-line-between-pairs": "error",
1163
+ "toml/padding-line-between-tables": "error",
1164
+ "toml/quoted-keys": "error",
1165
+ "toml/spaced-comment": "error",
1166
+ "toml/table-bracket-spacing": "error"
1167
+ }
1168
+ }
1169
+ ];
1170
+ return config;
1171
+ };
1172
+
1185
1173
  const typescript = () => {
1186
1174
  const config = [
1187
1175
  {
@@ -1315,6 +1303,7 @@ const unicorn = () => {
1315
1303
  unicorn: pluginUnicorn__default.default
1316
1304
  },
1317
1305
  rules: {
1306
+ ...pluginUnicorn__default.default.configs.recommended.rules,
1318
1307
  "unicorn/consistent-empty-array-spread": "error",
1319
1308
  "unicorn/error-message": "error",
1320
1309
  "unicorn/escape-case": "error",
@@ -1338,17 +1327,10 @@ const unicorn = () => {
1338
1327
 
1339
1328
  const yml = () => {
1340
1329
  const config = [
1330
+ ...pluginYml__default.default.configs.standard,
1341
1331
  {
1342
1332
  files: [GLOB_YAML],
1343
- languageOptions: {
1344
- parser: yamlParser__default.default
1345
- },
1346
- plugins: {
1347
- yml: pluginYaml__default.default
1348
- },
1349
1333
  rules: {
1350
- ...pluginYaml__default.default.configs.standard.rules,
1351
- // yml
1352
1334
  "spaced-comment": "off",
1353
1335
  "yml/quotes": ["error", { prefer: "double", avoidEscape: false }],
1354
1336
  "yml/no-empty-document": "off"
@@ -1357,12 +1339,6 @@ const yml = () => {
1357
1339
  {
1358
1340
  files: [GLOB_WORKFLOW_YAML],
1359
1341
  rules: {
1360
- /**
1361
- * on:
1362
- * push:
1363
- * pull_request:
1364
- * branches: []
1365
- */
1366
1342
  "yml/no-empty-mapping-value": "off"
1367
1343
  }
1368
1344
  }
@@ -1384,7 +1360,8 @@ const presetTypescript = [
1384
1360
  const presetLangsExtensions = [
1385
1361
  ...yml(),
1386
1362
  ...markdown(),
1387
- ...jsonc()
1363
+ ...jsonc(),
1364
+ ...toml()
1388
1365
  ];
1389
1366
  const presetDefault = [
1390
1367
  ...presetTypescript,