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

eslint

Package Overview
Dependencies
Maintainers
4
Versions
373
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 8.24.0 to 8.25.0

36

lib/cli.js

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

const { findFlatConfigFile } = require("./eslint/flat-eslint");
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
const { ModuleImporter } = require("@humanwhocodes/module-importer");

@@ -42,2 +41,3 @@

/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
/** @typedef {import("./shared/types").ResultsMeta} ResultsMeta */

@@ -150,3 +150,3 @@ //------------------------------------------------------------------------------

overrideConfig.push({
ignores: ignorePattern.map(gitignoreToMinimatch)
ignores: ignorePattern
});

@@ -188,3 +188,2 @@ }

ignore,
ignorePath,
overrideConfig,

@@ -200,2 +199,3 @@ overrideConfigFile,

options.extensions = ext;
options.ignorePath = ignorePath;
}

@@ -209,3 +209,3 @@

* @param {LintResult[]} results The lint results.
* @returns {{errorCount:number;warningCount:number}} The number of error messages.
* @returns {{errorCount:number;fatalErrorCount:number,warningCount:number}} The number of error messages.
*/

@@ -248,6 +248,7 @@ function countErrors(results) {

* @param {string} outputFile The path for the output file.
* @param {ResultsMeta} resultsMeta Warning count and max threshold.
* @returns {Promise<boolean>} True if the printing succeeds, false if not.
* @private
*/
async function printResults(engine, results, format, outputFile) {
async function printResults(engine, results, format, outputFile, resultsMeta) {
let formatter;

@@ -262,3 +263,3 @@

const output = await formatter.format(results);
const output = await formatter.format(results, resultsMeta);

@@ -418,13 +419,20 @@ if (output) {

if (await printResults(engine, resultsToPrint, options.format, options.outputFile)) {
const resultCounts = countErrors(results);
const tooManyWarnings = options.maxWarnings >= 0 && resultCounts.warningCount > options.maxWarnings;
const resultsMeta = tooManyWarnings
? {
maxWarningsExceeded: {
maxWarnings: options.maxWarnings,
foundWarnings: resultCounts.warningCount
}
}
: {};
if (await printResults(engine, resultsToPrint, options.format, options.outputFile, resultsMeta)) {
// Errors and warnings from the original unfiltered results should determine the exit code
const { errorCount, fatalErrorCount, warningCount } = countErrors(results);
const tooManyWarnings =
options.maxWarnings >= 0 && warningCount > options.maxWarnings;
const shouldExitForFatalErrors =
options.exitOnFatalError && fatalErrorCount > 0;
options.exitOnFatalError && resultCounts.fatalErrorCount > 0;
if (!errorCount && tooManyWarnings) {
if (!resultCounts.errorCount && tooManyWarnings) {
log.error(

@@ -440,3 +448,3 @@ "ESLint found too many warnings (maximum: %s).",

return (errorCount || tooManyWarnings) ? 1 : 0;
return (resultCounts.errorCount || tooManyWarnings) ? 1 : 0;
}

@@ -443,0 +451,0 @@

@@ -73,3 +73,3 @@ /**

/**
* The baes config used to build the config array.
* The base config used to build the config array.
* @type {Array<FlatConfig>}

@@ -76,0 +76,0 @@ */

@@ -70,5 +70,5 @@ /**

/**
* Check if a given value is an array of non-empty stringss or not.
* Check if a given value is an array of non-empty strings or not.
* @param {any} x The value to check.
* @returns {boolean} `true` if `x` is an array of non-empty stringss.
* @returns {boolean} `true` if `x` is an array of non-empty strings.
*/

@@ -414,3 +414,2 @@ function isArrayOfNonEmptyString(x) {

ignore = true,
ignorePath = null, // ← should be null by default because if it's a string then it may throw ENOENT.
ignorePatterns = null,

@@ -446,2 +445,5 @@ overrideConfig = null,

}
if (unknownOptionKeys.includes("ignorePath")) {
errors.push("'ignorePath' has been removed.");
}
if (unknownOptionKeys.includes("ignorePattern")) {

@@ -499,5 +501,2 @@ errors.push("'ignorePattern' has been removed. Please use the 'overrideConfig.ignorePatterns' option instead.");

}
if (!isNonEmptyString(ignorePath) && ignorePath !== null) {
errors.push("'ignorePath' must be a non-empty string or null.");
}
if (typeof overrideConfig !== "object") {

@@ -545,3 +544,2 @@ errors.push("'overrideConfig' must be an object or null.");

ignore,
ignorePath,
ignorePatterns,

@@ -548,0 +546,0 @@ reportUnusedDisableDirectives

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

/** @typedef {import("../shared/types").LintResult} LintResult */
/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */

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

* @typedef LoadedFormatter
* @property {function(LintResult[]): string | Promise<string>} format format function.
* @property {(results: LintResult[], resultsMeta: ResultsMeta) => string | Promise<string>} format format function.
*/

@@ -630,5 +631,6 @@

* @param {LintResult[]} results The lint results to format.
* @param {ResultsMeta} resultsMeta Warning count and max threshold.
* @returns {string | Promise<string>} The formatted lint results.
*/
format(results) {
format(results, resultsMeta) {
let rulesMeta = null;

@@ -639,2 +641,3 @@

return formatter(results, {
...resultsMeta,
get cwd() {

@@ -641,0 +644,0 @@ return options.cwd;

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

const { getRuleFromConfig } = require("../config/flat-config-helpers");
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
const {

@@ -32,3 +31,2 @@ Legacy: {

const {
fileExists,
findFiles,

@@ -64,2 +62,3 @@ getCacheFile,

/** @typedef {import("../shared/types").Plugin} Plugin */
/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */
/** @typedef {import("../shared/types").RuleConf} RuleConf */

@@ -82,5 +81,4 @@ /** @typedef {import("../shared/types").Rule} Rule */

* @property {boolean} [globInputPaths] Set to false to skip glob resolution of input file paths to lint (default: true). If false, each input file paths is assumed to be a non-glob path to an existing file.
* @property {boolean} [ignore] False disables use of .eslintignore.
* @property {string} [ignorePath] The ignore file to use instead of .eslintignore.
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to .eslintignore.
* @property {boolean} [ignore] False disables all ignore patterns except for the default ones.
* @property {string[]} [ignorePatterns] Ignore file patterns to use in addition to config ignores.
* @property {ConfigData} [overrideConfig] Override config object, overrides all configs used with this instance

@@ -159,26 +157,2 @@ * @property {boolean|string} [overrideConfigFile] Searches for default config file when falsy;

/**
* Loads global ignore patterns from an ignore file (usually .eslintignore).
* @param {string} filePath The filename to load.
* @returns {ignore} A function encapsulating the ignore patterns.
* @throws {Error} If the file cannot be read.
* @private
*/
async function loadIgnoreFilePatterns(filePath) {
debug(`Loading ignore file: ${filePath}`);
try {
const ignoreFileText = await fs.readFile(filePath, { encoding: "utf8" });
return ignoreFileText
.split(/\r?\n/gu)
.filter(line => line.trim() !== "" && !line.startsWith("#"));
} catch (e) {
debug(`Error reading ignore file: ${filePath}`);
e.message = `Cannot read ignore file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
/**
* Create rulesMeta object.

@@ -327,3 +301,2 @@ * @param {Map<string,Rule>} rules a map of rules from which to generate the object.

ignore: shouldIgnore,
ignorePath,
ignorePatterns

@@ -373,19 +346,3 @@ }) {

let allIgnorePatterns = [];
let ignoreFilePath;
// load ignore file if necessary
if (shouldIgnore) {
if (ignorePath) {
ignoreFilePath = path.resolve(cwd, ignorePath);
allIgnorePatterns = await loadIgnoreFilePatterns(ignoreFilePath);
} else {
ignoreFilePath = path.resolve(cwd, ".eslintignore");
// no error if .eslintignore doesn't exist`
if (fileExists(ignoreFilePath)) {
allIgnorePatterns = await loadIgnoreFilePatterns(ignoreFilePath);
}
}
}
// append command line ignore patterns

@@ -438,3 +395,3 @@ if (ignorePatterns) {

configs.push({
ignores: allIgnorePatterns.map(gitignoreToMinimatch)
ignores: allIgnorePatterns
});

@@ -883,3 +840,3 @@ }

// set up fixer for fixtypes if necessary
// set up fixer for fixTypes if necessary
let fixer = fix;

@@ -1060,3 +1017,3 @@

* - A builtin formatter name ... Load the builtin formatter.
* - A thirdparty formatter name:
* - A third-party formatter name:
* - `foo` → `eslint-formatter-foo`

@@ -1127,5 +1084,6 @@ * - `@foo` → `@foo/eslint-formatter`

* @param {LintResults[]} results The lint results to format.
* @param {ResultsMeta} resultsMeta Warning count and max threshold.
* @returns {string} The formatted lint results.
*/
format(results) {
format(results, resultsMeta) {
let rulesMeta = null;

@@ -1136,2 +1094,3 @@

return formatter(results, {
...resultsMeta,
cwd,

@@ -1138,0 +1097,0 @@ get rulesMeta() {

@@ -70,3 +70,3 @@ /**

* @param {boolean} usingFlatConfig Indicates if flat config is being used.
* @returns {Object} The opinionator instance.
* @returns {Object} The optionator instance.
*/

@@ -133,2 +133,12 @@ module.exports = function(usingFlatConfig) {

let ignorePathFlag;
if (!usingFlatConfig) {
ignorePathFlag = {
option: "ignore-path",
type: "path::String",
description: "Specify path of ignore file"
};
}
return optionator({

@@ -208,8 +218,4 @@ prepend: "eslint [options] file.js [file.js] [dir]",

},
ignorePathFlag,
{
option: "ignore-path",
type: "path::String",
description: "Specify path of ignore file"
},
{
option: "ignore",

@@ -216,0 +222,0 @@ type: "Boolean",

@@ -10,2 +10,41 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const GraphemeSplitter = require("grapheme-splitter");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Checks if the string given as argument is ASCII or not.
* @param {string} value A string that you want to know if it is ASCII or not.
* @returns {boolean} `true` if `value` is ASCII string.
*/
function isASCII(value) {
if (typeof value !== "string") {
return false;
}
return /^[\u0020-\u007f]*$/u.test(value);
}
/** @type {GraphemeSplitter | undefined} */
let splitter;
/**
* Gets the length of the string. If the string is not in ASCII, counts graphemes.
* @param {string} value A string that you want to get the length.
* @returns {number} The length of `value`.
*/
function getStringLength(value) {
if (isASCII(value)) {
return value.length;
}
if (!splitter) {
splitter = new GraphemeSplitter();
}
return splitter.countGraphemes(value);
}
//------------------------------------------------------------------------------
// Rule Definition

@@ -134,5 +173,7 @@ //------------------------------------------------------------------------------

const isShort = name.length < minLength;
const isLong = name.length > maxLength;
const nameLength = getStringLength(name);
const isShort = nameLength < minLength;
const isLong = nameLength > maxLength;
if (!(isShort || isLong) || exceptions.has(name) || matchesExceptionPattern(name)) {

@@ -139,0 +180,0 @@ return; // Nothing to report

@@ -18,3 +18,3 @@ /**

/**
* Return an array with with any line numbers that are empty.
* Return an array with any line numbers that are empty.
* @param {Array} lines An array of each line of the file.

@@ -33,3 +33,3 @@ * @returns {Array} An array of line numbers.

/**
* Return an array with with any line numbers that contain comments.
* Return an array with any line numbers that contain comments.
* @param {Array} comments An array of comment tokens.

@@ -36,0 +36,0 @@ * @returns {Array} An array of line numbers.

@@ -108,3 +108,3 @@ /**

/**
* Converts an integer to to an object containing the integer's coefficient and order of magnitude
* Converts an integer to an object containing the integer's coefficient and order of magnitude
* @param {string} stringInteger the string representation of the integer being converted

@@ -124,3 +124,3 @@ * @returns {Object} the object containing the integer's coefficient and order of magnitude

*
* Converts a float to to an object containing the floats's coefficient and order of magnitude
* Converts a float to an object containing the floats's coefficient and order of magnitude
* @param {string} stringFloat the string representation of the float being converted

@@ -127,0 +127,0 @@ * @returns {Object} the object containing the integer's coefficient and order of magnitude

@@ -71,3 +71,3 @@ /**

/**
* Checks whether a given scope is the scope of a a class static initializer.
* Checks whether a given scope is the scope of a class static initializer.
* Static initializers are static blocks and initializers of static fields.

@@ -74,0 +74,0 @@ * @param {eslint-scope.Scope} scope A scope to check.

@@ -77,3 +77,3 @@ /**

/**
* Gives a a copy of the ancestor nodes.
* Gives a copy of the ancestor nodes.
* @returns {ASTNode[]} The ancestor nodes.

@@ -80,0 +80,0 @@ */

@@ -194,7 +194,20 @@ /**

/**
* Information provided when the maximum warning threshold is exceeded.
* @typedef {Object} MaxWarningsExceeded
* @property {number} maxWarnings Number of warnings to trigger nonzero exit code.
* @property {number} foundWarnings Number of warnings found while linting.
*/
/**
* Metadata about results for formatters.
* @typedef {Object} ResultsMeta
* @property {MaxWarningsExceeded} [maxWarningsExceeded] Present if the maxWarnings threshold was exceeded.
*/
/**
* A formatter function.
* @callback FormatterFunction
* @param {LintResult[]} results The list of linting results.
* @param {{cwd: string, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
* @param {{cwd: string, maxWarningsExceeded?: MaxWarningsExceeded, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
* @returns {string | Promise<string>} Formatted text.
*/
{
"name": "eslint",
"version": "8.24.0",
"version": "8.25.0",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",

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

"dependencies": {
"@eslint/eslintrc": "^1.3.2",
"@eslint/eslintrc": "^1.3.3",
"@humanwhocodes/config-array": "^0.10.5",
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
"@humanwhocodes/module-importer": "^1.0.1",

@@ -125,3 +124,2 @@ "ajv": "^6.10.0",

"gray-matter": "^4.0.3",
"jsdoc": "^3.5.5",
"karma": "^6.1.1",

@@ -128,0 +126,0 @@ "karma-chrome-launcher": "^3.1.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