eslint-plugin-intl-mobile
Version:
Intl Mobile ESLint Rules.
28 lines (22 loc) • 539 B
JavaScript
// 用于检测 typeof 判断 object 警告
;
const { get } = require('lodash');
const desc = 'Be careful with using typeof for object checking';
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: desc,
category: 'Best Practices',
},
},
create: function(context){
return {
UnaryExpression(node) {
if (get(node, 'operator') === 'typeof' && get(node, 'parent.right.value') === 'object') {
context.report(node, desc);
}
},
}
},
}