如何在ESLint.js文件中配置TypeScript分号规则?
解决TypeScript中ESLint分号错误问题
你的ESLint配置是.js格式,只需将@typescript-eslint/semi规则正确添加到rules对象中即可。JS配置里,属性名包含@这类特殊字符时,需要用引号包裹(单引号或双引号均可),这是之前添加规则出错的核心原因。
修改后的完整配置代码如下:
module.exports = { env: { browser: true, es2021: true }, extends: [ 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'standard-with-typescript' ], overrides: [], parserOptions: { ecmaVersion: 'latest', sourceType: 'module', project: ['./tsconfig.json'] }, plugins: ['react'], rules: { semi: 'off', '@typescript-eslint/semi': 'warn' } };
关键说明
- 必须关闭基础的
semi规则,避免和TypeScript专属规则产生冲突 - 规则值设为
warn时,出现多余分号会触发警告;如果要强制要求使用分号,可改为error,不符合规则时直接抛出错误
内容的提问来源于stack exchange,提问作者SmarTv
相关产品推荐
相关产品推荐

