本文翻译自:Turning off eslint rule for a specific file
Is it possible to turn off the eslint rule for the whole file? 是否可以关闭整个文件的eslint规则? Something such as: 像这样的东西:
// eslint-disable-file no-use-before-define
(Analogous to eslint-disable-line.) It happens to me quite often, that in a certain file, I'm breaking a specific rule on many places which is considered OK for that file, but I don't want to disable the rule for the whole project nor do I want to disable other rules for that specific file. (类似于eslint-disable-line。)它经常发生在我身上,在某个文件中,我打破了许多地方的特定规则,对于该文件被认为是正常的,但我不想禁用整个项目的规则,我也不想禁用该特定文件的其他规则。
#1楼
参考:https://stackoom.com/question/2LrmJ/关闭特定文件的eslint规则
#2楼
You can turn off/change a particular rule for a file by putting the configurations at the top of the file. 您可以通过将配置放在文件顶部来关闭/更改文件的特定规则。
/* eslint no-use-before-define: 0 */ // --> OFF
or
/* eslint no-use-before-define: 2 */ // --> ON
More info: http://eslint.org/docs/user-guide/configuring.html#configuring-rules 更多信息: http : //eslint.org/docs/user-guide/configuring.html#configuring-rules
#3楼
You can also disable/enable a rule like this: 您还可以禁用/启用这样的规则:
/* eslint-disable no-use-before-define */
... code that violates rule ...
/* eslint-enable no-use-before-define */
Similar to eslint-disable-line
as mentioned in the question. 与问题中提到的eslint-disable-line
类似。 It might be a better method if you don't want to have to restore a complicated rule configuration when re-enabling it. 如果您不希望在重新启用它时还原复杂的规则配置,那么这可能是更好的方法。
#4楼
/*eslint-disable */
//suppress all warnings between comments
alert('foo');
/*eslint-enable */
it worked for me 它对我有用
#5楼
Just place /* eslint-disable */
at the top of the file 只需将/* eslint-disable */
放在文件的顶部即可
Check: https://evanhahn.com/disable-eslint-for-a-file/ 检查: https : //evanhahn.com/disable-eslint-for-a-file/
#6楼
You can tell ESLint to ignore specific files and directories by creating an .eslintignore
file in your project's root directory: 您可以通过在项目的根目录中创建.eslintignore
文件来告诉ESLint 忽略特定的文件和目录:
.eslintignore .eslintignore
build/*.js
config/*.js
bower_components/foo/*.js
The ignore patterns behave according to the .gitignore
specification. 忽略模式的行为符合.gitignore
规范。 (Don't forget to restart your editor.) (别忘了重新启动编辑器。)