Socket
Socket
Sign inDemoInstall

eslint-plugin-angular

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-angular - npm Package Compare versions

Comparing version 1.5.1 to 1.6.1

rules/constant-name.js

2

package.json
{
"name": "eslint-plugin-angular",
"version": "1.5.1",
"version": "1.6.1",
"description": "ESLint rules for AngularJS projects",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -139,8 +139,12 @@ # eslint plugin angular [![Npm version](https://img.shields.io/npm/v/eslint-plugin-angular.svg)](https://www.npmjs.com/package/eslint-plugin-angular) [![Npm downloads per month](https://img.shields.io/npm/dm/eslint-plugin-angular.svg)](https://www.npmjs.com/package/eslint-plugin-angular)

* [component-name](docs/component-name.md) - require and specify a prefix for all component names
* [constant-name](docs/constant-name.md) - require and specify a prefix for all constant names ([y125](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y125))
* [controller-name](docs/controller-name.md) - require and specify a prefix for all controller names ([y123](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y123), [y124](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y124))
* [directive-name](docs/directive-name.md) - require and specify a prefix for all directive names ([y073](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y073), [y126](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y126))
* [factory-name](docs/factory-name.md) - require and specify a prefix for all factory names ([y125](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y125))
* [file-name](docs/file-name.md) - require and specify a consistent component name pattern ([y120](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y120), [y121](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y121))
* [filter-name](docs/filter-name.md) - require and specify a prefix for all filter names
* [module-name](docs/module-name.md) - require and specify a prefix for all module names ([y127](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y127))
* [provider-name](docs/provider-name.md) - require and specify a prefix for all provider names ([y125](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y125))
* [service-name](docs/service-name.md) - require and specify a prefix for all service names ([y125](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y125))
* [value-name](docs/value-name.md) - require and specify a prefix for all value names ([y125](https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y125))

@@ -147,0 +151,0 @@ ### Conventions

@@ -23,2 +23,5 @@ /**

utils.isAngularServiceDeclaration(node.expression) ||
utils.isAngularFactoryDeclaration(node.expression) ||
utils.isAngularConstantDeclaration(node.expression) ||
utils.isAngularValueDeclaration(node.expression) ||
utils.isAngularDirectiveDeclaration(node.expression) ||

@@ -25,0 +28,0 @@ utils.isAngularRunSection(node.expression) ||

@@ -15,4 +15,34 @@ /**

var utils = require('./utils/utils');
/**
* @param {Array.<*>} options
* @returns {?string}
*/
function getPrefixFromOptions(options) {
return options.find(function(option) {
return ['String', 'RegExp', 'Null', 'Undefined'].indexOf(utils.getToStringTagType(option)) !== -1;
});
}
/**
* @param {Array.<*>} options
* @returns {Object}
*/
function getConfig(options) {
var config = options.find(function(option) {
return utils.getToStringTagType(option) === 'Object';
});
config = config || {};
if (typeof config.oldBehavior !== 'boolean') {
config = Object.assign({
oldBehavior: true
});
}
return config;
}
module.exports = function(context) {

@@ -22,4 +52,6 @@ return {

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

@@ -32,3 +64,12 @@ if (prefix === undefined) {

if (utils.isAngularServiceDeclaration(node)) {
if (config.oldBehavior) {
isService = utils.isAngularServiceDeclarationDeprecated(node);
// Warning that the API is deprecated
// eslint-disable-next-line
console.warn('The rule `angular/service-name` will be split up to different rules in the next version. Please read the docs for more information');
} else {
isService = utils.isAngularServiceDeclaration(node);
}
if (isService) {
var name = node.arguments[0].value;

@@ -35,0 +76,0 @@

@@ -47,3 +47,8 @@ 'use strict';

isAngularDirectiveDeclaration: isAngularDirectiveDeclaration,
isAngularServiceDeclarationDeprecated: isAngularServiceDeclarationDeprecated,
isAngularServiceDeclaration: isAngularServiceDeclaration,
isAngularProviderDeclaration: isAngularProviderDeclaration,
isAngularFactoryDeclaration: isAngularFactoryDeclaration,
isAngularConstantDeclaration: isAngularConstantDeclaration,
isAngularValueDeclaration: isAngularValueDeclaration,
isAngularModuleDeclaration: isAngularModuleDeclaration,

@@ -57,3 +62,4 @@ isAngularModuleGetter: isAngularModuleGetter,

getControllerDefinition: getControllerDefinition,
isAngularServiceImport: isAngularServiceImport
isAngularServiceImport: isAngularServiceImport,
getToStringTagType: getToStringTagType
};

@@ -342,3 +348,3 @@

*/
function isAngularServiceDeclaration(node) {
function isAngularServiceDeclarationDeprecated(node) {
return isAngularComponent(node) &&

@@ -354,2 +360,53 @@ isMemberExpression(node.callee) &&

/*
* @param {Object}
* @returns {boolean}
*/
function isAngularServiceDeclaration(node) {
return isAngularComponent(node) &&
isMemberExpression(node.callee) &&
node.callee.object.name !== '$provide' &&
node.callee.property.name === 'service';
}
/*
* @param {Object}
* @returns {boolean}
*/
function isAngularProviderDeclaration(node) {
return isAngularComponent(node) &&
isMemberExpression(node.callee) &&
node.callee.object.name !== '$provide' &&
node.callee.property.name === 'provider';
}
/*
* @param {Object}
* @returns {boolean}
*/
function isAngularFactoryDeclaration(node) {
return isAngularComponent(node) &&
isMemberExpression(node.callee) &&
node.callee.object.name !== '$provide' &&
node.callee.property.name === 'factory';
}
/*
* @param {Object}
* @returns {boolean}
*/
function isAngularConstantDeclaration(node) {
return isAngularComponent(node) &&
isMemberExpression(node.callee) &&
node.callee.object.name !== '$provide' &&
node.callee.property.name === 'constant';
}
function isAngularValueDeclaration(node) {
return isAngularComponent(node) &&
isMemberExpression(node.callee) &&
node.callee.object.name !== '$provide' &&
node.callee.property.name === 'value';
}
/**

@@ -547,1 +604,12 @@ * Check whether a CallExpression node declares an Angular module.

}
/**
* Return the value of the given param that retrieved by Object#toString()
*
* @param {*} obj
* @return {string}
*/
function getToStringTagType(obj) {
return Object.prototype.toString.apply(obj)
.match(/^\[object\s(.+)]$/)[1];
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc