Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.6.3 #455

Merged
merged 9 commits into from
Mar 18, 2017
Merged

1.6.3 #455

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
env:
node: true

parserOptions:
ecmaVersion: 6

rules:
# http://eslint.org/docs/rules/#possible-errors
comma-dangle:
Expand Down
6 changes: 3 additions & 3 deletions docs/timeout-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ The following patterns are considered problems;
window.setTimeout(function() {
// ...
}, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method
// invalid

// invalid
$window.setTimeout(function() {
// ...
}, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method
}, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method

The following patterns are **not** considered problems;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-angular",
"version": "1.6.2",
"version": "1.6.3",
"description": "ESLint rules for AngularJS projects",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"chai": "^3.5.0",
"chai-spies": "^0.7.1",
"coveralls": "^2.11.6",
"eslint": "^3.0.0",
"eslint": "^3.18.0",
"espree": "^3.0.1",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
Expand Down
20 changes: 10 additions & 10 deletions rules/component-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ module.exports = {
}

return {
'angular:animation': checkLimit,
'angular:config': checkLimit,
'angular:controller': checkLimit,
'angular:directive': checkLimit,
'angular:factory': checkLimit,
'angular:filter': checkLimit,
'angular:provider': checkLimit,
'angular:run': checkLimit,
'angular:service': checkLimit,
'angular:component': checkLimit
'angular?animation': checkLimit,
'angular?config': checkLimit,
'angular?controller': checkLimit,
'angular?directive': checkLimit,
'angular?factory': checkLimit,
'angular?filter': checkLimit,
'angular?provider': checkLimit,
'angular?run': checkLimit,
'angular?service': checkLimit,
'angular?component': checkLimit
};
})
};
20 changes: 10 additions & 10 deletions rules/di-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ module.exports = {
}

return {
'angular:animation': checkOrder,
'angular:config': checkOrder,
'angular:controller': checkOrder,
'angular:directive': checkOrder,
'angular:factory': checkOrder,
'angular:filter': checkOrder,
'angular:inject': checkOrder,
'angular:run': checkOrder,
'angular:service': checkOrder,
'angular:provider': function(callee, providerFn, $get) {
'angular?animation': checkOrder,
'angular?config': checkOrder,
'angular?controller': checkOrder,
'angular?directive': checkOrder,
'angular?factory': checkOrder,
'angular?filter': checkOrder,
'angular?inject': checkOrder,
'angular?run': checkOrder,
'angular?service': checkOrder,
'angular?provider': function(callee, providerFn, $get) {
checkOrder(null, providerFn);
checkOrder(null, $get);
}
Expand Down
20 changes: 10 additions & 10 deletions rules/di-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ module.exports = {
}

return {
'angular:animation': reportUnusedVariables,
'angular:config': reportUnusedVariables,
'angular:controller': reportUnusedVariables,
'angular:directive': reportUnusedVariables,
'angular:factory': reportUnusedVariables,
'angular:filter': reportUnusedVariables,
'angular:inject': reportUnusedVariables,
'angular:run': reportUnusedVariables,
'angular:service': reportUnusedVariables,
'angular:provider': function(callee, providerFn, $get) {
'angular?animation': reportUnusedVariables,
'angular?config': reportUnusedVariables,
'angular?controller': reportUnusedVariables,
'angular?directive': reportUnusedVariables,
'angular?factory': reportUnusedVariables,
'angular?filter': reportUnusedVariables,
'angular?inject': reportUnusedVariables,
'angular?run': reportUnusedVariables,
'angular?service': reportUnusedVariables,
'angular?provider': function(callee, providerFn, $get) {
reportUnusedVariables(null, providerFn);
reportUnusedVariables(null, $get);
},
Expand Down
20 changes: 10 additions & 10 deletions rules/di.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ module.exports = {
}

return {
'angular:animation': checkDi,
'angular:config': checkDi,
'angular:controller': checkDi,
'angular:directive': checkDi,
'angular:factory': checkDi,
'angular:filter': checkDi,
'angular:inject': checkDi,
'angular:run': checkDi,
'angular:service': checkDi,
'angular:provider': function(callee, providerFn, $get) {
'angular?animation': checkDi,
'angular?config': checkDi,
'angular?controller': checkDi,
'angular?directive': checkDi,
'angular?factory': checkDi,
'angular?filter': checkDi,
'angular?inject': checkDi,
'angular?run': checkDi,
'angular?service': checkDi,
'angular?provider': function(callee, providerFn, $get) {
checkDi(null, providerFn);
checkDi(null, $get);
},
Expand Down
2 changes: 1 addition & 1 deletion rules/dumb-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
}

return {
'angular:inject': function(callExpression, fn) {
'angular?inject': function(callExpression, fn) {
if (!fn) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions rules/file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ module.exports = {
return;
}

if (!name) {
return;
}
expectedName = filenameUtil.createExpectedName(name, type, options);

if (expectedName !== filename) {
Expand Down
2 changes: 1 addition & 1 deletion rules/no-directive-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
}

return {
'angular:directive': function(callExpressionNode, fnNode) {
'angular?directive': function(callExpressionNode, fnNode) {
if (!fnNode || !fnNode.body) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-run-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
}

return {
'angular:run': function(callExpression, fn) {
'angular?run': function(callExpression, fn) {
if (!fn) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
}

return {
'angular:directive': function(callExpressionNode, fnNode) {
'angular?directive': function(callExpressionNode, fnNode) {
if (!fnNode || !fnNode.body) {
return;
}
Expand Down
26 changes: 13 additions & 13 deletions rules/utils/angular-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ var angularChainableNames = [
* ```js
* module.exports = angularRule(function(context) {
* return {
* 'angular:animation': function(configCallee, configFn) {},
* 'angular:component': function(componentCallee, componentObj) {},
* 'angular:config': function(configCallee, configFn) {},
* 'angular:controller': function(controllerCallee, controllerFn) {},
* 'angular:directive': function(directiveCallee, directiveFn) {},
* 'angular:factory': function(factoryCallee, factoryFn) {},
* 'angular:filter': function(filterCallee, filterFn) {},
* 'angular:inject': function(injectCallee, injectFn) {}, // inject() calls from angular-mocks
* 'angular:run': function(runCallee, runFn) {},
* 'angular:service': function(serviceCallee, serviceFn) {},
* 'angular:provider': function(providerCallee, providerFn, provider$getFn) {}
* 'angular?animation': function(configCallee, configFn) {},
* 'angular?component': function(componentCallee, componentObj) {},
* 'angular?config': function(configCallee, configFn) {},
* 'angular?controller': function(controllerCallee, controllerFn) {},
* 'angular?directive': function(directiveCallee, directiveFn) {},
* 'angular?factory': function(factoryCallee, factoryFn) {},
* 'angular?filter': function(filterCallee, filterFn) {},
* 'angular?inject': function(injectCallee, injectFn) {}, // inject() calls from angular-mocks
* 'angular?run': function(runCallee, runFn) {},
* 'angular?service': function(serviceCallee, serviceFn) {},
* 'angular?provider': function(providerCallee, providerFn, provider$getFn) {}
* };
* })
* ```
Expand Down Expand Up @@ -227,13 +227,13 @@ function angularRule(ruleDefinition) {
function callAngularRules(ruleObject, context) {
angularComponents.forEach(function(component) {
var name = component.callExpression.callee.property.name;
var fn = ruleObject['angular:' + name];
var fn = ruleObject['angular?' + name];
if (!fn) {
return;
}
fn.apply(ruleObject, assembleArguments(component, context));
});
var injectRule = ruleObject['angular:inject'];
var injectRule = ruleObject['angular?inject'];
if (injectRule) {
injectCalls.forEach(function(node) {
injectRule.call(ruleObject, node.CallExpression, node.fn);
Expand Down
3 changes: 2 additions & 1 deletion rules/utils/false-values.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

module.exports = {
config: ['jwtOptionsProvider', 'ngTableHelperProvider', '$ocLazyLoadProvider', '$route', '$localForageProvider']
config: [/Provider$/, /$route/],
run: [/mocha/, /Service$/]
};
6 changes: 3 additions & 3 deletions rules/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var falseConfigValues = require('./false-values').config;
var falseRunValues = require('./false-values').run;

var scopeProperties = [
'$id',
Expand Down Expand Up @@ -458,8 +459,7 @@ function isAngularRunSection(node) {
return isMemberExpression(node.callee) &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'run' &&
(node.callee.object.type === 'Identifier' &&
node.callee.object.name !== 'mocha');
!falseRunValues.find(pattern => new RegExp(pattern).test(node.callee.object.name));
}

/**
Expand Down Expand Up @@ -488,7 +488,7 @@ function isAngularConfigSection(node) {
return isMemberExpression(node.callee) &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'config' &&
falseConfigValues.indexOf(node.callee.object.name) < 0;
!falseConfigValues.find(pattern => new RegExp(pattern).test(node.callee.object.name));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/file-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ var commonFalsePositives = require('./utils/commonFalsePositives');
var eslintTester = new RuleTester();
eslintTester.run('file-name', rule, {
valid: [{
// basic module
filename: 'app.module.js',
options: [{
typeSeparator: 'dot',
ignoreTypeSuffix: true,
ignorePrefix: 'fs'
}],
code: `(function () {

var mod = 'shared.sales';

angular.module(mod + 'shared.sales.core.angular', ['ngCookies', 'ngRoute', 'ngLocale', 'ngResource', 'ngAnimate', 'ngSanitize', 'ngMessages', 'ngIOS9UIWebViewPatch']);

angular.module(mod + 'shared.sales.thirdparty', ['tmh.dynamicLocale', 'gettext', 'ngMaterial', 'md.data.table', 'fixed.table.header', 'as.sortable', 'ngCsv', 'telemetry']);

angular.module(mod, [mod + '.core.angular', mod + '.thirdparty']);
})();`
}, {
// basic module
filename: 'myModule.js',
code: 'angular.module("myModule", []);'
Expand Down
1 change: 1 addition & 0 deletions test/module-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ eslintTester.run('module-getter', rule, {
'angular.module("module").config(function(ngTableHelperProvider){' +
'ngTableHelperProvider.config({count: 10}, {});' +
'})',
'angular.module("module").controller("ctrl", function(ReportService) { ReportService.run();});',
'angular.module("module").controller("TestCtrl", function() {});',
'angular.module("module").factory("TestService", function() {});',
'angular.module("module").service("TestService", function() {});',
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-array', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'Object.prototype.toString.call([]) === "[object Array]"', errors: [{message: 'You should use the angular.isArray method'}]},
{code: 'function name(){return variable === "[object Array]";}', errors: [{message: 'You should use the angular.isArray method'}]},
{code: '"[object Array]" === Object.prototype.toString.call([])', errors: [{message: 'You should use the angular.isArray method'}]},
{code: 'variable === "[object Array]"', errors: [{message: 'You should use the angular.isArray method'}]},
{code: '"[object Array]" === variable', errors: [{message: 'You should use the angular.isArray method'}]},
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-date', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'Object.prototype.toString.call(variable) === "[object Date]"', errors: [{message: 'You should use the angular.isDate method'}]},
{code: 'function name(){return variable === "[object Date]";}', errors: [{message: 'You should use the angular.isDate method'}]},
{code: '"[object Date]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isDate method'}]},
{code: 'variable === "[object Date]"', errors: [{message: 'You should use the angular.isDate method'}]},
{code: '"[object Date]" === variable', errors: [{message: 'You should use the angular.isDate method'}]},
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-function', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'typeof variable === "function"', errors: [{message: 'You should use the angular.isFunction method'}]},
{code: 'function name(){return variable === "function";}', errors: [{message: 'You should use the angular.isFunction method'}]},
{code: '"function" === typeof variable', errors: [{message: 'You should use the angular.isFunction method'}]},
{code: 'variable === "function"', errors: [{message: 'You should use the angular.isFunction method'}]},
{code: '"function" === variable', errors: [{message: 'You should use the angular.isFunction method'}]},
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-number', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'Object.prototype.toString.call(variable) === "[object Number]"', errors: [{message: 'You should use the angular.isNumber method'}]},
{code: 'function name(){return variable === "[object Number]";}', errors: [{message: 'You should use the angular.isNumber method'}]},
{code: '"[object Number]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isNumber method'}]},
{code: 'variable === "[object Number]"', errors: [{message: 'You should use the angular.isNumber method'}]},
{code: '"[object Number]" === variable', errors: [{message: 'You should use the angular.isNumber method'}]},
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-object', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'typeof variable === "object"', errors: [{message: 'You should use the angular.isObject method'}]},
{code: 'function name(){return variable === "object";}', errors: [{message: 'You should use the angular.isObject method'}]},
{code: '"object" === typeof variable', errors: [{message: 'You should use the angular.isObject method'}]},
{code: 'variable === "object"', errors: [{message: 'You should use the angular.isObject method'}]},
{code: '"object" === variable', errors: [{message: 'You should use the angular.isObject method'}]},
Expand Down
1 change: 1 addition & 0 deletions test/typecheck-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eslintTester.run('typecheck-string', rule, {
].concat(commonFalsePositives),
invalid: [
{code: 'Object.prototype.toString.call(variable) === "[object String]"', errors: [{message: 'You should use the angular.isString method'}]},
{code: 'function name(){return variable === "[object String]";}', errors: [{message: 'You should use the angular.isString method'}]},
{code: '"[object String]" === Object.prototype.toString.call(variable)', errors: [{message: 'You should use the angular.isString method'}]},
{code: 'variable === "[object String]"', errors: [{message: 'You should use the angular.isString method'}]},
{code: '"[object String]" === variable', errors: [{message: 'You should use the angular.isString method'}]},
Expand Down