eslint-plugin-angular
Advanced tools
Comparing version 2.3.0 to 2.4.0
{ | ||
"name": "eslint-plugin-angular", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "ESLint rules for AngularJS projects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,8 +13,12 @@ /** | ||
var utils = require('./utils/utils'); | ||
const utils = require('./utils/utils'); | ||
const SHOULD_USE_ISDEFINED_OR_ISUNDEFINED = 'You should not use directly the "undefined" keyword. Prefer ' + | ||
'angular.isUndefined or angular.isDefined'; | ||
const SHOULD_NOT_USE_BANG_WITH_ISDEFINED = 'Instead of !angular.isDefined, you can use the out-of-box angular.isUndefined method'; | ||
const SHOULD_NOT_USE_BANG_WITH_ISUNDEFINED = 'Instead of !angular.isUndefined, you can use the out-of-box angular.isDefined method'; | ||
module.exports = { | ||
meta: { | ||
schema: [] | ||
schema: [], | ||
fixable: 'code' | ||
}, | ||
@@ -25,6 +29,11 @@ create: function(context) { | ||
} | ||
function reportError(node) { | ||
context.report(node, 'You should not use directly the "undefined" keyword. Prefer ' + | ||
'angular.isUndefined or angular.isDefined', {}); | ||
function reportError(node, message, fix) { | ||
context.report({ | ||
node, | ||
message, | ||
fix | ||
}); | ||
} | ||
var sourceCode = context.getSourceCode(); | ||
/** | ||
@@ -40,5 +49,5 @@ * Rule that check if we use angular.is(Un)defined() instead of the undefined keyword | ||
if (node.property.name === 'isDefined') { | ||
context.report(node, 'Instead of !angular.isDefined, you can use the out-of-box angular.isUndefined method', {}); | ||
reportError(node, SHOULD_NOT_USE_BANG_WITH_ISDEFINED, fixer => fixer.replaceText(node.parent.parent, `angular.isUndefined(${node.parent.arguments[0].name})`)); | ||
} else if (node.property.name === 'isUndefined') { | ||
context.report(node, 'Instead of !angular.isUndefined, you can use the out-of-box angular.isDefined method', {}); | ||
reportError(node, SHOULD_NOT_USE_BANG_WITH_ISUNDEFINED, fixer => fixer.replaceText(node.parent.parent, `angular.isDefined(${node.parent.arguments[0].name})`)); | ||
} | ||
@@ -49,10 +58,12 @@ } | ||
if (isCompareOperator(node.operator)) { | ||
let method = (node.operator === '!=' || node.operator === '!==') ? 'isDefined' : 'isUndefined'; | ||
if (utils.isTypeOfStatement(node.left) && node.right.value === 'undefined') { | ||
reportError(node); | ||
reportError(node, SHOULD_USE_ISDEFINED_OR_ISUNDEFINED, fixer => fixer.replaceText(node, `angular.${method}(${sourceCode.getText(node.left)})`)); | ||
} else if (utils.isTypeOfStatement(node.right) && node.left.value === 'undefined') { | ||
reportError(node); | ||
reportError(node, SHOULD_USE_ISDEFINED_OR_ISUNDEFINED, fixer => fixer.replaceText(node, `angular.${method}(${sourceCode.getText(node.right)})`)); | ||
} else if (node.left.type === 'Identifier' && node.left.name === 'undefined') { | ||
reportError(node); | ||
reportError(node, SHOULD_USE_ISDEFINED_OR_ISUNDEFINED, fixer => fixer.replaceText(node, `angular.${method}(${node.right.name})`)); | ||
} else if (node.right.type === 'Identifier' && node.right.name === 'undefined') { | ||
reportError(node); | ||
reportError(node, SHOULD_USE_ISDEFINED_OR_ISUNDEFINED, fixer => fixer.replaceText(node, `angular.${method}(${node.left.name})`)); | ||
} | ||
@@ -59,0 +70,0 @@ } |
@@ -45,2 +45,10 @@ /** | ||
var expression = statement.expression; | ||
/** | ||
* issue #466 | ||
*/ | ||
if (expression.type === 'Literal' && expression.value.indexOf('use strict') >= 0) { | ||
return; | ||
} | ||
if (expression.type !== 'CallExpression') { | ||
@@ -56,3 +64,3 @@ return report(statement); | ||
expression.arguments.forEach(function(argument) { | ||
if (argument.type !== 'Literal' && argument.type !== 'Identifier') { | ||
if (argument && argument.type !== 'Literal' && argument.type !== 'Identifier') { | ||
context.report(argument, 'Run function call expressions may only take simple arguments'); | ||
@@ -59,0 +67,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
283993
4610