eslint-plugin-angular
Version:
ESLint rules for AngularJS projects
61 lines (53 loc) • 2.25 kB
JavaScript
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require('../rules/service-name');
var RuleTester = require('eslint').RuleTester;
var commonFalsePositives = require('./utils/commonFalsePositives');
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
var eslintTester = new RuleTester();
var valid = [];
var invalid = [];
['service', 'factory', 'provider', 'constant', 'value'].forEach(function(syntax) {
valid.push({
code: 'app.' + syntax + '("eslintService", function() {});',
options: ['eslint']
}, {
code: 'app.' + syntax + '("eslintService", function() {});',
options: [/^eslint/]
}, {
code: 'app.' + syntax + '("eslintService", function() {});',
options: [undefined]
}, {
code: 'app.' + syntax + '("eslintService", function() {});',
options: ['/^eslint/']
});
invalid.push({
code: 'app.' + syntax + '("Service", function() {});',
options: ['eslint'],
errors: [{message: 'The Service service should be prefixed by eslint'}]
}, {
code: 'app.' + syntax + '("esLintService", function() {});',
options: ['eslint'],
errors: [{message: 'The esLintService service should be prefixed by eslint'}]
}, {
code: 'app.' + syntax + '("Service", function() {});',
options: [/^eslint/],
errors: [{message: 'The Service service should follow this pattern: /^eslint/'}]
}, {
code: 'app.' + syntax + '("Service", function() {});',
options: ['/^eslint/'],
errors: [{message: 'The Service service should follow this pattern: /^eslint/'}]
}, {
code: 'app.' + syntax + '("$Service", function() {});',
options: [/^eslint/],
errors: [{message: 'The $Service service should not start with "$". This is reserved for AngularJS services'}]
});
});
eslintTester.run('service-name', rule, {
valid: valid.concat(commonFalsePositives),
invalid: invalid
});