[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 ...
随机推荐
- 23. Angular 中用 a 标签 href 路由时在浏览器中显示异常 "%2F" 路由失败问题1
这个是angular1.6默认给hash路由上添加了!(感叹号),导致出错,修改方法如下(添加配置,去掉默认前缀感叹号): angular.module('routingDemoApp',['ng ...
- Vsftp权限控制(持续增加中)
把用户限制在自己的home目录中,例如限制用户Leon只能访问/home/Leon目录下的文件,不允许访问上级目录. 先打开配置文件 vi /etc/vsftpd/vsftpd.conf 第一种方法: ...
- SGU 461 Wiki Lists dfs
不难的题,不过蛮有意思的dfs #include <iostream> #include <cstdio> #include <fstream> #include ...
- py2exe打包python脚本
在工作中遇到将python脚本转换成exe可执行程序的需求,通过查询可以使用py2exe来构建满足要求的程序,这里简要说明一下使用步骤. 一.py2exe是一个将python脚本转换成windows上 ...
- BZOJ3105: [cqoi2013]新Nim游戏(Xor线性无关组)
Description 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作,每次可以选一个火柴堆拿走若干根火柴.可以只拿一根,也可以拿走整堆火柴 ...
- 概率编程:《贝叶斯方法概率编程与贝叶斯推断》中文PDF+英文PDF+代码
贝叶斯推理的方法非常自然和极其强大.然而,大多数图书讨论贝叶斯推理,依赖于非常复杂的数学分析和人工的例子,使没有强大数学背景的人无法接触.<贝叶斯方法概率编程与贝叶斯推断>从编程.计算的角 ...
- ZOJ 2532 Internship
Internship Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: ...
- TRIZ系列-创新原理-31-多孔材料原理
多孔材料原理的详细描写叙述例如以下:1)让物体变成多孔的.或者使用辅助的多孔部件(如插入,覆盖):2)假设一个物体已经是多孔了,那么事先往里面填充某种物质:这个原理提出的原因是,一般机械系统通常都是由 ...
- Hbuilder开发app实战-识岁06-face++的js实现【完结】
前言 因为识岁app比較简单.所以这节就完结吧, 当然另一些能够优化完好的地方,可是个人兴趣不是非常大, 有想继续完好的,源代码在这里:https://github.com/uikoo9/shisui ...
- dreamweaver 8的替换功能
dreamweaver 8的替换功能 下面教你用dreamweaver 8的替换功能来删除这些冗余代码. 查找范围:文件夹(然后选取你需要替换的文件夹) 搜索:源代码查找:\btppabs=" ...