Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-rb-validate-js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rb-validate-js - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

99

index.js

@@ -32,3 +32,3 @@ /*jslint node: true*/

if (abort) {
gutil.log('[' + guideline + '] ' + gutil.colors.white(tag + ": ") + gutil.colors.red(mistake) + " [FAIL]");
gutil.log('[' + guideline + '] ' + gutil.colors.white(tag + ": ") + gutil.colors.red(mistake) + " [Level: RED]");
errorBreak = true;

@@ -109,67 +109,71 @@ } else {

var ast = esprima.parse(file);
try {
var ast = esprima.parse(file);
estraverse.traverse(ast, {
enter: function (node, parent) {
estraverse.traverse(ast, {
enter: function (node, parent) {
// Declaration of function
if (node.type === 'FunctionDeclaration') {
// Declaration of function
if (node.type === 'FunctionDeclaration') {
// Special Case: Angular Controller declared as function
if (node.id.name && (node.id.name.indexOf('Ctrl') > 0 || node.id.name.indexOf('Controller') > 0)) {
if (!isUpperCamelCase(node.id.name) && !isLowerCamelCase(node.id.name)) {
validationError('Angular Controller names must be camel case', node.id.name, 'CI-FE-4003', false);
// Special Case: Angular Controller declared as function
if (node.id.name && (node.id.name.indexOf('Ctrl') > 0 || node.id.name.indexOf('Controller') > 0)) {
if (!isUpperCamelCase(node.id.name) && !isLowerCamelCase(node.id.name)) {
validationError('Angular Controller names must be camel case', node.id.name, 'CI-FE-4003', false);
}
} else if (node.id.name && !isLowerCamelCase(node.id.name)) {
validationError('Function names must be lower camel case', node.id.name, 'CI-FE-4003', true);
}
} else if (node.id.name && !isLowerCamelCase(node.id.name)) {
validationError('Function names must be lower camel case', node.id.name, 'CI-FE-4003', true);
}
}
// Variables
else if (node.type === 'VariableDeclarator') {
// Variables
else if (node.type === 'VariableDeclarator') {
// Explicitly declared constant
if (node.kind && node.kind === 'const') {
if (node.id.name && !isConstant(node.id.name)) {
validationError('Constant names must be fully capitalized', node.id.name, 'CI-FE-4003', true);
// Explicitly declared constant
if (node.kind && node.kind === 'const') {
if (node.id.name && !isConstant(node.id.name)) {
validationError('Constant names must be fully capitalized', node.id.name, 'CI-FE-4003', true);
}
}
}
// Declaration of class
else if (node.declarations && node.declarations.init.type === 'ObjectExpression') {
if (node.id.name && !isUpperCamelCase(node.id.name)) {
validationError('Class names must be upper camel case', node.id.name, 'CI-FE-4003', true);
// Declaration of class
else if (node.declarations && node.declarations.init.type === 'ObjectExpression') {
if (node.id.name && !isUpperCamelCase(node.id.name)) {
validationError('Class names must be upper camel case', node.id.name, 'CI-FE-4003', true);
}
}
}
// Declaration of variable (or possibly non-explicit constant)
else {
if (node.id.name && !isLowerCamelCase(node.id.name) && !isPrivateVar(node.id.name) && !isConstant(node.id.name)) {
validationError('Variable names must begin with underscore or be lower camel case', node.id.name, 'CI-FE-4003', true);
// Declaration of variable (or possibly non-explicit constant)
else {
if (node.id.name && !isLowerCamelCase(node.id.name) && !isPrivateVar(node.id.name) && !isConstant(node.id.name)) {
validationError('Variable names must begin with underscore or be lower camel case', node.id.name, 'CI-FE-4003', true);
}
}
}
}
// Private assignment
else if (node.type === 'ExpressionStatement') {
if (node.expression.type === 'AssignmentExpression') {
// Private assignment
else if (node.type === 'ExpressionStatement') {
if (node.expression.type === 'AssignmentExpression') {
// Private Variable Expression
if (node.expression.left.type === 'MemberExpression' && node.expression.right.type !== 'FunctionExpression') {
// Private Variable Expression
if (node.expression.left.type === 'MemberExpression' && node.expression.right.type !== 'FunctionExpression') {
if (node.expression.left.property.name && !isLowerCamelCase(node.expression.left.property.name) && !isPrivateVar(node.expression.left.property.name)) {
validationError('Private variables must begin with underscore or be lower camel case', node.expression.left.property.name, 'CI-FE-4003', true);
if (node.expression.left.property.name && !isLowerCamelCase(node.expression.left.property.name) && !isPrivateVar(node.expression.left.property.name)) {
validationError('Private variables must begin with underscore or be lower camel case', node.expression.left.property.name, 'CI-FE-4003', true);
}
}
}
// Declaration of prototype function
else if (node.expression.left.type === 'MemberExpression' && node.expression.right.type === 'FunctionExpression') {
if (node.expression.left.property.name && !isLowerCamelCase(node.expression.left.property.name)) {
validationError('Function names must be lower camel case', node.expression.left.property.name, 'CI-FE-4003', true);
// Declaration of prototype function
else if (node.expression.left.type === 'MemberExpression' && node.expression.right.type === 'FunctionExpression') {
if (node.expression.left.property.name && !isLowerCamelCase(node.expression.left.property.name)) {
validationError('Function names must be lower camel case', node.expression.left.property.name, 'CI-FE-4003', true);
}
}
}
}
}
},
leave: function (node, parent) {}
});
},
leave: function (node, parent) {}
});
} catch (e) {
validationError('JavaScript Parser Error', e, 'Syntax', false);
}
}

@@ -201,2 +205,3 @@

gutil.log(gutil.colors.cyan("File: " + file.path));
error = false;

@@ -220,4 +225,4 @@

if (error) {
gutil.log(gutil.colors.cyan("File: " + file.path));
if (options.abortOnError && errorBreak) {

@@ -224,0 +229,0 @@ gutil.log(gutil.colors.red("Critical validation error -> ABORT"));

{
"name": "gulp-rb-validate-js",
"version": "0.0.3",
"version": "0.0.4",
"description": "Gulp plugin to check JS files according to web frontend guidelines",

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

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