AlloyTeam / eslint-config-alloy

Progressive ESLint config for your React/Vue/TypeScript projects
https://alloyteam.github.io/eslint-config-alloy/
2.65k stars 317 forks source link

当启用 @typescript-eslint/naming-convention 进行命名限制时报错 #233

Closed yuntian001 closed 1 year ago

yuntian001 commented 2 years ago

.eslintrc.cjs

module.exports = {
  extends: ['alloy', 'alloy/vue', 'alloy/typescript'],
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: {
      js: '@babel/eslint-parser',
      jsx: '@babel/eslint-parser',

      ts: '@typescript-eslint/parser',
      tsx: '@typescript-eslint/parser',
      // Leave the template parser unspecified, so that it could be determined by `<script lang="...">`
    },
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  overrides: [
    {
      files: ['*.vue', '*.ts'],
      rules: {
        'no-undef': 'off', // ts(2304)
      },
    },
    {
      files: ['*.cjs'],
      rules: {
        '@typescript-eslint/no-require-imports': 'off',
      },
    },
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
    //
    // Please keep this rule off because it requiresTypeChecking
    // https://github.com/vuejs/vue-eslint-parser/issues/104
    // https://github.com/typescript-eslint/typescript-eslint/pull/5318
    '@typescript-eslint/prefer-optional-chain': 0,
    'no-param-reassign': 0,
    '@typescript-eslint/consistent-type-assertions': 0,
    'prefer-object-spread': 0,
    'max-params': ['error', 4],
    'vue/no-duplicate-attributes': 0,
    'vue/no-duplicate-attr-inheritance': 0,
    '@typescript-eslint/explicit-member-accessibility': 0,
    'spaced-comment': 0,
    '@typescript-eslint/naming-convention':[
      'error',
        {
          selector: 'default',
          format: ['camelCase'],
          leadingUnderscore: 'allow',
          trailingUnderscore: 'allow',
        },

        {
          selector: 'variable',
          format: ['camelCase', 'UPPER_CASE'],
          leadingUnderscore: 'allow',
          trailingUnderscore: 'allow',
        },

        {
          selector: 'typeLike',
          format: ['PascalCase'],
        },
      ]
  },
};

错误信息

Oops! Something went wrong! :(

ESLint: 8.22.0

Error: Error while loading rule '@typescript-eslint/naming-convention': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
GoodbyeNJN commented 1 year ago

非 eslint-config-alloy 本身的问题,善用搜索引擎可以更快地获得结果: https://stackoverflow.com/questions/58510287/parseroptions-project-has-been-set-for-typescript-eslint-parser

xcatliu commented 1 year ago

需要配置 parserOptions.project