Skip to content

Commit

Permalink
Merge pull request #500 from Gillespie59/development
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
EmmanuelDemey committed Aug 16, 2017
2 parents 0a74425 + c6f5a71 commit c0392fe
Show file tree
Hide file tree
Showing 69 changed files with 169 additions and 66 deletions.
118 changes: 59 additions & 59 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Looking for the rule documentation?

It’s over in [`docs/rules`](./rules).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion docs/service-name.md → docs/rules/service-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
All your services should have a name starting with the parameter you can define in your config object.
The second parameter can be a Regexp wrapped in quotes.
You can not prefix your services by "$" (reserved keyword for AngularJS services) ("service-name": [2, "ng"])
*

If the oldBehavior is true (default value), this rule will check the name of all services defined with the different methods
provided by the framework : provider, service, factory, ... If this parameter is false, only services defined with the
service method will be checked.

**Rule based on Angular 1.x**

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ gulp.task('test', function(cb) {
});


gulp.task('docs', function(cb) {
gulp.task('docs', function() {
docs.updateReadme('README.md');
docs.createDocFiles();
docs.testDocs(cb);
// docs.testDocs(cb);
});

gulp.task('default', ['quality', 'docs', 'test']);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-angular",
"version": "3.0.0",
"version": "3.0.1",
"description": "ESLint rules for AngularJS projects",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion rules/avoid-scope-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const bad = ['new', 'watch', 'watchGroup', 'watchCollection',
'digest', 'destroy', 'eval', 'evalAsync', 'apply',
'applyAsync', 'on', 'emit', 'broadcast'];

const scope = ['scope', '$scope', '$rootScope'];

module.exports = {
meta: {
schema: [ ]
},
create: function(context) {
function check(node, name) {
if (bad.indexOf(name) >= 0) {
if (bad.indexOf(name) >= 0 && scope.indexOf(node.parent.object.name) >= 0) {
context.report(node, `The ${name} method should be replaced by $${name}, or you should rename it in order to avoid confusions`, {});
}
}
Expand Down
46 changes: 46 additions & 0 deletions rules/directive-restrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ module.exports = {
return true;
}
});

if (!directiveNode) {
// Try to find an ancestor function used as definition for one of the found directives
context.getAncestors().some(function(ancestor) {
if (isFunctionDeclaration(ancestor)) {
var fnName = ancestor.id.name;

var correspondingDirective = foundDirectives.find(function(directive) {
var directiveFnName = getDirectiveFunctionName(directive);
return directiveFnName === fnName;
});

directiveNode = correspondingDirective;
return true;
}
});
}

// The restrict property was not defined inside of a directive.
if (!directiveNode) {
return;
Expand All @@ -71,6 +89,34 @@ module.exports = {
checkedDirectives.push(directiveNode);
}

function isFunctionDeclaration(node) {
return node.type === 'FunctionDeclaration';
}

function getDirectiveFunctionName(node) {
var directiveArg = node.arguments[1];

// Three ways of creating a directive function: function expression,
// variable name that references a function, and an array with a function
// as the last item
if (utils.isFunctionType(directiveArg)) {
return directiveArg.id.name;
}

if (utils.isArrayType(directiveArg)) {
directiveArg = directiveArg.elements[directiveArg.elements.length - 1];

if (utils.isIdentifierType(directiveArg)) {
return directiveArg.name;
}
return directiveArg.id.name;
}

if (utils.isIdentifierType(directiveArg)) {
return directiveArg.name;
}
}

return {
CallExpression: function(node) {
if (utils.isAngularDirectiveDeclaration(node)) {
Expand Down
6 changes: 5 additions & 1 deletion rules/service-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* All your services should have a name starting with the parameter you can define in your config object.
* The second parameter can be a Regexp wrapped in quotes.
* You can not prefix your services by "$" (reserved keyword for AngularJS services) ("service-name": [2, "ng"])
**
*
* If the oldBehavior is true (default value), this rule will check the name of all services defined with the different methods
* provided by the framework : provider, service, factory, ... If this parameter is false, only services defined with the
* service method will be checked.
*
* @styleguideReference {johnpapa} `y125` Naming - Factory and Service Names
* @version 0.1.0
* @category naming
Expand Down
2 changes: 1 addition & 1 deletion scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var _ = require('lodash');

var templates = {
ruleSourcePath: _.template('rules/<%= ruleName %>.js'),
ruleDocumentationPath: _.template('docs/<%= ruleName %>.md'),
ruleDocumentationPath: _.template('docs/rules/<%= ruleName %>.md'),
ruleExamplesPath: _.template('examples/<%= ruleName %>.js'),
styleguide: _.template('[<%= name %> by <%= type %> - <%= description %>](<%= link %>)'),
styleguideShort: _.template('[<%= name %>](<%= link %>)'),
Expand Down
5 changes: 5 additions & 0 deletions test/avoid-scope-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ variables.forEach(function(variable) {
});
});
});

valid.push({
code: '$ionicPlatform.on("resume", "blabla")'
});

eslintTester.run('avoid-scope-typos', rule, {
valid: valid.concat(commonFalsePositives),
invalid
Expand Down
40 changes: 40 additions & 0 deletions test/directive-restrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ eslintTester.run('directive-restrict', rule, {
}, {
code: 'app.directive("", function() {return {restrict:"E"}})',
options: [{restrict: 'EA'}]
}, {
code: `app.directive("snapContainer", ['$scope', myDirective]);
function myDirective($scope) {
return {
restrict: "A"
}
}
`,
options: [{restrict: 'A'}]
}, {
code: `app.directive("snapContainer", myDirective);
/* @ngInject */
function myDirective($rootScope) {
return {
restrict: "A"
}
}
`,
options: [{restrict: 'A'}]
},
// Allowed with explicit restrict
{
Expand Down Expand Up @@ -87,6 +106,27 @@ eslintTester.run('directive-restrict', rule, {
code: 'app.directive("", function() {return {restrict:"E"}})',
options: [{restrict: 'A'}],
errors: [{message: 'Disallowed directive restriction. It must be one of A in that order'}]
}, {
code: `app.directive("snapContainer", ['$scope', myDirective]);
function myDirective($scope) {
return {
restrict: "A"
}
}
`,
options: [{restrict: 'E'}],
errors: [{message: 'Disallowed directive restriction. It must be one of E in that order'}]
}, {
code: `app.directive("snapContainer", myDirective);
/* @ngInject */
function myDirective($rootScope) {
return {
restrict: "A"
}
}
`,
options: [{restrict: 'E'}],
errors: [{message: 'Disallowed directive restriction. It must be one of E in that order'}]
},
// Disallowed with wrong order
{
Expand Down

0 comments on commit c0392fe

Please sign in to comment.