惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
博客园 - 叶小钗
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
博客园_首页
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
Help Net Security
Help Net Security
Cloudbric
Cloudbric
AI
AI
N
News | PayPal Newsroom
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
SecWiki News
SecWiki News
H
Heimdal Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
V
V2EX
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
S
Security Affairs
L
LangChain Blog
The Hacker News
The Hacker News
F
Full Disclosure
aimingoo的专栏
aimingoo的专栏
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
Webroot Blog
Webroot Blog
A
About on SuperTechFans
H
Hacker News: Front Page
Cyberwarzone
Cyberwarzone
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
M
MIT News - Artificial intelligence

PixelNest

会议是效率的杀手 国庆出游记录 对居家办公的一些想法 2022 春节 《搏击俱乐部》的结局 纪念 PAI 头一回达到 100 卡片笔记法 《刑法学讲义》的部分摘录 迁移博客 《UNIX 传奇》摘录 就地过年 一点记录:docker-compose 编排不同项目间的网络 近期读的几本书 办新身份证 git 获取其他分支的单个文件或目录 我的高考成绩 推荐 2020 年上半年的 8 部影视作品 ChromeOS 开发者模式 终于下单了《守望者》 联通来电管家服务 一些实用的 bash 代码片段 关于 鸟枪换炮 《架构整洁之道》摘录 惨淡的星球大战 旧笔记本电脑 if...then... 命令行检测 SSL 证书过期时间 《程序员的职业素养》读书笔记 2019 国庆假期 在 Ubuntu 里按空格键预览 《基本穿搭》笔记 我在 Ubuntu 里安装的一些软件 让人郁闷的英语学习过程 色彩理论基础 向百度主动推送网站链接 两部电视剧 《历史的教训》摘录 新工具 Koa 获取客户端 IP 备案了 apiDoc 基础语法 《代码整洁之道》摘录 BBC 纪录片 《逻辑的乐趣》 读不下去的《原则》 蓝牙鼠标唤醒休眠的 Ubuntu Google 发布会 2018 国庆假期 开发者的时间追踪和统计 使用 curl 发送 POST 请求的几种方式 《重来 2》读书笔记 Linux 和 MacOS 命令行转换图片用法整理 《Go 语言实战》笔记 Win10 微软拼音添加小鹤双拼以及其他配置 《好妈妈胜过好老师》读书笔记 配置 Win10 Linux 子系统作为开发环境 又读完一本尤·奈斯博的小说 近期写 Go 的一点语法碎片整理 ffmpeg 合并 MP4 M4A 文件 睡前看手机的大问题 《局外人》读书笔记 菊次郎与佐纪 读书笔记 3 菊次郎与佐纪 读书笔记 2 菊次郎与佐纪 读书笔记 1 豆瓣图片服务器防盗链 《如何有效阅读一本书》读书笔记 - 3 《如何有效阅读一本书》读书笔记 - 2 《如何有效阅读一本书》读书笔记 - 1 Vim iskeyword 济南 图个乐 开始看不懂《西部世界》了 剧透 听到几个好故事 过周末 相亲 让人失望的 Apple 悬疑故事 AI 记忆 世纪三部曲 上帝的梦
针对不同场景临时禁用 eslint 规则的方法
2018-08-31 · via PixelNest

最近我新开始的前端项目,或者后端 NodeJS 项目,总之涉及到 Javascript 的代码都刻意用了最严格 airbnb 规则进行检查,检查工具是 eslint。凡事总有例外,有个别情况下,我需要对某个文件,或者某一块代码,或者某一行代码禁用所有检查或禁用某条规则,毕竟这个规则太严了。最初遇到这种需求,我去 Google 搜索,后来意识到这些内容应该在官网写得很清楚。于是,这篇文章也从一份资料整理变成了官网翻译。

ESLint & airbnb

针对一块代码

/* eslint-disable */

alert('foo');

/* eslint-enable */

针对在 /* eslint-disable *//* eslint-enable */ 之间的代码禁用检查。

指定规则

跟上面类似,加上指定规则名称即可。

/* eslint-disable no-alert, no-console */

alert('foo');
console.log('bar');

/* eslint-enable no-alert, no-console */

针对整个文件

在文件开头加上 /* eslint-disable */

/* eslint-disable */

alert('foo');

指定规则

同样是在后面加上规则名称就可以了。

/* eslint-disable no-alert */

alert('foo');

针对一行代码

eslint-disable-line 禁用对当前行的检查,用 eslint-disable-next-line 禁用对下一行代码的检查。

alert('foo'); // eslint-disable-line

// eslint-disable-next-line
alert('foo');

/* eslint-disable-next-line */
alert('foo');

alert('foo'); /* eslint-disable-line */

指定规则

毫无意外,仍然是后面加规则名称。

alert('foo'); // eslint-disable-line no-alert, quotes, semi

// eslint-disable-next-line no-alert, quotes, semi
alert('foo');

alert('foo'); /* eslint-disable-line no-alert, quotes, semi */

/* eslint-disable-next-line no-alert, quotes, semi */
alert('foo');

关于插件

如果要禁用的规则名称属于某个插件,比如要禁用 eslint-plugin-examplerule-name 规则,那么规则名称就写成 example/rule-name

foo(); // eslint-disable-line example/rule-name
foo(); /* eslint-disable-line example/rule-name */

这个例子是针对一行代码禁用某个插件的一条规则,这个插件规则名称的写法适用于上述所有场景比如针对整个文件、一块代码的禁用。