eslint-plugin-depend
Advanced tools
Comparing version
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.config = void 0; | ||
exports.config = { | ||
export const config = { | ||
plugins: ['depend'], | ||
@@ -6,0 +3,0 @@ rules: { |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configFactory = void 0; | ||
const configFactory = (plugin) => ({ | ||
export const configFactory = (plugin) => ({ | ||
plugins: { | ||
@@ -12,2 +9,1 @@ depend: plugin | ||
}); | ||
exports.configFactory = configFactory; |
import type { Rule, ESLint } from 'eslint'; | ||
export declare const rules: Record<string, Rule.RuleModule>; | ||
declare const plugin: ESLint.Plugin; | ||
export declare const configs: { | ||
@@ -7,1 +8,2 @@ recommended: ESLint.ConfigData<import("eslint").Linter.RulesRecord>; | ||
}; | ||
export default plugin; |
@@ -1,14 +0,21 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configs = exports.rules = void 0; | ||
const recommended_js_1 = require("./configs/recommended.js"); | ||
const legacy_recommended_js_1 = require("./configs/legacy-recommended.js"); | ||
const ban_dependencies_js_1 = require("./rules/ban-dependencies.js"); | ||
exports.rules = { | ||
'ban-dependencies': ban_dependencies_js_1.rule | ||
import { configFactory as configRecommended } from './configs/recommended.js'; | ||
import { config as configLegacyRecommended } from './configs/legacy-recommended.js'; | ||
import { rule as banDependencies } from './rules/ban-dependencies.js'; | ||
import { readFileSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const { name, version } = JSON.parse(readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')); | ||
export const rules = { | ||
'ban-dependencies': banDependencies | ||
}; | ||
const plugin = { rules: exports.rules }; | ||
exports.configs = { | ||
recommended: legacy_recommended_js_1.config, | ||
'flat/recommended': (0, recommended_js_1.configFactory)(plugin) | ||
const plugin = { | ||
meta: { name, version }, | ||
rules | ||
}; | ||
export const configs = { | ||
recommended: configLegacyRecommended, | ||
'flat/recommended': configRecommended(plugin) | ||
}; | ||
plugin.configs = configs; | ||
export default plugin; |
@@ -1,14 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.rule = void 0; | ||
const rule_meta_js_1 = require("../util/rule-meta.js"); | ||
const module_replacements_1 = require("module-replacements"); | ||
const imports_js_1 = require("../util/imports.js"); | ||
import { getDocsUrl } from '../util/rule-meta.js'; | ||
import { microUtilsReplacements, preferredReplacements, nativeReplacements } from 'module-replacements'; | ||
import { createReplacementListener } from '../util/imports.js'; | ||
const availablePresets = { | ||
microutilities: module_replacements_1.microUtilsReplacements.moduleReplacements, | ||
native: module_replacements_1.nativeReplacements.moduleReplacements, | ||
preferred: module_replacements_1.preferredReplacements.moduleReplacements | ||
microutilities: microUtilsReplacements.moduleReplacements, | ||
native: nativeReplacements.moduleReplacements, | ||
preferred: preferredReplacements.moduleReplacements | ||
}; | ||
const defaultPresets = ['microutilities', 'native', 'preferred']; | ||
exports.rule = { | ||
export const rule = { | ||
meta: { | ||
@@ -18,3 +15,3 @@ type: 'suggestion', | ||
description: 'Bans a list of dependencies from being used', | ||
url: (0, rule_meta_js_1.getDocsUrl)('ban-dependencies') | ||
url: getDocsUrl('ban-dependencies') | ||
}, | ||
@@ -84,5 +81,5 @@ schema: [ | ||
return { | ||
...(0, imports_js_1.createReplacementListener)(context, replacements) | ||
...createReplacementListener(context, replacements) | ||
}; | ||
} | ||
}; |
@@ -1,8 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createImportListener = createImportListener; | ||
exports.createPackageJsonListener = createPackageJsonListener; | ||
exports.createReplacementListener = createReplacementListener; | ||
const package_json_js_1 = require("./package-json.js"); | ||
const rule_meta_js_1 = require("./rule-meta.js"); | ||
import { closestPackageSatisfiesNodeVersion } from './package-json.js'; | ||
import { getMdnUrl, getReplacementsDocUrl } from './rule-meta.js'; | ||
/** | ||
@@ -15,3 +10,3 @@ * Creates a rule listener which listens for import/require calls and | ||
*/ | ||
function createImportListener(context, callback) { | ||
export function createImportListener(context, callback) { | ||
return { | ||
@@ -69,3 +64,3 @@ ImportDeclaration: (node) => { | ||
if (replacement.nodeVersion && | ||
!(0, package_json_js_1.closestPackageSatisfiesNodeVersion)(context, replacement.nodeVersion)) { | ||
!closestPackageSatisfiesNodeVersion(context, replacement.nodeVersion)) { | ||
return; | ||
@@ -79,3 +74,3 @@ } | ||
replacement: replacement.replacement, | ||
url: (0, rule_meta_js_1.getMdnUrl)(replacement.mdnPath) | ||
url: getMdnUrl(replacement.mdnPath) | ||
} | ||
@@ -90,3 +85,3 @@ }); | ||
name: replacement.moduleName, | ||
url: (0, rule_meta_js_1.getReplacementsDocUrl)(replacement.docPath) | ||
url: getReplacementsDocUrl(replacement.docPath) | ||
} | ||
@@ -123,3 +118,3 @@ }); | ||
*/ | ||
function createPackageJsonListener(context, callback) { | ||
export function createPackageJsonListener(context, callback) { | ||
return { | ||
@@ -149,3 +144,3 @@ 'Program > JSONExpressionStatement > JSONObjectExpression > JSONProperty': (astNode) => { | ||
*/ | ||
function createReplacementListener(context, replacements) { | ||
export function createReplacementListener(context, replacements) { | ||
if (packageJsonLikePath.test(context.filename)) { | ||
@@ -152,0 +147,0 @@ return createPackageJsonListener(context, (context, node, name) => replacementListenerCallback(context, replacements, node, name)); |
@@ -1,12 +0,4 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNodeConstraint = getNodeConstraint; | ||
exports.getClosestPackage = getClosestPackage; | ||
exports.closestPackageSatisfiesNodeVersion = closestPackageSatisfiesNodeVersion; | ||
const fd_package_json_1 = require("fd-package-json"); | ||
const satisfies_js_1 = __importDefault(require("semver/functions/satisfies.js")); | ||
const ltr_js_1 = __importDefault(require("semver/ranges/ltr.js")); | ||
import { findPackageSync } from 'fd-package-json'; | ||
import semverSatisfies from 'semver/functions/satisfies.js'; | ||
import semverLessThan from 'semver/ranges/ltr.js'; | ||
/** | ||
@@ -17,3 +9,3 @@ * Gets the node engine constraint from `package.json` if possible | ||
*/ | ||
function getNodeConstraint(packageJson) { | ||
export function getNodeConstraint(packageJson) { | ||
const engines = packageJson.engines; | ||
@@ -35,3 +27,3 @@ if (typeof engines !== 'object' || engines === null || !('node' in engines)) { | ||
*/ | ||
function getClosestPackage(context) { | ||
export function getClosestPackage(context) { | ||
const cachedPackageJson = packageCache.get(context); | ||
@@ -41,3 +33,3 @@ if (cachedPackageJson !== undefined) { | ||
} | ||
const packageJson = (0, fd_package_json_1.findPackageSync)(context.cwd); | ||
const packageJson = findPackageSync(context.cwd); | ||
packageCache.set(context, packageJson); | ||
@@ -55,3 +47,3 @@ return packageJson; | ||
*/ | ||
function closestPackageSatisfiesNodeVersion(context, version) { | ||
export function closestPackageSatisfiesNodeVersion(context, version) { | ||
const packageJson = getClosestPackage(context); | ||
@@ -65,4 +57,4 @@ if (!packageJson) { | ||
} | ||
return ((0, ltr_js_1.default)(version, nodeConstraint) || | ||
(0, satisfies_js_1.default)(version, nodeConstraint)); | ||
return (semverLessThan(version, nodeConstraint) || | ||
semverSatisfies(version, nodeConstraint)); | ||
} |
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDocsUrl = getDocsUrl; | ||
exports.getMdnUrl = getMdnUrl; | ||
exports.getReplacementsDocUrl = getReplacementsDocUrl; | ||
/** | ||
@@ -11,3 +6,3 @@ * Generates a standard URL to the docs of a given rule | ||
*/ | ||
function getDocsUrl(name) { | ||
export function getDocsUrl(name) { | ||
return `https://github.com/es-tooling/eslint-plugin-depend/blob/main/docs/rules/${name}.md`; | ||
@@ -20,3 +15,3 @@ } | ||
*/ | ||
function getMdnUrl(path) { | ||
export function getMdnUrl(path) { | ||
return `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/${path}`; | ||
@@ -29,4 +24,4 @@ } | ||
*/ | ||
function getReplacementsDocUrl(path) { | ||
export function getReplacementsDocUrl(path) { | ||
return `https://github.com/es-tooling/module-replacements/blob/main/docs/modules/${path}.md`; | ||
} |
{ | ||
"name": "eslint-plugin-depend", | ||
"version": "0.12.0", | ||
"version": "1.0.0-esm", | ||
"description": "An ESLint plugin to suggest optimized dependencies, native alternatives and more", | ||
"main": "lib/main.js", | ||
"type": "module", | ||
"files": [ | ||
@@ -7,0 +8,0 @@ "lib", |
@@ -19,13 +19,14 @@ # eslint-plugin-depend | ||
```ts | ||
import * as depend from 'eslint-plugin-depend'; | ||
import depend from 'eslint-plugin-depend'; | ||
import {defineConfig} from 'eslint/config'; | ||
export default [ | ||
depend.configs['flat/recommended'], | ||
// or if you want to specify `files`, or other options | ||
export default defineConfig([ | ||
{ | ||
...depend.configs['flat/recommended'], | ||
files: ['test/**/*.js'] | ||
files: ['**/*.js'], | ||
plugins: { | ||
depend | ||
}, | ||
extends: ['depend/flat/recommended'], | ||
} | ||
]; | ||
]); | ||
``` | ||
@@ -32,0 +33,0 @@ |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
76
1.33%Yes
NaN19646
-4.75%422
-4.31%