New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@roadmunk/eslint-plugin-roadmunk-custom

Package Overview
Dependencies
Maintainers
10
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roadmunk/eslint-plugin-roadmunk-custom - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

docs/rules/no-require-path-js.md

69

lib/helper.js

@@ -6,2 +6,10 @@ 'use strict';

/**
* Object containing information about the modules being imported & the corresponding AST node
* @typedef {Object} ModuleInfo
* @property {String} moduleInfo.type - Contains detail about the type of the require/import statement. Possible values include "Literal" & "ArrayExpression"
* @property {String[]} moduleInfo.moduleNames - An array containing the names of module that are being imported
*/
/**
* Checks if the given node contains properties that have certain values

@@ -42,12 +50,16 @@ *

/**
* Checks if the given node is a require statement function call
* Checks if the given node is a require statement function call with a single argument of type literal
* This function will return true for the following statement
* require('account')
*
* This function will return false for the following statement
* require([ 'account' ], account => .....)
*
* @param {ASTNode} node - the node whose properties need to be looked up
* @returns {Boolean} true if it is a require function call with a single argument literal. Otherwise, returns false
*/
function isRequireCall(node) {
function isRequireCallLiteral(node) {
return node
&& node.type === 'CallExpression'
&& node.callee.type === 'Identifier'
&& node.callee.name === 'require'
&& isNodeAnIdentifierWithName(node, 'callee', 'require')
&& node.arguments.length === 1

@@ -58,2 +70,48 @@ && node.arguments[0].type === 'Literal';

/**
* Checks if the given node is a require statement function call with an array as its first argument
* This function will return true for the following statement
* require([ 'account' ], account => .....)
*
* This function will return false for the following statement
* require('account')
*
* @param {ASTNode} node - the node whose properties need to be looked up
* @returns {Boolean} true if it is a require function call with a single argument literal. Otherwise, returns false
*/
function isRequireCallArrayExpression(node) {
return node
&& node.type === 'CallExpression'
&& isNodeAnIdentifierWithName(node, 'callee', 'require')
&& node.arguments.length > 0
&& node.arguments[0].type === 'ArrayExpression';
}
/**
* Checks if the given node is a require statement
* @param {ASTNode} node - the node whose properties need to be looked up
*/
function isRequireCall(node) {
return isRequireCallLiteral(node) || isRequireCallArrayExpression(node);
}
/**
* Given a node that corresponds with a require call, this function will return the type of require call & the names of all modules being required
* @param {ASTNode} node - The node whose properties need to be looked up
* @returns {ModuleInfo}
*/
function getModuleNamesFromRequireCall(node) {
if (!isRequireCall(node)) {
return [];
}
const isLiteralRequire = isRequireCallLiteral(node);
const args = isLiteralRequire ? node.arguments : node.arguments[0].elements;
return {
type : isLiteralRequire ? 'Literal' : 'ArrayExpression',
moduleNames : args.map(arg => arg.value),
};
}
/**
* node : The node on which lint rule has fired. (MemberExpression)

@@ -122,2 +180,5 @@ * context : context object

isRequireCall,
isRequireCallLiteral,
isRequireCallArrayExpression,
getModuleNamesFromRequireCall,
};

2

lib/rules/align-assign.js

@@ -7,3 +7,3 @@ /**

const { hasPropsWithValues } = require('../helper.js');
const { hasPropsWithValues } = require('../helper');

@@ -10,0 +10,0 @@ const DEFAULT_MAX_SPACES = 25;

@@ -7,3 +7,3 @@ /**

const _ = require('lodash');
const { hasPropsWithValues, isPropertyAnIdentifierWithName } = require('../helper.js');
const { hasPropsWithValues, isPropertyAnIdentifierWithName } = require('../helper');
// ------------------------------------------------------------------------------

@@ -10,0 +10,0 @@ // Rule Definition

@@ -8,3 +8,3 @@ /**

const _ = require('lodash');
const { isPropertyAnIdentifierWithName, isObjectAnIdentifierWithName } = require('../helper.js');
const { isPropertyAnIdentifierWithName, isObjectAnIdentifierWithName } = require('../helper');

@@ -11,0 +11,0 @@ // ------------------------------------------------------------------------------

@@ -7,3 +7,3 @@ /**

const { lodashAutofix, hasPropsWithValues } = require('../helper.js');
const { lodashAutofix, hasPropsWithValues } = require('../helper');
// ------------------------------------------------------------------------------

@@ -10,0 +10,0 @@ // Rule Definition

@@ -7,3 +7,3 @@ /**

const { lodashAutofix, hasPropsWithValues } = require('../helper.js');
const { lodashAutofix, hasPropsWithValues } = require('../helper');
// ------------------------------------------------------------------------------

@@ -10,0 +10,0 @@ // Rule Definition

@@ -6,3 +6,3 @@ /**

'use strict';
const { isPropertyAnIdentifierWithName, isObjectAnIdentifierWithName } = require('../helper.js');
const { isPropertyAnIdentifierWithName, isObjectAnIdentifierWithName } = require('../helper');

@@ -9,0 +9,0 @@ module.exports = {

@@ -7,4 +7,4 @@ /**

const _ = require('lodash');
const { isRequireCall } = require('../helper.js');
const _ = require('lodash');
const { isRequireCallLiteral } = require('../helper');

@@ -27,3 +27,3 @@ // ------------------------------------------------------------------------------

CallExpression(node) {
if (!isRequireCall(node)) {
if (!isRequireCallLiteral(node)) {
return;

@@ -30,0 +30,0 @@ }

{
"name": "@roadmunk/eslint-plugin-roadmunk-custom",
"version": "1.7.0",
"version": "1.8.0",
"description": "Plugin to hold custom ESLint rules for Roadmunk",

@@ -24,3 +24,3 @@ "keywords": [

"devDependencies": {
"@roadmunk/eslint-config-roadmunk": "^3.8.1",
"@roadmunk/eslint-config-roadmunk": "^3.9.0",
"eslint": "^5.1.0",

@@ -27,0 +27,0 @@ "mocha": "^5.2.0"

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