[Javascript AST] 4. Continue: Report ESLint error
const disallowedMethods = ["log", "info", "warn", "error", "dir"];
module.exports = {
meta: {
docs: {
description: "Disallow use of console",
category: "Best Practices",
recommended: true
}
},
create(context) {
return {
Identifier(node) {
const isConsoleCall = looksLike(node, {
name: "console",
parent: {
type: "MemberExpression",
property: {
name: val => disallowedMethods.includes(val)
}
}
});
// find the identifier with name 'console'
if (!isConsoleCall) {
return;
}
context.report({
node,
message: "Using {{identifier}} is not allowed",
data: {
identifier: node.name // console
}
});
}
};
}
};
function looksLike(a, b) {
return (
a &&
b &&
Object.keys(b).every(bKey => {
const bVal = b[bKey];
const aVal = a[bKey];
if (typeof bVal === "function") {
return bVal(aVal);
}
return isPrimitive(bVal) ? bVal === aVal : looksLike(aVal, bVal);
})
);
}
function isPrimitive(val) {
return val == null || /^[sbn]/.test(typeof val);
}
We can use placeholder for more detail information:
"Using {{identifier}} is not allowed"
The placeholder can be found in data prop:
data: {
identifier: node.name // console
}
[Javascript AST] 4. Continue: Report ESLint error的更多相关文章
- [Javascript AST] 3. Continue: Write ESLint rule
The rule we want to write is show warning if user using console method: // valid foo.console() conso ...
- [Javascript AST] 1. Continue: Write a simple Babel plugin
We want to write a Babel Plugin, which move 'const versionRegex = /(/d+)\.(/d+)\.(/d+)/gi' out of fu ...
- An internal error occurred during: "Requesting JavaScript AST from selection". GC overhead limit exc
1.错误描述 An internal error occurred during: "Requesting JavaScript AST from selection". ...
- ESLint error level
ESLint error level https://eslint.org/docs/user-guide/getting-started#configuration .eslintrc { &quo ...
- [Javascript AST] 2. Introduction: Write a simple ESLint rule
What we want to do is checking if user write nested if statements which actually can combine to one: ...
- BugHD for JavaScript上线,轻松收集前端 Error
从收集 APP 崩溃信息到全面收集网站出现的 Error,现在的 BugHD 变得更加强大.目前,BugHD JS Error 收集功能 已正式上线,前端 er 们不用再面对一堆 Bug 无处下手. ...
- JavaScript break和continue 跳出循环
在JavaScript中,使用 break 和 continue 语句跳出循环: break语句的作用是立即跳出循环,即不再执行后面的所有循环: continue语句的作用是停止正在执行的循环,直接进 ...
- JavaScript Break 和 Continue 语句
1.break:终止本层循坏,继续执行本次循坏后面的语句: 当循坏有多层时,break只会跳过一层循坏 2.continue:跳过本次循坏,继续执行下次循坏 对于for循环,continue执行后,继 ...
- 对比JavaScript中的Continue和Break
译者按: 最好是不用,不过基础知识要掌握. 原文: JavaScript: Continue vs Break - Learn the difference between the continue ...
随机推荐
- Codeforces 344D Alternating Current 简单使用栈
Description Mad scientist Mike has just finished constructing a new device to search for extraterres ...
- eq3
然而一旦美国经济进入持续复苏,美联储必将逐步退出量化宽松和逐渐收紧银根,美国联邦基金利率和银行同业间拆借利率将会上升.这将使美元升值,并使部分套利交易平仓.而一旦美元企稳走强,国债利率上扬,大宗商品价 ...
- 记录一下 mysql 的查询中like字段的用法
SELECT * from t_yymp_auth_role where role_name not like '%测试%' and role_name not like '%部门%' and rol ...
- OpenSUSE Leap 42.3下通过Firefox Opera Chromium浏览器直接执行java应用程序(打开java jnlp文件)实现在服务器远程虚拟控制台完成远程管理的方法
远程虚拟控制台依赖于java运行环境(jre),在通过浏览器打开链接前,系统必须安装jre环境,远程管理控制台其实就是一个java程序,打开相应的网站会下载一个jnlp(java网络加载协议)的文件, ...
- Huawei交换机VRP配置介绍
一.命令视图• 用户视图<Huawei>• 系统视图 [Huawei]• 接口视图 [Huawei-GigabitEthernet0/0/1]• 协议视图 [Huawei-rip-1]• ...
- Flex 编译器及编译步骤
通过为Flex项目添加编译器参数:-keep-generated-actionscript=true 可以看到经过编译器处理过的源程序文件集合. 在这些文件的文件名中包含有“xxx-generated ...
- CMD规范学习笔记——基于SEAJS实现
CMD(Common Module Definition):该规范明确了模块的书写格式和基本交互规则.通常一个模块就是一个JS文件. 通过define关键字来定义模块,最基本的格式为: define( ...
- 【Django】Cookie
目录 Cookie介绍 操作Cookie 获取Cookie 设置 Cookie 删除Cookie @ Cookie介绍 Cookie的由来 大家都知道==HTTP协议是无状态的==. ==无状态的的意 ...
- 注解:@SuppressWarning()的用法
@SuppressWarning() 作用:J2SE 提供的一个批注或者注解.该批注的作用是给编译器一条指令,忽略这些警告信息. 常用:unchecked,serial. 1.如果传入多种情况,这几种 ...
- python编程:从入门到实践--项目1-外星人入侵_学习笔记_源码
这里有九个.py文件,在工作的间隙,和老板斗智斗勇,终于完成了,实现了游戏的功能,恰逢博客园开通,虽然是对着书上的代码敲了一遍,但是对pygam这个库的了解增加了一些,作为一个python初学者,也作 ...