关闭eslint检查(全局和局部两种方式禁用ESLint语法检查)
简介
有时候eslint 代码检查造成文件到处报错,一看就非常烦,也许eslint 有很强的代码防错和代码规范作用,但是在你非常清楚和了解这段代码时,eslint报错了,不想弃用eslint 检查又不想改代码,你可以使用禁用ESLint 代码检查。
全局禁用
禁用规则
在项目文件.eslintrc.js下,增加rules选项,把你想要的ruleName 设置成off,也可以针对环境变量来动态配置。如下:
rules: {
'max-len': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
}禁用文件
在项目文件.eslintignore下,增加文件。如下:
src/pages/Test.vue
当个文件禁用
整个文件范围内禁止规则出现警告
将/* eslint-disable */放置于文件最顶部
/* eslint-disable */
alert('foo');在文件中临时禁止规则出现警告
将需要忽略的代码块用注释包裹起来
/* eslint-disable */
alert('foo');
/* eslint-enable */对指定规则的启用或者禁用警告
将需要忽略的代码块用注释包裹起来
/* eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/* eslint-enable no-alert, no-console */对指定行禁用规则警告
有两种形式
alert('foo'); // eslint-disable-line
// eslint-disable-next-line
alert('foo');在指定行上禁用指定的某个规则
alert('foo'); // eslint-disable-line no-alert
// eslint-disable-next-line no-alert
alert('foo');在某个特定的行上禁用多个规则
alert('foo'); // eslint-disable-line no-alert, quotes, semi
// eslint-disable-next-line no-alert, quotes, semi
alert('foo');除注明外的文章,均为来源:老汤博客,转载请保留本文地址!
原文地址:https://tangjiusheng.cn/web/qdkf/476.html
原文地址:https://tangjiusheng.cn/web/qdkf/476.html
