Socket
Socket
Sign inDemoInstall

eslint

Package Overview
Dependencies
Maintainers
2
Versions
366
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint - npm Package Compare versions

Comparing version 9.7.0 to 9.8.0

20

lib/cli.js

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

const { ModuleImporter } = require("@humanwhocodes/module-importer");
const { inactiveFlags, activeFlags } = require("./shared/flags");
const debug = require("debug")("eslint:cli");

@@ -492,21 +491,2 @@

const eslintOptions = await translateOptions(options, usingFlatConfig ? "flat" : "eslintrc");
if (eslintOptions.flags) {
debug("Checking for inactive flags");
for (const flag of eslintOptions.flags) {
if (inactiveFlags.has(flag)) {
log.warn(`InactiveFlag: The '${flag}' flag is no longer active: ${inactiveFlags.get(flag)}`);
continue;
}
if (activeFlags.has(flag)) {
continue;
}
log.error(`InvalidFlag: The '${flag}' flag is invalid.`);
return 2;
}
}
const engine = new ActiveESLint(eslintOptions);

@@ -513,0 +493,0 @@ let results;

19

lib/languages/js/source-code/source-code.js

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

}
/**
* Returns the locatin of the given node or token.
* @param {ASTNode|Token} nodeOrToken The node or token to get the location of.
* @returns {SourceLocation} The location of the node or token.
*/
getLoc(nodeOrToken) {
return nodeOrToken.loc;
}
/**
* Returns the range of the given node or token.
* @param {ASTNode|Token} nodeOrToken The node or token to get the range of.
* @returns {[number, number]} The range of the node or token.
*/
getRange(nodeOrToken) {
return nodeOrToken.range;
}
/* eslint-enable class-methods-use-this -- node is owned by SourceCode */

@@ -921,0 +940,0 @@

36

lib/linter/apply-disable-directives.js

@@ -64,6 +64,9 @@ /**

* @param {Token} node The backing Comment token.
* @param {SourceCode} sourceCode The source code object for the file being linted.
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
*/
function createIndividualDirectivesRemoval(directives, node) {
function createIndividualDirectivesRemoval(directives, node, sourceCode) {
const range = sourceCode.getRange(node);
/*

@@ -73,3 +76,3 @@ * `node.value` starts right after `//` or `/*`.

*/
const commentValueStart = node.range[0] + "//".length;
const commentValueStart = range[0] + "//".length;

@@ -170,6 +173,7 @@ // Find where the list of rules starts. `\S+` matches with the directive name (e.g. `eslint-disable-line`)

* @param {Token} node The backing Comment token.
* @param {SourceCode} sourceCode The source code object for the file being linted.
* @returns {{ description, fix, unprocessedDirective }} Details for later creation of an output problem.
*/
function createDirectiveRemoval(directives, node) {
const { range } = node;
function createDirectiveRemoval(directives, node, sourceCode) {
const range = sourceCode.getRange(node);
const ruleIds = directives.filter(directive => directive.ruleId).map(directive => `'${directive.ruleId}'`);

@@ -192,5 +196,6 @@

* @param {Iterable<Directive>} allDirectives Unused directives to be removed.
* @param {SourceCode} sourceCode The source code object for the file being linted.
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
*/
function processUnusedDirectives(allDirectives) {
function processUnusedDirectives(allDirectives, sourceCode) {
const directiveGroups = groupByParentDirective(allDirectives);

@@ -208,4 +213,4 @@

return remainingRuleIds.size
? createIndividualDirectivesRemoval(directives, parentDirective.node)
: [createDirectiveRemoval(directives, parentDirective.node)];
? createIndividualDirectivesRemoval(directives, parentDirective.node, sourceCode)
: [createDirectiveRemoval(directives, parentDirective.node, sourceCode)];
}

@@ -317,2 +322,3 @@ );

const usedDisableDirectives = new Set();
const { sourceCode } = options;

@@ -379,4 +385,4 @@ for (const problem of options.problems) {

const processed = processUnusedDirectives(unusedDisableDirectivesToReport)
.concat(processUnusedDirectives(unusedEnableDirectivesToReport));
const processed = processUnusedDirectives(unusedDisableDirectivesToReport, sourceCode)
.concat(processUnusedDirectives(unusedEnableDirectivesToReport, sourceCode));
const columnOffset = options.language.columnStart === 1 ? 0 : 1;

@@ -400,7 +406,10 @@ const lineOffset = options.language.lineStart === 1 ? 0 : 1;

}
const loc = sourceCode.getLoc(parentDirective.node);
return {
ruleId: null,
message,
line: type === "disable-next-line" ? parentDirective.node.loc.start.line + lineOffset : line,
column: type === "disable-next-line" ? parentDirective.node.loc.start.column + columnOffset : column,
line: type === "disable-next-line" ? loc.start.line + lineOffset : line,
column: type === "disable-next-line" ? loc.start.column + columnOffset : column,
severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2,

@@ -420,2 +429,3 @@ nodeType: null,

* @param {Language} options.language The language being linted.
* @param {SourceCode} options.sourceCode The source code object for the file being linted.
* @param {{

@@ -439,3 +449,3 @@ * type: ("disable"|"enable"|"disable-line"|"disable-next-line"),

*/
module.exports = ({ language, directives, disableFixes, problems, configuredRules, ruleFilter, reportUnusedDisableDirectives = "off" }) => {
module.exports = ({ language, sourceCode, directives, disableFixes, problems, configuredRules, ruleFilter, reportUnusedDisableDirectives = "off" }) => {
const blockDirectives = directives

@@ -490,2 +500,3 @@ .filter(directive => directive.type === "disable" || directive.type === "enable")

language,
sourceCode,
problems,

@@ -499,2 +510,3 @@ directives: blockDirectives,

language,
sourceCode,
problems: blockDirectivesResult.problems,

@@ -501,0 +513,0 @@ directives: lineDirectives,

@@ -13,3 +13,3 @@ /**

const assert = require("node:assert");
const ruleFixer = require("./rule-fixer");
const { RuleFixer } = require("./rule-fixer");
const { interpolate } = require("./interpolate");

@@ -95,9 +95,6 @@

function normalizeReportLoc(descriptor) {
if (descriptor.loc) {
if (descriptor.loc.start) {
return descriptor.loc;
}
return { start: descriptor.loc, end: null };
if (descriptor.loc.start) {
return descriptor.loc;
}
return descriptor.node.loc;
return { start: descriptor.loc, end: null };
}

@@ -195,2 +192,4 @@

const ruleFixer = new RuleFixer({ sourceCode });
// @type {null | Fix | Fix[] | IterableIterator<Fix>}

@@ -341,2 +340,3 @@ const fix = descriptor.fix(ruleFixer);

const messages = metadata.messageIds;
const { sourceCode } = metadata;

@@ -374,5 +374,5 @@ assertValidNodeInfo(descriptor);

messageId: descriptor.messageId,
loc: normalizeReportLoc(descriptor),
fix: metadata.disableFixes ? null : normalizeFixes(descriptor, metadata.sourceCode),
suggestions: metadata.disableFixes ? [] : mapSuggestions(descriptor, metadata.sourceCode, messages),
loc: descriptor.loc ? normalizeReportLoc(descriptor) : sourceCode.getLoc(descriptor.node),
fix: metadata.disableFixes ? null : normalizeFixes(descriptor, sourceCode),
suggestions: metadata.disableFixes ? [] : mapSuggestions(descriptor, sourceCode, messages),
language: metadata.language

@@ -379,0 +379,0 @@ });

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

/* eslint class-methods-use-this: off -- Methods desired on instance */
//------------------------------------------------------------------------------

@@ -39,6 +41,20 @@ // Requirements

*/
class RuleFixer {
const ruleFixer = Object.freeze({
/**
* The source code object representing the text to be fixed.
* @type {SourceCode}
*/
#sourceCode;
/**
* Creates a new instance.
* @param {Object} options The options for the fixer.
* @param {SourceCode} options.sourceCode The source code object representing the text to be fixed.
*/
constructor({ sourceCode }) {
this.#sourceCode = sourceCode;
}
/**
* Creates a fix command that inserts text after the given node or token.

@@ -51,5 +67,7 @@ * The fix is not applied until applyFixes() is called.

insertTextAfter(nodeOrToken, text) {
return this.insertTextAfterRange(nodeOrToken.range, text);
},
const range = this.#sourceCode.getRange(nodeOrToken);
return this.insertTextAfterRange(range, text);
}
/**

@@ -65,3 +83,3 @@ * Creates a fix command that inserts text after the specified range in the source text.

return insertTextAt(range[1], text);
},
}

@@ -76,5 +94,7 @@ /**

insertTextBefore(nodeOrToken, text) {
return this.insertTextBeforeRange(nodeOrToken.range, text);
},
const range = this.#sourceCode.getRange(nodeOrToken);
return this.insertTextBeforeRange(range, text);
}
/**

@@ -90,3 +110,3 @@ * Creates a fix command that inserts text before the specified range in the source text.

return insertTextAt(range[0], text);
},
}

@@ -101,5 +121,7 @@ /**

replaceText(nodeOrToken, text) {
return this.replaceTextRange(nodeOrToken.range, text);
},
const range = this.#sourceCode.getRange(nodeOrToken);
return this.replaceTextRange(range, text);
}
/**

@@ -118,3 +140,3 @@ * Creates a fix command that replaces text at the specified range in the source text.

};
},
}

@@ -128,5 +150,7 @@ /**

remove(nodeOrToken) {
return this.removeRange(nodeOrToken.range);
},
const range = this.#sourceCode.getRange(nodeOrToken);
return this.removeRange(range);
}
/**

@@ -145,6 +169,5 @@ * Creates a fix command that removes the specified range of text from the source.

}
}
});
module.exports = ruleFixer;
module.exports = { RuleFixer };

@@ -12,3 +12,3 @@ /**

const activeFlags = new Map([
["test_only", "This flag is only used for testing."]
["test_only", "Used only for testing."]
]);

@@ -21,3 +21,3 @@

const inactiveFlags = new Map([
["test_only_old", "This flag is no longer used for testing."]
["test_only_old", "Used only for testing."]
]);

@@ -24,0 +24,0 @@

{
"name": "eslint",
"version": "9.7.0",
"version": "9.8.0",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",

@@ -71,5 +71,5 @@ "description": "An AST-based pattern checker for JavaScript.",

"@eslint-community/regexpp": "^4.11.0",
"@eslint/config-array": "^0.17.0",
"@eslint/config-array": "^0.17.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "9.7.0",
"@eslint/js": "9.8.0",
"@humanwhocodes/module-importer": "^1.0.1",

@@ -108,3 +108,4 @@ "@humanwhocodes/retry": "^0.3.0",

"@babel/preset-env": "^7.4.3",
"@eslint/core": "^0.1.0",
"@eslint/core": "^0.2.0",
"@eslint/json": "^0.2.0",
"@types/estree": "^1.0.5",

@@ -111,0 +112,0 @@ "@types/node": "^20.11.5",

Sorry, the diff of this file is too big to display

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