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

eslint-plugin-eslint-plugin

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-eslint-plugin - npm Package Compare versions

Comparing version 4.0.1 to 4.0.2

18

lib/index.js

@@ -16,3 +16,2 @@ /**

const PLUGIN_NAME = packageMetadata.name.replace(/^eslint-plugin-/, '');
const PLUGIN_VERSION = packageMetadata.version;

@@ -32,16 +31,2 @@ const configFilters = {

/**
* Loads a given rule from the filesystem and generates its documentation URL
* @param {string} ruleName The name of the rule
* @returns {Rule} The ESLint rule to export
*/
function loadRule (ruleName) {
const rule = require(path.join(__dirname, 'rules', ruleName));
rule.meta.docs.url =
`https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/v${PLUGIN_VERSION}/docs/rules/${ruleName}.md`;
return rule;
}
// import all rules in lib/rules

@@ -52,3 +37,4 @@ const allRules = Object.fromEntries(fs

.map(fileName => fileName.replace(/\.js$/, ''))
.map(ruleName => [ruleName, loadRule(ruleName)]));
.map(ruleName => [ruleName, require(path.join(__dirname, 'rules', ruleName))])
);

@@ -55,0 +41,0 @@ module.exports.rules = allRules;

1

lib/rules/consistent-output.js

@@ -21,2 +21,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/consistent-output.md',
},

@@ -23,0 +24,0 @@ fixable: null, // or "code" or "whitespace"

@@ -26,2 +26,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/fixer-return.md',
},

@@ -96,4 +97,5 @@ fixable: null,

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
const sourceCode = context.getSourceCode();
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -100,0 +102,0 @@

@@ -20,2 +20,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/meta-property-ordering.md',
},

@@ -22,0 +23,0 @@ fixable: 'code',

@@ -44,2 +44,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-deprecated-context-methods.md',
},

@@ -61,4 +62,4 @@ fixable: 'code',

return {
'Program:exit' () {
[...utils.getContextIdentifiers(context, sourceCode.ast)]
'Program:exit' (ast) {
[...utils.getContextIdentifiers(sourceCode.scopeManager, ast)]
.filter(

@@ -65,0 +66,0 @@ contextId =>

@@ -21,2 +21,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-deprecated-report-api.md',
},

@@ -39,4 +40,4 @@ fixable: 'code', // or "code" or "whitespace"

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -43,0 +44,0 @@ CallExpression (node) {

@@ -21,2 +21,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-identical-tests.md',
},

@@ -23,0 +24,0 @@ fixable: 'code',

@@ -22,2 +22,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-missing-placeholders.md',
},

@@ -40,3 +41,4 @@ fixable: null,

Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(context, ast);
const sourceCode = context.getSourceCode();
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -43,0 +45,0 @@ CallExpression (node) {

@@ -13,2 +13,3 @@ 'use strict';

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-only-tests.md',
},

@@ -15,0 +16,0 @@ hasSuggestions: true,

@@ -22,2 +22,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-unused-placeholders.md',
},

@@ -40,3 +41,4 @@ fixable: null,

Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(context, ast);
const sourceCode = context.getSourceCode();
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -43,0 +45,0 @@ CallExpression (node) {

@@ -21,2 +21,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/no-useless-token-range.md',
},

@@ -110,3 +111,3 @@ fixable: 'code',

'Program:exit' (ast) {
[...utils.getSourceCodeIdentifiers(context, ast)]
[...utils.getSourceCodeIdentifiers(sourceCode.scopeManager, ast)]
.filter(identifier => identifier.parent.type === 'MemberExpression' &&

@@ -113,0 +114,0 @@ identifier.parent.object === identifier &&

@@ -17,2 +17,3 @@ 'use strict';

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-message-ids.md',
},

@@ -39,5 +40,5 @@ fixable: null,

Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(context, ast);
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
if (info === null || info.meta === null) {
if (info === null) {
return;

@@ -53,3 +54,3 @@ }

if (!messagesNode) {
context.report({ node: metaNode, messageId: 'messagesMissing' });
context.report({ node: metaNode || info.create, messageId: 'messagesMissing' });
return;

@@ -56,0 +57,0 @@ }

@@ -20,2 +20,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-object-rule.md',
},

@@ -22,0 +23,0 @@ fixable: 'code',

@@ -21,2 +21,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-output-null.md',
},

@@ -23,0 +24,0 @@ fixable: 'code',

@@ -22,2 +22,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-placeholders.md',
},

@@ -42,4 +43,4 @@ fixable: null,

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
},

@@ -46,0 +47,0 @@ CallExpression (node) {

@@ -21,2 +21,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/prefer-replace-text.md',
},

@@ -41,4 +42,4 @@ fixable: null,

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -45,0 +46,0 @@

@@ -22,2 +22,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/report-message-format.md',
},

@@ -62,5 +63,6 @@ fixable: null,

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
const ruleInfo = utils.getRuleInfo(context.getSourceCode());
Program (ast) {
const sourceCode = context.getSourceCode();
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
const ruleInfo = utils.getRuleInfo(sourceCode);
const messagesObject = ruleInfo &&

@@ -67,0 +69,0 @@ ruleInfo.meta &&

@@ -19,2 +19,3 @@ 'use strict';

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-docs-description.md',
},

@@ -42,8 +43,8 @@ fixable: null,

create (context) {
const sourceCode = context.getSourceCode();
const info = utils.getRuleInfo(sourceCode);
return {
Program () {
if (info === null || info.meta === null) {
const sourceCode = context.getSourceCode();
const info = utils.getRuleInfo(sourceCode);
if (info === null) {
return;

@@ -66,3 +67,3 @@ }

if (!descriptionNode) {
context.report({ node: docsNode ? docsNode : metaNode, messageId: 'missing' });
context.report({ node: docsNode || metaNode || info.create, messageId: 'missing' });
return;

@@ -69,0 +70,0 @@ }

@@ -26,2 +26,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-docs-url.md',
},

@@ -52,3 +53,3 @@ fixable: 'code',

const filename = context.getFilename();
const ruleName = filename === '<input>' ? undefined : path.basename(filename, '.js');
const ruleName = filename === '<input>' ? undefined : path.basename(filename, path.extname(filename));
const expectedUrl = !options.pattern || !ruleName

@@ -55,0 +56,0 @@ ? undefined

@@ -22,2 +22,3 @@ /**

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-fixable.md',
},

@@ -60,4 +61,4 @@ schema: [

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -64,0 +65,0 @@ CallExpression (node) {

@@ -17,2 +17,3 @@ 'use strict';

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-has-suggestions.md',
},

@@ -34,4 +35,4 @@ fixable: 'code',

return {
Program (node) {
contextIdentifiers = utils.getContextIdentifiers(context, node);
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(sourceCode.scopeManager, ast);
},

@@ -75,3 +76,3 @@ CallExpression (node) {

context.report({
node: metaNode ? metaNode : ruleInfo.create,
node: metaNode || ruleInfo.create,
messageId: 'shouldBeSuggestable',

@@ -78,0 +79,0 @@ fix (fixer) {

@@ -17,2 +17,3 @@ 'use strict';

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-schema.md',
},

@@ -44,3 +45,3 @@ hasSuggestions: true,

const info = utils.getRuleInfo(sourceCode);
if (info === null || info.meta === null) {
if (info === null) {
return {};

@@ -61,3 +62,3 @@ }

Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(context, ast);
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);

@@ -111,5 +112,5 @@ schemaNode =

context.report({
node: metaNode,
node: metaNode || info.create,
messageId: 'missing',
suggest: isUsingOptions ? [] : [
suggest: !isUsingOptions && metaNode && metaNode.type === 'ObjectExpression' ? [
{

@@ -121,3 +122,3 @@ messageId: 'addEmptySchema',

},
],
] : [],
});

@@ -137,3 +138,3 @@ }

isUsingOptions = true;
context.report({ node: schemaNode || metaNode, messageId: 'foundOptionsUsage' });
context.report({ node: schemaNode || metaNode || info.create, messageId: 'foundOptionsUsage' });
}

@@ -140,0 +141,0 @@ },

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

recommended: true,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/require-meta-type.md',
},

@@ -34,10 +35,3 @@ fixable: null,

create (context) {
const sourceCode = context.getSourceCode();
const info = utils.getRuleInfo(sourceCode);
// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Public

@@ -48,3 +42,6 @@ // ----------------------------------------------------------------------

Program () {
if (info === null || info.meta === null) {
const sourceCode = context.getSourceCode();
const info = utils.getRuleInfo(sourceCode);
if (info === null) {
return;

@@ -60,3 +57,3 @@ }

if (!typeNode) {
context.report({ node: metaNode, messageId: 'missing' });
context.report({ node: metaNode || info.create, messageId: 'missing' });
return;

@@ -63,0 +60,0 @@ }

@@ -21,2 +21,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/test-case-property-ordering.md',
},

@@ -23,0 +24,0 @@ fixable: 'code',

@@ -21,2 +21,3 @@ /**

recommended: false,
url: 'https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/test-case-shorthand-strings.md',
},

@@ -23,0 +24,0 @@ fixable: 'code',

'use strict';
const { getStaticValue } = require('eslint-utils');
const { getStaticValue, findVariable } = require('eslint-utils');
const estraverse = require('estraverse');

@@ -21,55 +21,2 @@

/**
* Determines whether a node is a reference to function expression.
* @param {ASTNode} node The node in question
* @param {ScopeManager} scopeManager The scope manager to use for resolving references
* @returns {boolean} `true` if the node is a reference to a function expression
*/
function isNormalFunctionExpressionReference (node, scopeManager) {
if (!node || !scopeManager) {
return false;
}
if (node.type !== 'Identifier') {
return false;
}
const scope = scopeManager.acquire(node) || scopeManager.globalScope;
const scopes = [scope];
let createReference;
while (scopes.length > 0) {
const currentScope = scopes.shift();
const found = currentScope.references.find(reference => {
return reference.resolved && reference.identifier === node;
});
if (found) {
createReference = found;
break;
}
scopes.push(...currentScope.childScopes);
}
if (!createReference) {
return false;
}
const definitions = createReference.resolved.defs;
if (!definitions || definitions.length === 0) {
return false;
}
// Assumes it is immediately initialized to a function
let definitionNode = definitions[0].node;
// If we find something like `const create = () => {}` then send the
// righthand side into the type check.
if (definitionNode.type === 'VariableDeclarator') {
definitionNode = definitionNode.init;
}
return isNormalFunctionExpression(definitionNode);
}
/**
* Determines whether a node is constructing a RuleTester instance

@@ -238,2 +185,29 @@ * @param {ASTNode} node The node in question

/**
* Get the first value (or function) that a variable is initialized to.
* @param {Node} node - the Identifier node for the variable.
* @param {ScopeManager} scopeManager
* @returns the first value (or function) that the given variable is initialized to.
*/
function findVariableValue (node, scopeManager) {
const variable = findVariable(
scopeManager.acquire(node) || scopeManager.globalScope,
node
);
if (
variable &&
variable.defs &&
variable.defs[0] &&
variable.defs[0].node
) {
if (variable.defs[0].node.type === 'VariableDeclarator' && variable.defs[0].node.init) {
// Given node `x`, get `123` from `const x = 123;`.
return variable.defs[0].node.init;
} else if (variable.defs[0].node.type === 'FunctionDeclaration') {
// Given node `foo`, get `function foo() {}` from `function foo() {}`.
return variable.defs[0].node;
}
}
}
module.exports = {

@@ -256,6 +230,14 @@ /**

// If create/meta are defined in variables, get their values.
for (const key of Object.keys(exportNodes)) {
if (exportNodes[key] && exportNodes[key].type === 'Identifier') {
const value = findVariableValue(exportNodes[key], scopeManager);
if (value) {
exportNodes[key] = value;
}
}
}
const createIsFunction = isNormalFunctionExpression(exportNodes.create);
const createIsFunctionReference = isNormalFunctionExpressionReference(exportNodes.create, scopeManager);
if (!createIsFunction && !createIsFunctionReference) {
if (!createIsFunction) {
return null;

@@ -270,8 +252,8 @@ }

* only work correctly after traversing the AST has started (e.g. in the first `Program` node).
* @param {RuleContext} context The `context` variable for the source file itself
* @param {RuleContext} scopeManager
* @param {ASTNode} ast The `Program` node for the file
* @returns {Set<ASTNode>} A Set of all `Identifier` nodes that are references to the `context` value for the file
*/
getContextIdentifiers (context, ast) {
const ruleInfo = module.exports.getRuleInfo({ ast });
getContextIdentifiers (scopeManager, ast) {
const ruleInfo = module.exports.getRuleInfo({ ast, scopeManager });

@@ -283,3 +265,3 @@ if (!ruleInfo || ruleInfo.create.params.length === 0 || ruleInfo.create.params[0].type !== 'Identifier') {

return new Set(
context.getDeclaredVariables(ruleInfo.create)
scopeManager.getDeclaredVariables(ruleInfo.create)
.find(variable => variable.name === ruleInfo.create.params[0].name)

@@ -420,8 +402,8 @@ .references

* Gets a set of all `sourceCode` identifiers.
* @param {RuleContext} context The context for the rule file
* @param {ScopeManager} scopeManager
* @param {ASTNode} ast The AST of the file. This must have `parent` properties.
* @returns {Set<ASTNode>} A set of all identifiers referring to the `SourceCode` object.
*/
getSourceCodeIdentifiers (context, ast) {
return new Set([...module.exports.getContextIdentifiers(context, ast)]
getSourceCodeIdentifiers (scopeManager, ast) {
return new Set([...module.exports.getContextIdentifiers(scopeManager, ast)]
.filter(identifier => identifier.parent &&

@@ -438,3 +420,3 @@ identifier.parent.type === 'MemberExpression' &&

)
.flatMap(identifier => context.getDeclaredVariables(identifier.parent.parent.parent))
.flatMap(identifier => scopeManager.getDeclaredVariables(identifier.parent.parent.parent))
.flatMap(variable => variable.references)

@@ -441,0 +423,0 @@ .map(ref => ref.identifier));

{
"name": "eslint-plugin-eslint-plugin",
"version": "4.0.1",
"version": "4.0.2",
"description": "An ESLint plugin for linting ESLint plugins",

@@ -13,3 +13,3 @@ "author": "Teddy Katz",

"generate-readme-table": "node build/generate-readme-table.js",
"generate-release": "release-it",
"release": "release-it",
"test": "nyc --all --check-coverage --include lib mocha tests --recursive"

@@ -44,2 +44,5 @@ },

"devDependencies": {
"@commitlint/cli": "^13.2.1",
"@commitlint/config-conventional": "^13.2.0",
"@release-it/conventional-changelog": "^3.3.0",
"@typescript-eslint/parser": "^5.0.0",

@@ -57,2 +60,3 @@ "auto-changelog": "^2.3.0",

"espree": "^9.0.0",
"husky": "^7.0.2",
"lodash": "^4.17.2",

@@ -73,5 +77,11 @@ "markdownlint-cli": "^0.28.1",

"release-it": {
"hooks": {
"after:bump": "auto-changelog -p"
"git": {
"commitMessage": "chore: release v${version}"
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "conventionalcommits",
"infile": "CHANGELOG.md"
}
},
"github": {

@@ -78,0 +88,0 @@ "release": true

@@ -1,2 +0,2 @@

# eslint-plugin-eslint-plugin ![CI](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/workflows/CI/badge.svg) [![NPM version](https://img.shields.io/npm/v/eslint-plugin-eslint-plugin.svg?style=flat)](https://npmjs.org/package/eslint-plugin-eslint-plugin)
# eslint-plugin-eslint-plugin ![CI](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/workflows/CI/badge.svg) [![NPM version](https://img.shields.io/npm/v/eslint-plugin-eslint-plugin.svg?style=flat)](https://npmjs.org/package/eslint-plugin-eslint-plugin) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

@@ -3,0 +3,0 @@ An ESLint plugin for linting ESLint plugins. Rules written in CJS, ESM, and TypeScript are all supported.

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