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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. 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".     ...

  4. ESLint error level

    ESLint error level https://eslint.org/docs/user-guide/getting-started#configuration .eslintrc { &quo ...

  5. [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: ...

  6. BugHD for JavaScript上线,轻松收集前端 Error

    从收集 APP 崩溃信息到全面收集网站出现的 Error,现在的 BugHD 变得更加强大.目前,BugHD JS Error 收集功能 已正式上线,前端 er 们不用再面对一堆 Bug 无处下手. ...

  7. JavaScript break和continue 跳出循环

    在JavaScript中,使用 break 和 continue 语句跳出循环: break语句的作用是立即跳出循环,即不再执行后面的所有循环: continue语句的作用是停止正在执行的循环,直接进 ...

  8. JavaScript Break 和 Continue 语句

    1.break:终止本层循坏,继续执行本次循坏后面的语句: 当循坏有多层时,break只会跳过一层循坏 2.continue:跳过本次循坏,继续执行下次循坏 对于for循环,continue执行后,继 ...

  9. 对比JavaScript中的Continue和Break

    译者按: 最好是不用,不过基础知识要掌握. 原文: JavaScript: Continue vs Break - Learn the difference between the continue ...

随机推荐

  1. .Net 路由处理厉害了

    通过设置路由,可以灵活的显示地址内容.它会自动转换为想要的控制器和方法中去. using System; using System.Collections.Generic; using System. ...

  2. tensorflow学习之路-----简单卷积神经网路

    import tensorflow as tf#取数据,目的是辨别数字from tensorflow.examples.tutorials.mnist import input_data'''手动添加 ...

  3. mysql 中sql 语句查询今天、昨天、近7天、近30天、一个月内、上一月数据

    ·1.几个小时内的数据 DATE_SUB(NOW(), INTERVAL 5 HOUR) 1 ·2.今天 select * from 表名 where to_days(时间字段名) = to_days ...

  4. Swift学习笔记(12)--数组和字典的复制

    Swift中,数组Array和字典Dictionary是用结构来实现的,但是数组与字典和其它结构在进行赋值或者作为参数传递给函数的时候有一些不同. 并且数组和字典的这些操作,又与Foundation中 ...

  5. 【安卓】数据库基于脚本的"增量更新",每次更新时不需改动java代码、!

    思路: 1.当然是基于SQLiteOpenHelper.onCreate(第一次安装程序时调用).onUpdate(升级程序时调用) 2.用"脚本"(脚本制作详细方法问度娘)做数据 ...

  6. [Python] Python Libs

    The Python Standard Library has a lot of modules! To help you get familiar with what's available, he ...

  7. 数据库范式小结 1NF 2NF BCNF 3NF 4NF DB normal form

    1. 1NF指关系中的每个变量不可再分 2. 2NF指消除了非主属性对码(candidate key)的部分依赖的1NF 比如(S#,C#)-> SN ,(S#,C#)-> SD .S#- ...

  8. DB2物化视图(Materialized Query Tables, MQT)

    DB2的物化视图MQT是基于查询结果定义的一个表,MQT中包括的数据来自MQT定义所基于的一个或多个表, 使用MQT能够显著提高查询的操作性能. 数据库的视图和MQT都是基于一个查询来定义的.每当视图 ...

  9. CI框架源代码阅读笔记6 扩展钩子 Hook.php

    CI框架同意你在不改动系统核心代码的基础上加入或者更改系统的核心功能(如重写缓存.输出等). 比如,在系统开启hook的条件下(config.php中$config['enable_hooks'] = ...

  10. vue UI 框架

    (1)Element 饿了么 vue 2.0后台UI框架 (Star:18382) https://github.com/ElemeFE/element (1-1)Vuetify   最新的ui 框架 ...