Eslint

coderljw 2024-10-13 Lint
  • Lint
  • Eslint
大约 1 分钟

# 1. .eslintrc.js

/**
 * @link https://eslint.org
 * @type {import('eslint').Linter.Config}
 */
module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
    commonjs: true,
    es6: true,
    jest: true,
  },
  parser: '@babel/eslint-parser',
  extends: [
    'standard',
    'plugin:react/recommended',
    'plugin:react/jsx-runtime',
    'plugin:react-hooks/recommended',
    'prettier',
  ],
  settings: {
    react: {
      version: 'detect',
    },
  },
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 'latest',
    ecmaFeatures: { jsx: true },
    requireConfigFile: false,
    babelOptions: {
      cwd: __dirname,
      presets: ['@babel/preset-react'],
    },
  },
  rules: {
    'no-eval': 0,
    'no-void': 0,
    'no-with': 0,
    'react/display-name': 0,
    'react/self-closing-comp': 1,
    'react/style-prop-object': 1,
    'react/void-dom-elements-no-children': 1,
    'react/jsx-fragments': 1,
    'react/jsx-boolean-value': 1,
    'react/jsx-curly-brace-presence': 1,
    'react-hooks/exhaustive-deps': 0,
  },
  overrides: [
    {
      files: ['**/*.{ts,cts,mts,tsx}'],
      parser: '@typescript-eslint/parser',
      extends: [
        'standard-with-typescript',
        'plugin:react/recommended',
        'plugin:react/jsx-runtime',
        'plugin:react-hooks/recommended',
        'prettier',
      ],
      parserOptions: {
        sourceType: 'module',
        ecmaVersion: 'latest',
        ecmaFeatures: { jsx: true },
        project: true,
      },
      rules: {
        'no-eval': 0,
        'no-void': 0,
        'no-with': 0,
        'react-hooks/exhaustive-deps': 0,
        '@typescript-eslint/ban-ts-comment': 0,
        '@typescript-eslint/no-floating-promises': 0,
        '@typescript-eslint/no-non-null-assertion': 0,
        '@typescript-eslint/prefer-ts-expect-error': 0,
        '@typescript-eslint/promise-function-async': 0,
        '@typescript-eslint/no-unsafe-member-access': 0,
        '@typescript-eslint/strict-boolean-expressions': 0,
        '@typescript-eslint/consistent-type-definitions': 0,
        '@typescript-eslint/no-confusing-void-expression': 0,
        '@typescript-eslint/explicit-function-return-type': 0,
      },
    },
    {
      files: ['**/*.vue'],
      parser: 'vue-eslint-parser',
      extends: ['standard-with-typescript', 'plugin:vue/vue3-recommended', 'prettier'],
      parserOptions: {
        sourceType: 'module',
        ecmaVersion: 'latest',
        ecmaFeatures: { jsx: true },
        parser: '@typescript-eslint/parser',
        extraFileExtensions: ['.vue'],
        project: true,
      },
      rules: {
        'vue/no-useless-mustaches': 1,
        'vue/multi-word-component-names': 0,
        'vue/prefer-separate-static-class': 1,
        '@typescript-eslint/ban-ts-comment': 0,
        '@typescript-eslint/no-floating-promises': 0,
        '@typescript-eslint/no-non-null-assertion': 0,
        '@typescript-eslint/prefer-ts-expect-error': 0,
        '@typescript-eslint/promise-function-async': 0,
        '@typescript-eslint/no-unsafe-member-access': 0,
        '@typescript-eslint/strict-boolean-expressions': 0,
        '@typescript-eslint/consistent-type-definitions': 0,
        '@typescript-eslint/no-confusing-void-expression': 0,
        '@typescript-eslint/explicit-function-return-type': 0,
      },
    },
    {
      files: ['**/*.html'],
      plugins: ['html'],
      parserOptions: {
        sourceType: 'module',
        ecmaVersion: 'latest',
      },
    },
  ],
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

# 2. .eslintignore

# https://eslint.org/docs/latest/use/configure/ignore
temp
docs
mock
dist
build
public
scripts
coverage

1
2
3
4
5
6
7
8
9
10
以父之名
周杰伦.mp3