Skip to content

Commit

Permalink
Merge pull request #447 from Gillespie59/development
Browse files Browse the repository at this point in the history
1.6.2
  • Loading branch information
EmmanuelDemey committed Mar 5, 2017
2 parents 1e1bedb + 368ecb9 commit dd988bd
Show file tree
Hide file tree
Showing 69 changed files with 2,325 additions and 2,089 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
@@ -1,6 +1,7 @@
language: node_js
node_js:
- "6.0"
- "5.0"
- "4.2"
- 7
- 6
- 5
- 4
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
5 changes: 5 additions & 0 deletions docs/timeout-service.md
Expand Up @@ -26,6 +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
$window.setTimeout(function() {
// ...
}, 1000) // error: You should use the $timeout service instead of the default window.setTimeout method

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

Expand Down
6 changes: 6 additions & 0 deletions examples/timeout-service.js
Expand Up @@ -15,3 +15,9 @@ window.setTimeout(function() {
// ...
}, 1000)


// example - valid: false, errorMessage: "You should use the $timeout service instead of the default window.setTimeout method"
$window.setTimeout(function() {
// ...
}, 1000)

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-angular",
"version": "1.6.1",
"version": "1.6.2",
"description": "ESLint rules for AngularJS projects",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,10 +29,10 @@
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.0.0",
"gulp-mocha": "^2.2.0",
"gulp-mocha": "^3.0.1",
"istanbul": "^0.4.2",
"lodash": "^4.13.1",
"mocha": "^2.4.5",
"mocha": "^3.2.0",
"parse-comments": "^0.4.3",
"shelljs": "^0.7.1",
"shelljs-nodecli": "^0.1.1"
Expand Down
21 changes: 12 additions & 9 deletions rules/angularelement.js
Expand Up @@ -10,14 +10,17 @@
*/
'use strict';

module.exports = function(context) {
return {
CallExpression: function(node) {
if (node.callee.name === '$' || node.callee.name === 'jQuery') {
context.report(node, 'You should use angular.element instead of the jQuery $ object', {});
module.exports = {
meta: {
schema: []
},
create: function(context) {
return {
CallExpression: function(node) {
if (node.callee.name === '$' || node.callee.name === 'jQuery') {
context.report(node, 'You should use angular.element instead of the jQuery $ object', {});
}
}
}
};
};
}
};

module.exports.schema = [];
63 changes: 33 additions & 30 deletions rules/component-limit.js
Expand Up @@ -18,36 +18,39 @@
var angularRule = require('./utils/angular-rule');


module.exports = angularRule(function(context) {
var limit = context.options[0] || 1;
var count = 0;
var msg = 'There may be at most {{limit}} AngularJS {{component}} per file, but found {{number}}';
module.exports = {
meta: {
schema: [{
type: 'integer'
}]
},
create: angularRule(function(context) {
var limit = context.options[0] || 1;
var count = 0;
var msg = 'There may be at most {{limit}} AngularJS {{component}} per file, but found {{number}}';

function checkLimit(callee) {
count++;
if (count > limit) {
context.report(callee, msg, {
limit: limit,
component: limit === 1 ? 'component' : 'components',
number: count
});
function checkLimit(callee) {
count++;
if (count > limit) {
context.report(callee, msg, {
limit: limit,
component: limit === 1 ? 'component' : 'components',
number: count
});
}
}
}

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
};
});

module.exports.schema = [{
type: 'integer'
}];
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
};
})
};
67 changes: 37 additions & 30 deletions rules/component-name.js
Expand Up @@ -13,44 +13,51 @@

var utils = require('./utils/utils');

module.exports = function(context) {
if (context.settings.angular === 2) {
return {};
}
module.exports = {
meta: {
schema: [{
type: ['string', 'object']
}]
},
create: function(context) {
if (context.settings.angular === 2) {
return {};
}

return {
return {

CallExpression: function(node) {
var prefix = context.options[0];
var convertedPrefix; // convert string from JSON .eslintrc to regex
CallExpression: function(node) {
var prefix = context.options[0];
var convertedPrefix; // convert string from JSON .eslintrc to regex

if (prefix === undefined) {
return;
}
if (prefix === undefined) {
return;
}

convertedPrefix = utils.convertPrefixToRegex(prefix);
convertedPrefix = utils.convertPrefixToRegex(prefix);

if (utils.isAngularComponentDeclaration(node)) {
var name = node.arguments[0].value;
if (utils.isAngularComponentDeclaration(node)) {
var name = node.arguments[0].value;

if (name !== undefined && name.indexOf('ng') === 0) {
context.report(node, 'The {{component}} component should not start with "ng". This is reserved for AngularJS components', {
component: name
});
} else if (name !== undefined && !convertedPrefix.test(name)) {
if (typeof prefix === 'string' && !utils.isStringRegexp(prefix)) {
context.report(node, 'The {{component}} component should be prefixed by {{prefix}}', {
component: name,
prefix: prefix
});
} else {
context.report(node, 'The {{component}} component should follow this pattern: {{prefix}}', {
component: name,
prefix: prefix.toString()
if (name !== undefined && name.indexOf('ng') === 0) {
context.report(node, 'The {{component}} component should not start with "ng". This is reserved for AngularJS components', {
component: name
});
} else if (name !== undefined && !convertedPrefix.test(name)) {
if (typeof prefix === 'string' && !utils.isStringRegexp(prefix)) {
context.report(node, 'The {{component}} component should be prefixed by {{prefix}}', {
component: name,
prefix: prefix
});
} else {
context.report(node, 'The {{component}} component should follow this pattern: {{prefix}}', {
component: name,
prefix: prefix.toString()
});
}
}
}
}
}
};
};
}
};
71 changes: 40 additions & 31 deletions rules/constant-name.js
Expand Up @@ -15,42 +15,51 @@
var utils = require('./utils/utils');


module.exports = function(context) {
return {
module.exports = {
meta: {
schema: [{
type: ['string', 'object']
}, {
type: 'object'
}]
},
create: function(context) {
return {

CallExpression: function(node) {
var prefix = context.options[0];
var convertedPrefix; // convert string from JSON .eslintrc to regex
var isConstant;
CallExpression: function(node) {
var prefix = context.options[0];
var convertedPrefix; // convert string from JSON .eslintrc to regex
var isConstant;

if (prefix === undefined) {
return;
}
if (prefix === undefined) {
return;
}

convertedPrefix = utils.convertPrefixToRegex(prefix);
isConstant = utils.isAngularConstantDeclaration(node);

if (isConstant) {
var name = node.arguments[0].value;

if (name !== undefined && name.indexOf('$') === 0) {
context.report(node, 'The {{constant}} constant should not start with "$". This is reserved for AngularJS services', {
constant: name
});
} else if (name !== undefined && !convertedPrefix.test(name)) {
if (typeof prefix === 'string' && !utils.isStringRegexp(prefix)) {
context.report(node, 'The {{constant}} constant should be prefixed by {{prefix}}', {
constant: name,
prefix: prefix
});
} else {
context.report(node, 'The {{constant}} constant should follow this pattern: {{prefix}}', {
constant: name,
prefix: prefix.toString()
convertedPrefix = utils.convertPrefixToRegex(prefix);
isConstant = utils.isAngularConstantDeclaration(node);

if (isConstant) {
var name = node.arguments[0].value;

if (name !== undefined && name.indexOf('$') === 0) {
context.report(node, 'The {{constant}} constant should not start with "$". This is reserved for AngularJS services', {
constant: name
});
} else if (name !== undefined && !convertedPrefix.test(name)) {
if (typeof prefix === 'string' && !utils.isStringRegexp(prefix)) {
context.report(node, 'The {{constant}} constant should be prefixed by {{prefix}}', {
constant: name,
prefix: prefix
});
} else {
context.report(node, 'The {{constant}} constant should follow this pattern: {{prefix}}', {
constant: name,
prefix: prefix.toString()
});
}
}
}
}
}
};
};
}
};

0 comments on commit dd988bd

Please sign in to comment.