@lincy/eslint-config 4.4.0 → 4.5.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/README.md CHANGED
@@ -508,7 +508,7 @@ pnpm add eslint-plugin-format -D
508
508
  运行“npx eslint”会提示您安装所需的依赖项,当然,也可以手动安装它们:
509
509
 
510
510
  ```bash
511
- pnpm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
511
+ pnpm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh
512
512
  ```
513
513
 
514
514
  #### UnoCSS
@@ -540,14 +540,14 @@ pnpm i -D @unocss/eslint-plugin
540
540
 
541
541
  建议使用[configuration comments]单独选择每个文件。(https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
542
542
 
543
- ```js
543
+ ```ts
544
544
  /* eslint perfectionist/sort-objects: "error" */
545
545
  const objectWantedToSort = {
546
546
  a: 2,
547
547
  b: 1,
548
548
  c: 3,
549
549
  }
550
- /* eslint perfectionist/sort-objects: "off" */
550
+ /* e slint perfectionist/sort-objects: "off" */
551
551
  ```
552
552
 
553
553
  ### 类型感知规则
package/dist/index.cjs CHANGED
@@ -997,152 +997,116 @@ async function react(options = {}) {
997
997
  typescript: typescript2 = true,
998
998
  version = "detect"
999
999
  } = options;
1000
+ const tsconfigPath = options?.tsconfigPath ? toArray(options.tsconfigPath) : void 0;
1001
+ const isTypeAware = !!tsconfigPath || !typescript2;
1000
1002
  await ensurePackages([
1001
- "eslint-plugin-react",
1003
+ "@eslint-react/eslint-plugin",
1002
1004
  "eslint-plugin-react-hooks",
1003
1005
  "eslint-plugin-react-refresh"
1004
1006
  ]);
1005
1007
  const [
1006
1008
  pluginReact,
1007
1009
  pluginReactHooks,
1008
- pluginReactRefresh
1010
+ pluginReactRefresh,
1011
+ parserTs
1009
1012
  ] = await Promise.all([
1010
- // @ts-expect-error missing types
1011
- interopDefault(import("eslint-plugin-react")),
1013
+ interopDefault(import("@eslint-react/eslint-plugin")),
1012
1014
  // @ts-expect-error missing types
1013
1015
  interopDefault(import("eslint-plugin-react-hooks")),
1014
1016
  // @ts-expect-error missing types
1015
- interopDefault(import("eslint-plugin-react-refresh"))
1017
+ interopDefault(import("eslint-plugin-react-refresh")),
1018
+ interopDefault(import("@typescript-eslint/parser"))
1016
1019
  ]);
1017
1020
  const _isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1018
1021
  (i) => (0, import_local_pkg2.isPackageExists)(i)
1019
1022
  );
1023
+ const plugins = pluginReact.configs.all.plugins;
1020
1024
  return [
1021
1025
  {
1022
1026
  name: "eslint:react:setup",
1023
1027
  plugins: {
1024
- "react": pluginReact,
1028
+ "react": plugins["@eslint-react"],
1029
+ "react-dom": plugins["@eslint-react/dom"],
1025
1030
  "react-hooks": pluginReactHooks,
1031
+ "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
1032
+ "react-naming-convention": plugins["@eslint-react/naming-convention"],
1026
1033
  "react-refresh": pluginReactRefresh
1027
1034
  }
1028
1035
  },
1029
1036
  {
1030
1037
  files,
1031
1038
  languageOptions: {
1039
+ parser: parserTs,
1032
1040
  parserOptions: {
1033
1041
  ecmaFeatures: {
1034
1042
  jsx
1035
- }
1043
+ },
1044
+ ...isTypeAware ? { project: tsconfigPath } : {}
1036
1045
  }
1037
1046
  },
1038
1047
  name: "eslint:react:rules",
1039
1048
  rules: {
1040
- // react-hooks
1049
+ // recommended rules from @eslint-react/dom
1050
+ "react-dom/no-children-in-void-dom-elements": "warn",
1051
+ "react-dom/no-dangerously-set-innerhtml": "warn",
1052
+ "react-dom/no-dangerously-set-innerhtml-with-children": "error",
1053
+ "react-dom/no-find-dom-node": "error",
1054
+ "react-dom/no-missing-button-type": "warn",
1055
+ "react-dom/no-missing-iframe-sandbox": "warn",
1056
+ "react-dom/no-namespace": "error",
1057
+ "react-dom/no-render-return-value": "error",
1058
+ "react-dom/no-script-url": "warn",
1059
+ "react-dom/no-unsafe-iframe-sandbox": "warn",
1060
+ "react-dom/no-unsafe-target-blank": "warn",
1061
+ // recommended rules react-hooks
1041
1062
  "react-hooks/exhaustive-deps": "warn",
1042
1063
  "react-hooks/rules-of-hooks": "error",
1043
- // react-refresh
1064
+ // react refresh
1044
1065
  // 'react-refresh/only-export-components': [
1045
1066
  // 'warn',
1046
- // { allowConstantExport: _isAllowConstantExport },
1067
+ // { allowConstantExport: isAllowConstantExport },
1047
1068
  // ],
1048
- "react-refresh/only-export-components": "off",
1049
- // react
1050
- "react/boolean-prop-naming": "error",
1051
- "react/button-has-type": "error",
1052
- "react/default-props-match-prop-types": "error",
1053
- "react/destructuring-assignment": "error",
1054
- "react/display-name": "error",
1055
- "react/forbid-component-props": "off",
1056
- // 禁止组件上使用某些 props
1057
- "react/forbid-dom-props": "error",
1058
- "react/forbid-elements": "error",
1059
- "react/forbid-foreign-prop-types": "error",
1060
- "react/forbid-prop-types": "error",
1061
- "react/function-component-definition": "error",
1062
- "react/hook-use-state": "off",
1063
- // useState 钩子值和 setter 变量的解构和对称命名
1064
- "react/iframe-missing-sandbox": "error",
1065
- "react/jsx-boolean-value": "error",
1066
- "react/jsx-filename-extension": "off",
1067
- // 禁止可能包含 JSX 文件扩展名
1068
- "react/jsx-fragments": "error",
1069
- "react/jsx-handler-names": "error",
1070
- "react/jsx-key": "error",
1071
- "react/jsx-max-depth": "off",
1072
- // 强制 JSX 最大深度
1073
- "react/jsx-no-bind": "off",
1074
- // .bind()JSX 属性中禁止使用箭头函数
1075
- "react/jsx-no-comment-textnodes": "error",
1076
- "react/jsx-no-constructed-context-values": "error",
1077
- "react/jsx-no-duplicate-props": "error",
1078
- "react/jsx-no-leaked-render": "error",
1079
- "react/jsx-no-literals": "off",
1080
- // 禁止在 JSX 中使用字符串文字
1081
- "react/jsx-no-script-url": "error",
1082
- "react/jsx-no-target-blank": "error",
1083
- "react/jsx-no-undef": "error",
1084
- "react/jsx-no-useless-fragment": "error",
1085
- "react/jsx-props-no-spreading": "off",
1086
- // 强制任何 JSX 属性都不会传播
1087
- "react/jsx-uses-react": "error",
1088
- "react/jsx-uses-vars": "error",
1069
+ // recommended rules from @eslint-react
1070
+ "react/ensure-forward-ref-using-ref": "warn",
1089
1071
  "react/no-access-state-in-setstate": "error",
1090
- "react/no-adjacent-inline-elements": "error",
1091
- "react/no-array-index-key": "error",
1092
- "react/no-arrow-function-lifecycle": "error",
1093
- "react/no-children-prop": "error",
1094
- "react/no-danger": "off",
1095
- // 禁止使用 dangerouslySetInnerHTML
1096
- "react/no-danger-with-children": "error",
1097
- "react/no-deprecated": "error",
1098
- "react/no-did-mount-set-state": "error",
1099
- "react/no-did-update-set-state": "error",
1072
+ "react/no-array-index-key": "warn",
1073
+ "react/no-children-count": "warn",
1074
+ "react/no-children-for-each": "warn",
1075
+ "react/no-children-map": "warn",
1076
+ "react/no-children-only": "warn",
1077
+ "react/no-children-prop": "warn",
1078
+ "react/no-children-to-array": "warn",
1079
+ "react/no-clone-element": "warn",
1080
+ "react/no-comment-textnodes": "warn",
1081
+ "react/no-component-will-mount": "error",
1082
+ "react/no-component-will-receive-props": "error",
1083
+ "react/no-component-will-update": "error",
1084
+ "react/no-create-ref": "error",
1100
1085
  "react/no-direct-mutation-state": "error",
1101
- "react/no-find-dom-node": "error",
1102
- "react/no-invalid-html-attribute": "error",
1103
- "react/no-is-mounted": "error",
1104
- "react/no-multi-comp": "error",
1105
- "react/no-namespace": "error",
1106
- "react/no-object-type-as-default-prop": "error",
1086
+ "react/no-duplicate-key": "error",
1087
+ "react/no-implicit-key": "error",
1088
+ "react/no-missing-key": "error",
1089
+ "react/no-nested-components": "warn",
1107
1090
  "react/no-redundant-should-component-update": "error",
1108
- "react/no-render-return-value": "error",
1109
- "react/no-set-state": "error",
1091
+ "react/no-set-state-in-component-did-mount": "warn",
1092
+ "react/no-set-state-in-component-did-update": "warn",
1093
+ "react/no-set-state-in-component-will-update": "warn",
1110
1094
  "react/no-string-refs": "error",
1111
- "react/no-this-in-sfc": "error",
1112
- "react/no-typos": "error",
1113
- "react/no-unescaped-entities": "error",
1114
- "react/no-unknown-property": "error",
1115
- "react/no-unsafe": "off",
1116
- // 禁止使用不安全的生命周期方法
1117
- "react/no-unstable-nested-components": "error",
1118
- "react/no-unused-class-component-methods": "error",
1119
- "react/no-unused-prop-types": "error",
1120
- "react/no-unused-state": "error",
1121
- "react/no-will-update-set-state": "error",
1122
- "react/prefer-es6-class": "error",
1123
- "react/prefer-exact-props": "error",
1124
- "react/prefer-read-only-props": "error",
1125
- "react/prefer-stateless-function": "error",
1126
- "react/prop-types": "error",
1127
- "react/react-in-jsx-scope": "off",
1128
- // 使用 JSX 时需要引入 React
1129
- "react/require-default-props": "off",
1130
- // 为每个非必需 prop 强制执行 defaultProps 定义
1131
- "react/require-optimization": "error",
1132
- "react/require-render-return": "error",
1133
- "react/self-closing-comp": "error",
1134
- "react/sort-comp": "error",
1135
- "react/sort-default-props": "error",
1136
- "react/sort-prop-types": "error",
1137
- "react/state-in-constructor": "error",
1138
- "react/static-property-placement": "error",
1139
- "react/style-prop-object": "error",
1140
- "react/void-dom-elements-no-children": "error",
1141
- "style/jsx-pascal-case": "error",
1142
- ...typescript2 ? {
1143
- "react/jsx-no-undef": "off",
1144
- "react/prop-type": "off"
1095
+ "react/no-unsafe-component-will-mount": "warn",
1096
+ "react/no-unsafe-component-will-receive-props": "warn",
1097
+ "react/no-unsafe-component-will-update": "warn",
1098
+ "react/no-unstable-context-value": "error",
1099
+ "react/no-unstable-default-props": "error",
1100
+ "react/no-unused-class-component-members": "warn",
1101
+ "react/no-unused-state": "warn",
1102
+ "react/no-useless-fragment": "warn",
1103
+ "react/prefer-destructuring-assignment": "warn",
1104
+ "react/prefer-shorthand-boolean": "warn",
1105
+ "react/prefer-shorthand-fragment": "warn",
1106
+ ...isTypeAware ? {
1107
+ "react/no-leaked-conditional-rendering": "warn"
1145
1108
  } : {},
1109
+ // overrides
1146
1110
  ...overrides
1147
1111
  },
1148
1112
  settings: {
@@ -1972,6 +1936,10 @@ var VuePackages = [
1972
1936
  "@slidev/cli"
1973
1937
  ];
1974
1938
  var defaultPluginRenaming = {
1939
+ "@eslint-react": "react",
1940
+ "@eslint-react/dom": "react-dom",
1941
+ "@eslint-react/hooks-extra": "react-hooks-extra",
1942
+ "@eslint-react/naming-convention": "react-naming-convention",
1975
1943
  "@stylistic": "style",
1976
1944
  "@typescript-eslint": "ts",
1977
1945
  "import-x": "import",