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

eslint-plugin-depend

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

eslint-plugin-depend - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

8

lib/util/imports.d.ts

@@ -13,2 +13,10 @@ import { Rule } from 'eslint';

/**
* Creates a rule listener for detecting dependencies in a `package.json`
* file
* @param {Rule.RuleContext} context ESLint context
* @param {ImportListenerCallback} callback Listener callback
* @return {Rule.RuleListener}
*/
export declare function createPackageJsonListener(context: Rule.RuleContext, callback: ImportListenerCallback): Rule.RuleListener;
/**
* Creates a rule listener which finds replacements in imports/requires

@@ -15,0 +23,0 @@ * @param {Rule.RuleContext} context ESLint context

33

lib/util/imports.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createReplacementListener = exports.createImportListener = void 0;
exports.createReplacementListener = exports.createPackageJsonListener = exports.createImportListener = void 0;
const package_json_js_1 = require("./package-json.js");

@@ -110,3 +110,31 @@ const rule_meta_js_1 = require("./rule-meta.js");

}
const dependencyKeys = ['dependencies', 'devDependencies'];
/**
* Creates a rule listener for detecting dependencies in a `package.json`
* file
* @param {Rule.RuleContext} context ESLint context
* @param {ImportListenerCallback} callback Listener callback
* @return {Rule.RuleListener}
*/
function createPackageJsonListener(context, callback) {
return {
'Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty': (astNode) => {
const node = astNode;
if (node.key.type === 'JSONLiteral' &&
typeof node.key.value === 'string' &&
dependencyKeys.includes(node.key.value) &&
node.value.type === 'JSONObjectExpression') {
for (const prop of node.value.properties) {
if (prop.key.type === 'JSONLiteral' &&
typeof prop.key.value === 'string') {
callback(context, prop, prop.key.value);
}
}
}
}
};
}
exports.createPackageJsonListener = createPackageJsonListener;
const packageJsonLikePath = /(^|[/\\])package.json$/;
/**
* Creates a rule listener which finds replacements in imports/requires

@@ -118,4 +146,7 @@ * @param {Rule.RuleContext} context ESLint context

function createReplacementListener(context, replacements) {
if (packageJsonLikePath.test(context.filename)) {
return createPackageJsonListener(context, (context, node, name) => replacementListenerCallback(context, replacements, node, name));
}
return createImportListener(context, (context, node, source) => replacementListenerCallback(context, replacements, node, source));
}
exports.createReplacementListener = createReplacementListener;

3

package.json
{
"name": "eslint-plugin-depend",
"version": "0.2.0",
"version": "0.3.0",
"description": "An ESLint plugin to suggest optimized dependencies, native alternatives and more",

@@ -49,2 +49,3 @@ "main": "lib/main.js",

"eslint-plugin-eslint-plugin": "^5.3.0",
"jsonc-eslint-parser": "^2.4.0",
"prettier": "^3.2.5",

@@ -51,0 +52,0 @@ "rimraf": "^5.0.5",

@@ -42,2 +42,28 @@ # eslint-plugin-depend

### With `package.json`
Some rules (e.g. `ban-dependencies`) can be used against your `package.json`.
You can achieve this by using `jsonc-eslint-parser`.
For example, in your `.eslintrc.json`:
```json
{
"overrides": [
{
"files": ["package.json"],
"parser": "jsonc-eslint-parser",
"plugins": ["depend"],
"rules": {
"depend/ban-dependencies": "error"
}
}
]
}
```
Read more at the
[`jsonc-eslint-parser` docs](https://github.com/ota-meshi/jsonc-eslint-parser).
## Rules

@@ -44,0 +70,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