Socket
Socket
Sign inDemoInstall

eslint

Package Overview
Dependencies
Maintainers
4
Versions
370
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.4.1 to 8.54.0

lib/cli-engine/formatters/formatters-meta.json

59

bin/eslint.js

@@ -12,5 +12,2 @@ #!/usr/bin/env node

// to use V8's code cache to speed up instantiation time
require("v8-compile-cache");
// must do this initialization *before* other requires in order to work

@@ -73,3 +70,3 @@ if (process.argv.includes("--debug")) {

// Foolproof -- thirdparty module might throw non-object.
// Foolproof -- third-party module might throw non-object.
if (typeof error !== "object" || error === null) {

@@ -101,2 +98,15 @@ return String(error);

/**
* Tracks error messages that are shown to the user so we only ever show the
* same message once.
* @type {Set<string>}
*/
const displayedErrors = new Set();
/**
* Tracks whether an unexpected error was caught
* @type {boolean}
*/
let hadFatalError = false;
/**
* Catch and report unexpected error.

@@ -108,7 +118,6 @@ * @param {any} error The thrown error object.

process.exitCode = 2;
hadFatalError = true;
const { version } = require("../package.json");
const message = getErrorMessage(error);
console.error(`
const message = `
Oops! Something went wrong! :(

@@ -118,3 +127,8 @@

${message}`);
${getErrorMessage(error)}`;
if (!displayedErrors.has(message)) {
console.error(message);
displayedErrors.add(message);
}
}

@@ -132,3 +146,9 @@

if (process.argv.includes("--init")) {
await require("../lib/init/config-initializer").initializeConfig();
// `eslint --init` has been moved to `@eslint/create-config`
console.warn("You can also run this command directly using 'npm init @eslint/config'.");
const spawn = require("cross-spawn");
spawn.sync("npm", ["init", "@eslint/config"], { encoding: "utf8", stdio: "inherit" });
return;

@@ -138,6 +158,23 @@ }

// Otherwise, call the CLI.
process.exitCode = await require("../lib/cli").execute(
const exitCode = await require("../lib/cli").execute(
process.argv,
process.argv.includes("--stdin") ? await readStdin() : null
process.argv.includes("--stdin") ? await readStdin() : null,
true
);
/*
* If an uncaught exception or unhandled rejection was detected in the meantime,
* keep the fatal exit code 2 that is already assigned to `process.exitCode`.
* Without this condition, exit code 2 (unsuccessful execution) could be overwritten with
* 1 (successful execution, lint problems found) or even 0 (successful execution, no lint problems found).
* This ensures that unexpected errors that seemingly don't affect the success
* of the execution will still cause a non-zero exit code, as it's a common
* practice and the default behavior of Node.js to exit with non-zero
* in case of an uncaught exception or unhandled rejection.
*
* Otherwise, assign the exit code returned from CLI.
*/
if (!hadFatalError) {
process.exitCode = exitCode;
}
}()).catch(onFatalError);

@@ -127,3 +127,11 @@ /**

const es2023 = {
...es2022
};
const es2024 = {
...es2023
};
//-----------------------------------------------------------------------------

@@ -144,3 +152,5 @@ // Exports

es2021,
es2022
es2022,
es2023,
es2024
};

58

conf/rule-type-list.json
{
"types": [
{ "name": "problem", "displayName": "Possible Problems", "description": "These rules relate to possible logic errors in code:" },
{ "name": "suggestion", "displayName": "Suggestions", "description": "These rules suggest alternate ways of doing things:" },
{ "name": "layout", "displayName": "Layout & Formatting", "description": "These rules care about how the code looks rather than how it executes:" }
],
"deprecated": {
"name": "Deprecated",
"description": "These rules have been deprecated in accordance with the <a href=\"/docs/user-guide/rule-deprecation\">deprecation policy</a>, and replaced by newer rules:",
"rules": []
"types": {
"problem": [],
"suggestion": [],
"layout": []
},
"removed": {
"name": "Removed",
"description": "These rules from older versions of ESLint (before the <a href=\"/docs/user-guide/rule-deprecation\">deprecation policy</a> existed) have been replaced by newer rules:",
"rules": [
{ "removed": "generator-star", "replacedBy": ["generator-star-spacing"] },
{ "removed": "global-strict", "replacedBy": ["strict"] },
{ "removed": "no-arrow-condition", "replacedBy": ["no-confusing-arrow", "no-constant-condition"] },
{ "removed": "no-comma-dangle", "replacedBy": ["comma-dangle"] },
{ "removed": "no-empty-class", "replacedBy": ["no-empty-character-class"] },
{ "removed": "no-empty-label", "replacedBy": ["no-labels"] },
{ "removed": "no-extra-strict", "replacedBy": ["strict"] },
{ "removed": "no-reserved-keys", "replacedBy": ["quote-props"] },
{ "removed": "no-space-before-semi", "replacedBy": ["semi-spacing"] },
{ "removed": "no-wrap-func", "replacedBy": ["no-extra-parens"] },
{ "removed": "space-after-function-name", "replacedBy": ["space-before-function-paren"] },
{ "removed": "space-after-keywords", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-before-function-parentheses", "replacedBy": ["space-before-function-paren"] },
{ "removed": "space-before-keywords", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-in-brackets", "replacedBy": ["object-curly-spacing", "array-bracket-spacing"] },
{ "removed": "space-return-throw-case", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-unary-word-ops", "replacedBy": ["space-unary-ops"] },
{ "removed": "spaced-line-comment", "replacedBy": ["spaced-comment"] }
]
}
"deprecated": [],
"removed": [
{ "removed": "generator-star", "replacedBy": ["generator-star-spacing"] },
{ "removed": "global-strict", "replacedBy": ["strict"] },
{ "removed": "no-arrow-condition", "replacedBy": ["no-confusing-arrow", "no-constant-condition"] },
{ "removed": "no-comma-dangle", "replacedBy": ["comma-dangle"] },
{ "removed": "no-empty-class", "replacedBy": ["no-empty-character-class"] },
{ "removed": "no-empty-label", "replacedBy": ["no-labels"] },
{ "removed": "no-extra-strict", "replacedBy": ["strict"] },
{ "removed": "no-reserved-keys", "replacedBy": ["quote-props"] },
{ "removed": "no-space-before-semi", "replacedBy": ["semi-spacing"] },
{ "removed": "no-wrap-func", "replacedBy": ["no-extra-parens"] },
{ "removed": "space-after-function-name", "replacedBy": ["space-before-function-paren"] },
{ "removed": "space-after-keywords", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-before-function-parentheses", "replacedBy": ["space-before-function-paren"] },
{ "removed": "space-before-keywords", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-in-brackets", "replacedBy": ["object-curly-spacing", "array-bracket-spacing"] },
{ "removed": "space-return-throw-case", "replacedBy": ["keyword-spacing"] },
{ "removed": "space-unary-word-ops", "replacedBy": ["space-unary-ops"] },
{ "removed": "spaced-line-comment", "replacedBy": ["spaced-comment"] }
]
}

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

/** @typedef {import("../shared/types").LintMessage} LintMessage */
/** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
/** @typedef {import("../shared/types").ParserOptions} ParserOptions */

@@ -59,2 +60,3 @@ /** @typedef {import("../shared/types").Plugin} Plugin */

/** @typedef {import("../shared/types").Rule} Rule */
/** @typedef {import("../shared/types").FormatterFunction} FormatterFunction */
/** @typedef {ReturnType<CascadingConfigArrayFactory.getConfigArrayForFile>} ConfigArray */

@@ -96,3 +98,5 @@ /** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */

* @property {LintMessage[]} messages All of the messages for the result.
* @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
* @property {number} errorCount Number of errors for the result.
* @property {number} fatalErrorCount Number of fatal errors for the result.
* @property {number} warningCount Number of warnings for the result.

@@ -110,2 +114,3 @@ * @property {number} fixableErrorCount Number of fixable errors for the result.

* @property {number} errorCount Number of errors for the result.
* @property {number} fatalErrorCount Number of fatal errors for the result.
* @property {number} warningCount Number of warnings for the result.

@@ -160,3 +165,13 @@ * @property {number} fixableErrorCount Number of fixable errors for the result.

function calculateStatsPerFile(messages) {
return messages.reduce((stat, message) => {
const stat = {
errorCount: 0,
fatalErrorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0
};
for (let i = 0; i < messages.length; i++) {
const message = messages[i];
if (message.fatal || message.severity === 2) {

@@ -176,10 +191,4 @@ stat.errorCount++;

}
return stat;
}, {
errorCount: 0,
fatalErrorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0
});
}
return stat;
}

@@ -194,3 +203,13 @@

function calculateStatsPerRun(results) {
return results.reduce((stat, result) => {
const stat = {
errorCount: 0,
fatalErrorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0
};
for (let i = 0; i < results.length; i++) {
const result = results[i];
stat.errorCount += result.errorCount;

@@ -201,10 +220,5 @@ stat.fatalErrorCount += result.fatalErrorCount;

stat.fixableWarningCount += result.fixableWarningCount;
return stat;
}, {
errorCount: 0,
fatalErrorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0
});
}
return stat;
}

@@ -272,2 +286,3 @@

messages,
suppressedMessages: linter.getSuppressedMessages(),
...calculateStatsPerFile(messages)

@@ -314,8 +329,12 @@ };

{
ruleId: null,
fatal: false,
severity: 1,
message
message,
nodeType: null
}
],
suppressedMessages: [],
errorCount: 0,
fatalErrorCount: 0,
warningCount: 1,

@@ -371,5 +390,3 @@ fixableErrorCount: 0,

/** @type {ExtractedConfig[]} */
const configs = [].concat(
...usedConfigArrays.map(getUsedExtractedConfigs)
);
const configs = usedConfigArrays.flatMap(getUsedExtractedConfigs);

@@ -422,3 +439,3 @@ // Traverse rule configs.

*
* if cacheFile points to a file or looks like a file then in will just use that file
* if cacheFile points to a file or looks like a file then it will just use that file
* @param {string} cacheFile The name of file to be used to store the cache

@@ -624,4 +641,4 @@ * @param {string} cwd Current working directory

loadRules,
eslintRecommendedPath: path.resolve(__dirname, "../../conf/eslint-recommended.js"),
eslintAllPath: path.resolve(__dirname, "../../conf/eslint-all.js")
getEslintRecommendedConfig: () => require("@eslint/js").configs.recommended,
getEslintAllConfig: () => require("@eslint/js").configs.all
});

@@ -696,2 +713,3 @@ const fileEnumerator = new FileEnumerator({

const filteredMessages = result.messages.filter(isErrorMessage);
const filteredSuppressedMessages = result.suppressedMessages.filter(isErrorMessage);

@@ -702,2 +720,3 @@ if (filteredMessages.length > 0) {

messages: filteredMessages,
suppressedMessages: filteredSuppressedMessages,
errorCount: filteredMessages.length,

@@ -1011,3 +1030,3 @@ warningCount: 0,

* @throws {any} As may be thrown by requiring of formatter
* @returns {(Function|null)} The formatter function or null if the `format` is not a string.
* @returns {(FormatterFunction|null)} The formatter function or null if the `format` is not a string.
*/

@@ -1032,3 +1051,3 @@ getFormatter(format) {

// if there's a slash, then it's a file (TODO: this check seems dubious for scoped npm packages)
if (!namespace && normalizedFormatName.indexOf("/") > -1) {
if (!namespace && normalizedFormatName.includes("/")) {
formatterPath = path.resolve(cwd, normalizedFormatName);

@@ -1035,0 +1054,0 @@ } else {

@@ -125,3 +125,4 @@ /**

} catch (error) {
/* istanbul ignore next */
/* c8 ignore next */
if (error.code !== "ENOENT") {

@@ -145,3 +146,4 @@ throw error;

} catch (error) {
/* istanbul ignore next */
/* c8 ignore next */
if (error.code !== "ENOENT") {

@@ -220,4 +222,4 @@ throw error;

cwd,
eslintRecommendedPath: path.resolve(__dirname, "../../conf/eslint-recommended.js"),
eslintAllPath: path.resolve(__dirname, "../../conf/eslint-all.js")
getEslintRecommendedConfig: () => require("@eslint/js").configs.recommended,
getEslintAllConfig: () => require("@eslint/js").configs.all
}),

@@ -353,3 +355,3 @@ extensions = null,

if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(absolutePath, isDot);
return this._iterateFilesWithGlob(pattern, isDot);
}

@@ -403,4 +405,6 @@

const directoryPath = path.resolve(getGlobParent(pattern));
const globPart = pattern.slice(directoryPath.length + 1);
const { cwd } = internalSlotsMap.get(this);
const directoryPath = path.resolve(cwd, getGlobParent(pattern));
const absolutePath = path.resolve(cwd, pattern);
const globPart = absolutePath.slice(directoryPath.length + 1);

@@ -412,3 +416,3 @@ /*

const recursive = /\*\*|\/|\\/u.test(globPart);
const selector = new Minimatch(pattern, minimatchOpts);
const selector = new Minimatch(absolutePath, minimatchOpts);

@@ -415,0 +419,0 @@ debug(`recursive? ${recursive}`);

@@ -42,83 +42,110 @@ /**

<title>ESLint Report</title>
<link rel="icon" type="image/png" sizes="any" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAHaAAAB2gGFomX7AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABD1JREFUWMPFl11sk2UUx3/nbYtjxS1MF7MLMTECMgSTtSSyrQkLhAj7UBPnDSEGoxegGzMwojhXVpmTAA5iYpSoMQa8GBhFOrMFk03buei6yRAlcmOM0SEmU9d90b19jxcM1o5+sGnsc/e+z/l6ztf/HFFVMnns6QieeOCHBePGsHM+wrOtvLG2C4WRVDSSygNV7sCjlspxwDnPB44aols/DXk+mbMBmx/6OseITF1CuOtfevkPh2Uu+/jbdX8lujSScRlT5r7/QDlAfsRmfzmpnkQ/H3H13gf6bBrBn1uqK8WylgEnU8eZmk1repbfchJG1TyKyIKEwuBHFd3lD3naY3O1siiwXsVoBV2VgM1ht/QQUJk2ByqKghsQziYQ8ifKgexIXmuyzC4r67Y7R+xPAfuB/Nn3Cpva+0s7khpQVtZtd4bt51BWxtBYAiciprG7c7D4SixzU9PYalDL6110Ifb/w8W9eY7JqFeFHbO8fPGyLHwwFHJNJTSgwtVTB9oaw9BlQ+tO93vOxypoaQnfEYlI43SeCHDC4TDq9+51/h5fxr33q0ZfV9g04wat9Q943rjJgCp3952W2i8Bi6eDvdsfKj0cK/DYMRyXL4/sUJUmIHd2zYMezsvLaamp4WpcWN3BXSiHpuMwbGbZlnZ8tXY4rgosy+G7oRwQ0cAsd28YGgqfU5UjCZQDLALxDg+Hv/P5Rqvj4hwrS8izXzWb4spwc1GgENFnkpWRzxeuB+ssUHgLdb9UVdt8vpGdKQpze7n7y1U3DBChNRUuqOo9c+0+qpKKxyZqtAIYla7gY4JszAAQri93BSsMRZoyBcUC+w3Q3AyOA4sNhAOZ0q7Iq0b2vUNvK5zPgP+/H8+Zetdoa6uOikhdGurxebwvJY8Iz3V1rTMNAH+opEuQj5KTT/qA1yC+wyUjBm12OidaUtCcPNNX2h0Hx2JG69VulANZAJZJwfU7rzd/FHixuXniTdM0m4GtSQT7bTartqEh9yfImUEzkwKZmTwmo5a5JwkYBfcDL01/RkR5y8iWhtPBknB8ZxwtU9UjwOrrKCeizzc25nTGg1F/turEHoU9wMLpDvWKf8DTmNCAKnd/tqUTF4ElMXJ+A5rWDJS+41WsGWzALhJ+ErBWrLj9g+pqojHxlXJX8HGUg0BsR/x1yhxf3jm4cSzpQFLp6tmi6PEE7g1ZhtZ91ufpSZUAFa6gC+UoQslNaSmypT1U8mHKiUgEKS8KfgF4EpYunFI16tsHin+OG0LcgQK7yj7g6cSzpva2D3hKVNG0Y3mVO1BkqfSlmJrHBQ4uvM12gJHc6ETW8HZVfMRmXvyxxNC1Z/o839zyXlDuCr4nsC11J+MXueaVJWn6yPv+/pJtc9oLTNN4AeTvNGByd3rlhE2x9s5pLwDoHCy+grDzWmOZ95lUtLYj5Bma126Y8eX0/zj/ADxGyViSg4BXAAAAAElFTkSuQmCC">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PScwIDAgMjk0LjgyNSAyNTguOTgyJyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPg0KPHBhdGggZmlsbD0nIzgwODBGMicgZD0nTTk3LjAyMSw5OS4wMTZsNDguNDMyLTI3Ljk2MmMxLjIxMi0wLjcsMi43MDYtMC43LDMuOTE4LDBsNDguNDMzLDI3Ljk2MiBjMS4yMTEsMC43LDEuOTU5LDEuOTkzLDEuOTU5LDMuMzkzdjU1LjkyNGMwLDEuMzk5LTAuNzQ4LDIuNjkzLTEuOTU5LDMuMzk0bC00OC40MzMsMjcuOTYyYy0xLjIxMiwwLjctMi43MDYsMC43LTMuOTE4LDAgbC00OC40MzItMjcuOTYyYy0xLjIxMi0wLjctMS45NTktMS45OTQtMS45NTktMy4zOTR2LTU1LjkyNEM5NS4wNjMsMTAxLjAwOSw5NS44MSw5OS43MTYsOTcuMDIxLDk5LjAxNicvPg0KPHBhdGggZmlsbD0nIzRCMzJDMycgZD0nTTI3My4zMzYsMTI0LjQ4OEwyMTUuNDY5LDIzLjgxNmMtMi4xMDItMy42NC01Ljk4NS02LjMyNS0xMC4xODgtNi4zMjVIODkuNTQ1IGMtNC4yMDQsMC04LjA4OCwyLjY4NS0xMC4xOSw2LjMyNWwtNTcuODY3LDEwMC40NWMtMi4xMDIsMy42NDEtMi4xMDIsOC4yMzYsMCwxMS44NzdsNTcuODY3LDk5Ljg0NyBjMi4xMDIsMy42NCw1Ljk4Niw1LjUwMSwxMC4xOSw1LjUwMWgxMTUuNzM1YzQuMjAzLDAsOC4wODctMS44MDUsMTAuMTg4LTUuNDQ2bDU3Ljg2Ny0xMDAuMDEgQzI3NS40MzksMTMyLjM5NiwyNzUuNDM5LDEyOC4xMjgsMjczLjMzNiwxMjQuNDg4IE0yMjUuNDE5LDE3Mi44OThjMCwxLjQ4LTAuODkxLDIuODQ5LTIuMTc0LDMuNTlsLTczLjcxLDQyLjUyNyBjLTEuMjgyLDAuNzQtMi44ODgsMC43NC00LjE3LDBsLTczLjc2Ny00Mi41MjdjLTEuMjgyLTAuNzQxLTIuMTc5LTIuMTA5LTIuMTc5LTMuNTlWODcuODQzYzAtMS40ODEsMC44ODQtMi44NDksMi4xNjctMy41OSBsNzMuNzA3LTQyLjUyN2MxLjI4Mi0wLjc0MSwyLjg4Ni0wLjc0MSw0LjE2OCwwbDczLjc3Miw0Mi41MjdjMS4yODMsMC43NDEsMi4xODYsMi4xMDksMi4xODYsMy41OVYxNzIuODk4eicvPg0KPC9zdmc+">
<style>
body {
font-family:Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size:16px;
font-weight:normal;
margin:0;
padding:0;
color:#333
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
margin: 0;
padding: 0;
color: #333;
}
#overview {
padding:20px 30px
padding: 20px 30px;
}
td, th {
padding:5px 10px
td,
th {
padding: 5px 10px;
}
h1 {
margin:0
margin: 0;
}
table {
margin:30px;
width:calc(100% - 60px);
max-width:1000px;
border-radius:5px;
border:1px solid #ddd;
border-spacing:0px;
margin: 30px;
width: calc(100% - 60px);
max-width: 1000px;
border-radius: 5px;
border: 1px solid #ddd;
border-spacing: 0;
}
th {
font-weight:400;
font-size:medium;
text-align:left;
cursor:pointer
font-weight: 400;
font-size: medium;
text-align: left;
cursor: pointer;
}
td.clr-1, td.clr-2, th span {
font-weight:700
td.clr-1,
td.clr-2,
th span {
font-weight: 700;
}
th span {
float:right;
margin-left:20px
float: right;
margin-left: 20px;
}
th span:after {
content:"";
clear:both;
display:block
th span::after {
content: "";
clear: both;
display: block;
}
tr:last-child td {
border-bottom:none
border-bottom: none;
}
tr td:first-child, tr td:last-child {
color:#9da0a4
tr td:first-child,
tr td:last-child {
color: #9da0a4;
}
#overview.bg-0, tr.bg-0 th {
color:#468847;
background:#dff0d8;
border-bottom:1px solid #d6e9c6
#overview.bg-0,
tr.bg-0 th {
color: #468847;
background: #dff0d8;
border-bottom: 1px solid #d6e9c6;
}
#overview.bg-1, tr.bg-1 th {
color:#f0ad4e;
background:#fcf8e3;
border-bottom:1px solid #fbeed5
#overview.bg-1,
tr.bg-1 th {
color: #f0ad4e;
background: #fcf8e3;
border-bottom: 1px solid #fbeed5;
}
#overview.bg-2, tr.bg-2 th {
color:#b94a48;
background:#f2dede;
border-bottom:1px solid #eed3d7
#overview.bg-2,
tr.bg-2 th {
color: #b94a48;
background: #f2dede;
border-bottom: 1px solid #eed3d7;
}
td {
border-bottom:1px solid #ddd
border-bottom: 1px solid #ddd;
}
td.clr-1 {
color:#f0ad4e
color: #f0ad4e;
}
td.clr-2 {
color:#b94a48
color: #b94a48;
}
td a {
color:#3a33d1;
text-decoration:none
color: #3a33d1;
text-decoration: none;
}
td a:hover {
color:#272296;
text-decoration:underline
color: #272296;
text-decoration: underline;
}

@@ -153,3 +180,3 @@ </style>

</html>
`.trimLeft();
`.trimStart();
}

@@ -217,3 +244,3 @@

return `
<tr style="display:none" class="f-${parentIndex}">
<tr style="display: none;" class="f-${parentIndex}">
<td>${lineNumber}:${columnNumber}</td>

@@ -226,3 +253,3 @@ <td class="clr-${severityNumber}">${severityName}</td>

</tr>
`.trimLeft();
`.trimStart();
}

@@ -285,3 +312,3 @@

</tr>
`.trimLeft();
`.trimStart();
}

@@ -288,0 +315,0 @@

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

return (
validCacheStrategies.indexOf(cacheStrategy) !== -1
validCacheStrategies.includes(cacheStrategy)
);

@@ -132,12 +132,24 @@ }

const cachedResults = fileDescriptor.meta.results;
// Just in case, not sure if this can ever happen.
if (!cachedResults) {
return cachedResults;
}
/*
* Shallow clone the object to ensure that any properties added or modified afterwards
* will not be accidentally stored in the cache file when `reconcile()` is called.
* https://github.com/eslint/eslint/issues/13507
* All intentional changes to the cache file must be done through `setCachedLintResults()`.
*/
const results = { ...cachedResults };
// If source is present but null, need to reread the file from the filesystem.
if (
fileDescriptor.meta.results &&
fileDescriptor.meta.results.source === null
) {
if (results.source === null) {
debug(`Rereading cached result source from filesystem: ${filePath}`);
fileDescriptor.meta.results.source = fs.readFileSync(filePath, "utf-8");
results.source = fs.readFileSync(filePath, "utf-8");
}
return fileDescriptor.meta.results;
return results;
}

@@ -144,0 +156,0 @@

@@ -9,3 +9,3 @@ /**

/*
* The CLI object should *not* call process.exit() directly. It should only return
* NOTE: The CLI object should *not* call process.exit() directly. It should only return
* exit codes. This allows other programs to use the CLI object and still control

@@ -23,5 +23,8 @@ * when the program exits.

{ ESLint } = require("./eslint"),
CLIOptions = require("./options"),
{ FlatESLint, shouldUseFlatConfig } = require("./eslint/flat-eslint"),
createCLIOptions = require("./options"),
log = require("./shared/logging"),
RuntimeInfo = require("./shared/runtime-info");
const { Legacy: { naming } } = require("@eslint/eslintrc");
const { ModuleImporter } = require("@humanwhocodes/module-importer");

@@ -38,2 +41,3 @@ const debug = require("debug")("eslint:cli");

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

@@ -60,8 +64,10 @@ //------------------------------------------------------------------------------

/**
* Translates the CLI options into the options expected by the CLIEngine.
* Translates the CLI options into the options expected by the ESLint constructor.
* @param {ParsedCLIOptions} cliOptions The CLI options to translate.
* @returns {ESLintOptions} The options object for the CLIEngine.
* @param {"flat"|"eslintrc"} [configType="eslintrc"] The format of the
* config to generate.
* @returns {Promise<ESLintOptions>} The options object for the ESLint constructor.
* @private
*/
function translateOptions({
async function translateOptions({
cache,

@@ -72,2 +78,3 @@ cacheFile,

config,
configLookup,
env,

@@ -92,16 +99,58 @@ errorOnUnmatchedPattern,

rule,
rulesdir
}) {
return {
allowInlineConfig: inlineConfig,
cache,
cacheLocation: cacheLocation || cacheFile,
cacheStrategy,
errorOnUnmatchedPattern,
extensions: ext,
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
fixTypes: fixType,
ignore,
ignorePath,
overrideConfig: {
rulesdir,
warnIgnored
}, configType) {
let overrideConfig, overrideConfigFile;
const importer = new ModuleImporter();
if (configType === "flat") {
overrideConfigFile = (typeof config === "string") ? config : !configLookup;
if (overrideConfigFile === false) {
overrideConfigFile = void 0;
}
let globals = {};
if (global) {
globals = global.reduce((obj, name) => {
if (name.endsWith(":true")) {
obj[name.slice(0, -5)] = "writable";
} else {
obj[name] = "readonly";
}
return obj;
}, globals);
}
overrideConfig = [{
languageOptions: {
globals,
parserOptions: parserOptions || {}
},
rules: rule ? rule : {}
}];
if (parser) {
overrideConfig[0].languageOptions.parser = await importer.import(parser);
}
if (plugin) {
const plugins = {};
for (const pluginName of plugin) {
const shortName = naming.getShorthandName(pluginName, "eslint-plugin");
const longName = naming.normalizePackageName(pluginName, "eslint-plugin");
plugins[shortName] = await importer.import(longName);
}
overrideConfig[0].plugins = plugins;
}
} else {
overrideConfigFile = config;
overrideConfig = {
env: env && env.reduce((obj, name) => {

@@ -124,9 +173,31 @@ obj[name] = true;

rules: rule
},
overrideConfigFile: config,
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0,
resolvePluginsRelativeTo,
rulePaths: rulesdir,
useEslintrc: eslintrc
};
}
const options = {
allowInlineConfig: inlineConfig,
cache,
cacheLocation: cacheLocation || cacheFile,
cacheStrategy,
errorOnUnmatchedPattern,
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
fixTypes: fixType,
ignore,
overrideConfig,
overrideConfigFile,
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0
};
if (configType === "flat") {
options.ignorePatterns = ignorePattern;
options.warnIgnored = warnIgnored;
} else {
options.resolvePluginsRelativeTo = resolvePluginsRelativeTo;
options.rulePaths = rulesdir;
options.useEslintrc = eslintrc;
options.extensions = ext;
options.ignorePath = ignorePath;
}
return options;
}

@@ -137,3 +208,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.
*/

@@ -176,6 +247,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;

@@ -190,3 +262,3 @@

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

@@ -231,5 +303,6 @@ if (output) {

* @param {string} [text] The text to lint (used for TTY).
* @param {boolean} [allowFlatConfig] Whether or not to allow flat config.
* @returns {Promise<number>} The exit code for the operation.
*/
async execute(args, text) {
async execute(args, text, allowFlatConfig) {
if (Array.isArray(args)) {

@@ -239,2 +312,15 @@ debug("CLI args: %o", args.slice(2));

/*
* Before doing anything, we need to see if we are using a
* flat config file. If so, then we need to change the way command
* line args are parsed. This is temporary, and when we fully
* switch to flat config we can remove this logic.
*/
const usingFlatConfig = allowFlatConfig && await shouldUseFlatConfig();
debug("Using flat config?", usingFlatConfig);
const CLIOptions = createCLIOptions(usingFlatConfig);
/** @type {ParsedCLIOptions} */

@@ -246,3 +332,11 @@ let options;

} catch (error) {
log.error(error.message);
debug("Error parsing CLI options:", error.message);
let errorMessage = error.message;
if (usingFlatConfig) {
errorMessage += "\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.";
}
log.error(errorMessage);
return 2;

@@ -267,2 +361,3 @@ }

} catch (err) {
debug("Error retrieving environment info");
log.error(err.message);

@@ -283,3 +378,5 @@ return 2;

const engine = new ESLint(translateOptions(options));
const engine = usingFlatConfig
? new FlatESLint(await translateOptions(options, "flat"))
: new ESLint(await translateOptions(options));
const fileConfig =

@@ -307,3 +404,5 @@ await engine.calculateConfigForFile(options.printConfig);

const engine = new ESLint(translateOptions(options));
const ActiveESLint = usingFlatConfig ? FlatESLint : ESLint;
const engine = new ActiveESLint(await translateOptions(options, usingFlatConfig ? "flat" : "eslintrc"));
let results;

@@ -314,3 +413,5 @@

filePath: options.stdinFilename,
warnIgnored: true
// flatConfig respects CLI flag and constructor warnIgnored, eslintrc forces true for backwards compatibility
warnIgnored: usingFlatConfig ? void 0 : true
});

@@ -323,3 +424,3 @@ } else {

debug("Fix mode enabled - applying fixes");
await ESLint.outputFixes(results);
await ActiveESLint.outputFixes(results);
}

@@ -331,16 +432,23 @@

debug("Quiet mode enabled - filtering out warnings");
resultsToPrint = ESLint.getErrorResults(resultsToPrint);
resultsToPrint = ActiveESLint.getErrorResults(resultsToPrint);
}
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(

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

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

@@ -359,0 +467,0 @@

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

exports.defaultConfig = [

@@ -24,5 +23,2 @@ {

"@": {
parsers: {
espree: require("espree")
},

@@ -46,19 +42,29 @@ /*

},
ignores: [
"**/node_modules/**",
".git/**"
],
languageOptions: {
sourceType: "module",
ecmaVersion: "latest",
sourceType: "module",
parser: "@/espree",
parser: require("espree"),
parserOptions: {}
}
},
// default ignores are listed here
{
ignores: [
"**/node_modules/",
".git/"
]
},
// intentionally empty config to ensure these files are globbed by default
{
files: ["**/*.js", "**/*.mjs"]
},
{
files: ["**/*.cjs"],
languageOptions: {
sourceType: "commonjs"
sourceType: "commonjs",
ecmaVersion: "latest"
}
}
];

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

const { defaultConfig } = require("./default-config");
const recommendedConfig = require("../../conf/eslint-recommended");
const allConfig = require("../../conf/eslint-all");
const jsPlugin = require("@eslint/js");

@@ -41,2 +40,43 @@ //-----------------------------------------------------------------------------

/**
* Returns the name of an object in the config by reading its `meta` key.
* @param {Object} object The object to check.
* @returns {string?} The name of the object if found or `null` if there
* is no name.
*/
function getObjectId(object) {
// first check old-style name
let name = object.name;
if (!name) {
if (!object.meta) {
return null;
}
name = object.meta.name;
if (!name) {
return null;
}
}
// now check for old-style version
let version = object.version;
if (!version) {
version = object.meta && object.meta.version;
}
// if there's a version then append that
if (version) {
return `${name}@${version}`;
}
return name;
}
const originalBaseConfig = Symbol("originalBaseConfig");
//-----------------------------------------------------------------------------

@@ -54,6 +94,10 @@ // Exports

* @param {*[]} configs An array of configuration information.
* @param {{basePath: string, baseConfig: FlatConfig}} options The options
* @param {{basePath: string, shouldIgnore: boolean, baseConfig: FlatConfig}} options The options
* to use for the config array instance.
*/
constructor(configs, { basePath, baseConfig = defaultConfig } = {}) {
constructor(configs, {
basePath,
shouldIgnore = true,
baseConfig = defaultConfig
} = {}) {
super(configs, {

@@ -64,3 +108,23 @@ basePath,

this.unshift(...baseConfig);
if (baseConfig[Symbol.iterator]) {
this.unshift(...baseConfig);
} else {
this.unshift(baseConfig);
}
/**
* The base config used to build the config array.
* @type {Array<FlatConfig>}
*/
this[originalBaseConfig] = baseConfig;
Object.defineProperty(this, originalBaseConfig, { writable: false });
/**
* Determines if `ignores` fields should be honored.
* If true, then all `ignores` fields are honored.
* if false, then only `ignores` fields in the baseConfig are honored.
* @type {boolean}
*/
this.shouldIgnore = shouldIgnore;
Object.defineProperty(this, "shouldIgnore", { writable: false });
}

@@ -78,9 +142,38 @@

if (config === "eslint:recommended") {
return recommendedConfig;
// if we are in a Node.js environment warn the user
if (typeof process !== "undefined" && process.emitWarning) {
process.emitWarning("The 'eslint:recommended' string configuration is deprecated and will be replaced by the @eslint/js package's 'recommended' config.");
}
return jsPlugin.configs.recommended;
}
if (config === "eslint:all") {
return allConfig;
// if we are in a Node.js environment warn the user
if (typeof process !== "undefined" && process.emitWarning) {
process.emitWarning("The 'eslint:all' string configuration is deprecated and will be replaced by the @eslint/js package's 'all' config.");
}
return jsPlugin.configs.all;
}
/*
* If `shouldIgnore` is false, we remove any ignore patterns specified
* in the config so long as it's not a default config and it doesn't
* have a `files` entry.
*/
if (
!this.shouldIgnore &&
!this[originalBaseConfig].includes(config) &&
config.ignores &&
!config.files
) {
/* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
const { ignores, ...otherKeys } = config;
return otherKeys;
}
return config;

@@ -99,23 +192,44 @@ }

const { plugins, languageOptions, processor } = config;
let parserName, processorName;
let invalidParser = false,
invalidProcessor = false;
// Check parser value
if (languageOptions && languageOptions.parser && typeof languageOptions.parser === "string") {
const { pluginName, objectName: parserName } = splitPluginIdentifier(languageOptions.parser);
if (languageOptions && languageOptions.parser) {
const { parser } = languageOptions;
if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[parserName]) {
throw new TypeError(`Key "parser": Could not find "${parserName}" in plugin "${pluginName}".`);
if (typeof parser === "object") {
parserName = getObjectId(parser);
if (!parserName) {
invalidParser = true;
}
} else {
invalidParser = true;
}
languageOptions.parser = plugins[pluginName].parsers[parserName];
}
// Check processor value
if (processor && typeof processor === "string") {
const { pluginName, objectName: processorName } = splitPluginIdentifier(processor);
if (processor) {
if (typeof processor === "string") {
const { pluginName, objectName: localProcessorName } = splitPluginIdentifier(processor);
if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[processorName]) {
throw new TypeError(`Key "processor": Could not find "${processorName}" in plugin "${pluginName}".`);
processorName = processor;
if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[localProcessorName]) {
throw new TypeError(`Key "processor": Could not find "${localProcessorName}" in plugin "${pluginName}".`);
}
config.processor = plugins[pluginName].processors[localProcessorName];
} else if (typeof processor === "object") {
processorName = getObjectId(processor);
if (!processorName) {
invalidProcessor = true;
}
} else {
invalidProcessor = true;
}
config.processor = plugins[pluginName].processors[processorName];
}

@@ -125,2 +239,37 @@

// apply special logic for serialization into JSON
/* eslint-disable object-shorthand -- shorthand would change "this" value */
Object.defineProperty(config, "toJSON", {
value: function() {
if (invalidParser) {
throw new Error("Could not serialize parser object (missing 'meta' object).");
}
if (invalidProcessor) {
throw new Error("Could not serialize processor object (missing 'meta' object).");
}
return {
...this,
plugins: Object.entries(plugins).map(([namespace, plugin]) => {
const pluginId = getObjectId(plugin);
if (!pluginId) {
return namespace;
}
return `${namespace}:${pluginId}`;
}),
languageOptions: {
...languageOptions,
parser: parserName
},
processor: processorName
};
}
});
/* eslint-enable object-shorthand -- ok to enable now */
return config;

@@ -127,0 +276,0 @@ }

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

if (ruleId.includes("/")) {
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
// mimic scoped npm packages
if (ruleId.startsWith("@")) {
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
} else {
pluginName = ruleId.slice(0, ruleId.indexOf("/"));
}
ruleName = ruleId.slice(pluginName.length + 1);

@@ -51,2 +58,3 @@ } else {

// normalize function rules into objects

@@ -62,2 +70,37 @@ if (rule && typeof rule === "function") {

/**
* Gets a complete options schema for a rule.
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
* @returns {Object} JSON Schema for the rule's options.
*/
function getRuleOptionsSchema(rule) {
if (!rule) {
return null;
}
const schema = rule.schema || rule.meta && rule.meta.schema;
if (Array.isArray(schema)) {
if (schema.length) {
return {
type: "array",
items: schema,
minItems: 0,
maxItems: schema.length
};
}
return {
type: "array",
minItems: 0,
maxItems: 0
};
}
// Given a full schema, leave it alone
return schema || null;
}
//-----------------------------------------------------------------------------

@@ -69,3 +112,4 @@ // Exports

parseRuleId,
getRuleFromConfig
getRuleFromConfig,
getRuleOptionsSchema
};

@@ -9,2 +9,12 @@ /**

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
/*
* Note: This can be removed in ESLint v9 because structuredClone is available globally
* starting in Node.js v17.
*/
const structuredClone = require("@ungap/structured-clone").default;
//-----------------------------------------------------------------------------
// Type Definitions

@@ -123,3 +133,3 @@ //-----------------------------------------------------------------------------

finalOptions[0] = ruleSeverities.get(finalOptions[0]);
return finalOptions;
return structuredClone(finalOptions);
}

@@ -132,11 +142,27 @@

/**
* The error type when a rule's options are configured with an invalid type.
*/
class InvalidRuleOptionsError extends Error {
/**
* @param {string} ruleId Rule name being configured.
* @param {any} value The invalid value.
*/
constructor(ruleId, value) {
super(`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`);
this.messageTemplate = "invalid-rule-options";
this.messageData = { ruleId, value };
}
}
/**
* Validates that a value is a valid rule options entry.
* @param {string} ruleId Rule name being configured.
* @param {any} value The value to check.
* @returns {void}
* @throws {TypeError} If the value isn't a valid rule options.
* @throws {InvalidRuleOptionsError} If the value isn't a valid rule options.
*/
function assertIsRuleOptions(value) {
function assertIsRuleOptions(ruleId, value) {
if (typeof value !== "string" && typeof value !== "number" && !Array.isArray(value)) {
throw new TypeError("Expected a string, number, or array.");
throw new InvalidRuleOptionsError(ruleId, value);
}

@@ -146,14 +172,29 @@ }

/**
* The error type when a rule's severity is invalid.
*/
class InvalidRuleSeverityError extends Error {
/**
* @param {string} ruleId Rule name being configured.
* @param {any} value The invalid value.
*/
constructor(ruleId, value) {
super(`Key "${ruleId}": Expected severity of "off", 0, "warn", 1, "error", or 2.`);
this.messageTemplate = "invalid-rule-severity";
this.messageData = { ruleId, value };
}
}
/**
* Validates that a value is valid rule severity.
* @param {string} ruleId Rule name being configured.
* @param {any} value The value to check.
* @returns {void}
* @throws {TypeError} If the value isn't a valid rule severity.
* @throws {InvalidRuleSeverityError} If the value isn't a valid rule severity.
*/
function assertIsRuleSeverity(value) {
const severity = typeof value === "string"
? ruleSeverities.get(value.toLowerCase())
: ruleSeverities.get(value);
function assertIsRuleSeverity(ruleId, value) {
const severity = ruleSeverities.get(value);
if (typeof severity === "undefined") {
throw new TypeError("Expected severity of \"off\", 0, \"warn\", 1, \"error\", or 2.");
throw new InvalidRuleSeverityError(ruleId, value);
}

@@ -187,13 +228,33 @@ }

/**
* Validates that a value is an object or a string.
* @param {any} value The value to check.
* @returns {void}
* @throws {TypeError} If the value isn't an object or a string.
* The error type when there's an eslintrc-style options in a flat config.
*/
function assertIsObjectOrString(value) {
if ((!value || typeof value !== "object") && typeof value !== "string") {
throw new TypeError("Expected an object or string.");
class IncompatibleKeyError extends Error {
/**
* @param {string} key The invalid key.
*/
constructor(key) {
super("This appears to be in eslintrc format rather than flat config format.");
this.messageTemplate = "eslintrc-incompat";
this.messageData = { key };
}
}
/**
* The error type when there's an eslintrc-style plugins array found.
*/
class IncompatiblePluginsError extends Error {
/**
* Creates a new instance.
* @param {Array<string>} plugins The plugins array.
*/
constructor(plugins) {
super("This appears to be in eslintrc format (array of strings) rather than flat config format (object).");
this.messageTemplate = "eslintrc-plugins";
this.messageData = { plugins };
}
}
//-----------------------------------------------------------------------------

@@ -250,11 +311,9 @@ // Low-Level Schemas

validate(value) {
assertIsObjectOrString(value);
if (typeof value === "object" && typeof value.parse !== "function" && typeof value.parseForESLint !== "function") {
throw new TypeError("Expected object to have a parse() or parseForESLint() method.");
if (!value || typeof value !== "object" ||
(typeof value.parse !== "function" && typeof value.parseForESLint !== "function")
) {
throw new TypeError("Expected object with parse() or parseForESLint() method.");
}
if (typeof value === "string") {
assertIsPluginMemberName(value);
}
}

@@ -293,2 +352,7 @@ };

// make sure it's not an array, which would mean eslintrc-style is used
if (Array.isArray(value)) {
throw new IncompatiblePluginsError(value);
}
// second check the keys to make sure they are objects

@@ -334,44 +398,53 @@ for (const key of Object.keys(value)) {

for (const ruleId of Object.keys(result)) {
// avoid hairy edge case
if (ruleId === "__proto__") {
try {
/* eslint-disable-next-line no-proto -- Though deprecated, may still be present */
delete result.__proto__;
continue;
}
// avoid hairy edge case
if (ruleId === "__proto__") {
result[ruleId] = normalizeRuleOptions(result[ruleId]);
/* eslint-disable-next-line no-proto -- Though deprecated, may still be present */
delete result.__proto__;
continue;
}
/*
* If either rule config is missing, then the correct
* config is already present and we just need to normalize
* the severity.
*/
if (!(ruleId in first) || !(ruleId in second)) {
continue;
}
result[ruleId] = normalizeRuleOptions(result[ruleId]);
const firstRuleOptions = normalizeRuleOptions(first[ruleId]);
const secondRuleOptions = normalizeRuleOptions(second[ruleId]);
/*
* If either rule config is missing, then the correct
* config is already present and we just need to normalize
* the severity.
*/
if (!(ruleId in first) || !(ruleId in second)) {
continue;
}
/*
* If the second rule config only has a severity (length of 1),
* then use that severity and keep the rest of the options from
* the first rule config.
*/
if (secondRuleOptions.length === 1) {
result[ruleId] = [secondRuleOptions[0], ...firstRuleOptions.slice(1)];
continue;
const firstRuleOptions = normalizeRuleOptions(first[ruleId]);
const secondRuleOptions = normalizeRuleOptions(second[ruleId]);
/*
* If the second rule config only has a severity (length of 1),
* then use that severity and keep the rest of the options from
* the first rule config.
*/
if (secondRuleOptions.length === 1) {
result[ruleId] = [secondRuleOptions[0], ...firstRuleOptions.slice(1)];
continue;
}
/*
* In any other situation, then the second rule config takes
* precedence. That means the value at `result[ruleId]` is
* already correct and no further work is necessary.
*/
} catch (ex) {
throw new Error(`Key "${ruleId}": ${ex.message}`, { cause: ex });
}
/*
* In any other situation, then the second rule config takes
* precedence. That means the value at `result[ruleId]` is
* already correct and no further work is necessary.
*/
}
return result;
},

@@ -382,35 +455,24 @@

let lastRuleId;
/*
* We are not checking the rule schema here because there is no
* guarantee that the rule definition is present at this point. Instead
* we wait and check the rule schema during the finalization step
* of calculating a config.
*/
for (const ruleId of Object.keys(value)) {
// Performance: One try-catch has less overhead than one per loop iteration
try {
// avoid hairy edge case
if (ruleId === "__proto__") {
continue;
}
/*
* We are not checking the rule schema here because there is no
* guarantee that the rule definition is present at this point. Instead
* we wait and check the rule schema during the finalization step
* of calculating a config.
*/
for (const ruleId of Object.keys(value)) {
const ruleOptions = value[ruleId];
// avoid hairy edge case
if (ruleId === "__proto__") {
continue;
}
assertIsRuleOptions(ruleId, ruleOptions);
lastRuleId = ruleId;
const ruleOptions = value[ruleId];
assertIsRuleOptions(ruleOptions);
if (Array.isArray(ruleOptions)) {
assertIsRuleSeverity(ruleOptions[0]);
} else {
assertIsRuleSeverity(ruleOptions);
}
if (Array.isArray(ruleOptions)) {
assertIsRuleSeverity(ruleId, ruleOptions[0]);
} else {
assertIsRuleSeverity(ruleId, ruleOptions);
}
} catch (error) {
error.message = `Key "${lastRuleId}": ${error.message}`;
throw error;
}

@@ -442,2 +504,30 @@ }

/**
* Creates a schema that always throws an error. Useful for warning
* about eslintrc-style keys.
* @param {string} key The eslintrc key to create a schema for.
* @returns {ObjectPropertySchema} The schema.
*/
function createEslintrcErrorSchema(key) {
return {
merge: "replace",
validate() {
throw new IncompatibleKeyError(key);
}
};
}
const eslintrcKeys = [
"env",
"extends",
"globals",
"ignorePatterns",
"noInlineConfig",
"overrides",
"parser",
"parserOptions",
"reportUnusedDisableDirectives",
"root"
];
//-----------------------------------------------------------------------------

@@ -447,3 +537,8 @@ // Full schema

exports.flatConfigSchema = {
const flatConfigSchema = {
// eslintrc-style keys that should always error
...Object.fromEntries(eslintrcKeys.map(key => [key, createEslintrcErrorSchema(key)])),
// flat config keys
settings: deepObjectAssignSchema,

@@ -469,1 +564,11 @@ linterOptions: {

};
//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------
module.exports = {
flatConfigSchema,
assertIsRuleSeverity,
assertIsRuleOptions
};

@@ -12,4 +12,9 @@ /**

const ajv = require("../shared/ajv")();
const { parseRuleId, getRuleFromConfig } = require("./flat-config-helpers");
const ajvImport = require("../shared/ajv");
const ajv = ajvImport();
const {
parseRuleId,
getRuleFromConfig,
getRuleOptionsSchema
} = require("./flat-config-helpers");
const ruleReplacements = require("../../conf/replacements.json");

@@ -65,36 +70,2 @@

/**
* Gets a complete options schema for a rule.
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
* @returns {Object} JSON Schema for the rule's options.
*/
function getRuleOptionsSchema(rule) {
if (!rule) {
return null;
}
const schema = rule.schema || rule.meta && rule.meta.schema;
if (Array.isArray(schema)) {
if (schema.length) {
return {
type: "array",
items: schema,
minItems: 0,
maxItems: schema.length
};
}
return {
type: "array",
minItems: 0,
maxItems: 0
};
}
// Given a full schema, leave it alone
return schema || null;
}
//-----------------------------------------------------------------------------

@@ -101,0 +72,0 @@ // Exports

@@ -35,9 +35,12 @@ /**

/** @typedef {import("../shared/types").LintMessage} LintMessage */
/** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
/** @typedef {import("../shared/types").Plugin} Plugin */
/** @typedef {import("../shared/types").Rule} Rule */
/** @typedef {import("../shared/types").LintResult} LintResult */
/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */
/**
* The main formatter object.
* @typedef Formatter
* @property {function(LintResult[]): string | Promise<string>} format format function.
* @typedef LoadedFormatter
* @property {(results: LintResult[], resultsMeta: ResultsMeta) => string | Promise<string>} format format function.
*/

@@ -78,16 +81,2 @@

/**
* A linting result.
* @typedef {Object} LintResult
* @property {string} filePath The path to the file that was linted.
* @property {LintMessage[]} messages All of the messages for the result.
* @property {number} errorCount Number of errors for the result.
* @property {number} warningCount Number of warnings for the result.
* @property {number} fixableErrorCount Number of fixable errors for the result.
* @property {number} fixableWarningCount Number of fixable warnings for the result.
* @property {string} [source] The source code of the file that was linted.
* @property {string} [output] The source code of the file that was linted, with as many fixes applied as possible.
* @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules.
*/
/**
* Private members for the `ESLint` instance.

@@ -121,5 +110,5 @@ * @typedef {Object} ESLintPrivateMembers

/**
* 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.
*/

@@ -306,3 +295,3 @@ function isArrayOfNonEmptyString(x) {

configFile: overrideConfigFile,
cwd,
cwd: path.normalize(cwd),
errorOnUnmatchedPattern,

@@ -532,2 +521,5 @@ extensions,

}
for (const { ruleId } of result.suppressedMessages) {
resultRuleIds.add(ruleId);
}
}

@@ -616,3 +608,3 @@

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

@@ -622,3 +614,3 @@ * - `@foo` → `@foo/eslint-formatter`

* - A file path ... Load the file.
* @returns {Promise<Formatter>} A promise resolving to the formatter object.
* @returns {Promise<LoadedFormatter>} A promise resolving to the formatter object.
* This promise will be rejected if the given formatter was not found or not

@@ -643,6 +635,7 @@ * a function.

* The main formatter method.
* @param {LintResults[]} results The lint results to format.
* @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;

@@ -653,2 +646,3 @@

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

@@ -655,0 +649,0 @@ return options.cwd;

"use strict";
const { ESLint } = require("./eslint");
const { FlatESLint } = require("./flat-eslint");
module.exports = {
ESLint
ESLint,
FlatESLint
};

@@ -8,2 +8,12 @@ /**

//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/** @typedef {import("../shared/types").LintMessage} LintMessage */
//------------------------------------------------------------------------------
// Module Definition
//------------------------------------------------------------------------------
const escapeRegExp = require("escape-string-regexp");

@@ -24,3 +34,3 @@

* Groups a set of directives into sub-arrays by their parent comment.
* @param {Directive[]} directives Unused directives to be removed.
* @param {Iterable<Directive>} directives Unused directives to be removed.
* @returns {Directive[][]} Directives grouped by their parent comment.

@@ -48,3 +58,3 @@ */

* @param {Token} commentToken The backing Comment token.
* @returns {{ description, fix, position }[]} Details for later creation of output Problems.
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
*/

@@ -72,3 +82,3 @@ function createIndividualDirectivesRemoval(directives, commentToken) {

.split(/\s-{2,}\s/u)[0] // remove `-- comment`, if it exists
.trimRight(); // remove all whitespace after the list
.trimEnd(); // remove all whitespace after the list

@@ -84,3 +94,3 @@ /*

const regex = new RegExp(String.raw`(?:^|\s*,\s*)${escapeRegExp(ruleId)}(?:\s*,\s*|$)`, "u");
const regex = new RegExp(String.raw`(?:^|\s*,\s*)(?<quote>['"]?)${escapeRegExp(ruleId)}\k<quote>(?:\s*,\s*|$)`, "u");
const match = regex.exec(listText);

@@ -146,3 +156,3 @@ const matchedText = match[0];

},
position: directive.unprocessedDirective
unprocessedDirective: directive.unprocessedDirective
};

@@ -156,3 +166,3 @@ });

* @param {Token} commentToken The backing Comment token.
* @returns {{ description, fix, position }} Details for later creation of an output Problem.
* @returns {{ description, fix, unprocessedDirective }} Details for later creation of an output Problem.
*/

@@ -171,3 +181,3 @@ function createCommentRemoval(directives, commentToken) {

},
position: directives[0].unprocessedDirective
unprocessedDirective: directives[0].unprocessedDirective
};

@@ -178,6 +188,6 @@ }

* Parses details from directives to create output Problems.
* @param {Directive[]} allDirectives Unused directives to be removed.
* @returns {{ description, fix, position }[]} Details for later creation of output Problems.
* @param {Iterable<Directive>} allDirectives Unused directives to be removed.
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
*/
function processUnusedDisableDirectives(allDirectives) {
function processUnusedDirectives(allDirectives) {
const directiveGroups = groupByParentComment(allDirectives);

@@ -202,2 +212,91 @@

/**
* Collect eslint-enable comments that are removing suppressions by eslint-disable comments.
* @param {Directive[]} directives The directives to check.
* @returns {Set<Directive>} The used eslint-enable comments
*/
function collectUsedEnableDirectives(directives) {
/**
* A Map of `eslint-enable` keyed by ruleIds that may be marked as used.
* If `eslint-enable` does not have a ruleId, the key will be `null`.
* @type {Map<string|null, Directive>}
*/
const enabledRules = new Map();
/**
* A Set of `eslint-enable` marked as used.
* It is also the return value of `collectUsedEnableDirectives` function.
* @type {Set<Directive>}
*/
const usedEnableDirectives = new Set();
/*
* Checks the directives backwards to see if the encountered `eslint-enable` is used by the previous `eslint-disable`,
* and if so, stores the `eslint-enable` in `usedEnableDirectives`.
*/
for (let index = directives.length - 1; index >= 0; index--) {
const directive = directives[index];
if (directive.type === "disable") {
if (enabledRules.size === 0) {
continue;
}
if (directive.ruleId === null) {
// If encounter `eslint-disable` without ruleId,
// mark all `eslint-enable` currently held in enabledRules as used.
// e.g.
// /* eslint-disable */ <- current directive
// /* eslint-enable rule-id1 */ <- used
// /* eslint-enable rule-id2 */ <- used
// /* eslint-enable */ <- used
for (const enableDirective of enabledRules.values()) {
usedEnableDirectives.add(enableDirective);
}
enabledRules.clear();
} else {
const enableDirective = enabledRules.get(directive.ruleId);
if (enableDirective) {
// If encounter `eslint-disable` with ruleId, and there is an `eslint-enable` with the same ruleId in enabledRules,
// mark `eslint-enable` with ruleId as used.
// e.g.
// /* eslint-disable rule-id */ <- current directive
// /* eslint-enable rule-id */ <- used
usedEnableDirectives.add(enableDirective);
} else {
const enabledDirectiveWithoutRuleId = enabledRules.get(null);
if (enabledDirectiveWithoutRuleId) {
// If encounter `eslint-disable` with ruleId, and there is no `eslint-enable` with the same ruleId in enabledRules,
// mark `eslint-enable` without ruleId as used.
// e.g.
// /* eslint-disable rule-id */ <- current directive
// /* eslint-enable */ <- used
usedEnableDirectives.add(enabledDirectiveWithoutRuleId);
}
}
}
} else if (directive.type === "enable") {
if (directive.ruleId === null) {
// If encounter `eslint-enable` without ruleId, the `eslint-enable` that follows it are unused.
// So clear enabledRules.
// e.g.
// /* eslint-enable */ <- current directive
// /* eslint-enable rule-id *// <- unused
// /* eslint-enable */ <- unused
enabledRules.clear();
enabledRules.set(null, directive);
} else {
enabledRules.set(directive.ruleId, directive);
}
}
}
return usedEnableDirectives;
}
/**
* This is the same as the exported function, except that it

@@ -209,16 +308,13 @@ * doesn't handle disable-line and disable-next-line directives, and it always reports unused

* (this function always reports unused disable directives).
* @returns {{problems: Problem[], unusedDisableDirectives: Problem[]}} An object with a list
* of filtered problems and unused eslint-disable directives
* @returns {{problems: LintMessage[], unusedDirectives: LintMessage[]}} An object with a list
* of problems (including suppressed ones) and unused eslint-disable directives
*/
function applyDirectives(options) {
const problems = [];
let nextDirectiveIndex = 0;
let currentGlobalDisableDirective = null;
const disabledRuleMap = new Map();
// enabledRules is only used when there is a current global disable directive.
const enabledRules = new Set();
const usedDisableDirectives = new Set();
for (const problem of options.problems) {
let disableDirectivesForProblem = [];
let nextDirectiveIndex = 0;
while (

@@ -230,39 +326,32 @@ nextDirectiveIndex < options.directives.length &&

switch (directive.type) {
case "disable":
if (directive.ruleId === null) {
currentGlobalDisableDirective = directive;
disabledRuleMap.clear();
enabledRules.clear();
} else if (currentGlobalDisableDirective) {
enabledRules.delete(directive.ruleId);
disabledRuleMap.set(directive.ruleId, directive);
} else {
disabledRuleMap.set(directive.ruleId, directive);
}
break;
if (directive.ruleId === null || directive.ruleId === problem.ruleId) {
switch (directive.type) {
case "disable":
disableDirectivesForProblem.push(directive);
break;
case "enable":
if (directive.ruleId === null) {
currentGlobalDisableDirective = null;
disabledRuleMap.clear();
} else if (currentGlobalDisableDirective) {
enabledRules.add(directive.ruleId);
disabledRuleMap.delete(directive.ruleId);
} else {
disabledRuleMap.delete(directive.ruleId);
}
break;
case "enable":
disableDirectivesForProblem = [];
break;
// no default
// no default
}
}
}
if (disabledRuleMap.has(problem.ruleId)) {
usedDisableDirectives.add(disabledRuleMap.get(problem.ruleId));
} else if (currentGlobalDisableDirective && !enabledRules.has(problem.ruleId)) {
usedDisableDirectives.add(currentGlobalDisableDirective);
} else {
problems.push(problem);
if (disableDirectivesForProblem.length > 0) {
const suppressions = disableDirectivesForProblem.map(directive => ({
kind: "directive",
justification: directive.unprocessedDirective.justification
}));
if (problem.suppressions) {
problem.suppressions = problem.suppressions.concat(suppressions);
} else {
problem.suppressions = suppressions;
usedDisableDirectives.add(disableDirectivesForProblem[disableDirectivesForProblem.length - 1]);
}
}
problems.push(problem);
}

@@ -273,18 +362,47 @@

const processed = processUnusedDisableDirectives(unusedDisableDirectivesToReport);
const unusedDisableDirectives = processed
.map(({ description, fix, position }) => ({
ruleId: null,
message: description
? `Unused eslint-disable directive (no problems were reported from ${description}).`
: "Unused eslint-disable directive (no problems were reported).",
line: position.line,
column: position.column,
severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2,
nodeType: null,
...options.disableFixes ? {} : { fix }
}));
const unusedEnableDirectivesToReport = new Set(
options.directives.filter(directive => directive.unprocessedDirective.type === "enable")
);
return { problems, unusedDisableDirectives };
/*
* If directives has the eslint-enable directive,
* check whether the eslint-enable comment is used.
*/
if (unusedEnableDirectivesToReport.size > 0) {
for (const directive of collectUsedEnableDirectives(options.directives)) {
unusedEnableDirectivesToReport.delete(directive);
}
}
const processed = processUnusedDirectives(unusedDisableDirectivesToReport)
.concat(processUnusedDirectives(unusedEnableDirectivesToReport));
const unusedDirectives = processed
.map(({ description, fix, unprocessedDirective }) => {
const { parentComment, type, line, column } = unprocessedDirective;
let message;
if (type === "enable") {
message = description
? `Unused eslint-enable directive (no matching eslint-disable directives were found for ${description}).`
: "Unused eslint-enable directive (no matching eslint-disable directives were found).";
} else {
message = description
? `Unused eslint-disable directive (no problems were reported from ${description}).`
: "Unused eslint-disable directive (no problems were reported).";
}
return {
ruleId: null,
message,
line: type === "disable-next-line" ? parentComment.commentToken.loc.start.line : line,
column: type === "disable-next-line" ? parentComment.commentToken.loc.start.column + 1 : column,
severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2,
nodeType: null,
...options.disableFixes ? {} : { fix }
};
});
return { problems, unusedDirectives };
}

@@ -294,3 +412,3 @@

* Given a list of directive comments (i.e. metadata about eslint-disable and eslint-enable comments) and a list
* of reported problems, determines which problems should be reported.
* of reported problems, adds the suppression information to the problems.
* @param {Object} options Information about directives and problems

@@ -301,3 +419,4 @@ * @param {{

* line: number,
* column: number
* column: number,
* justification: string
* }} options.directives Directive comments found in the file, with one-based columns.

@@ -310,4 +429,4 @@ * Two directive comments can only have the same location if they also have the same type (e.g. a single eslint-disable

* @param {boolean} options.disableFixes If true, it doesn't make `fix` properties.
* @returns {{ruleId: (string|null), line: number, column: number}[]}
* A list of reported problems that were not disabled by the directive comments.
* @returns {{ruleId: (string|null), line: number, column: number, suppressions?: {kind: string, justification: string}}[]}
* An object with a list of reported problems, the suppressed of which contain the suppression information.
*/

@@ -358,6 +477,6 @@ module.exports = ({ directives, disableFixes, problems, reportUnusedDisableDirectives = "off" }) => {

? lineDirectivesResult.problems
.concat(blockDirectivesResult.unusedDisableDirectives)
.concat(lineDirectivesResult.unusedDisableDirectives)
.concat(blockDirectivesResult.unusedDirectives)
.concat(lineDirectivesResult.unusedDirectives)
.sort(compareLocations)
: lineDirectivesResult.problems;
};

@@ -195,11 +195,14 @@ /**

if (currentSegment !== headSegment && currentSegment) {
debug.dump(`onCodePathSegmentEnd ${currentSegment.id}`);
if (currentSegment.reachable) {
analyzer.emitter.emit(
"onCodePathSegmentEnd",
currentSegment,
node
);
}
const eventName = currentSegment.reachable
? "onCodePathSegmentEnd"
: "onUnreachableCodePathSegmentEnd";
debug.dump(`${eventName} ${currentSegment.id}`);
analyzer.emitter.emit(
eventName,
currentSegment,
node
);
}

@@ -217,12 +220,15 @@ }

if (currentSegment !== headSegment && headSegment) {
debug.dump(`onCodePathSegmentStart ${headSegment.id}`);
const eventName = headSegment.reachable
? "onCodePathSegmentStart"
: "onUnreachableCodePathSegmentStart";
debug.dump(`${eventName} ${headSegment.id}`);
CodePathSegment.markUsed(headSegment);
if (headSegment.reachable) {
analyzer.emitter.emit(
"onCodePathSegmentStart",
headSegment,
node
);
}
analyzer.emitter.emit(
eventName,
headSegment,
node
);
}

@@ -246,11 +252,13 @@ }

const currentSegment = currentSegments[i];
const eventName = currentSegment.reachable
? "onCodePathSegmentEnd"
: "onUnreachableCodePathSegmentEnd";
debug.dump(`onCodePathSegmentEnd ${currentSegment.id}`);
if (currentSegment.reachable) {
analyzer.emitter.emit(
"onCodePathSegmentEnd",
currentSegment,
node
);
}
debug.dump(`${eventName} ${currentSegment.id}`);
analyzer.emitter.emit(
eventName,
currentSegment,
node
);
}

@@ -257,0 +265,0 @@

/**
* @fileoverview A class of the code path segment.
* @fileoverview The CodePathSegment class.
* @author Toru Nagashima

@@ -33,2 +33,13 @@ */

* A code path segment.
*
* Each segment is arranged in a series of linked lists (implemented by arrays)
* that keep track of the previous and next segments in a code path. In this way,
* you can navigate between all segments in any code path so long as you have a
* reference to any segment in that code path.
*
* When first created, the segment is in a detached state, meaning that it knows the
* segments that came before it but those segments don't know that this new segment
* follows it. Only when `CodePathSegment#markUsed()` is called on a segment does it
* officially become part of the code path by updating the previous segments to know
* that this new segment follows.
*/

@@ -38,2 +49,3 @@ class CodePathSegment {

/**
* Creates a new instance.
* @param {string} id An identifier.

@@ -54,3 +66,3 @@ * @param {CodePathSegment[]} allPrevSegments An array of the previous segments.

/**
* An array of the next segments.
* An array of the next reachable segments.
* @type {CodePathSegment[]}

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

/**
* An array of the previous segments.
* An array of the previous reachable segments.
* @type {CodePathSegment[]}

@@ -68,4 +80,3 @@ */

/**
* An array of the next segments.
* This array includes unreachable segments.
* An array of all next segments including reachable and unreachable.
* @type {CodePathSegment[]}

@@ -76,4 +87,3 @@ */

/**
* An array of the previous segments.
* This array includes unreachable segments.
* An array of all previous segments including reachable and unreachable.
* @type {CodePathSegment[]}

@@ -92,3 +102,7 @@ */

value: {
// determines if the segment has been attached to the code path
used: false,
// array of previous segments coming from the end of a loop
loopedPrevSegments: []

@@ -98,6 +112,6 @@ }

/* istanbul ignore if */
/* c8 ignore start */
if (debug.enabled) {
this.internal.nodes = [];
}
}/* c8 ignore stop */
}

@@ -111,3 +125,3 @@

isLoopedPrevSegment(segment) {
return this.internal.loopedPrevSegments.indexOf(segment) !== -1;
return this.internal.loopedPrevSegments.includes(segment);
}

@@ -125,5 +139,6 @@

/**
* Creates a segment that follows given segments.
* Creates a new segment and appends it after the given segments.
* @param {string} id An identifier.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments
* to append to.
* @returns {CodePathSegment} The created segment.

@@ -140,3 +155,3 @@ */

/**
* Creates an unreachable segment that follows given segments.
* Creates an unreachable segment and appends it after the given segments.
* @param {string} id An identifier.

@@ -151,3 +166,3 @@ * @param {CodePathSegment[]} allPrevSegments An array of the previous segments.

* In `if (a) return a; foo();` case, the unreachable segment preceded by
* the return statement is not used but must not be remove.
* the return statement is not used but must not be removed.
*/

@@ -172,3 +187,3 @@ CodePathSegment.markUsed(segment);

/**
* Makes a given segment being used.
* Marks a given segment as used.
*

@@ -188,2 +203,9 @@ * And this function registers the segment into the previous segments as a next.

if (segment.reachable) {
/*
* If the segment is reachable, then it's officially part of the
* code path. This loops through all previous segments to update
* their list of next segments. Because the segment is reachable,
* it's added to both `nextSegments` and `allNextSegments`.
*/
for (i = 0; i < segment.allPrevSegments.length; ++i) {

@@ -196,2 +218,9 @@ const prevSegment = segment.allPrevSegments[i];

} else {
/*
* If the segment is not reachable, then it's not officially part of the
* code path. This loops through all previous segments to update
* their list of next segments. Because the segment is not reachable,
* it's added only to `allNextSegments`.
*/
for (i = 0; i < segment.allPrevSegments.length; ++i) {

@@ -214,9 +243,10 @@ segment.allPrevSegments[i].allNextSegments.push(segment);

/**
* Replaces unused segments with the previous segments of each unused segment.
* @param {CodePathSegment[]} segments An array of segments to replace.
* @returns {CodePathSegment[]} The replaced array.
* Creates a new array based on an array of segments. If any segment in the
* array is unused, then it is replaced by all of its previous segments.
* All used segments are returned as-is without replacement.
* @param {CodePathSegment[]} segments The array of segments to flatten.
* @returns {CodePathSegment[]} The flattened array.
*/
static flattenUnusedSegments(segments) {
const done = Object.create(null);
const retv = [];
const done = new Set();

@@ -227,3 +257,3 @@ for (let i = 0; i < segments.length; ++i) {

// Ignores duplicated.
if (done[segment.id]) {
if (done.has(segment)) {
continue;

@@ -237,14 +267,12 @@ }

if (!done[prevSegment.id]) {
done[prevSegment.id] = true;
retv.push(prevSegment);
if (!done.has(prevSegment)) {
done.add(prevSegment);
}
}
} else {
done[segment.id] = true;
retv.push(segment);
done.add(segment);
}
}
return retv;
return [...done];
}

@@ -251,0 +279,0 @@ }

@@ -83,3 +83,5 @@ /**

/**
* The initial code path segment.
* The initial code path segment. This is the segment that is at the head
* of the code path.
* This is a passthrough to the underlying `CodePathState`.
* @type {CodePathSegment}

@@ -92,4 +94,6 @@ */

/**
* Final code path segments.
* This array is a mix of `returnedSegments` and `thrownSegments`.
* Final code path segments. These are the terminal (tail) segments in the
* code path, which is the combination of `returnedSegments` and `thrownSegments`.
* All segments in this array are reachable.
* This is a passthrough to the underlying `CodePathState`.
* @type {CodePathSegment[]}

@@ -102,5 +106,10 @@ */

/**
* Final code path segments which is with `return` statements.
* This array contains the last path segment if it's reachable.
* Since the reachable last path returns `undefined`.
* Final code path segments that represent normal completion of the code path.
* For functions, this means both explicit `return` statements and implicit returns,
* such as the last reachable segment in a function that does not have an
* explicit `return` as this implicitly returns `undefined`. For scripts,
* modules, class field initializers, and class static blocks, this means
* all lines of code have been executed.
* These segments are also present in `finalSegments`.
* This is a passthrough to the underlying `CodePathState`.
* @type {CodePathSegment[]}

@@ -113,3 +122,5 @@ */

/**
* Final code path segments which is with `throw` statements.
* Final code path segments that represent `throw` statements.
* This is a passthrough to the underlying `CodePathState`.
* These segments are also present in `finalSegments`.
* @type {CodePathSegment[]}

@@ -122,4 +133,10 @@ */

/**
* Current code path segments.
* Tracks the traversal of the code path through each segment. This array
* starts empty and segments are added or removed as the code path is
* traversed. This array always ends up empty at the end of a code path
* traversal. The `CodePathState` uses this to track its progress through
* the code path.
* This is a passthrough to the underlying `CodePathState`.
* @type {CodePathSegment[]}
* @deprecated
*/

@@ -133,3 +150,3 @@ get currentSegments() {

*
* codePath.traverseSegments(function(segment, controller) {
* codePath.traverseSegments((segment, controller) => {
* // do something.

@@ -140,36 +157,60 @@ * });

*
* The `controller` object has two methods.
* The `controller` argument has two methods:
*
* - `controller.skip()` - Skip the following segments in this branch.
* - `controller.break()` - Skip all following segments.
* @param {Object} [options] Omittable.
* @param {CodePathSegment} [options.first] The first segment to traverse.
* @param {CodePathSegment} [options.last] The last segment to traverse.
* - `skip()` - skips the following segments in this branch
* - `break()` - skips all following segments in the traversal
*
* A note on the parameters: the `options` argument is optional. This means
* the first argument might be an options object or the callback function.
* @param {Object} [optionsOrCallback] Optional first and last segments to traverse.
* @param {CodePathSegment} [optionsOrCallback.first] The first segment to traverse.
* @param {CodePathSegment} [optionsOrCallback.last] The last segment to traverse.
* @param {Function} callback A callback function.
* @returns {void}
*/
traverseSegments(options, callback) {
traverseSegments(optionsOrCallback, callback) {
// normalize the arguments into a callback and options
let resolvedOptions;
let resolvedCallback;
if (typeof options === "function") {
resolvedCallback = options;
if (typeof optionsOrCallback === "function") {
resolvedCallback = optionsOrCallback;
resolvedOptions = {};
} else {
resolvedOptions = options || {};
resolvedOptions = optionsOrCallback || {};
resolvedCallback = callback;
}
// determine where to start traversing from based on the options
const startSegment = resolvedOptions.first || this.internal.initialSegment;
const lastSegment = resolvedOptions.last;
let item = null;
// set up initial location information
let record = null;
let index = 0;
let end = 0;
let segment = null;
const visited = Object.create(null);
// segments that have already been visited during traversal
const visited = new Set();
// tracks the traversal steps
const stack = [[startSegment, 0]];
// tracks the last skipped segment during traversal
let skippedSegment = null;
// indicates if we exited early from the traversal
let broken = false;
/**
* Maintains traversal state.
*/
const controller = {
/**
* Skip the following segments in this branch.
* @returns {void}
*/
skip() {

@@ -182,2 +223,8 @@ if (stack.length <= 1) {

},
/**
* Stop traversal completely - do not traverse to any
* other segments.
* @returns {void}
*/
break() {

@@ -189,3 +236,3 @@ broken = true;

/**
* Checks a given previous segment has been visited.
* Checks if a given previous segment has been visited.
* @param {CodePathSegment} prevSegment A previous segment to check.

@@ -196,3 +243,3 @@ * @returns {boolean} `true` if the segment has been visited.

return (
visited[prevSegment.id] ||
visited.has(prevSegment) ||
segment.isLoopedPrevSegment(prevSegment)

@@ -202,11 +249,25 @@ );

// the traversal
while (stack.length > 0) {
item = stack[stack.length - 1];
segment = item[0];
index = item[1];
/*
* This isn't a pure stack. We use the top record all the time
* but don't always pop it off. The record is popped only if
* one of the following is true:
*
* 1) We have already visited the segment.
* 2) We have not visited *all* of the previous segments.
* 3) We have traversed past the available next segments.
*
* Otherwise, we just read the value and sometimes modify the
* record as we traverse.
*/
record = stack[stack.length - 1];
segment = record[0];
index = record[1];
if (index === 0) {
// Skip if this segment has been visited already.
if (visited[segment.id]) {
if (visited.has(segment)) {
stack.pop();

@@ -225,14 +286,25 @@ continue;

// Reset the flag of skipping if all branches have been skipped.
if (skippedSegment && segment.prevSegments.indexOf(skippedSegment) !== -1) {
// Reset the skipping flag if all branches have been skipped.
if (skippedSegment && segment.prevSegments.includes(skippedSegment)) {
skippedSegment = null;
}
visited[segment.id] = true;
visited.add(segment);
// Call the callback when the first time.
/*
* If the most recent segment hasn't been skipped, then we call
* the callback, passing in the segment and the controller.
*/
if (!skippedSegment) {
resolvedCallback.call(this, segment, controller);
// exit if we're at the last segment
if (segment === lastSegment) {
controller.skip();
}
/*
* If the previous statement was executed, or if the callback
* called a method on the controller, we might need to exit the
* loop, so check for that and break accordingly.
*/
if (broken) {

@@ -247,8 +319,31 @@ break;

if (index < end) {
item[1] += 1;
/*
* If we haven't yet visited all of the next segments, update
* the current top record on the stack to the next index to visit
* and then push a record for the current segment on top.
*
* Setting the current top record's index lets us know how many
* times we've been here and ensures that the segment won't be
* reprocessed (because we only process segments with an index
* of 0).
*/
record[1] += 1;
stack.push([segment.nextSegments[index], 0]);
} else if (index === end) {
item[0] = segment.nextSegments[index];
item[1] = 0;
/*
* If we are at the last next segment, then reset the top record
* in the stack to next segment and set its index to 0 so it will
* be processed next.
*/
record[0] = segment.nextSegments[index];
record[1] = 0;
} else {
/*
* If index > end, that means we have no more segments that need
* processing. So, we pop that record off of the stack in order to
* continue traversing at the next level up.
*/
stack.pop();

@@ -255,0 +350,0 @@ }

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

*/
/* istanbul ignore next */
/* c8 ignore next */
function getId(segment) { // eslint-disable-line jsdoc/require-jsdoc -- Ignoring

@@ -71,3 +71,3 @@ return segment.id + (segment.reachable ? "" : "!");

*/
dumpState: !debug.enabled ? debug : /* istanbul ignore next */ function(node, state, leaving) {
dumpState: !debug.enabled ? debug : /* c8 ignore next */ function(node, state, leaving) {
for (let i = 0; i < state.currentSegments.length; ++i) {

@@ -103,3 +103,3 @@ const segInternal = state.currentSegments[i].internal;

*/
dumpDot: !debug.enabled ? debug : /* istanbul ignore next */ function(codePath) {
dumpDot: !debug.enabled ? debug : /* c8 ignore next */ function(codePath) {
let text =

@@ -115,3 +115,3 @@ "\n" +

if (codePath.thrownSegments.length > 0) {
text += "thrown[label=\"✘\",shape=circle,width=0.3,height=0.3,fixedsize];\n";
text += "thrown[label=\"✘\",shape=circle,width=0.3,height=0.3,fixedsize=true];\n";
}

@@ -118,0 +118,0 @@

@@ -24,4 +24,4 @@ /**

/**
* Gets whether or not a given segment is reachable.
* @param {CodePathSegment} segment A segment to get.
* Determines whether or not a given segment is reachable.
* @param {CodePathSegment} segment The segment to check.
* @returns {boolean} `true` if the segment is reachable.

@@ -34,22 +34,53 @@ */

/**
* Creates new segments from the specific range of `context.segmentsList`.
* Creates a new segment for each fork in the given context and appends it
* to the end of the specified range of segments. Ultimately, this ends up calling
* `new CodePathSegment()` for each of the forks using the `create` argument
* as a wrapper around special behavior.
*
* The `startIndex` and `endIndex` arguments specify a range of segments in
* `context` that should become `allPrevSegments` for the newly created
* `CodePathSegment` objects.
*
* When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and
* `end` is `-1`, this creates `[g, h]`. This `g` is from `a`, `c`, and `e`.
* This `h` is from `b`, `d`, and `f`.
* @param {ForkContext} context An instance.
* @param {number} begin The first index of the previous segments.
* @param {number} end The last index of the previous segments.
* @param {Function} create A factory function of new segments.
* @returns {CodePathSegment[]} New segments.
* `end` is `-1`, this creates two new segments, `[g, h]`. This `g` is appended to
* the end of the path from `a`, `c`, and `e`. This `h` is appended to the end of
* `b`, `d`, and `f`.
* @param {ForkContext} context An instance from which the previous segments
* will be obtained.
* @param {number} startIndex The index of the first segment in the context
* that should be specified as previous segments for the newly created segments.
* @param {number} endIndex The index of the last segment in the context
* that should be specified as previous segments for the newly created segments.
* @param {Function} create A function that creates new `CodePathSegment`
* instances in a particular way. See the `CodePathSegment.new*` methods.
* @returns {Array<CodePathSegment>} An array of the newly-created segments.
*/
function makeSegments(context, begin, end, create) {
function createSegments(context, startIndex, endIndex, create) {
/** @type {Array<Array<CodePathSegment>>} */
const list = context.segmentsList;
const normalizedBegin = begin >= 0 ? begin : list.length + begin;
const normalizedEnd = end >= 0 ? end : list.length + end;
/*
* Both `startIndex` and `endIndex` work the same way: if the number is zero
* or more, then the number is used as-is. If the number is negative,
* then that number is added to the length of the segments list to
* determine the index to use. That means -1 for either argument
* is the last element, -2 is the second to last, and so on.
*
* So if `startIndex` is 0, `endIndex` is -1, and `list.length` is 3, the
* effective `startIndex` is 0 and the effective `endIndex` is 2, so this function
* will include items at indices 0, 1, and 2.
*
* Therefore, if `startIndex` is -1 and `endIndex` is -1, that means we'll only
* be using the last segment in `list`.
*/
const normalizedBegin = startIndex >= 0 ? startIndex : list.length + startIndex;
const normalizedEnd = endIndex >= 0 ? endIndex : list.length + endIndex;
/** @type {Array<CodePathSegment>} */
const segments = [];
for (let i = 0; i < context.count; ++i) {
// this is passed into `new CodePathSegment` to add to code path.
const allPrevSegments = [];

@@ -61,2 +92,3 @@

// note: `create` is just a wrapper that augments `new CodePathSegment`.
segments.push(create(context.idGenerator.next(), allPrevSegments));

@@ -69,9 +101,8 @@ }

/**
* `segments` becomes doubly in a `finally` block. Then if a code path exits by a
* control statement (such as `break`, `continue`) from the `finally` block, the
* destination's segments may be half of the source segments. In that case, this
* merges segments.
* @param {ForkContext} context An instance.
* @param {CodePathSegment[]} segments Segments to merge.
* @returns {CodePathSegment[]} The merged segments.
* Inside of a `finally` block we end up with two parallel paths. If the code path
* exits by a control statement (such as `break` or `continue`) from the `finally`
* block, then we need to merge the remaining parallel paths back into one.
* @param {ForkContext} context The fork context to work on.
* @param {Array<CodePathSegment>} segments Segments to merge.
* @returns {Array<CodePathSegment>} The merged segments.
*/

@@ -81,6 +112,29 @@ function mergeExtraSegments(context, segments) {

/*
* We need to ensure that the array returned from this function contains no more
* than the number of segments that the context allows. `context.count` indicates
* how many items should be in the returned array to ensure that the new segment
* entries will line up with the already existing segment entries.
*/
while (currentSegments.length > context.count) {
const merged = [];
for (let i = 0, length = currentSegments.length / 2 | 0; i < length; ++i) {
/*
* Because `context.count` is a factor of 2 inside of a `finally` block,
* we can divide the segment count by 2 to merge the paths together.
* This loops through each segment in the list and creates a new `CodePathSegment`
* that has the segment and the segment two slots away as previous segments.
*
* If `currentSegments` is [a,b,c,d], this will create new segments e and f, such
* that:
*
* When `i` is 0:
* a->e
* c->e
*
* When `i` is 1:
* b->f
* d->f
*/
for (let i = 0, length = Math.floor(currentSegments.length / 2); i < length; ++i) {
merged.push(CodePathSegment.newNext(

@@ -91,4 +145,11 @@ context.idGenerator.next(),

}
/*
* Go through the loop condition one more time to see if we have the
* number of segments for the context. If not, we'll keep merging paths
* of the merged segments until we get there.
*/
currentSegments = merged;
}
return currentSegments;

@@ -102,3 +163,3 @@ }

/**
* A class to manage forking.
* Manages the forking of code paths.
*/

@@ -108,10 +169,40 @@ class ForkContext {

/**
* Creates a new instance.
* @param {IdGenerator} idGenerator An identifier generator for segments.
* @param {ForkContext|null} upper An upper fork context.
* @param {number} count A number of parallel segments.
* @param {ForkContext|null} upper The preceding fork context.
* @param {number} count The number of parallel segments in each element
* of `segmentsList`.
*/
constructor(idGenerator, upper, count) {
/**
* The ID generator that will generate segment IDs for any new
* segments that are created.
* @type {IdGenerator}
*/
this.idGenerator = idGenerator;
/**
* The preceding fork context.
* @type {ForkContext|null}
*/
this.upper = upper;
/**
* The number of elements in each element of `segmentsList`. In most
* cases, this is 1 but can be 2 when there is a `finally` present,
* which forks the code path outside of normal flow. In the case of nested
* `finally` blocks, this can be a multiple of 2.
* @type {number}
*/
this.count = count;
/**
* The segments within this context. Each element in this array has
* `count` elements that represent one step in each fork. For example,
* when `segmentsList` is `[[a, b], [c, d], [e, f]]`, there is one path
* a->c->e and one path b->d->f, and `count` is 2 because each element
* is an array with two elements.
* @type {Array<Array<CodePathSegment>>}
*/
this.segmentsList = [];

@@ -121,4 +212,4 @@ }

/**
* The head segments.
* @type {CodePathSegment[]}
* The segments that begin this fork context.
* @type {Array<CodePathSegment>}
*/

@@ -132,3 +223,3 @@ get head() {

/**
* A flag which shows empty.
* Indicates if the context contains no segments.
* @type {boolean}

@@ -141,3 +232,3 @@ */

/**
* A flag which shows reachable.
* Indicates if there are any segments that are reachable.
* @type {boolean}

@@ -152,38 +243,49 @@ */

/**
* Creates new segments from this context.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
* Creates new segments in this context and appends them to the end of the
* already existing `CodePathSegment`s specified by `startIndex` and
* `endIndex`.
* @param {number} startIndex The index of the first segment in the context
* that should be specified as previous segments for the newly created segments.
* @param {number} endIndex The index of the last segment in the context
* that should be specified as previous segments for the newly created segments.
* @returns {Array<CodePathSegment>} An array of the newly created segments.
*/
makeNext(begin, end) {
return makeSegments(this, begin, end, CodePathSegment.newNext);
makeNext(startIndex, endIndex) {
return createSegments(this, startIndex, endIndex, CodePathSegment.newNext);
}
/**
* Creates new segments from this context.
* The new segments is always unreachable.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
* Creates new unreachable segments in this context and appends them to the end of the
* already existing `CodePathSegment`s specified by `startIndex` and
* `endIndex`.
* @param {number} startIndex The index of the first segment in the context
* that should be specified as previous segments for the newly created segments.
* @param {number} endIndex The index of the last segment in the context
* that should be specified as previous segments for the newly created segments.
* @returns {Array<CodePathSegment>} An array of the newly created segments.
*/
makeUnreachable(begin, end) {
return makeSegments(this, begin, end, CodePathSegment.newUnreachable);
makeUnreachable(startIndex, endIndex) {
return createSegments(this, startIndex, endIndex, CodePathSegment.newUnreachable);
}
/**
* Creates new segments from this context.
* The new segments don't have connections for previous segments.
* But these inherit the reachable flag from this context.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
* Creates new segments in this context and does not append them to the end
* of the already existing `CodePathSegment`s specified by `startIndex` and
* `endIndex`. The `startIndex` and `endIndex` are only used to determine if
* the new segments should be reachable. If any of the segments in this range
* are reachable then the new segments are also reachable; otherwise, the new
* segments are unreachable.
* @param {number} startIndex The index of the first segment in the context
* that should be considered for reachability.
* @param {number} endIndex The index of the last segment in the context
* that should be considered for reachability.
* @returns {Array<CodePathSegment>} An array of the newly created segments.
*/
makeDisconnected(begin, end) {
return makeSegments(this, begin, end, CodePathSegment.newDisconnected);
makeDisconnected(startIndex, endIndex) {
return createSegments(this, startIndex, endIndex, CodePathSegment.newDisconnected);
}
/**
* Adds segments into this context.
* The added segments become the head.
* @param {CodePathSegment[]} segments Segments to add.
* Adds segments to the head of this context.
* @param {Array<CodePathSegment>} segments The segments to add.
* @returns {void}

@@ -193,3 +295,2 @@ */

assert(segments.length >= this.count, `${segments.length} >= ${this.count}`);
this.segmentsList.push(mergeExtraSegments(this, segments));

@@ -199,11 +300,13 @@ }

/**
* Replaces the head segments with given segments.
* Replaces the head segments with the given segments.
* The current head segments are removed.
* @param {CodePathSegment[]} segments Segments to add.
* @param {Array<CodePathSegment>} replacementHeadSegments The new head segments.
* @returns {void}
*/
replaceHead(segments) {
assert(segments.length >= this.count, `${segments.length} >= ${this.count}`);
this.segmentsList.splice(-1, 1, mergeExtraSegments(this, segments));
replaceHead(replacementHeadSegments) {
assert(
replacementHeadSegments.length >= this.count,
`${replacementHeadSegments.length} >= ${this.count}`
);
this.segmentsList.splice(-1, 1, mergeExtraSegments(this, replacementHeadSegments));
}

@@ -213,13 +316,8 @@

* Adds all segments of a given fork context into this context.
* @param {ForkContext} context A fork context to add.
* @param {ForkContext} otherForkContext The fork context to add from.
* @returns {void}
*/
addAll(context) {
assert(context.count === this.count);
const source = context.segmentsList;
for (let i = 0; i < source.length; ++i) {
this.segmentsList.push(source[i]);
}
addAll(otherForkContext) {
assert(otherForkContext.count === this.count);
this.segmentsList.push(...otherForkContext.segmentsList);
}

@@ -236,3 +334,4 @@

/**
* Creates the root fork context.
* Creates a new root context, meaning that there are no parent
* fork contexts.
* @param {IdGenerator} idGenerator An identifier generator for segments.

@@ -252,10 +351,12 @@ * @returns {ForkContext} New fork context.

* @param {ForkContext} parentContext The parent fork context.
* @param {boolean} forkLeavingPath A flag which shows inside of `finally` block.
* @param {boolean} shouldForkLeavingPath Indicates that we are inside of
* a `finally` block and should therefore fork the path that leaves
* `finally`.
* @returns {ForkContext} New fork context.
*/
static newEmpty(parentContext, forkLeavingPath) {
static newEmpty(parentContext, shouldForkLeavingPath) {
return new ForkContext(
parentContext.idGenerator,
parentContext,
(forkLeavingPath ? 2 : 1) * parentContext.count
(shouldForkLeavingPath ? 2 : 1) * parentContext.count
);

@@ -262,0 +363,0 @@ }

@@ -36,6 +36,6 @@ /**

/* istanbul ignore if */
/* c8 ignore start */
if (this.n < 0) {
this.n = 1;
}
}/* c8 ignore stop */

@@ -42,0 +42,0 @@ return this.prefix + this.n;

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

//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/** @typedef {import("../shared/types").LintMessage} LintMessage */
//------------------------------------------------------------------------------
// Public Interface

@@ -65,3 +71,3 @@ //------------------------------------------------------------------------------

* @param {Object} location Start line and column of comments for potential error message.
* @returns {({success: true, config: Object}|{success: false, error: Problem})} Result map object
* @returns {({success: true, config: Object}|{success: false, error: LintMessage})} Result map object
*/

@@ -114,3 +120,4 @@ parseJsonConfig(string, location) {

line: location.start.line,
column: location.start.column + 1
column: location.start.column + 1,
nodeType: null
}

@@ -137,5 +144,4 @@ };

// Collapse whitespace around commas
string.replace(/\s*,\s*/gu, ",").split(/,+/u).forEach(name => {
const trimmedName = name.trim();
string.split(",").forEach(name => {
const trimmedName = name.trim().replace(/^(?<quote>['"]?)(?<ruleId>.*)\k<quote>$/us, "$<ruleId>");

@@ -142,0 +148,0 @@ if (trimmedName) {

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

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

@@ -33,19 +35,2 @@ * An error message description

/**
* Information about the report
* @typedef {Object} ReportInfo
* @property {string} ruleId The rule ID
* @property {(0|1|2)} severity Severity of the error
* @property {(string|undefined)} message The message
* @property {(string|undefined)} [messageId] The message ID
* @property {number} line The line number
* @property {number} column The column number
* @property {(number|undefined)} [endLine] The ending line number
* @property {(number|undefined)} [endColumn] The ending column number
* @property {(string|null)} nodeType Type of node
* @property {string} source Source text
* @property {({text: string, range: (number[]|null)}|null)} [fix] The fix object
* @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions] Suggestion info
*/
//------------------------------------------------------------------------------

@@ -121,2 +106,18 @@ // Module Definition

/**
* Clones the given fix object.
* @param {Fix|null} fix The fix to clone.
* @returns {Fix|null} Deep cloned fix object or `null` if `null` or `undefined` was passed in.
*/
function cloneFix(fix) {
if (!fix) {
return null;
}
return {
range: [fix.range[0], fix.range[1]],
text: fix.text
};
}
/**
* Check that a fix has a valid range.

@@ -158,3 +159,3 @@ * @param {Fix|null} fix The fix to validate.

if (fixes.length === 1) {
return fixes[0];
return cloneFix(fixes[0]);
}

@@ -205,3 +206,3 @@

assertValidFix(fix);
return fix;
return cloneFix(fix);
}

@@ -247,3 +248,3 @@

* @param {Array<{text: string, range: (number[]|null)}>} options.suggestions The array of suggestions objects
* @returns {function(...args): ReportInfo} Function that returns information about the report
* @returns {LintMessage} Information about the report
*/

@@ -323,3 +324,3 @@ function createProblem(options) {

* @param {SourceCode} sourceCode The `SourceCode` instance for the text being linted
* @returns {function(...args): ReportInfo} Function that returns information about the report
* @returns {function(...args): LintMessage} Function that returns information about the report
*/

@@ -326,0 +327,0 @@

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

/* istanbul ignore next */
/* c8 ignore next */
/**

@@ -26,3 +26,3 @@ * Align the string to left

/* istanbul ignore next */
/* c8 ignore next */
/**

@@ -69,3 +69,3 @@ * Align the string to right

/* istanbul ignore next */
/* c8 ignore next */
/**

@@ -125,3 +125,3 @@ * display the data

/* istanbul ignore next */
/* c8 ignore next */
module.exports = (function() {

@@ -145,6 +145,7 @@

let t = process.hrtime();
const result = fn(...args);
fn(...args);
t = process.hrtime(t);
data[key] += t[0] * 1e3 + t[1] / 1e6;
return result;
};

@@ -151,0 +152,0 @@ }

@@ -50,3 +50,3 @@ /**

* @property {string} [printConfig] Print the configuration for the given file
* @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable directives
* @property {boolean | undefined} reportUnusedDisableDirectives Adds reported errors for unused eslint-disable and eslint-enable directives
* @property {string} [resolvePluginsRelativeTo] A folder where plugins should be resolved from, CWD by default

@@ -59,2 +59,3 @@ * @property {Object} [rule] Specify rules

* @property {boolean} [version] Output the version number
* @property {boolean} warnIgnored Show warnings when the file list includes ignored files
* @property {string[]} _ Positional filenames or patterns

@@ -68,13 +69,21 @@ */

// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
module.exports = optionator({
prepend: "eslint [options] file.js [file.js] [dir]",
defaults: {
concatRepeatedArrays: true,
mergeRepeatedObjects: true
},
options: [
{
heading: "Basic configuration"
},
{
/**
* Creates the CLI options for ESLint.
* @param {boolean} usingFlatConfig Indicates if flat config is being used.
* @returns {Object} The optionator instance.
*/
module.exports = function(usingFlatConfig) {
let lookupFlag;
if (usingFlatConfig) {
lookupFlag = {
option: "config-lookup",
type: "Boolean",
default: "true",
description: "Disable look up for eslint.config.js"
};
} else {
lookupFlag = {
option: "eslintrc",

@@ -84,244 +93,302 @@ type: "Boolean",

description: "Disable use of configuration from .eslintrc.*"
},
{
option: "config",
alias: "c",
type: "path::String",
description: "Use this configuration, overriding .eslintrc.* config options if present"
},
{
};
}
let envFlag;
if (!usingFlatConfig) {
envFlag = {
option: "env",
type: "[String]",
description: "Specify environments"
},
{
};
}
let extFlag;
if (!usingFlatConfig) {
extFlag = {
option: "ext",
type: "[String]",
description: "Specify JavaScript file extensions"
},
{
option: "global",
type: "[String]",
description: "Define global variables"
},
{
option: "parser",
type: "String",
description: "Specify the parser to be used"
},
{
option: "parser-options",
type: "Object",
description: "Specify parser options"
},
{
};
}
let resolvePluginsFlag;
if (!usingFlatConfig) {
resolvePluginsFlag = {
option: "resolve-plugins-relative-to",
type: "path::String",
description: "A folder where plugins should be resolved from, CWD by default"
},
{
heading: "Specifying rules and plugins"
},
{
option: "plugin",
type: "[String]",
description: "Specify plugins"
},
{
option: "rule",
type: "Object",
description: "Specify rules"
},
{
};
}
let rulesDirFlag;
if (!usingFlatConfig) {
rulesDirFlag = {
option: "rulesdir",
type: "[path::String]",
description: "Load additional rules from this directory. Deprecated: Use rules from plugins"
},
{
heading: "Fixing problems"
},
{
option: "fix",
type: "Boolean",
default: false,
description: "Automatically fix problems"
},
{
option: "fix-dry-run",
type: "Boolean",
default: false,
description: "Automatically fix problems without saving the changes to the file system"
},
{
option: "fix-type",
type: "Array",
description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)"
},
{
heading: "Ignoring files"
},
{
};
}
let ignorePathFlag;
if (!usingFlatConfig) {
ignorePathFlag = {
option: "ignore-path",
type: "path::String",
description: "Specify path of ignore file"
},
{
option: "ignore",
};
}
let warnIgnoredFlag;
if (usingFlatConfig) {
warnIgnoredFlag = {
option: "warn-ignored",
type: "Boolean",
default: "true",
description: "Disable use of ignore files and patterns"
description: "Suppress warnings when the file list includes ignored files"
};
}
return optionator({
prepend: "eslint [options] file.js [file.js] [dir]",
defaults: {
concatRepeatedArrays: true,
mergeRepeatedObjects: true
},
{
option: "ignore-pattern",
type: "[String]",
description: "Pattern of files to ignore (in addition to those in .eslintignore)",
concatRepeatedArrays: [true, {
oneValuePerFlag: true
}]
},
{
heading: "Using stdin"
},
{
option: "stdin",
type: "Boolean",
default: "false",
description: "Lint code provided on <STDIN>"
},
{
option: "stdin-filename",
type: "String",
description: "Specify filename to process STDIN as"
},
{
heading: "Handling warnings"
},
{
option: "quiet",
type: "Boolean",
default: "false",
description: "Report errors only"
},
{
option: "max-warnings",
type: "Int",
default: "-1",
description: "Number of warnings to trigger nonzero exit code"
},
{
heading: "Output"
},
{
option: "output-file",
alias: "o",
type: "path::String",
description: "Specify file to write report to"
},
{
option: "format",
alias: "f",
type: "String",
default: "stylish",
description: "Use a specific output format"
},
{
option: "color",
type: "Boolean",
alias: "no-color",
description: "Force enabling/disabling of color"
},
{
heading: "Inline configuration comments"
},
{
option: "inline-config",
type: "Boolean",
default: "true",
description: "Prevent comments from changing config or rules"
},
{
option: "report-unused-disable-directives",
type: "Boolean",
default: void 0,
description: "Adds reported errors for unused eslint-disable directives"
},
{
heading: "Caching"
},
{
option: "cache",
type: "Boolean",
default: "false",
description: "Only check changed files"
},
{
option: "cache-file",
type: "path::String",
default: ".eslintcache",
description: "Path to the cache file. Deprecated: use --cache-location"
},
{
option: "cache-location",
type: "path::String",
description: "Path to the cache file or directory"
},
{
option: "cache-strategy",
dependsOn: ["cache"],
type: "String",
default: "metadata",
enum: ["metadata", "content"],
description: "Strategy to use for detecting changed files in the cache"
},
{
heading: "Miscellaneous"
},
{
option: "init",
type: "Boolean",
default: "false",
description: "Run config initialization wizard"
},
{
option: "env-info",
type: "Boolean",
default: "false",
description: "Output execution environment information"
},
{
option: "error-on-unmatched-pattern",
type: "Boolean",
default: "true",
description: "Prevent errors when pattern is unmatched"
},
{
option: "exit-on-fatal-error",
type: "Boolean",
default: "false",
description: "Exit with exit code 2 in case of fatal error"
},
{
option: "debug",
type: "Boolean",
default: false,
description: "Output debugging information"
},
{
option: "help",
alias: "h",
type: "Boolean",
description: "Show help"
},
{
option: "version",
alias: "v",
type: "Boolean",
description: "Output the version number"
},
{
option: "print-config",
type: "path::String",
description: "Print the configuration for the given file"
}
]
});
options: [
{
heading: "Basic configuration"
},
lookupFlag,
{
option: "config",
alias: "c",
type: "path::String",
description: usingFlatConfig
? "Use this configuration instead of eslint.config.js"
: "Use this configuration, overriding .eslintrc.* config options if present"
},
envFlag,
extFlag,
{
option: "global",
type: "[String]",
description: "Define global variables"
},
{
option: "parser",
type: "String",
description: "Specify the parser to be used"
},
{
option: "parser-options",
type: "Object",
description: "Specify parser options"
},
resolvePluginsFlag,
{
heading: "Specify Rules and Plugins"
},
{
option: "plugin",
type: "[String]",
description: "Specify plugins"
},
{
option: "rule",
type: "Object",
description: "Specify rules"
},
rulesDirFlag,
{
heading: "Fix Problems"
},
{
option: "fix",
type: "Boolean",
default: false,
description: "Automatically fix problems"
},
{
option: "fix-dry-run",
type: "Boolean",
default: false,
description: "Automatically fix problems without saving the changes to the file system"
},
{
option: "fix-type",
type: "Array",
description: "Specify the types of fixes to apply (directive, problem, suggestion, layout)"
},
{
heading: "Ignore Files"
},
ignorePathFlag,
{
option: "ignore",
type: "Boolean",
default: "true",
description: "Disable use of ignore files and patterns"
},
{
option: "ignore-pattern",
type: "[String]",
description: "Pattern of files to ignore (in addition to those in .eslintignore)",
concatRepeatedArrays: [true, {
oneValuePerFlag: true
}]
},
{
heading: "Use stdin"
},
{
option: "stdin",
type: "Boolean",
default: "false",
description: "Lint code provided on <STDIN>"
},
{
option: "stdin-filename",
type: "String",
description: "Specify filename to process STDIN as"
},
{
heading: "Handle Warnings"
},
{
option: "quiet",
type: "Boolean",
default: "false",
description: "Report errors only"
},
{
option: "max-warnings",
type: "Int",
default: "-1",
description: "Number of warnings to trigger nonzero exit code"
},
{
heading: "Output"
},
{
option: "output-file",
alias: "o",
type: "path::String",
description: "Specify file to write report to"
},
{
option: "format",
alias: "f",
type: "String",
default: "stylish",
description: "Use a specific output format"
},
{
option: "color",
type: "Boolean",
alias: "no-color",
description: "Force enabling/disabling of color"
},
{
heading: "Inline configuration comments"
},
{
option: "inline-config",
type: "Boolean",
default: "true",
description: "Prevent comments from changing config or rules"
},
{
option: "report-unused-disable-directives",
type: "Boolean",
default: void 0,
description: "Adds reported errors for unused eslint-disable and eslint-enable directives"
},
{
heading: "Caching"
},
{
option: "cache",
type: "Boolean",
default: "false",
description: "Only check changed files"
},
{
option: "cache-file",
type: "path::String",
default: ".eslintcache",
description: "Path to the cache file. Deprecated: use --cache-location"
},
{
option: "cache-location",
type: "path::String",
description: "Path to the cache file or directory"
},
{
option: "cache-strategy",
dependsOn: ["cache"],
type: "String",
default: "metadata",
enum: ["metadata", "content"],
description: "Strategy to use for detecting changed files in the cache"
},
{
heading: "Miscellaneous"
},
{
option: "init",
type: "Boolean",
default: "false",
description: "Run config initialization wizard"
},
{
option: "env-info",
type: "Boolean",
default: "false",
description: "Output execution environment information"
},
{
option: "error-on-unmatched-pattern",
type: "Boolean",
default: "true",
description: "Prevent errors when pattern is unmatched"
},
{
option: "exit-on-fatal-error",
type: "Boolean",
default: "false",
description: "Exit with exit code 2 in case of fatal error"
},
warnIgnoredFlag,
{
option: "debug",
type: "Boolean",
default: false,
description: "Output debugging information"
},
{
option: "help",
alias: "h",
type: "Boolean",
description: "Show help"
},
{
option: "version",
alias: "v",
type: "Boolean",
description: "Output the version number"
},
{
option: "print-config",
type: "path::String",
description: "Print the configuration for the given file"
}
].filter(value => !!value)
});
};

@@ -7,3 +7,3 @@ /**

/* eslint-env mocha -- Mocha wrapper */
/* globals describe, it -- Mocha globals */

@@ -52,3 +52,4 @@ /*

{ getRuleOptionsSchema, validate } = require("../shared/config-validator"),
{ Linter, SourceCodeFixer, interpolate } = require("../linter");
{ Linter, SourceCodeFixer, interpolate } = require("../linter"),
CodePath = require("../linter/code-path-analysis/code-path");

@@ -67,4 +68,5 @@ const ajv = require("../shared/ajv")({ strictDefaults: true });

/** @typedef {import("../shared/types").Parser} Parser */
/** @typedef {import("../shared/types").Rule} Rule */
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
/**

@@ -114,3 +116,2 @@ * A test case that is expected to pass lint.

*/
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */

@@ -169,4 +170,39 @@ //------------------------------------------------------------------------------

const forbiddenMethods = [
"applyInlineConfig",
"applyLanguageOptions",
"finalize"
];
const hasOwnProperty = Function.call.bind(Object.hasOwnProperty);
const DEPRECATED_SOURCECODE_PASSTHROUGHS = {
getSource: "getText",
getSourceLines: "getLines",
getAllComments: "getAllComments",
getNodeByRangeIndex: "getNodeByRangeIndex",
// getComments: "getComments", -- already handled by a separate error
getCommentsBefore: "getCommentsBefore",
getCommentsAfter: "getCommentsAfter",
getCommentsInside: "getCommentsInside",
getJSDocComment: "getJSDocComment",
getFirstToken: "getFirstToken",
getFirstTokens: "getFirstTokens",
getLastToken: "getLastToken",
getLastTokens: "getLastTokens",
getTokenAfter: "getTokenAfter",
getTokenBefore: "getTokenBefore",
getTokenByRangeStart: "getTokenByRangeStart",
getTokens: "getTokens",
getTokensAfter: "getTokensAfter",
getTokensBefore: "getTokensBefore",
getTokensBetween: "getTokensBetween",
getScope: "getScope",
getAncestors: "getAncestors",
getDeclaredVariables: "getDeclaredVariables",
markVariableAsUsed: "markVariableAsUsed"
};
/**

@@ -224,2 +260,5 @@ * Clones a given value deeply.

function sanitize(text) {
if (typeof text !== "string") {
return "";
}
return text.replace(

@@ -311,2 +350,92 @@ /[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex -- Escaping controls

/**
* Function to replace forbidden `SourceCode` methods.
* @param {string} methodName The name of the method to forbid.
* @returns {Function} The function that throws the error.
*/
function throwForbiddenMethodError(methodName) {
return () => {
throw new Error(
`\`SourceCode#${methodName}()\` cannot be called inside a rule.`
);
};
}
/**
* Emit a deprecation warning if function-style format is being used.
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitLegacyRuleAPIWarning(ruleName) {
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) {
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/latest/extend/custom-rules`,
"DeprecationWarning"
);
}
}
/**
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitMissingSchemaWarning(ruleName) {
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) {
emitMissingSchemaWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/latest/extend/custom-rules#options-schemas`,
"DeprecationWarning"
);
}
}
/**
* Emit a deprecation warning if a rule uses a deprecated `context` method.
* @param {string} ruleName Name of the rule.
* @param {string} methodName The name of the method on `context` that was used.
* @returns {void}
*/
function emitDeprecatedContextMethodWarning(ruleName, methodName) {
if (!emitDeprecatedContextMethodWarning[`warned-${ruleName}-${methodName}`]) {
emitDeprecatedContextMethodWarning[`warned-${ruleName}-${methodName}`] = true;
process.emitWarning(
`"${ruleName}" rule is using \`context.${methodName}()\`, which is deprecated and will be removed in ESLint v9. Please use \`sourceCode.${DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]}()\` instead.`,
"DeprecationWarning"
);
}
}
/**
* Emit a deprecation warning if rule uses CodePath#currentSegments.
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitCodePathCurrentSegmentsWarning(ruleName) {
if (!emitCodePathCurrentSegmentsWarning[`warned-${ruleName}`]) {
emitCodePathCurrentSegmentsWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule uses CodePath#currentSegments and will stop working in ESLint v9. Please read the documentation for how to update your code: https://eslint.org/docs/latest/extend/code-path-analysis#usage-examples`,
"DeprecationWarning"
);
}
}
/**
* Emit a deprecation warning if `context.parserServices` is used.
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitParserServicesWarning(ruleName) {
if (!emitParserServicesWarning[`warned-${ruleName}`]) {
emitParserServicesWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule is using \`context.parserServices\`, which is deprecated and will be removed in ESLint v9. Please use \`sourceCode.parserServices\` instead.`,
"DeprecationWarning"
);
}
}
//------------------------------------------------------------------------------

@@ -389,3 +518,3 @@ // Public Interface

static setDefaultConfig(config) {
if (typeof config !== "object") {
if (typeof config !== "object" || config === null) {
throw new TypeError("RuleTester.setDefaultConfig: config must be an object");

@@ -471,3 +600,3 @@ }

"Set `RuleTester.itOnly` to use `only` with a custom test framework.\n" +
"See https://eslint.org/docs/developer-guide/nodejs-api#customizing-ruletester for more."
"See https://eslint.org/docs/latest/integrate/nodejs-api#customizing-ruletester for more."
);

@@ -488,6 +617,9 @@ }

* @param {string} name The name of the rule to define.
* @param {Function} rule The rule definition.
* @param {Function | Rule} rule The rule definition.
* @returns {void}
*/
defineRule(name, rule) {
if (typeof rule === "function") {
emitLegacyRuleAPIWarning(name);
}
this.rules[name] = rule;

@@ -499,3 +631,3 @@ }

* @param {string} ruleName The name of the rule to run.
* @param {Function} rule The rule to test.
* @param {Function | Rule} rule The rule to test.
* @param {{

@@ -532,2 +664,5 @@ * valid: (ValidTestCase | string)[],

if (typeof rule === "function") {
emitLegacyRuleAPIWarning(ruleName);
}

@@ -542,3 +677,34 @@ linter.defineRule(ruleName, Object.assign({}, rule, {

return (typeof rule === "function" ? rule : rule.create)(context);
// wrap all deprecated methods
const newContext = Object.create(
context,
Object.fromEntries(Object.keys(DEPRECATED_SOURCECODE_PASSTHROUGHS).map(methodName => [
methodName,
{
value(...args) {
// emit deprecation warning
emitDeprecatedContextMethodWarning(ruleName, methodName);
// call the original method
return context[methodName].call(this, ...args);
},
enumerable: true
}
]))
);
// emit warning about context.parserServices
const parserServices = context.parserServices;
Object.defineProperty(newContext, "parserServices", {
get() {
emitParserServicesWarning(ruleName);
return parserServices;
}
});
Object.freeze(newContext);
return (typeof rule === "function" ? rule : rule.create)(newContext);
}

@@ -591,2 +757,11 @@ }));

assert(Array.isArray(item.options), "options must be an array");
if (
item.options.length > 0 &&
typeof rule === "object" &&
(
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null))
)
) {
emitMissingSchemaWarning(ruleName);
}
config.rules[ruleName] = [1].concat(item.options);

@@ -604,10 +779,14 @@ } else {

*/
linter.defineRule("rule-tester/validate-ast", () => ({
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
linter.defineRule("rule-tester/validate-ast", {
create() {
return {
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
}
};
}
}));
});

@@ -651,3 +830,4 @@ if (typeof config.parser === "string") {

// Verify the code.
const { getComments } = SourceCode.prototype;
const { getComments, applyLanguageOptions, applyInlineConfig, finalize } = SourceCode.prototype;
const originalCurrentSegments = Object.getOwnPropertyDescriptor(CodePath.prototype, "currentSegments");
let messages;

@@ -657,5 +837,20 @@

SourceCode.prototype.getComments = getCommentsDeprecation;
Object.defineProperty(CodePath.prototype, "currentSegments", {
get() {
emitCodePathCurrentSegmentsWarning(ruleName);
return originalCurrentSegments.get.call(this);
}
});
forbiddenMethods.forEach(methodName => {
SourceCode.prototype[methodName] = throwForbiddenMethodError(methodName);
});
messages = linter.verify(code, config, filename);
} finally {
SourceCode.prototype.getComments = getComments;
Object.defineProperty(CodePath.prototype, "currentSegments", originalCurrentSegments);
SourceCode.prototype.applyInlineConfig = applyInlineConfig;
SourceCode.prototype.applyLanguageOptions = applyLanguageOptions;
SourceCode.prototype.finalize = finalize;
}

@@ -711,2 +906,9 @@

function testValidTemplate(item) {
const code = typeof item === "object" ? item.code : item;
assert.ok(typeof code === "string", "Test case must specify a string value for 'code'");
if (item.name) {
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
}
const result = runRuleForItem(item);

@@ -752,2 +954,6 @@ const messages = result.messages;

function testInvalidTemplate(item) {
assert.ok(typeof item.code === "string", "Test case must specify a string value for 'code'");
if (item.name) {
assert.ok(typeof item.name === "string", "Optional test case property 'name' must be a string");
}
assert.ok(item.errors || item.errors === 0,

@@ -984,25 +1190,31 @@ `Did not specify errors for an invalid test of ${ruleName}`);

* one of the templates above.
* The test suites for valid/invalid are created conditionally as
* test runners (eg. vitest) fail for empty test suites.
*/
RuleTester.describe(ruleName, () => {
RuleTester.describe("valid", () => {
test.valid.forEach(valid => {
RuleTester[valid.only ? "itOnly" : "it"](
sanitize(typeof valid === "object" ? valid.name || valid.code : valid),
() => {
testValidTemplate(valid);
}
);
this.constructor.describe(ruleName, () => {
if (test.valid.length > 0) {
this.constructor.describe("valid", () => {
test.valid.forEach(valid => {
this.constructor[valid.only ? "itOnly" : "it"](
sanitize(typeof valid === "object" ? valid.name || valid.code : valid),
() => {
testValidTemplate(valid);
}
);
});
});
});
}
RuleTester.describe("invalid", () => {
test.invalid.forEach(invalid => {
RuleTester[invalid.only ? "itOnly" : "it"](
sanitize(invalid.name || invalid.code),
() => {
testInvalidTemplate(invalid);
}
);
if (test.invalid.length > 0) {
this.constructor.describe("invalid", () => {
test.invalid.forEach(invalid => {
this.constructor[invalid.only ? "itOnly" : "it"](
sanitize(invalid.name || invalid.code),
() => {
testInvalidTemplate(invalid);
}
);
});
});
});
}
});

@@ -1009,0 +1221,0 @@ }

@@ -143,5 +143,5 @@ /**

docs: {
description: "enforce getter and setter pairs in objects and classes",
description: "Enforce getter and setter pairs in objects and classes",
recommended: false,
url: "https://eslint.org/docs/rules/accessor-pairs"
url: "https://eslint.org/docs/latest/rules/accessor-pairs"
},

@@ -182,3 +182,3 @@

const enforceForClassMembers = config.enforceForClassMembers !== false;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -229,49 +229,41 @@ /**

/**
* Creates a new `AccessorData` object for the given getter or setter node.
* @param {ASTNode} node A getter or setter node.
* @returns {AccessorData} New `AccessorData` object that contains the given node.
* Checks accessor pairs in the given list of nodes.
* @param {ASTNode[]} nodes The list to check.
* @returns {void}
* @private
*/
function createAccessorData(node) {
const name = astUtils.getStaticPropertyName(node);
const key = (name !== null) ? name : sourceCode.getTokens(node.key);
function checkList(nodes) {
const accessors = [];
let found = false;
return {
key,
getters: node.kind === "get" ? [node] : [],
setters: node.kind === "set" ? [node] : []
};
}
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
/**
* Merges the given `AccessorData` object into the given accessors list.
* @param {AccessorData[]} accessors The list to merge into.
* @param {AccessorData} accessorData The object to merge.
* @returns {AccessorData[]} The same instance with the merged object.
* @private
*/
function mergeAccessorData(accessors, accessorData) {
const equalKeyElement = accessors.find(a => areEqualKeys(a.key, accessorData.key));
if (isAccessorKind(node)) {
if (equalKeyElement) {
equalKeyElement.getters.push(...accessorData.getters);
equalKeyElement.setters.push(...accessorData.setters);
} else {
accessors.push(accessorData);
}
// Creates a new `AccessorData` object for the given getter or setter node.
const name = astUtils.getStaticPropertyName(node);
const key = (name !== null) ? name : sourceCode.getTokens(node.key);
return accessors;
}
// Merges the given `AccessorData` object into the given accessors list.
for (let j = 0; j < accessors.length; j++) {
const accessor = accessors[j];
/**
* Checks accessor pairs in the given list of nodes.
* @param {ASTNode[]} nodes The list to check.
* @returns {void}
* @private
*/
function checkList(nodes) {
const accessors = nodes
.filter(isAccessorKind)
.map(createAccessorData)
.reduce(mergeAccessorData, []);
if (areEqualKeys(accessor.key, key)) {
accessor.getters.push(...node.kind === "get" ? [node] : []);
accessor.setters.push(...node.kind === "set" ? [node] : []);
found = true;
break;
}
}
if (!found) {
accessors.push({
key,
getters: node.kind === "get" ? [node] : [],
setters: node.kind === "set" ? [node] : []
});
}
found = false;
}
}

@@ -305,8 +297,8 @@ for (const { getters, setters } of accessors) {

function checkPropertyDescriptor(node) {
const namesToCheck = node.properties
const namesToCheck = new Set(node.properties
.filter(p => p.type === "Property" && p.kind === "init" && !p.computed)
.map(({ key }) => key.name);
.map(({ key }) => key.name));
const hasGetter = namesToCheck.includes("get");
const hasSetter = namesToCheck.includes("set");
const hasGetter = namesToCheck.has("get");
const hasSetter = namesToCheck.has("set");

@@ -313,0 +305,0 @@ if (checkSetWithoutGet && hasSetter && !hasGetter) {

/**
* @fileoverview Rule to enforce linebreaks after open and before close array brackets
* @author Jan Peer Stöcklmair <https://github.com/JPeer264>
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce linebreaks after opening and before closing array brackets",
description: "Enforce linebreaks after opening and before closing array brackets",
recommended: false,
url: "https://eslint.org/docs/rules/array-bracket-newline"
url: "https://eslint.org/docs/latest/rules/array-bracket-newline"
},

@@ -60,3 +63,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -63,0 +66,0 @@

/**
* @fileoverview Disallows or enforces spaces inside of array brackets.
* @author Jamund Ferguson
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing inside array brackets",
description: "Enforce consistent spacing inside array brackets",
recommended: false,
url: "https://eslint.org/docs/rules/array-bracket-spacing"
url: "https://eslint.org/docs/latest/rules/array-bracket-spacing"
},

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

const spaced = context.options[0] === "always",
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -60,0 +63,0 @@ /**

@@ -19,14 +19,5 @@ /**

const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|flatMap|forEach|map|reduce(?:Right)?|some|sort)$/u;
const TARGET_METHODS = /^(?:every|filter|find(?:Last)?(?:Index)?|flatMap|forEach|map|reduce(?:Right)?|some|sort|toSorted)$/u;
/**
* Checks a given code path segment is reachable.
* @param {CodePathSegment} segment A segment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
return segment.reachable;
}
/**
* Checks a given node is a member access which has the specified name's

@@ -43,2 +34,18 @@ * property.

/**
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}
/**
* Returns a human-legible description of an array method

@@ -130,6 +137,76 @@ * @param {string} arrayMethodName A method name to fully qualify

/* istanbul ignore next: unreachable */
/* c8 ignore next */
return null;
}
/**
* Checks if the given node is a void expression.
* @param {ASTNode} node The node to check.
* @returns {boolean} - `true` if the node is a void expression
*/
function isExpressionVoid(node) {
return node.type === "UnaryExpression" && node.operator === "void";
}
/**
* Fixes the linting error by prepending "void " to the given node
* @param {Object} sourceCode context given by context.sourceCode
* @param {ASTNode} node The node to fix.
* @param {Object} fixer The fixer object provided by ESLint.
* @returns {Array<Object>} - An array of fix objects to apply to the node.
*/
function voidPrependFixer(sourceCode, node, fixer) {
const requiresParens =
// prepending `void ` will fail if the node has a lower precedence than void
astUtils.getPrecedence(node) < astUtils.getPrecedence({ type: "UnaryExpression", operator: "void" }) &&
// check if there are parentheses around the node to avoid redundant parentheses
!astUtils.isParenthesised(sourceCode, node);
// avoid parentheses issues
const returnOrArrowToken = sourceCode.getTokenBefore(
node,
node.parent.type === "ArrowFunctionExpression"
? astUtils.isArrowToken
// isReturnToken
: token => token.type === "Keyword" && token.value === "return"
);
const firstToken = sourceCode.getTokenAfter(returnOrArrowToken);
const prependSpace =
// is return token, as => allows void to be adjacent
returnOrArrowToken.value === "return" &&
// If two tokens (return and "(") are adjacent
returnOrArrowToken.range[1] === firstToken.range[0];
return [
fixer.insertTextBefore(firstToken, `${prependSpace ? " " : ""}void ${requiresParens ? "(" : ""}`),
fixer.insertTextAfter(node, requiresParens ? ")" : "")
];
}
/**
* Fixes the linting error by `wrapping {}` around the given node's body.
* @param {Object} sourceCode context given by context.sourceCode
* @param {ASTNode} node The node to fix.
* @param {Object} fixer The fixer object provided by ESLint.
* @returns {Array<Object>} - An array of fix objects to apply to the node.
*/
function curlyWrapFixer(sourceCode, node, fixer) {
const arrowToken = sourceCode.getTokenBefore(node.body, astUtils.isArrowToken);
const firstToken = sourceCode.getTokenAfter(arrowToken);
const lastToken = sourceCode.getLastToken(node);
return [
fixer.insertTextBefore(firstToken, "{"),
fixer.insertTextAfter(lastToken, "}")
];
}
//------------------------------------------------------------------------------

@@ -145,7 +222,10 @@ // Rule Definition

docs: {
description: "enforce `return` statements in callbacks of array methods",
description: "Enforce `return` statements in callbacks of array methods",
recommended: false,
url: "https://eslint.org/docs/rules/array-callback-return"
url: "https://eslint.org/docs/latest/rules/array-callback-return"
},
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- false positive
hasSuggestions: true,
schema: [

@@ -162,2 +242,6 @@ {

default: false
},
allowVoid: {
type: "boolean",
default: false
}

@@ -173,3 +257,5 @@ },

expectedReturnValue: "{{arrayMethodName}}() expects a return value from {{name}}.",
expectedNoReturnValue: "{{arrayMethodName}}() expects no useless return value from {{name}}."
expectedNoReturnValue: "{{arrayMethodName}}() expects no useless return value from {{name}}.",
wrapBraces: "Wrap the expression in `{}`.",
prependVoid: "Prepend `void` to the expression."
}

@@ -180,4 +266,4 @@ },

const options = context.options[0] || { allowImplicit: false, checkForEach: false };
const sourceCode = context.getSourceCode();
const options = context.options[0] || { allowImplicit: false, checkForEach: false, allowVoid: false };
const sourceCode = context.sourceCode;

@@ -208,15 +294,44 @@ let funcInfo = {

let messageId = null;
const messageAndSuggestions = { messageId: "", suggest: [] };
if (funcInfo.arrayMethodName === "forEach") {
if (options.checkForEach && node.type === "ArrowFunctionExpression" && node.expression) {
messageId = "expectedNoReturnValue";
if (options.allowVoid) {
if (isExpressionVoid(node.body)) {
return;
}
messageAndSuggestions.messageId = "expectedNoReturnValue";
messageAndSuggestions.suggest = [
{
messageId: "wrapBraces",
fix(fixer) {
return curlyWrapFixer(sourceCode, node, fixer);
}
},
{
messageId: "prependVoid",
fix(fixer) {
return voidPrependFixer(sourceCode, node.body, fixer);
}
}
];
} else {
messageAndSuggestions.messageId = "expectedNoReturnValue";
messageAndSuggestions.suggest = [{
messageId: "wrapBraces",
fix(fixer) {
return curlyWrapFixer(sourceCode, node, fixer);
}
}];
}
}
} else {
if (node.body.type === "BlockStatement" && funcInfo.codePath.currentSegments.some(isReachable)) {
messageId = funcInfo.hasReturn ? "expectedAtEnd" : "expectedInside";
if (node.body.type === "BlockStatement" && isAnySegmentReachable(funcInfo.currentSegments)) {
messageAndSuggestions.messageId = funcInfo.hasReturn ? "expectedAtEnd" : "expectedInside";
}
}
if (messageId) {
if (messageAndSuggestions.messageId) {
const name = astUtils.getFunctionNameWithKind(node);

@@ -227,4 +342,5 @@

loc: astUtils.getFunctionHeadLoc(node, sourceCode),
messageId,
data: { name, arrayMethodName: fullMethodName(funcInfo.arrayMethodName) }
messageId: messageAndSuggestions.messageId,
data: { name, arrayMethodName: fullMethodName(funcInfo.arrayMethodName) },
suggest: messageAndSuggestions.suggest.length !== 0 ? messageAndSuggestions.suggest : null
});

@@ -254,3 +370,4 @@ }

!node.generator,
node
node,
currentSegments: new Set()
};

@@ -264,2 +381,19 @@ },

onUnreachableCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
onCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
// Checks the return statement is valid.

@@ -274,3 +408,3 @@ ReturnStatement(node) {

let messageId = null;
const messageAndSuggestions = { messageId: "", suggest: [] };

@@ -281,3 +415,18 @@ if (funcInfo.arrayMethodName === "forEach") {

if (options.checkForEach && node.argument) {
messageId = "expectedNoReturnValue";
if (options.allowVoid) {
if (isExpressionVoid(node.argument)) {
return;
}
messageAndSuggestions.messageId = "expectedNoReturnValue";
messageAndSuggestions.suggest = [{
messageId: "prependVoid",
fix(fixer) {
return voidPrependFixer(sourceCode, node.argument, fixer);
}
}];
} else {
messageAndSuggestions.messageId = "expectedNoReturnValue";
}
}

@@ -288,14 +437,15 @@ } else {

if (!options.allowImplicit && !node.argument) {
messageId = "expectedReturnValue";
messageAndSuggestions.messageId = "expectedReturnValue";
}
}
if (messageId) {
if (messageAndSuggestions.messageId) {
context.report({
node,
messageId,
messageId: messageAndSuggestions.messageId,
data: {
name: astUtils.getFunctionNameWithKind(funcInfo.node),
arrayMethodName: fullMethodName(funcInfo.arrayMethodName)
}
},
suggest: messageAndSuggestions.suggest.length !== 0 ? messageAndSuggestions.suggest : null
});

@@ -302,0 +452,0 @@ }

/**
* @fileoverview Rule to enforce line breaks after each array element
* @author Jan Peer Stöcklmair <https://github.com/JPeer264>
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce line breaks after each array element",
description: "Enforce line breaks after each array element",
recommended: false,
url: "https://eslint.org/docs/rules/array-element-newline"
url: "https://eslint.org/docs/latest/rules/array-element-newline"
},

@@ -51,2 +54,3 @@

},
type: "array",
items: [

@@ -83,3 +87,3 @@ {

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -245,7 +249,11 @@ //----------------------------------------------------------------------

const linebreaksCount = node.elements.map((element, i) => {
let linebreaksCount = 0;
for (let i = 0; i < node.elements.length; i++) {
const element = node.elements[i];
const previousElement = elements[i - 1];
if (i === 0 || element === null || previousElement === null) {
return false;
continue;
}

@@ -257,4 +265,6 @@

return !astUtils.isTokenOnSameLine(lastTokenOfPreviousElement, firstTokenOfCurrentElement);
}).filter(isBreak => isBreak === true).length;
if (!astUtils.isTokenOnSameLine(lastTokenOfPreviousElement, firstTokenOfCurrentElement)) {
linebreaksCount++;
}
}

@@ -261,0 +271,0 @@ const needsLinebreaks = (

@@ -23,5 +23,5 @@ /**

docs: {
description: "require braces around arrow function bodies",
description: "Require braces around arrow function bodies",
recommended: false,
url: "https://eslint.org/docs/rules/arrow-body-style"
url: "https://eslint.org/docs/latest/rules/arrow-body-style"
},

@@ -78,3 +78,3 @@

const requireReturnForObjectLiteral = options[1] && options[1].requireReturnForObjectLiteral;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let funcInfo = null;

@@ -81,0 +81,0 @@

/**
* @fileoverview Rule to require parens in arrow function arguments.
* @author Jxck
* @deprecated in ESLint v8.53.0
*/

@@ -33,8 +34,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require parentheses around arrow function arguments",
description: "Require parentheses around arrow function arguments",
recommended: false,
url: "https://eslint.org/docs/rules/arrow-parens"
url: "https://eslint.org/docs/latest/rules/arrow-parens"
},

@@ -73,3 +76,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

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

/**
* @fileoverview Rule to define spacing before/after arrow function's arrow.
* @author Jxck
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before and after the arrow in arrow functions",
description: "Enforce consistent spacing before and after the arrow in arrow functions",
recommended: false,
url: "https://eslint.org/docs/rules/arrow-spacing"
url: "https://eslint.org/docs/latest/rules/arrow-spacing"
},

@@ -65,3 +68,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -68,0 +71,0 @@ /**

@@ -17,5 +17,5 @@ /**

docs: {
description: "enforce the use of variables within the scope they are defined",
description: "Enforce the use of variables within the scope they are defined",
recommended: false,
url: "https://eslint.org/docs/rules/block-scoped-var"
url: "https://eslint.org/docs/latest/rules/block-scoped-var"
},

@@ -26,3 +26,3 @@

messages: {
outOfScope: "'{{name}}' used outside of binding context."
outOfScope: "'{{name}}' declared on line {{definitionLine}} column {{definitionColumn}} is used outside of binding context."
}

@@ -33,2 +33,3 @@ },

let stack = [];
const sourceCode = context.sourceCode;

@@ -55,8 +56,18 @@ /**

* @param {eslint-scope.Reference} reference A reference to report.
* @param {eslint-scope.Definition} definition A definition for which to report reference.
* @returns {void}
*/
function report(reference) {
function report(reference, definition) {
const identifier = reference.identifier;
const definitionPosition = definition.name.loc.start;
context.report({ node: identifier, messageId: "outOfScope", data: { name: identifier.name } });
context.report({
node: identifier,
messageId: "outOfScope",
data: {
name: identifier.name,
definitionLine: definitionPosition.line,
definitionColumn: definitionPosition.column + 1
}
});
}

@@ -90,3 +101,3 @@

// Gets declared variables, and checks its references.
const variables = context.getDeclaredVariables(node);
const variables = sourceCode.getDeclaredVariables(node);

@@ -99,3 +110,3 @@ for (let i = 0; i < variables.length; ++i) {

.filter(isOutsideOfScope)
.forEach(report);
.forEach(ref => report(ref, variables[i].defs.find(def => def.parent === node)));
}

@@ -102,0 +113,0 @@ }

/**
* @fileoverview A rule to disallow or enforce spaces inside of single line blocks.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow or enforce spaces inside of blocks after opening block and before closing block",
description: "Disallow or enforce spaces inside of blocks after opening block and before closing block",
recommended: false,
url: "https://eslint.org/docs/rules/block-spacing"
url: "https://eslint.org/docs/latest/rules/block-spacing"
},

@@ -41,3 +44,3 @@

messageId = always ? "missing" : "extra",
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -44,0 +47,0 @@ /**

/**
* @fileoverview Rule to flag block statements that do not use the one true brace style
* @author Ian Christian Myers
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent brace style for blocks",
description: "Enforce consistent brace style for blocks",
recommended: false,
url: "https://eslint.org/docs/rules/brace-style"
url: "https://eslint.org/docs/latest/rules/brace-style"
},

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

params = context.options[1] || {},
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -60,0 +63,0 @@ //--------------------------------------------------------------------------

@@ -22,5 +22,5 @@ /**

docs: {
description: "require `return` statements after callbacks",
description: "Require `return` statements after callbacks",
recommended: false,
url: "https://eslint.org/docs/rules/callback-return"
url: "https://eslint.org/docs/latest/rules/callback-return"
},

@@ -41,3 +41,3 @@

const callbacks = context.options[0] || ["callback", "cb", "next"],
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -58,3 +58,3 @@ //--------------------------------------------------------------------------

}
if (types.indexOf(node.parent.type) === -1) {
if (!types.includes(node.parent.type)) {
return findClosestParentOfType(node.parent, types);

@@ -93,3 +93,3 @@ }

function isCallback(node) {
return containsOnlyIdentifiers(node.callee) && callbacks.indexOf(sourceCode.getText(node.callee)) > -1;
return containsOnlyIdentifiers(node.callee) && callbacks.includes(sourceCode.getText(node.callee));
}

@@ -96,0 +96,0 @@

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,5 +25,5 @@ //------------------------------------------------------------------------------

docs: {
description: "enforce camelcase naming convention",
description: "Enforce camelcase naming convention",
recommended: false,
url: "https://eslint.org/docs/rules/camelcase"
url: "https://eslint.org/docs/latest/rules/camelcase"
},

@@ -72,2 +78,3 @@

const allow = options.allow || [];
const sourceCode = context.sourceCode;

@@ -146,3 +153,3 @@ //--------------------------------------------------------------------------

* Checks if a given binding identifier uses the original name as-is.
* - If it's in object destructuring, the original name is its property name.
* - If it's in object destructuring or object expression, the original name is its property name.
* - If it's in import declaration, the original name is its exported name.

@@ -162,3 +169,3 @@ * @param {ASTNode} node The `Identifier` node to check.

return (
parent.parent.type === "ObjectPattern" &&
(parent.parent.type === "ObjectPattern" || parent.parent.type === "ObjectExpression") &&
parent.value === valueNode &&

@@ -173,3 +180,3 @@ !parent.computed &&

parent.local === node &&
parent.imported.name === localName
astUtils.getModuleExportName(parent.imported) === localName
);

@@ -248,4 +255,4 @@

// Report camelcase of global variable references ------------------
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);

@@ -299,3 +306,3 @@ if (!ignoreGlobals) {

]](node) {
for (const variable of context.getDeclaredVariables(node)) {
for (const variable of sourceCode.getDeclaredVariables(node)) {
if (isGoodName(variable.name)) {

@@ -350,3 +357,3 @@ continue;

ImportDeclaration(node) {
for (const variable of context.getDeclaredVariables(node)) {
for (const variable of sourceCode.getDeclaredVariables(node)) {
if (isGoodName(variable.name)) {

@@ -353,0 +360,0 @@ continue;

@@ -108,5 +108,5 @@ /**

docs: {
description: "enforce or disallow capitalization of the first letter of a comment",
description: "Enforce or disallow capitalization of the first letter of a comment",
recommended: false,
url: "https://eslint.org/docs/rules/capitalized-comments"
url: "https://eslint.org/docs/latest/rules/capitalized-comments"
},

@@ -143,3 +143,3 @@

normalizedOptions = getAllNormalizedOptions(context.options[1]),
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -190,3 +190,3 @@ createRegExpForIgnorePatterns(normalizedOptions);

previousTokenOrComment &&
["Block", "Line"].indexOf(previousTokenOrComment.type) !== -1
["Block", "Line"].includes(previousTokenOrComment.type)
);

@@ -193,0 +193,0 @@ }

@@ -24,5 +24,5 @@ /**

docs: {
description: "enforce that class methods utilize `this`",
description: "Enforce that class methods utilize `this`",
recommended: false,
url: "https://eslint.org/docs/rules/class-methods-use-this"
url: "https://eslint.org/docs/latest/rules/class-methods-use-this"
},

@@ -137,3 +137,3 @@

node,
loc: astUtils.getFunctionHeadLoc(node, context.getSourceCode()),
loc: astUtils.getFunctionHeadLoc(node, context.sourceCode),
messageId: "missingThis",

@@ -140,0 +140,0 @@ data: {

/**
* @fileoverview Rule to forbid or enforce dangling commas.
* @author Ian Christian Myers
* @deprecated in ESLint v8.53.0
*/

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

exports: optionValue,
functions: (!ecmaVersion || ecmaVersion < 8) ? "ignore" : optionValue
functions: ecmaVersion < 2017 ? "ignore" : optionValue
};

@@ -77,8 +78,10 @@ }

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow trailing commas",
description: "Require or disallow trailing commas",
recommended: false,
url: "https://eslint.org/docs/rules/comma-dangle"
url: "https://eslint.org/docs/latest/rules/comma-dangle"
},

@@ -139,5 +142,5 @@

create(context) {
const options = normalizeOptions(context.options[0], context.parserOptions.ecmaVersion);
const options = normalizeOptions(context.options[0], context.languageOptions.ecmaVersion);
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -249,4 +252,14 @@ /**

messageId: "unexpected",
fix(fixer) {
return fixer.remove(trailingToken);
*fix(fixer) {
yield fixer.remove(trailingToken);
/*
* Extend the range of the fix to include surrounding tokens to ensure
* that the element after which the comma is removed stays _last_.
* This intentionally makes conflicts in fix ranges with rules that may be
* adding or removing elements in the same autofix pass.
* https://github.com/eslint/eslint/issues/15660
*/
yield fixer.insertTextBefore(sourceCode.getTokenBefore(trailingToken), "");
yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
}

@@ -289,4 +302,14 @@ });

messageId: "missing",
fix(fixer) {
return fixer.insertTextAfter(trailingToken, ",");
*fix(fixer) {
yield fixer.insertTextAfter(trailingToken, ",");
/*
* Extend the range of the fix to include surrounding tokens to ensure
* that the element after which the comma is inserted stays _last_.
* This intentionally makes conflicts in fix ranges with rules that may be
* adding or removing elements in the same autofix pass.
* https://github.com/eslint/eslint/issues/15660
*/
yield fixer.insertTextBefore(trailingToken, "");
yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
}

@@ -334,3 +357,3 @@ });

never: forbidTrailingComma,
ignore: () => {}
ignore() {}
};

@@ -337,0 +360,0 @@

/**
* @fileoverview Comma spacing - validates spacing before and after comma
* @author Vignesh Anand aka vegetableman.
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before and after commas",
description: "Enforce consistent spacing before and after commas",
recommended: false,
url: "https://eslint.org/docs/rules/comma-spacing"
url: "https://eslint.org/docs/latest/rules/comma-spacing"
},

@@ -52,3 +55,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const tokensAndComments = sourceCode.tokensAndComments;

@@ -109,34 +112,2 @@

/**
* Validates the spacing around a comma token.
* @param {Object} tokens The tokens to be validated.
* @param {Token} tokens.comma The token representing the comma.
* @param {Token} [tokens.left] The last token before the comma.
* @param {Token} [tokens.right] The first token after the comma.
* @param {Token|ASTNode} reportItem The item to use when reporting an error.
* @returns {void}
* @private
*/
function validateCommaItemSpacing(tokens, reportItem) {
if (tokens.left && astUtils.isTokenOnSameLine(tokens.left, tokens.comma) &&
(options.before !== sourceCode.isSpaceBetweenTokens(tokens.left, tokens.comma))
) {
report(reportItem, "before", tokens.left);
}
if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
return;
}
if (tokens.right && !options.after && tokens.right.type === "Line") {
return;
}
if (tokens.right && astUtils.isTokenOnSameLine(tokens.comma, tokens.right) &&
(options.after !== sourceCode.isSpaceBetweenTokens(tokens.comma, tokens.right))
) {
report(reportItem, "after", tokens.right);
}
}
/**
* Adds null elements of the given ArrayExpression or ArrayPattern node to the ignore list.

@@ -178,14 +149,40 @@ * @param {ASTNode} node An ArrayExpression or ArrayPattern node.

if (token && token.type === "JSXText") {
return;
}
const previousToken = tokensAndComments[i - 1];
const nextToken = tokensAndComments[i + 1];
validateCommaItemSpacing({
comma: token,
left: astUtils.isCommaToken(previousToken) || commaTokensToIgnore.includes(token) ? null : previousToken,
right: astUtils.isCommaToken(nextToken) ? null : nextToken
}, token);
if (
previousToken &&
!astUtils.isCommaToken(previousToken) && // ignore spacing between two commas
/*
* `commaTokensToIgnore` are ending commas of `null` elements (array holes/elisions).
* In addition to spacing between two commas, this can also ignore:
*
* - Spacing after `[` (controlled by array-bracket-spacing)
* Example: [ , ]
* ^
* - Spacing after a comment (for backwards compatibility, this was possibly unintentional)
* Example: [a, /* * / ,]
* ^
*/
!commaTokensToIgnore.includes(token) &&
astUtils.isTokenOnSameLine(previousToken, token) &&
options.before !== sourceCode.isSpaceBetweenTokens(previousToken, token)
) {
report(token, "before", previousToken);
}
if (
nextToken &&
!astUtils.isCommaToken(nextToken) && // ignore spacing between two commas
!astUtils.isClosingParenToken(nextToken) && // controlled by space-in-parens
!astUtils.isClosingBracketToken(nextToken) && // controlled by array-bracket-spacing
!astUtils.isClosingBraceToken(nextToken) && // controlled by object-curly-spacing
!(!options.after && nextToken.type === "Line") && // special case, allow space before line comment
astUtils.isTokenOnSameLine(token, nextToken) &&
options.after !== sourceCode.isSpaceBetweenTokens(token, nextToken)
) {
report(token, "after", nextToken);
}
});

@@ -192,0 +189,0 @@ },

/**
* @fileoverview Comma style - enforces comma styles of two types: last and first
* @author Vignesh Anand aka vegetableman
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent comma style",
description: "Enforce consistent comma style",
recommended: false,
url: "https://eslint.org/docs/rules/comma-style"
url: "https://eslint.org/docs/latest/rules/comma-style"
},

@@ -55,3 +58,3 @@

const style = context.options[0] || "last",
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;
const exceptions = {

@@ -58,0 +61,0 @@ ArrayPattern: true,

@@ -26,5 +26,5 @@ /**

docs: {
description: "enforce a maximum cyclomatic complexity allowed in a program",
description: "Enforce a maximum cyclomatic complexity allowed in a program",
recommended: false,
url: "https://eslint.org/docs/rules/complexity"
url: "https://eslint.org/docs/latest/rules/complexity"
},

@@ -31,0 +31,0 @@

/**
* @fileoverview Disallows or enforces spaces inside computed properties.
* @author Jamund Ferguson
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing inside computed property brackets",
description: "Enforce consistent spacing inside computed property brackets",
recommended: false,
url: "https://eslint.org/docs/rules/computed-property-spacing"
url: "https://eslint.org/docs/latest/rules/computed-property-spacing"
},

@@ -53,3 +56,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const propertyNameMustBeSpaced = context.options[0] === "always"; // default is "never"

@@ -56,0 +59,0 @@ const enforceForClassMembers = !context.options[1] || context.options[1].enforceForClassMembers;

@@ -19,8 +19,15 @@ /**

/**
* Checks whether or not a given code path segment is unreachable.
* @param {CodePathSegment} segment A CodePathSegment to check.
* @returns {boolean} `true` if the segment is unreachable.
* Checks all segments in a set and returns true if all are unreachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if all segments are unreachable; false otherwise.
*/
function isUnreachable(segment) {
return !segment.reachable;
function areAllSegmentsUnreachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return false;
}
}
return true;
}

@@ -50,5 +57,5 @@

docs: {
description: "require `return` statements to either always or never specify values",
description: "Require `return` statements to either always or never specify values",
recommended: false,
url: "https://eslint.org/docs/rules/consistent-return"
url: "https://eslint.org/docs/latest/rules/consistent-return"
},

@@ -93,3 +100,3 @@

if (!funcInfo.hasReturnValue ||
funcInfo.codePath.currentSegments.every(isUnreachable) ||
areAllSegmentsUnreachable(funcInfo.currentSegments) ||
astUtils.isES5Constructor(node) ||

@@ -110,3 +117,3 @@ isClassConstructor(node)

// `=>` token
loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc;
loc = context.sourceCode.getTokenBefore(node.body, astUtils.isArrowToken).loc;
} else if (

@@ -122,3 +129,3 @@ node.parent.type === "MethodDefinition" ||

// Function name or `function` keyword.
loc = (node.id || context.getSourceCode().getFirstToken(node)).loc;
loc = (node.id || context.sourceCode.getFirstToken(node)).loc;
}

@@ -149,3 +156,4 @@

messageId: "",
node
node,
currentSegments: new Set()
};

@@ -157,2 +165,19 @@ },

onUnreachableCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
onCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
// Reports a given return statement if it's inconsistent.

@@ -159,0 +184,0 @@ ReturnStatement(node) {

@@ -17,5 +17,5 @@ /**

docs: {
description: "enforce consistent naming when capturing the current execution context",
description: "Enforce consistent naming when capturing the current execution context",
recommended: false,
url: "https://eslint.org/docs/rules/consistent-this"
url: "https://eslint.org/docs/latest/rules/consistent-this"
},

@@ -40,2 +40,3 @@

let aliases = [];
const sourceCode = context.sourceCode;

@@ -70,3 +71,3 @@ if (context.options.length === 0) {

if (aliases.indexOf(name) !== -1) {
if (aliases.includes(name)) {
if (!isThis || node.operator && node.operator !== "=") {

@@ -121,6 +122,7 @@ reportBadAssignment(node, name);

* Check each alias to ensure that is was assigned to the correct value.
* @param {ASTNode} node The node that represents the scope to check.
* @returns {void}
*/
function ensureWasAssigned() {
const scope = context.getScope();
function ensureWasAssigned(node) {
const scope = sourceCode.getScope(node);

@@ -127,0 +129,0 @@ aliases.forEach(alias => {

@@ -13,8 +13,15 @@ /**

/**
* Checks whether a given code path segment is reachable or not.
* @param {CodePathSegment} segment A code path segment to check.
* @returns {boolean} `true` if the segment is reachable.
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isReachable(segment) {
return segment.reachable;
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}

@@ -126,5 +133,5 @@

docs: {
description: "require `super()` calls in constructors",
description: "Require `super()` calls in constructors",
recommended: true,
url: "https://eslint.org/docs/rules/constructor-super"
url: "https://eslint.org/docs/latest/rules/constructor-super"
},

@@ -215,3 +222,4 @@

superIsConstructor: isPossibleConstructor(superClass),
codePath
codePath,
currentSegments: new Set()
};

@@ -224,3 +232,4 @@ } else {

superIsConstructor: false,
codePath
codePath,
currentSegments: new Set()
};

@@ -268,2 +277,5 @@ }

onCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
if (!(funcInfo && funcInfo.isConstructor && funcInfo.hasExtends)) {

@@ -289,2 +301,15 @@ return;

onUnreachableCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
/**

@@ -353,8 +378,7 @@ * Update information of the code path segment when a code path was

if (funcInfo.hasExtends) {
const segments = funcInfo.codePath.currentSegments;
const segments = funcInfo.currentSegments;
let duplicate = false;
let info = null;
for (let i = 0; i < segments.length; ++i) {
const segment = segments[i];
for (const segment of segments) {

@@ -384,3 +408,3 @@ if (segment.reachable) {

}
} else if (funcInfo.codePath.currentSegments.some(isReachable)) {
} else if (isAnySegmentReachable(funcInfo.currentSegments)) {
context.report({

@@ -409,6 +433,5 @@ messageId: "unexpected",

// Returning argument is a substitute of 'super()'.
const segments = funcInfo.codePath.currentSegments;
const segments = funcInfo.currentSegments;
for (let i = 0; i < segments.length; ++i) {
const segment = segments[i];
for (const segment of segments) {

@@ -415,0 +438,0 @@ if (segment.reachable) {

@@ -23,5 +23,5 @@ /**

docs: {
description: "enforce consistent brace style for all control statements",
description: "Enforce consistent brace style for all control statements",
recommended: false,
url: "https://eslint.org/docs/rules/curly"
url: "https://eslint.org/docs/latest/rules/curly"
},

@@ -74,3 +74,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -77,0 +77,0 @@ //--------------------------------------------------------------------------

@@ -18,5 +18,5 @@ /**

docs: {
description: "enforce default clauses in switch statements to be last",
description: "Enforce default clauses in switch statements to be last",
recommended: false,
url: "https://eslint.org/docs/rules/default-case-last"
url: "https://eslint.org/docs/latest/rules/default-case-last"
},

@@ -23,0 +23,0 @@

@@ -19,5 +19,5 @@ /**

docs: {
description: "require `default` cases in `switch` statements",
description: "Require `default` cases in `switch` statements",
recommended: false,
url: "https://eslint.org/docs/rules/default-case"
url: "https://eslint.org/docs/latest/rules/default-case"
},

@@ -46,3 +46,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -49,0 +49,0 @@ //--------------------------------------------------------------------------

@@ -14,5 +14,5 @@ /**

docs: {
description: "enforce default parameters to be last",
description: "Enforce default parameters to be last",
recommended: false,
url: "https://eslint.org/docs/rules/default-param-last"
url: "https://eslint.org/docs/latest/rules/default-param-last"
},

@@ -19,0 +19,0 @@

/**
* @fileoverview Validates newlines before and after dots
* @author Greg Cochard
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent newlines before and after dots",
description: "Enforce consistent newlines before and after dots",
recommended: false,
url: "https://eslint.org/docs/rules/dot-location"
url: "https://eslint.org/docs/latest/rules/dot-location"
},

@@ -47,3 +50,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -50,0 +53,0 @@ /**

@@ -29,5 +29,5 @@ /**

docs: {
description: "enforce dot notation whenever possible",
description: "Enforce dot notation whenever possible",
recommended: false,
url: "https://eslint.org/docs/rules/dot-notation"
url: "https://eslint.org/docs/latest/rules/dot-notation"
},

@@ -63,3 +63,3 @@

const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -81,3 +81,3 @@ let allowPattern;

validIdentifier.test(value) &&
(allowKeywords || keywords.indexOf(String(value)) === -1) &&
(allowKeywords || !keywords.includes(String(value))) &&
!(allowPattern && allowPattern.test(value))

@@ -139,4 +139,3 @@ ) {

node.computed &&
node.property.type === "TemplateLiteral" &&
node.property.expressions.length === 0
astUtils.isStaticTemplateLiteral(node.property)
) {

@@ -149,3 +148,3 @@ checkComputedProperty(node, node.property.quasis[0].value.cooked);

node.property.type === "Identifier" &&
keywords.indexOf(String(node.property.name)) !== -1
keywords.includes(String(node.property.name))
) {

@@ -152,0 +151,0 @@ context.report({

/**
* @fileoverview Require or disallow newline at the end of files
* @author Nodeca Team <https://github.com/nodeca>
* @deprecated in ESLint v8.53.0
*/

@@ -14,8 +15,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow newline at the end of files",
description: "Require or disallow newline at the end of files",
recommended: false,
url: "https://eslint.org/docs/rules/eol-last"
url: "https://eslint.org/docs/latest/rules/eol-last"
},

@@ -44,3 +47,3 @@

Program: function checkBadEOF(node) {
const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
src = sourceCode.getText(),

@@ -47,0 +50,0 @@ lastLine = sourceCode.lines[sourceCode.lines.length - 1],

@@ -24,5 +24,5 @@ /**

docs: {
description: "require the use of `===` and `!==`",
description: "Require the use of `===` and `!==`",
recommended: false,
url: "https://eslint.org/docs/rules/eqeqeq"
url: "https://eslint.org/docs/latest/rules/eqeqeq"
},

@@ -72,3 +72,3 @@

const options = context.options[1] || {};
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -75,0 +75,0 @@ const nullOption = (config === "always")

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { getStaticValue } = require("@eslint-community/eslint-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,5 +25,5 @@ //------------------------------------------------------------------------------

docs: {
description: "enforce \"for\" loop update clause moving the counter in the right direction.",
description: "Enforce \"for\" loop update clause moving the counter in the right direction",
recommended: true,
url: "https://eslint.org/docs/rules/for-direction"
url: "https://eslint.org/docs/latest/rules/for-direction"
},

@@ -34,2 +40,3 @@

create(context) {
const { sourceCode } = context;

@@ -52,13 +59,13 @@ /**

* @param {int} dir expected direction that could either be turned around or invalidated
* @returns {int} return dir, the negated dir or zero if it's not clear for identifiers
* @returns {int} return dir, the negated dir, or zero if the counter does not change or the direction is not clear
*/
function getRightDirection(update, dir) {
if (update.right.type === "UnaryExpression") {
if (update.right.operator === "-") {
return -dir;
}
} else if (update.right.type === "Identifier") {
return 0;
const staticValue = getStaticValue(update.right, sourceCode.getScope(update));
if (staticValue && ["bigint", "boolean", "number"].includes(typeof staticValue.value)) {
const sign = Math.sign(Number(staticValue.value)) || 0; // convert NaN to 0
return dir * sign;
}
return dir;
return 0;
}

@@ -101,26 +108,33 @@

}
return {
ForStatement(node) {
if (node.test && node.test.type === "BinaryExpression" && node.test.left.type === "Identifier" && node.update) {
const counter = node.test.left.name;
const operator = node.test.operator;
const update = node.update;
if (node.test && node.test.type === "BinaryExpression" && node.update) {
for (const counterPosition of ["left", "right"]) {
if (node.test[counterPosition].type !== "Identifier") {
continue;
}
let wrongDirection;
const counter = node.test[counterPosition].name;
const operator = node.test.operator;
const update = node.update;
if (operator === "<" || operator === "<=") {
wrongDirection = -1;
} else if (operator === ">" || operator === ">=") {
wrongDirection = 1;
} else {
return;
}
let wrongDirection;
if (update.type === "UpdateExpression") {
if (getUpdateDirection(update, counter) === wrongDirection) {
if (operator === "<" || operator === "<=") {
wrongDirection = counterPosition === "left" ? -1 : 1;
} else if (operator === ">" || operator === ">=") {
wrongDirection = counterPosition === "left" ? 1 : -1;
} else {
return;
}
if (update.type === "UpdateExpression") {
if (getUpdateDirection(update, counter) === wrongDirection) {
report(node);
}
} else if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection) {
report(node);
}
} else if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection) {
report(node);
}

@@ -127,0 +141,0 @@ }

/**
* @fileoverview Rule to control spacing within function calls
* @author Matt DuVall <http://www.mattduvall.com>
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow spacing between function identifiers and their invocations",
description: "Require or disallow spacing between function identifiers and their invocations",
recommended: false,
url: "https://eslint.org/docs/rules/func-call-spacing"
url: "https://eslint.org/docs/latest/rules/func-call-spacing"
},

@@ -77,3 +80,3 @@

const allowNewlines = !never && context.options[1] && context.options[1].allowNewlines;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const text = sourceCode.getText();

@@ -80,0 +83,0 @@

@@ -47,3 +47,3 @@ /**

function isIdentifier(name, ecmaVersion) {
if (ecmaVersion >= 6) {
if (ecmaVersion >= 2015) {
return esutils.keyword.isIdentifierES6(name);

@@ -78,5 +78,5 @@ }

docs: {
description: "require function names to match the name of the variable or property to which they are assigned",
description: "Require function names to match the name of the variable or property to which they are assigned",
recommended: false,
url: "https://eslint.org/docs/rules/func-name-matching"
url: "https://eslint.org/docs/latest/rules/func-name-matching"
},

@@ -109,3 +109,3 @@

const includeModuleExports = options.includeCommonJSModuleExports;
const ecmaVersion = context.parserOptions && context.parserOptions.ecmaVersion ? context.parserOptions.ecmaVersion : 5;
const ecmaVersion = context.languageOptions.ecmaVersion;

@@ -112,0 +112,0 @@ /**

@@ -33,5 +33,5 @@ /**

docs: {
description: "require or disallow named `function` expressions",
description: "Require or disallow named `function` expressions",
recommended: false,
url: "https://eslint.org/docs/rules/func-names"
url: "https://eslint.org/docs/latest/rules/func-names"
},

@@ -73,3 +73,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -164,3 +164,3 @@ /**

// Skip recursive functions.
const nameVar = context.getDeclaredVariables(node)[0];
const nameVar = sourceCode.getDeclaredVariables(node)[0];

@@ -167,0 +167,0 @@ if (isFunctionName(nameVar) && nameVar.references.length > 0) {

@@ -17,5 +17,5 @@ /**

docs: {
description: "enforce the consistent use of either `function` declarations or expressions",
description: "Enforce the consistent use of either `function` declarations or expressions",
recommended: false,
url: "https://eslint.org/docs/rules/func-style"
url: "https://eslint.org/docs/latest/rules/func-style"
},

@@ -22,0 +22,0 @@

/**
* @fileoverview Rule to enforce line breaks between arguments of a function call
* @author Alexey Gonchar <https://github.com/finico>
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce line breaks between arguments of a function call",
description: "Enforce line breaks between arguments of a function call",
recommended: false,
url: "https://eslint.org/docs/rules/function-call-argument-newline"
url: "https://eslint.org/docs/latest/rules/function-call-argument-newline"
},

@@ -39,3 +42,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -42,0 +45,0 @@ const checkers = {

/**
* @fileoverview enforce consistent line breaks inside function parentheses
* @author Teddy Katz
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent line breaks inside function parentheses",
description: "Enforce consistent line breaks inside function parentheses",
recommended: false,
url: "https://eslint.org/docs/rules/function-paren-newline"
url: "https://eslint.org/docs/latest/rules/function-paren-newline"
},

@@ -61,3 +64,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const rawOption = context.options[0] || "multiline";

@@ -188,3 +191,3 @@ const multilineOption = rawOption === "multiline";

* @param {ASTNode} node The node with parens
* @throws {TypeError} Unexecpted node type.
* @throws {TypeError} Unexpected node type.
* @returns {Object} An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token.

@@ -197,6 +200,9 @@ * Can also return `null` if an expression has no parens (e.g. a NewExpression with no arguments, or an ArrowFunctionExpression

case "NewExpression":
if (!node.arguments.length && !(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
astUtils.isClosingParenToken(sourceCode.getLastToken(node))
)) {
if (!node.arguments.length &&
!(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
astUtils.isClosingParenToken(sourceCode.getLastToken(node)) &&
node.callee.range[1] < node.range[1]
)
) {

@@ -234,5 +240,9 @@ // If the NewExpression does not have parens (e.g. `new Foo`), return null.

const rightParen = node.params.length
? sourceCode.getTokenAfter(node.params[node.params.length - 1], astUtils.isClosingParenToken)
: sourceCode.getTokenAfter(firstToken);
return {
leftParen: firstToken,
rightParen: sourceCode.getTokenBefore(node.body, astUtils.isClosingParenToken)
rightParen
};

@@ -239,0 +249,0 @@ }

/**
* @fileoverview Rule to check the spacing around the * in generator functions.
* @author Jamund Ferguson
* @deprecated in ESLint v8.53.0
*/

@@ -31,8 +32,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing around `*` operators in generator functions",
description: "Enforce consistent spacing around `*` operators in generator functions",
recommended: false,
url: "https://eslint.org/docs/rules/generator-star-spacing"
url: "https://eslint.org/docs/latest/rules/generator-star-spacing"
},

@@ -106,3 +109,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -109,0 +112,0 @@ /**

@@ -17,11 +17,19 @@ /**

//------------------------------------------------------------------------------
const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
/**
* Checks a given code path segment is reachable.
* @param {CodePathSegment} segment A segment to check.
* @returns {boolean} `true` if the segment is reachable.
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isReachable(segment) {
return segment.reachable;
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}

@@ -39,5 +47,5 @@

docs: {
description: "enforce `return` statements in getters",
description: "Enforce `return` statements in getters",
recommended: true,
url: "https://eslint.org/docs/rules/getter-return"
url: "https://eslint.org/docs/latest/rules/getter-return"
},

@@ -69,3 +77,3 @@

const options = context.options[0] || { allowImplicit: false };
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -77,3 +85,4 @@ let funcInfo = {

shouldCheck: false,
node: null
node: null,
currentSegments: []
};

@@ -92,3 +101,3 @@

if (funcInfo.shouldCheck &&
funcInfo.codePath.currentSegments.some(isReachable)
isAnySegmentReachable(funcInfo.currentSegments)
) {

@@ -120,14 +129,20 @@ context.report({

// Object.defineProperty()
if (parent.parent.parent.type === "CallExpression" &&
astUtils.getStaticPropertyName(parent.parent.parent.callee) === "defineProperty") {
return true;
// Object.defineProperty() or Reflect.defineProperty()
if (parent.parent.parent.type === "CallExpression") {
const callNode = parent.parent.parent.callee;
if (astUtils.isSpecificMemberAccess(callNode, "Object", "defineProperty") ||
astUtils.isSpecificMemberAccess(callNode, "Reflect", "defineProperty")) {
return true;
}
}
// Object.defineProperties()
// Object.defineProperties() or Object.create()
if (parent.parent.parent.type === "Property" &&
parent.parent.parent.parent.type === "ObjectExpression" &&
parent.parent.parent.parent.parent.type === "CallExpression" &&
astUtils.getStaticPropertyName(parent.parent.parent.parent.parent.callee) === "defineProperties") {
return true;
parent.parent.parent.parent.parent.type === "CallExpression") {
const callNode = parent.parent.parent.parent.parent.callee;
return astUtils.isSpecificMemberAccess(callNode, "Object", "defineProperties") ||
astUtils.isSpecificMemberAccess(callNode, "Object", "create");
}

@@ -147,3 +162,4 @@ }

shouldCheck: isGetter(node),
node
node,
currentSegments: new Set()
};

@@ -156,3 +172,18 @@ },

},
onUnreachableCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
onCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
// Checks the return statement is valid.

@@ -159,0 +190,0 @@ ReturnStatement(node) {

@@ -9,3 +9,3 @@ /**

const ACCEPTABLE_PARENTS = [
const ACCEPTABLE_PARENTS = new Set([
"AssignmentExpression",

@@ -20,3 +20,3 @@ "VariableDeclarator",

"ChainExpression"
];
]);

@@ -33,6 +33,7 @@ /**

/* istanbul ignore else: correctly returns null */
if (references.length === 1) {
return references[0];
}
/* c8 ignore next */
return null;

@@ -64,5 +65,5 @@

docs: {
description: "require `require()` calls to be placed at top-level module scope",
description: "Require `require()` calls to be placed at top-level module scope",
recommended: false,
url: "https://eslint.org/docs/rules/global-require"
url: "https://eslint.org/docs/latest/rules/global-require"
},

@@ -77,8 +78,10 @@

create(context) {
const sourceCode = context.sourceCode;
return {
CallExpression(node) {
const currentScope = context.getScope();
const currentScope = sourceCode.getScope(node);
if (node.callee.name === "require" && !isShadowed(currentScope, node.callee)) {
const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1);
const isGoodRequire = sourceCode.getAncestors(node).every(parent => ACCEPTABLE_PARENTS.has(parent.type));

@@ -85,0 +88,0 @@ if (!isGoodRequire) {

@@ -99,5 +99,5 @@ /**

docs: {
description: "require grouped accessor pairs in object literals and classes",
description: "Require grouped accessor pairs in object literals and classes",
recommended: false,
url: "https://eslint.org/docs/rules/grouped-accessor-pairs"
url: "https://eslint.org/docs/latest/rules/grouped-accessor-pairs"
},

@@ -119,3 +119,3 @@

const order = context.options[0] || "anyOrder";
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

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

/**
* Creates a new `AccessorData` object for the given getter or setter node.
* @param {ASTNode} node A getter or setter node.
* @returns {AccessorData} New `AccessorData` object that contains the given node.
* @private
*/
function createAccessorData(node) {
const name = astUtils.getStaticPropertyName(node);
const key = (name !== null) ? name : sourceCode.getTokens(node.key);
return {
key,
getters: node.kind === "get" ? [node] : [],
setters: node.kind === "set" ? [node] : []
};
}
/**
* Merges the given `AccessorData` object into the given accessors list.
* @param {AccessorData[]} accessors The list to merge into.
* @param {AccessorData} accessorData The object to merge.
* @returns {AccessorData[]} The same instance with the merged object.
* @private
*/
function mergeAccessorData(accessors, accessorData) {
const equalKeyElement = accessors.find(a => areEqualKeys(a.key, accessorData.key));
if (equalKeyElement) {
equalKeyElement.getters.push(...accessorData.getters);
equalKeyElement.setters.push(...accessorData.setters);
} else {
accessors.push(accessorData);
}
return accessors;
}
/**
* Checks accessor pairs in the given list of nodes.

@@ -188,8 +151,36 @@ * @param {ASTNode[]} nodes The list to check.

function checkList(nodes, shouldCheck) {
const accessors = nodes
.filter(shouldCheck)
.filter(isAccessorKind)
.map(createAccessorData)
.reduce(mergeAccessorData, []);
const accessors = [];
let found = false;
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (shouldCheck(node) && isAccessorKind(node)) {
// Creates a new `AccessorData` object for the given getter or setter node.
const name = astUtils.getStaticPropertyName(node);
const key = (name !== null) ? name : sourceCode.getTokens(node.key);
// Merges the given `AccessorData` object into the given accessors list.
for (let j = 0; j < accessors.length; j++) {
const accessor = accessors[j];
if (areEqualKeys(accessor.key, key)) {
accessor.getters.push(...node.kind === "get" ? [node] : []);
accessor.setters.push(...node.kind === "set" ? [node] : []);
found = true;
break;
}
}
if (!found) {
accessors.push({
key,
getters: node.kind === "get" ? [node] : [],
setters: node.kind === "set" ? [node] : []
});
}
found = false;
}
}
for (const { getters, setters } of accessors) {

@@ -196,0 +187,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "require `for-in` loops to include an `if` statement",
description: "Require `for-in` loops to include an `if` statement",
recommended: false,
url: "https://eslint.org/docs/rules/guard-for-in"
url: "https://eslint.org/docs/latest/rules/guard-for-in"
},

@@ -23,0 +23,0 @@

@@ -23,5 +23,5 @@ /**

docs: {
description: "require error handling in callbacks",
description: "Require error handling in callbacks",
recommended: false,
url: "https://eslint.org/docs/rules/handle-callback-err"
url: "https://eslint.org/docs/latest/rules/handle-callback-err"
},

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

const errorArgument = context.options[0] || "err";
const sourceCode = context.sourceCode;

@@ -84,3 +85,3 @@ /**

function checkForError(node) {
const scope = context.getScope(),
const scope = sourceCode.getScope(node),
parameters = getParameters(scope),

@@ -87,0 +88,0 @@ firstParameter = parameters[0];

@@ -122,5 +122,5 @@ /**

docs: {
description: "disallow specified identifiers",
description: "Disallow specified identifiers",
recommended: false,
url: "https://eslint.org/docs/rules/id-blacklist"
url: "https://eslint.org/docs/latest/rules/id-blacklist"
},

@@ -144,2 +144,3 @@

const reportedNodes = new Set();
const sourceCode = context.sourceCode;

@@ -236,4 +237,4 @@ let globalScope;

Program() {
globalScope = context.getScope();
Program(node) {
globalScope = sourceCode.getScope(node);
},

@@ -240,0 +241,0 @@

@@ -102,5 +102,5 @@ /**

docs: {
description: "disallow specified identifiers",
description: "Disallow specified identifiers",
recommended: false,
url: "https://eslint.org/docs/rules/id-denylist"
url: "https://eslint.org/docs/latest/rules/id-denylist"
},

@@ -125,2 +125,3 @@

const reportedNodes = new Set();
const sourceCode = context.sourceCode;

@@ -215,4 +216,4 @@ let globalScope;

Program() {
globalScope = context.getScope();
Program(node) {
globalScope = sourceCode.getScope(node);
},

@@ -219,0 +220,0 @@

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

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { getGraphemeCount } = require("../shared/string-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -20,5 +26,5 @@ //------------------------------------------------------------------------------

docs: {
description: "enforce minimum and maximum identifier lengths",
description: "Enforce minimum and maximum identifier lengths",
recommended: false,
url: "https://eslint.org/docs/rules/id-length"
url: "https://eslint.org/docs/latest/rules/id-length"
},

@@ -135,5 +141,7 @@

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

@@ -140,0 +148,0 @@ return; // Nothing to report

@@ -18,5 +18,5 @@ /**

docs: {
description: "require identifiers to match a specified regular expression",
description: "Require identifiers to match a specified regular expression",
recommended: false,
url: "https://eslint.org/docs/rules/id-match"
url: "https://eslint.org/docs/latest/rules/id-match"
},

@@ -71,2 +71,5 @@

const sourceCode = context.sourceCode;
let globalScope;
//--------------------------------------------------------------------------

@@ -83,2 +86,15 @@ // Helpers

/**
* Checks whether the given node represents a reference to a global variable that is not declared in the source code.
* These identifiers will be allowed, as it is assumed that user has no control over the names of external global variables.
* @param {ASTNode} node `Identifier` node to check.
* @returns {boolean} `true` if the node is a reference to a global variable.
*/
function isReferenceToGlobalVariable(node) {
const variable = globalScope.set.get(node.name);
return variable && variable.defs.length === 0 &&
variable.references.some(ref => ref.identifier === node);
}
/**
* Checks if a string matches the provided pattern

@@ -161,2 +177,6 @@ * @param {string} name The string to check.

Program(node) {
globalScope = sourceCode.getScope(node);
},
Identifier(node) {

@@ -167,2 +187,6 @@ const name = node.name,

if (isReferenceToGlobalVariable(node)) {
return;
}
if (parent.type === "MemberExpression") {

@@ -196,2 +220,13 @@

// For https://github.com/eslint/eslint/issues/15123
} else if (
parent.type === "Property" &&
parent.parent.type === "ObjectExpression" &&
parent.key === node &&
!parent.computed
) {
if (checkProperties && isInvalid(name)) {
report(node);
}
/*

@@ -225,3 +260,3 @@ * Properties have their own rules, and

// never check properties or always ignore destructuring
if (!checkProperties || (ignoreDestructuring && isInsideObjectPattern(node))) {
if ((!checkProperties && !parent.computed) || (ignoreDestructuring && isInsideObjectPattern(node))) {
return;

@@ -228,0 +263,0 @@ }

/**
* @fileoverview enforce the location of arrow function bodies
* @author Sharmila Jesupaul
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce the location of arrow function bodies",
description: "Enforce the location of arrow function bodies",
recommended: false,
url: "https://eslint.org/docs/rules/implicit-arrow-linebreak"
url: "https://eslint.org/docs/latest/rules/implicit-arrow-linebreak"
},

@@ -38,3 +41,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const option = context.options[0] || "beside";

@@ -41,0 +44,0 @@

@@ -21,4 +21,4 @@ /**

//------------------------------------------------------------------------------
/* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */
// this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway.
/* c8 ignore next */
/** @type {import('../shared/types').Rule} */

@@ -30,5 +30,5 @@ module.exports = {

docs: {
description: "enforce consistent indentation",
description: "Enforce consistent indentation",
recommended: false,
url: "https://eslint.org/docs/rules/indent-legacy"
url: "https://eslint.org/docs/latest/rules/indent-legacy"
},

@@ -211,3 +211,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -218,6 +218,6 @@ if (context.options.length) {

indentType = "tab";
} else /* istanbul ignore else : this will be caught by options validation */ if (typeof context.options[0] === "number") {
} else /* c8 ignore start */ if (typeof context.options[0] === "number") {
indentSize = context.options[0];
indentType = "space";
}
}/* c8 ignore stop */

@@ -760,3 +760,3 @@ if (context.options[1]) {

} else if (options.CallExpression.arguments === "first") {
if (parent.arguments.indexOf(node) !== -1) {
if (parent.arguments.includes(node)) {
nodeIndent = parent.arguments[0].loc.start.column;

@@ -848,3 +848,3 @@ }

if (node.parent && statementsWithProperties.indexOf(node.parent.type) !== -1 && isNodeBodyBlock(node)) {
if (node.parent && statementsWithProperties.includes(node.parent.type) && isNodeBodyBlock(node)) {
indent = getNodeIndent(node.parent).goodChar;

@@ -851,0 +851,0 @@ } else if (node.parent && node.parent.type === "CatchClause") {

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

"lines-between-class-members": () => require("./lines-between-class-members"),
"logical-assignment-operators": () => require("./logical-assignment-operators"),
"max-classes-per-file": () => require("./max-classes-per-file"),

@@ -107,2 +108,3 @@ "max-depth": () => require("./max-depth"),

"no-const-assign": () => require("./no-const-assign"),
"no-constant-binary-expression": () => require("./no-constant-binary-expression"),
"no-constant-condition": () => require("./no-constant-condition"),

@@ -126,2 +128,3 @@ "no-constructor-return": () => require("./no-constructor-return"),

"no-empty-pattern": () => require("./no-empty-pattern"),
"no-empty-static-block": () => require("./no-empty-static-block"),
"no-eq-null": () => require("./no-eq-null"),

@@ -171,2 +174,3 @@ "no-eval": () => require("./no-eval"),

"no-new-func": () => require("./no-new-func"),
"no-new-native-nonconstructor": () => require("./no-new-native-nonconstructor"),
"no-new-object": () => require("./no-new-object"),

@@ -178,2 +182,3 @@ "no-new-require": () => require("./no-new-require"),

"no-obj-calls": () => require("./no-obj-calls"),
"no-object-constructor": () => require("./no-object-constructor"),
"no-octal": () => require("./no-octal"),

@@ -263,2 +268,3 @@ "no-octal-escape": () => require("./no-octal-escape"),

"prefer-numeric-literals": () => require("./prefer-numeric-literals"),
"prefer-object-has-own": () => require("./prefer-object-has-own"),
"prefer-object-spread": () => require("./prefer-object-spread"),

@@ -265,0 +271,0 @@ "prefer-promise-reject-errors": () => require("./prefer-promise-reject-errors"),

@@ -51,5 +51,5 @@ /**

docs: {
description: "require or disallow initialization in variable declarations",
description: "Require or disallow initialization in variable declarations",
recommended: false,
url: "https://eslint.org/docs/rules/init-declarations"
url: "https://eslint.org/docs/latest/rules/init-declarations"
},

@@ -56,0 +56,0 @@

/**
* @fileoverview A rule to ensure consistent quotes used in jsx syntax.
* @author Mathias Schreck <https://github.com/lo1tuma>
* @deprecated in ESLint v8.53.0
*/

@@ -42,8 +43,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce the consistent use of either double or single quotes in JSX attributes",
description: "Enforce the consistent use of either double or single quotes in JSX attributes",
recommended: false,
url: "https://eslint.org/docs/rules/jsx-quotes"
url: "https://eslint.org/docs/latest/rules/jsx-quotes"
},

@@ -74,3 +77,3 @@

function usesExpectedQuotes(node) {
return node.value.indexOf(setting.quote) !== -1 || astUtils.isSurroundedBy(node.raw, setting.quote);
return node.value.includes(setting.quote) || astUtils.isSurroundedBy(node.raw, setting.quote);
}

@@ -77,0 +80,0 @@

/**
* @fileoverview Rule to specify spacing of object literal keys and values
* @author Brandon Mills
* @deprecated in ESLint v8.53.0
*/

@@ -12,7 +13,4 @@ "use strict";

const astUtils = require("./utils/ast-utils");
const { getGraphemeCount } = require("../shared/string-utils");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**

@@ -140,8 +138,10 @@ * Checks whether a string contains a line terminator as defined in

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing between keys and values in object literal properties",
description: "Enforce consistent spacing between keys and values in object literal properties",
recommended: false,
url: "https://eslint.org/docs/rules/key-spacing"
url: "https://eslint.org/docs/latest/rules/key-spacing"
},

@@ -334,5 +334,52 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
/**
* Determines if the given property is key-value property.
* @param {ASTNode} property Property node to check.
* @returns {boolean} Whether the property is a key-value property.
*/
function isKeyValueProperty(property) {
return !(
(property.method ||
property.shorthand ||
property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadElement"
);
}
/**
* Starting from the given node (a property.key node here) looks forward
* until it finds the colon punctuator and returns it.
* @param {ASTNode} node The node to start looking from.
* @returns {ASTNode} The colon punctuator.
*/
function getNextColon(node) {
return sourceCode.getTokenAfter(node, astUtils.isColonToken);
}
/**
* Starting from the given node (a property.key node here) looks forward
* until it finds the last token before a colon punctuator and returns it.
* @param {ASTNode} node The node to start looking from.
* @returns {ASTNode} The last token before a colon punctuator.
*/
function getLastTokenBeforeColon(node) {
const colonToken = getNextColon(node);
return sourceCode.getTokenBefore(colonToken);
}
/**
* Starting from the given node (a property.key node here) looks forward
* until it finds the first token after a colon punctuator and returns it.
* @param {ASTNode} node The node to start looking from.
* @returns {ASTNode} The first token after a colon punctuator.
*/
function getFirstTokenAfterColon(node) {
const colonToken = getNextColon(node);
return sourceCode.getTokenAfter(colonToken);
}
/**
* Checks whether a property is a member of the property group it follows.

@@ -345,5 +392,5 @@ * @param {ASTNode} lastMember The last Property known to be in the group.

const groupEndLine = lastMember.loc.start.line,
candidateStartLine = candidate.loc.start.line;
candidateValueStartLine = (isKeyValueProperty(candidate) ? getFirstTokenAfterColon(candidate.key) : candidate).loc.start.line;
if (candidateStartLine - groupEndLine <= 1) {
if (candidateValueStartLine - groupEndLine <= 1) {
return true;

@@ -362,3 +409,3 @@ }

leadingComments[0].loc.start.line - groupEndLine <= 1 &&
candidateStartLine - last(leadingComments).loc.end.line <= 1
candidateValueStartLine - last(leadingComments).loc.end.line <= 1
) {

@@ -377,37 +424,2 @@ for (let i = 1; i < leadingComments.length; i++) {

/**
* Determines if the given property is key-value property.
* @param {ASTNode} property Property node to check.
* @returns {boolean} Whether the property is a key-value property.
*/
function isKeyValueProperty(property) {
return !(
(property.method ||
property.shorthand ||
property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadElement"
);
}
/**
* Starting from the given a node (a property.key node here) looks forward
* until it finds the last token before a colon punctuator and returns it.
* @param {ASTNode} node The node to start looking from.
* @returns {ASTNode} The last token before a colon punctuator.
*/
function getLastTokenBeforeColon(node) {
const colonToken = sourceCode.getTokenAfter(node, astUtils.isColonToken);
return sourceCode.getTokenBefore(colonToken);
}
/**
* Starting from the given a node (a property.key node here) looks forward
* until it finds the colon punctuator and returns it.
* @param {ASTNode} node The node to start looking from.
* @returns {ASTNode} The colon punctuator.
*/
function getNextColon(node) {
return sourceCode.getTokenAfter(node, astUtils.isColonToken);
}
/**
* Gets an object literal property's key as the identifier name or string value.

@@ -517,3 +529,3 @@ * @param {ASTNode} property Property node whose key to retrieve.

return endToken.range[1] - startToken.range[0];
return getGraphemeCount(sourceCode.getText().slice(startToken.range[0], endToken.range[1]));
}

@@ -520,0 +532,0 @@

/**
* @fileoverview Rule to enforce spacing before and after keywords.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -67,8 +68,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before and after keywords",
description: "Enforce consistent spacing before and after keywords",
recommended: false,
url: "https://eslint.org/docs/rules/keyword-spacing"
url: "https://eslint.org/docs/latest/rules/keyword-spacing"
},

@@ -112,3 +115,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -474,2 +477,3 @@ const tokensToIgnore = new WeakSet();

checkSpacingBefore(asToken, PREV_TOKEN_M);
checkSpacingAfter(asToken, NEXT_TOKEN_M);
}

@@ -488,2 +492,31 @@

* keyword is invalid.
* @param {ASTNode} node An `ImportSpecifier` node to check.
* @returns {void}
*/
function checkSpacingForImportSpecifier(node) {
if (node.imported.range[0] !== node.local.range[0]) {
const asToken = sourceCode.getTokenBefore(node.local);
checkSpacingBefore(asToken, PREV_TOKEN_M);
}
}
/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
* @param {ASTNode} node An `ExportSpecifier` node to check.
* @returns {void}
*/
function checkSpacingForExportSpecifier(node) {
if (node.local.range[0] !== node.exported.range[0]) {
const asToken = sourceCode.getTokenBefore(node.exported);
checkSpacingBefore(asToken, PREV_TOKEN_M);
checkSpacingAfter(asToken, NEXT_TOKEN_M);
}
}
/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
* @param {ASTNode} node A node to report.

@@ -595,2 +628,4 @@ * @returns {void}

// Others
ImportSpecifier: checkSpacingForImportSpecifier,
ExportSpecifier: checkSpacingForExportSpecifier,
ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,

@@ -597,0 +632,0 @@ MethodDefinition: checkSpacingForProperty,

@@ -19,5 +19,5 @@ /**

docs: {
description: "enforce position of line comments",
description: "Enforce position of line comments",
recommended: false,
url: "https://eslint.org/docs/rules/line-comment-position"
url: "https://eslint.org/docs/latest/rules/line-comment-position"
},

@@ -82,3 +82,3 @@

const customIgnoreRegExp = new RegExp(ignorePattern, "u");
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -85,0 +85,0 @@ //--------------------------------------------------------------------------

/**
* @fileoverview Rule to enforce a single linebreak style.
* @author Erik Mueller
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent linebreak style",
description: "Enforce consistent linebreak style",
recommended: false,
url: "https://eslint.org/docs/rules/linebreak-style"
url: "https://eslint.org/docs/latest/rules/linebreak-style"
},

@@ -44,3 +47,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -47,0 +50,0 @@ //--------------------------------------------------------------------------

/**
* @fileoverview Enforces empty lines around comments.
* @author Jamund Ferguson
* @deprecated in ESLint v8.53.0
*/

@@ -18,3 +19,3 @@ "use strict";

/**
* 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 +34,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.

@@ -57,8 +58,10 @@ * @returns {Array} An array of line numbers.

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require empty lines around comments",
description: "Require empty lines around comments",
recommended: false,
url: "https://eslint.org/docs/rules/lines-around-comment"
url: "https://eslint.org/docs/latest/rules/lines-around-comment"
},

@@ -119,2 +122,6 @@

type: "boolean"
},
afterHashbangComment: {
type: "boolean",
default: false
}

@@ -141,3 +148,3 @@ },

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -149,3 +156,3 @@ const lines = sourceCode.lines,

emptyLines = getEmptyLineNums(lines),
commentAndEmptyLines = commentLines.concat(emptyLines);
commentAndEmptyLines = new Set(commentLines.concat(emptyLines));

@@ -240,6 +247,12 @@ /**

if (parent && isParentNodeType(parent, nodeType)) {
const parentStartNodeOrToken = parent.type === "StaticBlock"
? sourceCode.getFirstToken(parent, { skip: 1 }) // opening brace of the static block
: parent;
let parentStartNodeOrToken = parent;
if (parent.type === "StaticBlock") {
parentStartNodeOrToken = sourceCode.getFirstToken(parent, { skip: 1 }); // opening brace of the static block
} else if (parent.type === "SwitchStatement") {
parentStartNodeOrToken = sourceCode.getTokenAfter(parent.discriminant, {
filter: astUtils.isOpeningBraceToken
}); // opening brace of the switch statement
}
return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;

@@ -274,3 +287,4 @@ }

isCommentAtParentStart(token, "StaticBlock") ||
isCommentAtParentStart(token, "SwitchCase")
isCommentAtParentStart(token, "SwitchCase") ||
isCommentAtParentStart(token, "SwitchStatement")
);

@@ -404,3 +418,3 @@ }

// check for newline before
if (!exceptionStartAllowed && before && !commentAndEmptyLines.includes(prevLineNum) &&
if (!exceptionStartAllowed && before && !commentAndEmptyLines.has(prevLineNum) &&
!(astUtils.isCommentToken(previousTokenOrComment) && astUtils.isTokenOnSameLine(previousTokenOrComment, token))) {

@@ -420,3 +434,3 @@ const lineStart = token.range[0] - token.loc.start.column;

// check for newline after
if (!exceptionEndAllowed && after && !commentAndEmptyLines.includes(nextLineNum) &&
if (!exceptionEndAllowed && after && !commentAndEmptyLines.has(nextLineNum) &&
!(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) {

@@ -455,2 +469,9 @@ context.report({

}
} else if (token.type === "Shebang") {
if (options.afterHashbangComment) {
checkForEmptyLine(token, {
after: options.afterHashbangComment,
before: false
});
}
}

@@ -457,0 +478,0 @@ });

@@ -21,5 +21,5 @@ /**

docs: {
description: "require or disallow newlines around directives",
description: "Require or disallow newlines around directives",
recommended: false,
url: "https://eslint.org/docs/rules/lines-around-directive"
url: "https://eslint.org/docs/latest/rules/lines-around-directive"
},

@@ -58,3 +58,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const config = context.options[0] || "always";

@@ -61,0 +61,0 @@ const expectLineBefore = typeof config === "string" ? config : config.before;

/**
* @fileoverview Rule to check empty newline between class members
* @author 薛定谔的猫<hh_2013@foxmail.com>
* @deprecated in ESLint v8.53.0
*/

@@ -14,2 +15,17 @@ "use strict";

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Types of class members.
* Those have `test` method to check it matches to the given class member.
* @private
*/
const ClassMemberTypes = {
"*": { test: () => true },
field: { test: node => node.type === "PropertyDefinition" },
method: { test: node => node.type === "MethodDefinition" }
};
//------------------------------------------------------------------------------
// Rule Definition

@@ -21,8 +37,10 @@ //------------------------------------------------------------------------------

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow an empty line between class members",
description: "Require or disallow an empty line between class members",
recommended: false,
url: "https://eslint.org/docs/rules/lines-between-class-members"
url: "https://eslint.org/docs/latest/rules/lines-between-class-members"
},

@@ -34,3 +52,28 @@

{
enum: ["always", "never"]
anyOf: [
{
type: "object",
properties: {
enforce: {
type: "array",
items: {
type: "object",
properties: {
blankLine: { enum: ["always", "never"] },
prev: { enum: ["method", "field", "*"] },
next: { enum: ["method", "field", "*"] }
},
additionalProperties: false,
required: ["blankLine", "prev", "next"]
},
minItems: 1
}
},
additionalProperties: false,
required: ["enforce"]
},
{
enum: ["always", "never"]
}
]
},

@@ -61,3 +104,4 @@ {

const sourceCode = context.getSourceCode();
const configureList = typeof options[0] === "object" ? options[0].enforce : [{ blankLine: options[0], prev: "*", next: "*" }];
const sourceCode = context.sourceCode;

@@ -151,2 +195,34 @@ /**

/**
* Checks whether the given node matches the given type.
* @param {ASTNode} node The class member node to check.
* @param {string} type The class member type to check.
* @returns {boolean} `true` if the class member node matched the type.
* @private
*/
function match(node, type) {
return ClassMemberTypes[type].test(node);
}
/**
* Finds the last matched configuration from the configureList.
* @param {ASTNode} prevNode The previous node to match.
* @param {ASTNode} nextNode The current node to match.
* @returns {string|null} Padding type or `null` if no matches were found.
* @private
*/
function getPaddingType(prevNode, nextNode) {
for (let i = configureList.length - 1; i >= 0; --i) {
const configure = configureList[i];
const matched =
match(prevNode, configure.prev) &&
match(nextNode, configure.next);
if (matched) {
return configure.blankLine;
}
}
return null;
}
return {

@@ -166,8 +242,9 @@ ClassBody(node) {

const curLineLastToken = findLastConsecutiveTokenAfter(curLast, nextFirst, 0);
const paddingType = getPaddingType(body[i], body[i + 1]);
if ((options[0] === "always" && !skip && !isPadded) ||
(options[0] === "never" && isPadded)) {
if (paddingType === "never" && isPadded) {
context.report({
node: body[i + 1],
messageId: isPadded ? "never" : "always",
messageId: "never",
fix(fixer) {

@@ -177,8 +254,19 @@ if (hasTokenInPadding) {

}
return isPadded
? fixer.replaceTextRange([beforePadding.range[1], afterPadding.range[0]], "\n")
: fixer.insertTextAfter(curLineLastToken, "\n");
return fixer.replaceTextRange([beforePadding.range[1], afterPadding.range[0]], "\n");
}
});
} else if (paddingType === "always" && !skip && !isPadded) {
context.report({
node: body[i + 1],
messageId: "always",
fix(fixer) {
if (hasTokenInPadding) {
return null;
}
return fixer.insertTextAfter(curLineLastToken, "\n");
}
});
}
}

@@ -185,0 +273,0 @@ }

@@ -22,5 +22,5 @@ /**

docs: {
description: "enforce a maximum number of classes per file",
description: "Enforce a maximum number of classes per file",
recommended: false,
url: "https://eslint.org/docs/rules/max-classes-per-file"
url: "https://eslint.org/docs/latest/rules/max-classes-per-file"
},

@@ -27,0 +27,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "enforce a maximum depth that blocks can be nested",
description: "Enforce a maximum depth that blocks can be nested",
recommended: false,
url: "https://eslint.org/docs/rules/max-depth"
url: "https://eslint.org/docs/latest/rules/max-depth"
},

@@ -23,0 +23,0 @@

/**
* @fileoverview Rule to check for max length on a line.
* @author Matt DuVall <http://www.mattduvall.com>
* @deprecated in ESLint v8.53.0
*/

@@ -69,8 +70,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce a maximum line length",
description: "Enforce a maximum line length",
recommended: false,
url: "https://eslint.org/docs/rules/max-len"
url: "https://eslint.org/docs/latest/rules/max-len"
},

@@ -101,3 +104,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -257,15 +260,19 @@ /**

/**
* A reducer to group an AST node by line number, both start and end.
* @param {Object} acc the accumulator
* @param {ASTNode} node the AST node in question
* @returns {Object} the modified accumulator
* @private
*
* reduce an array of AST nodes by line number, both start and end.
* @param {ASTNode[]} arr array of AST nodes
* @returns {Object} accululated AST nodes
*/
function groupByLineNumber(acc, node) {
for (let i = node.loc.start.line; i <= node.loc.end.line; ++i) {
ensureArrayAndPush(acc, i, node);
function groupArrayByLineNumber(arr) {
const obj = {};
for (let i = 0; i < arr.length; i++) {
const node = arr[i];
for (let j = node.loc.start.line; j <= node.loc.end.line; ++j) {
ensureArrayAndPush(obj, j, node);
}
}
return acc;
return obj;
}

@@ -318,9 +325,9 @@

const strings = getAllStrings();
const stringsByLine = strings.reduce(groupByLineNumber, {});
const stringsByLine = groupArrayByLineNumber(strings);
const templateLiterals = getAllTemplateLiterals();
const templateLiteralsByLine = templateLiterals.reduce(groupByLineNumber, {});
const templateLiteralsByLine = groupArrayByLineNumber(templateLiterals);
const regExpLiterals = getAllRegExpLiterals();
const regExpLiteralsByLine = regExpLiterals.reduce(groupByLineNumber, {});
const regExpLiteralsByLine = groupArrayByLineNumber(regExpLiterals);

@@ -327,0 +334,0 @@ lines.forEach((line, i) => {

@@ -74,5 +74,5 @@ /**

docs: {
description: "enforce a maximum number of lines of code in a function",
description: "Enforce a maximum number of lines of code in a function",
recommended: false,
url: "https://eslint.org/docs/rules/max-lines-per-function"
url: "https://eslint.org/docs/latest/rules/max-lines-per-function"
},

@@ -89,3 +89,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const lines = sourceCode.lines;

@@ -92,0 +92,0 @@

@@ -37,5 +37,5 @@ /**

docs: {
description: "enforce a maximum number of lines per file",
description: "Enforce a maximum number of lines per file",
recommended: false,
url: "https://eslint.org/docs/rules/max-lines"
url: "https://eslint.org/docs/latest/rules/max-lines"
},

@@ -91,3 +91,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -164,6 +164,6 @@ /**

const commentLines = comments.flatMap(getLinesWithoutCode);
const commentLines = new Set(comments.flatMap(getLinesWithoutCode));
lines = lines.filter(
l => !commentLines.includes(l.lineNumber)
l => !commentLines.has(l.lineNumber)
);

@@ -170,0 +170,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "enforce a maximum depth that callbacks can be nested",
description: "Enforce a maximum depth that callbacks can be nested",
recommended: false,
url: "https://eslint.org/docs/rules/max-nested-callbacks"
url: "https://eslint.org/docs/latest/rules/max-nested-callbacks"
},

@@ -23,0 +23,0 @@

@@ -25,5 +25,5 @@ /**

docs: {
description: "enforce a maximum number of parameters in function definitions",
description: "Enforce a maximum number of parameters in function definitions",
recommended: false,
url: "https://eslint.org/docs/rules/max-params"
url: "https://eslint.org/docs/latest/rules/max-params"
},

@@ -61,3 +61,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const option = context.options[0];

@@ -64,0 +64,0 @@ let numParams = 3;

/**
* @fileoverview Specify the maximum number of statements allowed per line.
* @author Kenneth Williams
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce a maximum number of statements allowed per line",
description: "Enforce a maximum number of statements allowed per line",
recommended: false,
url: "https://eslint.org/docs/rules/max-statements-per-line"
url: "https://eslint.org/docs/latest/rules/max-statements-per-line"
},

@@ -49,3 +52,3 @@

const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
options = context.options[0] || {},

@@ -52,0 +55,0 @@ maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1;

@@ -25,5 +25,5 @@ /**

docs: {
description: "enforce a maximum number of statements allowed in function blocks",
description: "Enforce a maximum number of statements allowed in function blocks",
recommended: false,
url: "https://eslint.org/docs/rules/max-statements"
url: "https://eslint.org/docs/latest/rules/max-statements"
},

@@ -130,3 +130,3 @@

* This rule does not apply to class static blocks, but we have to track them so
* that stataments in them do not count as statements in the enclosing function.
* that statements in them do not count as statements in the enclosing function.
*/

@@ -133,0 +133,0 @@ if (node.type === "StaticBlock") {

@@ -19,9 +19,39 @@ /**

docs: {
description: "enforce a particular style for multiline comments",
description: "Enforce a particular style for multiline comments",
recommended: false,
url: "https://eslint.org/docs/rules/multiline-comment-style"
url: "https://eslint.org/docs/latest/rules/multiline-comment-style"
},
fixable: "whitespace",
schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }],
schema: {
anyOf: [
{
type: "array",
items: [
{
enum: ["starred-block", "bare-block"]
}
],
additionalItems: false
},
{
type: "array",
items: [
{
enum: ["separate-lines"]
},
{
type: "object",
properties: {
checkJSDoc: {
type: "boolean"
}
},
additionalProperties: false
}
],
additionalItems: false
}
]
},
messages: {

@@ -39,4 +69,6 @@ expectedBlock: "Expected a block comment instead of consecutive line comments.",

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const option = context.options[0] || "starred-block";
const params = context.options[1] || {};
const checkJSDoc = !!params.checkJSDoc;

@@ -338,7 +370,14 @@ //----------------------------------------------------------------------

if (firstComment.type !== "Block" || isJSDocComment(commentGroup)) {
const isJSDoc = isJSDocComment(commentGroup);
if (firstComment.type !== "Block" || (!checkJSDoc && isJSDoc)) {
return;
}
const commentLines = getCommentLines(commentGroup);
let commentLines = getCommentLines(commentGroup);
if (isJSDoc) {
commentLines = commentLines.slice(1, commentLines.length - 1);
}
const tokenAfter = sourceCode.getTokenAfter(firstComment, { includeComments: true });

@@ -345,0 +384,0 @@

/**
* @fileoverview Enforce newlines between operands of ternary expressions
* @author Kai Cataldo
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce newlines between operands of ternary expressions",
description: "Enforce newlines between operands of ternary expressions",
recommended: false,
url: "https://eslint.org/docs/rules/multiline-ternary"
url: "https://eslint.org/docs/latest/rules/multiline-ternary"
},

@@ -43,3 +46,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const option = context.options[0];

@@ -78,3 +81,3 @@ const multiline = option !== "never";

messageId: "unexpectedTestCons",
fix: fixer => {
fix(fixer) {
if (hasComments) {

@@ -107,3 +110,3 @@ return null;

messageId: "unexpectedConsAlt",
fix: fixer => {
fix(fixer) {
if (hasComments) {

@@ -110,0 +113,0 @@ return null;

@@ -42,6 +42,6 @@ /**

/* istanbul ignore if */
/* c8 ignore start */
if (Object.prototype.hasOwnProperty.call(obj, key) && !Array.isArray(obj[key])) {
throw new TypeError(`${key}, if provided, must be an Array`);
}
}/* c8 ignore stop */
return obj[key] || fallback;

@@ -86,5 +86,5 @@ }

docs: {
description: "require constructor names to begin with a capital letter",
description: "Require constructor names to begin with a capital letter",
recommended: false,
url: "https://eslint.org/docs/rules/new-cap"
url: "https://eslint.org/docs/latest/rules/new-cap"
},

@@ -152,3 +152,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -155,0 +155,0 @@ //--------------------------------------------------------------------------

/**
* @fileoverview Rule to flag when using constructor without parentheses
* @author Ilya Volodin
* @deprecated in ESLint v8.53.0
*/

@@ -25,25 +26,18 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce or disallow parentheses when invoking a constructor with no arguments",
description: "Enforce or disallow parentheses when invoking a constructor with no arguments",
recommended: false,
url: "https://eslint.org/docs/rules/new-parens"
url: "https://eslint.org/docs/latest/rules/new-parens"
},
fixable: "code",
schema: {
anyOf: [
{
type: "array",
items: [
{
enum: ["always", "never"]
}
],
minItems: 0,
maxItems: 1
}
]
},
schema: [
{
enum: ["always", "never"]
}
],
messages: {

@@ -59,3 +53,3 @@ missing: "Missing '()' invoking a constructor.",

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -62,0 +56,0 @@ return {

@@ -25,5 +25,5 @@ /**

docs: {
description: "require or disallow an empty line after variable declarations",
description: "Require or disallow an empty line after variable declarations",
recommended: false,
url: "https://eslint.org/docs/rules/newline-after-var"
url: "https://eslint.org/docs/latest/rules/newline-after-var"
},

@@ -47,3 +47,3 @@ schema: [

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -217,3 +217,2 @@ // Default `mode` to "always".

messageId: "unexpected",
data: { identifier: node.name },
fix(fixer) {

@@ -237,3 +236,2 @@ const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);

messageId: "expected",
data: { identifier: node.name },
fix(fixer) {

@@ -240,0 +238,0 @@ if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {

@@ -18,5 +18,5 @@ /**

docs: {
description: "require an empty line before `return` statements",
description: "Require an empty line before `return` statements",
recommended: false,
url: "https://eslint.org/docs/rules/newline-before-return"
url: "https://eslint.org/docs/latest/rules/newline-before-return"
},

@@ -35,3 +35,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -52,3 +52,3 @@ //--------------------------------------------------------------------------

return testTokens.some(token => tokenBefore.value === token);
return testTokens.includes(tokenBefore.value);
}

@@ -55,0 +55,0 @@

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

* @author Burak Yigit Kaya
* @deprecated in ESLint v8.53.0
*/

@@ -19,8 +20,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require a newline after each call in a method chain",
description: "Require a newline after each call in a method chain",
recommended: false,
url: "https://eslint.org/docs/rules/newline-per-chained-call"
url: "https://eslint.org/docs/latest/rules/newline-per-chained-call"
},

@@ -52,3 +55,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -55,0 +58,0 @@ /**

@@ -91,5 +91,5 @@ /**

docs: {
description: "disallow the use of `alert`, `confirm`, and `prompt`",
description: "Disallow the use of `alert`, `confirm`, and `prompt`",
recommended: false,
url: "https://eslint.org/docs/rules/no-alert"
url: "https://eslint.org/docs/latest/rules/no-alert"
},

@@ -105,6 +105,8 @@

create(context) {
const sourceCode = context.sourceCode;
return {
CallExpression(node) {
const callee = skipChainExpression(node.callee),
currentScope = context.getScope();
currentScope = sourceCode.getScope(node);

@@ -111,0 +113,0 @@ // without window.

@@ -9,2 +9,14 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const {
getVariableByName,
isClosingParenToken,
isOpeningParenToken,
isStartOfExpressionStatement,
needsPrecedingSemicolon
} = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,11 +31,15 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow `Array` constructors",
description: "Disallow `Array` constructors",
recommended: false,
url: "https://eslint.org/docs/rules/no-array-constructor"
url: "https://eslint.org/docs/latest/rules/no-array-constructor"
},
hasSuggestions: true,
schema: [],
messages: {
preferLiteral: "The array literal notation [] is preferable."
preferLiteral: "The array literal notation [] is preferable.",
useLiteral: "Replace with an array literal.",
useLiteralAfterSemicolon: "Replace with an array literal, add preceding semicolon."
}

@@ -34,3 +50,29 @@ },

const sourceCode = context.sourceCode;
/**
* Gets the text between the calling parentheses of a CallExpression or NewExpression.
* @param {ASTNode} node A CallExpression or NewExpression node.
* @returns {string} The text between the calling parentheses, or an empty string if there are none.
*/
function getArgumentsText(node) {
const lastToken = sourceCode.getLastToken(node);
if (!isClosingParenToken(lastToken)) {
return "";
}
let firstToken = node.callee;
do {
firstToken = sourceCode.getTokenAfter(firstToken);
if (!firstToken || firstToken === lastToken) {
return "";
}
} while (!isOpeningParenToken(firstToken));
return sourceCode.text.slice(firstToken.range[1], lastToken.range[0]);
}
/**
* Disallow construction of dense arrays using the Array constructor

@@ -43,8 +85,45 @@ * @param {ASTNode} node node to evaluate

if (
node.arguments.length !== 1 &&
node.callee.type === "Identifier" &&
node.callee.name === "Array"
) {
context.report({ node, messageId: "preferLiteral" });
node.callee.type !== "Identifier" ||
node.callee.name !== "Array" ||
node.arguments.length === 1 &&
node.arguments[0].type !== "SpreadElement") {
return;
}
const variable = getVariableByName(sourceCode.getScope(node), "Array");
/*
* Check if `Array` is a predefined global variable: predefined globals have no declarations,
* meaning that the `identifiers` list of the variable object is empty.
*/
if (variable && variable.identifiers.length === 0) {
const argsText = getArgumentsText(node);
let fixText;
let messageId;
/*
* Check if the suggested change should include a preceding semicolon or not.
* Due to JavaScript's ASI rules, a missing semicolon may be inserted automatically
* before an expression like `Array()` or `new Array()`, but not when the expression
* is changed into an array literal like `[]`.
*/
if (isStartOfExpressionStatement(node) && needsPrecedingSemicolon(sourceCode, node)) {
fixText = `;[${argsText}]`;
messageId = "useLiteralAfterSemicolon";
} else {
fixText = `[${argsText}]`;
messageId = "useLiteral";
}
context.report({
node,
messageId: "preferLiteral",
suggest: [
{
messageId,
fix: fixer => fixer.replaceText(node, fixText)
}
]
});
}
}

@@ -51,0 +130,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow using an async function as a Promise executor",
description: "Disallow using an async function as a Promise executor",
recommended: true,
url: "https://eslint.org/docs/rules/no-async-promise-executor"
url: "https://eslint.org/docs/latest/rules/no-async-promise-executor"
},

@@ -34,3 +34,3 @@

context.report({
node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"),
node: context.sourceCode.getFirstToken(node.arguments[0], token => token.value === "async"),
messageId: "async"

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

@@ -62,5 +62,5 @@ /**

docs: {
description: "disallow `await` inside of loops",
description: "Disallow `await` inside of loops",
recommended: false,
url: "https://eslint.org/docs/rules/no-await-in-loop"
url: "https://eslint.org/docs/latest/rules/no-await-in-loop"
},

@@ -67,0 +67,0 @@

@@ -29,5 +29,5 @@ /**

docs: {
description: "disallow bitwise operators",
description: "Disallow bitwise operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-bitwise"
url: "https://eslint.org/docs/latest/rules/no-bitwise"
},

@@ -80,3 +80,3 @@

function hasBitwiseOperator(node) {
return BITWISE_OPERATORS.indexOf(node.operator) !== -1;
return BITWISE_OPERATORS.includes(node.operator);
}

@@ -90,3 +90,3 @@

function allowedOperator(node) {
return allowed.indexOf(node.operator) !== -1;
return allowed.includes(node.operator);
}

@@ -93,0 +93,0 @@

@@ -22,5 +22,5 @@ /**

docs: {
description: "disallow use of the `Buffer()` constructor",
description: "Disallow use of the `Buffer()` constructor",
recommended: false,
url: "https://eslint.org/docs/rules/no-buffer-constructor"
url: "https://eslint.org/docs/latest/rules/no-buffer-constructor"
},

@@ -27,0 +27,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow the use of `arguments.caller` or `arguments.callee`",
description: "Disallow the use of `arguments.caller` or `arguments.callee`",
recommended: false,
url: "https://eslint.org/docs/rules/no-caller"
url: "https://eslint.org/docs/latest/rules/no-caller"
},

@@ -23,0 +23,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow lexical declarations in case clauses",
description: "Disallow lexical declarations in case clauses",
recommended: true,
url: "https://eslint.org/docs/rules/no-case-declarations"
url: "https://eslint.org/docs/latest/rules/no-case-declarations"
},

@@ -22,0 +22,0 @@

@@ -25,5 +25,5 @@ /**

docs: {
description: "disallow `catch` clause parameters from shadowing variables in the outer scope",
description: "Disallow `catch` clause parameters from shadowing variables in the outer scope",
recommended: false,
url: "https://eslint.org/docs/rules/no-catch-shadow"
url: "https://eslint.org/docs/latest/rules/no-catch-shadow"
},

@@ -43,2 +43,4 @@

const sourceCode = context.sourceCode;
//--------------------------------------------------------------------------

@@ -65,3 +67,3 @@ // Helpers

"CatchClause[param!=null]"(node) {
let scope = context.getScope();
let scope = sourceCode.getScope(node);

@@ -68,0 +70,0 @@ /*

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow reassigning class members",
description: "Disallow reassigning class members",
recommended: true,
url: "https://eslint.org/docs/rules/no-class-assign"
url: "https://eslint.org/docs/latest/rules/no-class-assign"
},

@@ -35,2 +35,4 @@

const sourceCode = context.sourceCode;
/**

@@ -54,3 +56,3 @@ * Finds and reports references that are non initializer and writable.

function checkForClass(node) {
context.getDeclaredVariables(node).forEach(checkVariable);
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}

@@ -57,0 +59,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow comparing against -0",
description: "Disallow comparing against -0",
recommended: true,
url: "https://eslint.org/docs/rules/no-compare-neg-zero"
url: "https://eslint.org/docs/latest/rules/no-compare-neg-zero"
},

@@ -22,0 +22,0 @@

@@ -37,5 +37,5 @@ /**

docs: {
description: "disallow assignment operators in conditional expressions",
description: "Disallow assignment operators in conditional expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-cond-assign"
url: "https://eslint.org/docs/latest/rules/no-cond-assign"
},

@@ -61,3 +61,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -64,0 +64,0 @@ /**

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

* @author Jxck <https://github.com/Jxck>
* @deprecated in ESLint v8.53.0
*/

@@ -32,8 +33,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "disallow arrow functions where they could be confused with comparisons",
description: "Disallow arrow functions where they could be confused with comparisons",
recommended: false,
url: "https://eslint.org/docs/rules/no-confusing-arrow"
url: "https://eslint.org/docs/latest/rules/no-confusing-arrow"
},

@@ -46,3 +49,4 @@

properties: {
allowParens: { type: "boolean", default: true }
allowParens: { type: "boolean", default: true },
onlyOneSimpleParam: { type: "boolean", default: false }
},

@@ -60,3 +64,4 @@ additionalProperties: false

const allowParens = config.allowParens || (config.allowParens === void 0);
const sourceCode = context.getSourceCode();
const onlyOneSimpleParam = config.onlyOneSimpleParam;
const sourceCode = context.sourceCode;

@@ -72,3 +77,5 @@

if (isConditional(body) && !(allowParens && astUtils.isParenthesised(sourceCode, body))) {
if (isConditional(body) &&
!(allowParens && astUtils.isParenthesised(sourceCode, body)) &&
!(onlyOneSimpleParam && !(node.params.length === 1 && node.params[0].type === "Identifier"))) {
context.report({

@@ -75,0 +82,0 @@ node,

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow the use of `console`",
description: "Disallow the use of `console`",
recommended: false,
url: "https://eslint.org/docs/rules/no-console"
url: "https://eslint.org/docs/latest/rules/no-console"
},

@@ -47,4 +47,7 @@

hasSuggestions: true,
messages: {
unexpected: "Unexpected console statement."
unexpected: "Unexpected console statement.",
removeConsole: "Remove the console.{{ propertyName }}()."
}

@@ -56,2 +59,3 @@ },

const allowed = options.allow || [];
const sourceCode = context.sourceCode;

@@ -78,3 +82,3 @@ /**

return propertyName && allowed.indexOf(propertyName) !== -1;
return propertyName && allowed.includes(propertyName);
}

@@ -101,2 +105,60 @@

/**
* Checks if removing the ExpressionStatement node will cause ASI to
* break.
* eg.
* foo()
* console.log();
* [1, 2, 3].forEach(a => doSomething(a))
*
* Removing the console.log(); statement should leave two statements, but
* here the two statements will become one because [ causes continuation after
* foo().
* @param {ASTNode} node The ExpressionStatement node to check.
* @returns {boolean} `true` if ASI will break after removing the ExpressionStatement
* node.
*/
function maybeAsiHazard(node) {
const SAFE_TOKENS_BEFORE = /^[:;{]$/u; // One of :;{
const UNSAFE_CHARS_AFTER = /^[-[(/+`]/u; // One of [(/+-`
const tokenBefore = sourceCode.getTokenBefore(node);
const tokenAfter = sourceCode.getTokenAfter(node);
return (
Boolean(tokenAfter) &&
UNSAFE_CHARS_AFTER.test(tokenAfter.value) &&
tokenAfter.value !== "++" &&
tokenAfter.value !== "--" &&
Boolean(tokenBefore) &&
!SAFE_TOKENS_BEFORE.test(tokenBefore.value)
);
}
/**
* Checks if the MemberExpression node's parent.parent.parent is a
* Program, BlockStatement, StaticBlock, or SwitchCase node. This check
* is necessary to avoid providing a suggestion that might cause a syntax error.
*
* eg. if (a) console.log(b), removing console.log() here will lead to a
* syntax error.
* if (a) { console.log(b) }, removing console.log() here is acceptable.
*
* Additionally, it checks if the callee of the CallExpression node is
* the node itself.
*
* eg. foo(console.log), cannot provide a suggestion here.
* @param {ASTNode} node The MemberExpression node to check.
* @returns {boolean} `true` if a suggestion can be provided for a node.
*/
function canProvideSuggestions(node) {
return (
node.parent.type === "CallExpression" &&
node.parent.callee === node &&
node.parent.parent.type === "ExpressionStatement" &&
astUtils.STATEMENT_LIST_PARENTS.has(node.parent.parent.parent.type) &&
!maybeAsiHazard(node.parent.parent)
);
}
/**
* Reports the given reference as a violation.

@@ -109,6 +171,17 @@ * @param {eslint-scope.Reference} reference The reference to report.

const propertyName = astUtils.getStaticPropertyName(node);
context.report({
node,
loc: node.loc,
messageId: "unexpected"
messageId: "unexpected",
suggest: canProvideSuggestions(node)
? [{
messageId: "removeConsole",
data: { propertyName },
fix(fixer) {
return fixer.remove(node.parent.parent);
}
}]
: []
});

@@ -118,4 +191,4 @@ }

return {
"Program:exit"() {
const scope = context.getScope();
"Program:exit"(node) {
const scope = sourceCode.getScope(node);
const consoleVar = astUtils.getVariableByName(scope, "console");

@@ -122,0 +195,0 @@ const shadowed = consoleVar && consoleVar.defs.length > 0;

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow reassigning `const` variables",
description: "Disallow reassigning `const` variables",
recommended: true,
url: "https://eslint.org/docs/rules/no-const-assign"
url: "https://eslint.org/docs/latest/rules/no-const-assign"
},

@@ -35,2 +35,4 @@

const sourceCode = context.sourceCode;
/**

@@ -50,3 +52,3 @@ * Finds and reports references that are non initializer and writable.

if (node.kind === "const") {
context.getDeclaredVariables(node).forEach(checkVariable);
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}

@@ -53,0 +55,0 @@ }

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

const { isConstant } = require("./utils/ast-utils");
//------------------------------------------------------------------------------

@@ -23,5 +25,5 @@ // Helpers

docs: {
description: "disallow constant expressions in conditions",
description: "Disallow constant expressions in conditions",
recommended: true,
url: "https://eslint.org/docs/rules/no-constant-condition"
url: "https://eslint.org/docs/latest/rules/no-constant-condition"
},

@@ -51,2 +53,3 @@

loopSetStack = [];
const sourceCode = context.sourceCode;

@@ -60,151 +63,2 @@ let loopsInCurrentScope = new Set();

/**
* Returns literal's value converted to the Boolean type
* @param {ASTNode} node any `Literal` node
* @returns {boolean | null} `true` when node is truthy, `false` when node is falsy,
* `null` when it cannot be determined.
*/
function getBooleanValue(node) {
if (node.value === null) {
/*
* it might be a null literal or bigint/regex literal in unsupported environments .
* https://github.com/estree/estree/blob/14df8a024956ea289bd55b9c2226a1d5b8a473ee/es5.md#regexpliteral
* https://github.com/estree/estree/blob/14df8a024956ea289bd55b9c2226a1d5b8a473ee/es2020.md#bigintliteral
*/
if (node.raw === "null") {
return false;
}
// regex is always truthy
if (typeof node.regex === "object") {
return true;
}
return null;
}
return !!node.value;
}
/**
* Checks if a branch node of LogicalExpression short circuits the whole condition
* @param {ASTNode} node The branch of main condition which needs to be checked
* @param {string} operator The operator of the main LogicalExpression.
* @returns {boolean} true when condition short circuits whole condition
*/
function isLogicalIdentity(node, operator) {
switch (node.type) {
case "Literal":
return (operator === "||" && getBooleanValue(node) === true) ||
(operator === "&&" && getBooleanValue(node) === false);
case "UnaryExpression":
return (operator === "&&" && node.operator === "void");
case "LogicalExpression":
/*
* handles `a && false || b`
* `false` is an identity element of `&&` but not `||`
*/
return operator === node.operator &&
(
isLogicalIdentity(node.left, operator) ||
isLogicalIdentity(node.right, operator)
);
case "AssignmentExpression":
return ["||=", "&&="].includes(node.operator) &&
operator === node.operator.slice(0, -1) &&
isLogicalIdentity(node.right, operator);
// no default
}
return false;
}
/**
* Checks if a node has a constant truthiness value.
* @param {ASTNode} node The AST node to check.
* @param {boolean} inBooleanPosition `false` if checking branch of a condition.
* `true` in all other cases
* @returns {Bool} true when node's truthiness is constant
* @private
*/
function isConstant(node, inBooleanPosition) {
// node.elements can return null values in the case of sparse arrays ex. [,]
if (!node) {
return true;
}
switch (node.type) {
case "Literal":
case "ArrowFunctionExpression":
case "FunctionExpression":
case "ObjectExpression":
case "ClassExpression":
return true;
case "TemplateLiteral":
return (inBooleanPosition && node.quasis.some(quasi => quasi.value.cooked.length)) ||
node.expressions.every(exp => isConstant(exp, inBooleanPosition));
case "ArrayExpression": {
if (node.parent.type === "BinaryExpression" && node.parent.operator === "+") {
return node.elements.every(element => isConstant(element, false));
}
return true;
}
case "UnaryExpression":
if (
node.operator === "void" ||
node.operator === "typeof" && inBooleanPosition
) {
return true;
}
if (node.operator === "!") {
return isConstant(node.argument, true);
}
return isConstant(node.argument, false);
case "BinaryExpression":
return isConstant(node.left, false) &&
isConstant(node.right, false) &&
node.operator !== "in";
case "LogicalExpression": {
const isLeftConstant = isConstant(node.left, inBooleanPosition);
const isRightConstant = isConstant(node.right, inBooleanPosition);
const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator));
const isRightShortCircuit = (inBooleanPosition && isRightConstant && isLogicalIdentity(node.right, node.operator));
return (isLeftConstant && isRightConstant) ||
isLeftShortCircuit ||
isRightShortCircuit;
}
case "NewExpression":
return inBooleanPosition;
case "AssignmentExpression":
if (node.operator === "=") {
return isConstant(node.right, inBooleanPosition);
}
if (["||=", "&&="].includes(node.operator) && inBooleanPosition) {
return isLogicalIdentity(node.right, node.operator.slice(0, -1));
}
return false;
case "SequenceExpression":
return isConstant(node.expressions[node.expressions.length - 1], inBooleanPosition);
// no default
}
return false;
}
/**
* Tracks when the given node contains a constant condition.

@@ -216,3 +70,3 @@ * @param {ASTNode} node The AST node to check.

function trackConstantConditionLoop(node) {
if (node.test && isConstant(node.test, true)) {
if (node.test && isConstant(sourceCode.getScope(node), node.test, true)) {
loopsInCurrentScope.add(node);

@@ -242,3 +96,3 @@ }

function reportIfConstant(node) {
if (node.test && isConstant(node.test, true)) {
if (node.test && isConstant(sourceCode.getScope(node), node.test, true)) {
context.report({ node: node.test, messageId: "unexpected" });

@@ -245,0 +99,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow returning value from constructor",
description: "Disallow returning value from constructor",
recommended: false,
url: "https://eslint.org/docs/rules/no-constructor-return"
url: "https://eslint.org/docs/latest/rules/no-constructor-return"
},

@@ -23,0 +23,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow `continue` statements",
description: "Disallow `continue` statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-continue"
url: "https://eslint.org/docs/latest/rules/no-continue"
},

@@ -23,0 +23,0 @@

@@ -8,3 +8,3 @@ /**

const RegExpValidator = require("regexpp").RegExpValidator;
const RegExpValidator = require("@eslint-community/regexpp").RegExpValidator;
const collector = new (class {

@@ -18,2 +18,12 @@ constructor() {

onPatternEnter() {
/*
* `RegExpValidator` may parse the pattern twice in one `validatePattern`.
* So `this._controlChars` should be cleared here as well.
*
* For example, the `/(?<a>\x1f)/` regex will parse the pattern twice.
* This is based on the content described in Annex B.
* If the regex contains a `GroupName` and the `u` flag is not used, `ParseText` will be called twice.
* See https://tc39.es/ecma262/2023/multipage/additional-ecmascript-features-for-web-browsers.html#sec-parsepattern-annexb
*/
this._controlChars = [];

@@ -35,6 +45,11 @@ }

collectControlChars(regexpStr) {
collectControlChars(regexpStr, flags) {
const uFlag = typeof flags === "string" && flags.includes("u");
const vFlag = typeof flags === "string" && flags.includes("v");
this._controlChars = [];
this._source = regexpStr;
try {
this._source = regexpStr;
this._validator.validatePattern(regexpStr); // Call onCharacter hook
this._validator.validatePattern(regexpStr, void 0, void 0, { unicode: uFlag, unicodeSets: vFlag }); // Call onCharacter hook
} catch {

@@ -58,5 +73,5 @@

docs: {
description: "disallow control characters in regular expressions",
description: "Disallow control characters in regular expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-control-regex"
url: "https://eslint.org/docs/latest/rules/no-control-regex"
},

@@ -75,9 +90,11 @@

* Get the regex expression
* @param {ASTNode} node node to evaluate
* @returns {RegExp|null} Regex if found else null
* @param {ASTNode} node `Literal` node to evaluate
* @returns {{ pattern: string, flags: string | null } | null} Regex if found (the given node is either a regex literal
* or a string literal that is the pattern argument of a RegExp constructor call). Otherwise `null`. If flags cannot be determined,
* the `flags` property will be `null`.
* @private
*/
function getRegExpPattern(node) {
function getRegExp(node) {
if (node.regex) {
return node.regex.pattern;
return node.regex;
}

@@ -90,3 +107,11 @@ if (typeof node.value === "string" &&

) {
return node.value;
const pattern = node.value;
const flags =
node.parent.arguments.length > 1 &&
node.parent.arguments[1].type === "Literal" &&
typeof node.parent.arguments[1].value === "string"
? node.parent.arguments[1].value
: null;
return { pattern, flags };
}

@@ -99,6 +124,7 @@

Literal(node) {
const pattern = getRegExpPattern(node);
const regExp = getRegExp(node);
if (pattern) {
const controlCharacters = collector.collectControlChars(pattern);
if (regExp) {
const { pattern, flags } = regExp;
const controlCharacters = collector.collectControlChars(pattern, flags);

@@ -105,0 +131,0 @@ if (controlCharacters.length > 0) {

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow the use of `debugger`",
description: "Disallow the use of `debugger`",
recommended: true,
url: "https://eslint.org/docs/rules/no-debugger"
url: "https://eslint.org/docs/latest/rules/no-debugger"
},

@@ -23,0 +23,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow deleting variables",
description: "Disallow deleting variables",
recommended: true,
url: "https://eslint.org/docs/rules/no-delete-var"
url: "https://eslint.org/docs/latest/rules/no-delete-var"
},

@@ -23,0 +23,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow division operators explicitly at the beginning of regular expressions",
description: "Disallow equal signs explicitly at the beginning of regular expressions",
recommended: false,
url: "https://eslint.org/docs/rules/no-div-regex"
url: "https://eslint.org/docs/latest/rules/no-div-regex"
},

@@ -34,3 +34,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -37,0 +37,0 @@ return {

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow duplicate arguments in `function` definitions",
description: "Disallow duplicate arguments in `function` definitions",
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-args"
url: "https://eslint.org/docs/latest/rules/no-dupe-args"
},

@@ -33,2 +33,4 @@

const sourceCode = context.sourceCode;
//--------------------------------------------------------------------------

@@ -54,3 +56,3 @@ // Helpers

function checkParams(node) {
const variables = context.getDeclaredVariables(node);
const variables = sourceCode.getDeclaredVariables(node);

@@ -57,0 +59,0 @@ for (let i = 0; i < variables.length; ++i) {

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow duplicate class members",
description: "Disallow duplicate class members",
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-class-members"
url: "https://eslint.org/docs/latest/rules/no-dupe-class-members"
},

@@ -25,0 +25,0 @@

@@ -55,5 +55,5 @@ /**

docs: {
description: "disallow duplicate conditions in if-else-if chains",
description: "Disallow duplicate conditions in if-else-if chains",
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-else-if"
url: "https://eslint.org/docs/latest/rules/no-dupe-else-if"
},

@@ -69,3 +69,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -72,0 +72,0 @@ /**

@@ -91,5 +91,5 @@ /**

docs: {
description: "disallow duplicate keys in object literals",
description: "Disallow duplicate keys in object literals",
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-keys"
url: "https://eslint.org/docs/latest/rules/no-dupe-keys"
},

@@ -96,0 +96,0 @@

@@ -25,5 +25,5 @@ /**

docs: {
description: "disallow duplicate case labels",
description: "Disallow duplicate case labels",
recommended: true,
url: "https://eslint.org/docs/rules/no-duplicate-case"
url: "https://eslint.org/docs/latest/rules/no-duplicate-case"
},

@@ -39,3 +39,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -42,0 +42,0 @@ /**

@@ -236,5 +236,5 @@ /**

docs: {
description: "disallow duplicate module imports",
description: "Disallow duplicate module imports",
recommended: false,
url: "https://eslint.org/docs/rules/no-duplicate-imports"
url: "https://eslint.org/docs/latest/rules/no-duplicate-imports"
},

@@ -241,0 +241,0 @@

@@ -25,5 +25,5 @@ /**

docs: {
description: "disallow `else` blocks after `return` statements in `if` statements",
description: "Disallow `else` blocks after `return` statements in `if` statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-else-return"
url: "https://eslint.org/docs/latest/rules/no-else-return"
},

@@ -51,2 +51,4 @@

const sourceCode = context.sourceCode;
//--------------------------------------------------------------------------

@@ -174,21 +176,20 @@ // Helpers

* Display the context report if rule is violated
* @param {Node} node The 'else' node
* @param {Node} elseNode The 'else' node
* @returns {void}
*/
function displayReport(node) {
const currentScope = context.getScope();
function displayReport(elseNode) {
const currentScope = sourceCode.getScope(elseNode.parent);
context.report({
node,
node: elseNode,
messageId: "unexpected",
fix: fixer => {
fix(fixer) {
if (!isSafeFromNameCollisions(node, currentScope)) {
if (!isSafeFromNameCollisions(elseNode, currentScope)) {
return null;
}
const sourceCode = context.getSourceCode();
const startToken = sourceCode.getFirstToken(node);
const startToken = sourceCode.getFirstToken(elseNode);
const elseToken = sourceCode.getTokenBefore(startToken);
const source = sourceCode.getText(node);
const source = sourceCode.getText(elseNode);
const lastIfToken = sourceCode.getTokenBefore(elseToken);

@@ -209,3 +210,3 @@ let fixedSource, firstTokenOfElseBlock;

*/
const ifBlockMaybeUnsafe = node.parent.consequent.type !== "BlockStatement" && lastIfToken.value !== ";";
const ifBlockMaybeUnsafe = elseNode.parent.consequent.type !== "BlockStatement" && lastIfToken.value !== ";";
const elseBlockUnsafe = /^[([/+`-]/u.test(firstTokenOfElseBlock.value);

@@ -217,3 +218,3 @@

const endToken = sourceCode.getLastToken(node);
const endToken = sourceCode.getLastToken(elseNode);
const lastTokenOfElseBlock = sourceCode.getTokenBefore(endToken);

@@ -252,4 +253,4 @@

return new FixTracker(fixer, sourceCode)
.retainEnclosingFunction(node)
.replaceTextRange([elseToken.range[0], node.range[1]], fixedSource);
.retainEnclosingFunction(elseNode)
.replaceTextRange([elseToken.range[0], elseNode.range[1]], fixedSource);
}

@@ -256,0 +257,0 @@ });

@@ -9,15 +9,13 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/*
* plain-English description of the following regexp:
* 0. `^` fix the match at the beginning of the string
* 1. `([^\\[]|\\.|\[([^\\\]]|\\.)+\])*`: regexp contents; 0 or more of the following
* 1.0. `[^\\[]`: any character that's not a `\` or a `[` (anything but escape sequences and character classes)
* 1.1. `\\.`: an escape sequence
* 1.2. `\[([^\\\]]|\\.)+\]`: a character class that isn't empty
* 2. `$`: fix the match at the end of the string
*/
const regex = /^([^\\[]|\\.|\[([^\\\]]|\\.)+\])*$/u;
const parser = new RegExpParser();
const QUICK_TEST_REGEX = /\[\]/u;

@@ -34,5 +32,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow empty character classes in regular expressions",
description: "Disallow empty character classes in regular expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-empty-character-class"
url: "https://eslint.org/docs/latest/rules/no-empty-character-class"
},

@@ -50,5 +48,28 @@

"Literal[regex]"(node) {
if (!regex.test(node.regex.pattern)) {
context.report({ node, messageId: "unexpected" });
const { pattern, flags } = node.regex;
if (!QUICK_TEST_REGEX.test(pattern)) {
return;
}
let regExpAST;
try {
regExpAST = parser.parsePattern(pattern, 0, pattern.length, {
unicode: flags.includes("u"),
unicodeSets: flags.includes("v")
});
} catch {
// Ignore regular expressions that regexpp cannot parse
return;
}
visitRegExpAST(regExpAST, {
onCharacterClassEnter(characterClass) {
if (!characterClass.negate && characterClass.elements.length === 0) {
context.report({ node, messageId: "unexpected" });
}
}
});
}

@@ -55,0 +76,0 @@ };

@@ -98,5 +98,5 @@ /**

docs: {
description: "disallow empty functions",
description: "Disallow empty functions",
recommended: false,
url: "https://eslint.org/docs/rules/no-empty-function"
url: "https://eslint.org/docs/latest/rules/no-empty-function"
},

@@ -127,3 +127,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -149,3 +149,3 @@ /**

if (allowed.indexOf(kind) === -1 &&
if (!allowed.includes(kind) &&
node.body.type === "BlockStatement" &&

@@ -152,0 +152,0 @@ node.body.body.length === 0 &&

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

const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------

@@ -18,8 +20,19 @@ // Rule Definition

docs: {
description: "disallow empty destructuring patterns",
description: "Disallow empty destructuring patterns",
recommended: true,
url: "https://eslint.org/docs/rules/no-empty-pattern"
url: "https://eslint.org/docs/latest/rules/no-empty-pattern"
},
schema: [],
schema: [
{
type: "object",
properties: {
allowObjectPatternsAsParameters: {
type: "boolean",
default: false
}
},
additionalProperties: false
}
],

@@ -32,7 +45,29 @@ messages: {

create(context) {
const options = context.options[0] || {},
allowObjectPatternsAsParameters = options.allowObjectPatternsAsParameters || false;
return {
ObjectPattern(node) {
if (node.properties.length === 0) {
context.report({ node, messageId: "unexpected", data: { type: "object" } });
if (node.properties.length > 0) {
return;
}
// Allow {} and {} = {} empty object patterns as parameters when allowObjectPatternsAsParameters is true
if (
allowObjectPatternsAsParameters &&
(
astUtils.isFunction(node.parent) ||
(
node.parent.type === "AssignmentPattern" &&
astUtils.isFunction(node.parent.parent) &&
node.parent.right.type === "ObjectExpression" &&
node.parent.right.properties.length === 0
)
)
) {
return;
}
context.report({ node, messageId: "unexpected", data: { type: "object" } });
},

@@ -39,0 +74,0 @@ ArrayPattern(node) {

@@ -20,8 +20,9 @@ /**

meta: {
hasSuggestions: true,
type: "suggestion",
docs: {
description: "disallow empty block statements",
description: "Disallow empty block statements",
recommended: true,
url: "https://eslint.org/docs/rules/no-empty"
url: "https://eslint.org/docs/latest/rules/no-empty"
},

@@ -43,3 +44,4 @@

messages: {
unexpected: "Empty {{type}} statement."
unexpected: "Empty {{type}} statement.",
suggestComment: "Add comment inside empty {{type}} statement."
}

@@ -52,3 +54,3 @@ },

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -77,3 +79,18 @@ return {

context.report({ node, messageId: "unexpected", data: { type: "block" } });
context.report({
node,
messageId: "unexpected",
data: { type: "block" },
suggest: [
{
messageId: "suggestComment",
data: { type: "block" },
fix(fixer) {
const range = [node.range[0] + 1, node.range[1] - 1];
return fixer.replaceTextRange(range, " /* empty */ ");
}
}
]
});
},

@@ -80,0 +97,0 @@

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow `null` comparisons without type-checking operators",
description: "Disallow `null` comparisons without type-checking operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-eq-null"
url: "https://eslint.org/docs/latest/rules/no-eq-null"
},

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

@@ -46,5 +46,5 @@ /**

docs: {
description: "disallow the use of `eval()`",
description: "Disallow the use of `eval()`",
recommended: false,
url: "https://eslint.org/docs/rules/no-eval"
url: "https://eslint.org/docs/latest/rules/no-eval"
},

@@ -72,16 +72,19 @@

);
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let funcInfo = null;
/**
* Pushs a variable scope (Program or Function) information to the stack.
* Pushes a `this` scope (non-arrow function, class static block, or class field initializer) information to the stack.
* Top-level scopes are handled separately.
*
* This is used in order to check whether or not `this` binding is a
* reference to the global object.
* @param {ASTNode} node A node of the scope. This is one of Program,
* FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression.
* @param {ASTNode} node A node of the scope.
* For functions, this is one of FunctionDeclaration, FunctionExpression.
* For class static blocks, this is StaticBlock.
* For class field initializers, this can be any node that is PropertyDefinition#value.
* @returns {void}
*/
function enterVarScope(node) {
const strict = context.getScope().isStrict;
function enterThisScope(node) {
const strict = sourceCode.getScope(node).isStrict;

@@ -92,2 +95,3 @@ funcInfo = {

strict,
isTopLevelOfScript: false,
defaultThis: false,

@@ -102,3 +106,3 @@ initialized: strict

*/
function exitVarScope() {
function exitThisScope() {
funcInfo = funcInfo.upper;

@@ -224,3 +228,3 @@ }

Program(node) {
const scope = context.getScope(),
const scope = sourceCode.getScope(node),
features = context.parserOptions.ecmaFeatures || {},

@@ -230,3 +234,4 @@ strict =

node.sourceType === "module" ||
(features.globalReturn && scope.childScopes[0].isStrict);
(features.globalReturn && scope.childScopes[0].isStrict),
isTopLevelOfScript = node.sourceType !== "module" && !features.globalReturn;

@@ -237,2 +242,3 @@ funcInfo = {

strict,
isTopLevelOfScript,
defaultThis: true,

@@ -243,6 +249,6 @@ initialized: true

"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);
exitVarScope();
exitThisScope();
reportAccessingEval(globalScope);

@@ -252,12 +258,10 @@ reportAccessingEvalViaGlobalObject(globalScope);

FunctionDeclaration: enterVarScope,
"FunctionDeclaration:exit": exitVarScope,
FunctionExpression: enterVarScope,
"FunctionExpression:exit": exitVarScope,
ArrowFunctionExpression: enterVarScope,
"ArrowFunctionExpression:exit": exitVarScope,
"PropertyDefinition > *.value": enterVarScope,
"PropertyDefinition > *.value:exit": exitVarScope,
StaticBlock: enterVarScope,
"StaticBlock:exit": exitVarScope,
FunctionDeclaration: enterThisScope,
"FunctionDeclaration:exit": exitThisScope,
FunctionExpression: enterThisScope,
"FunctionExpression:exit": exitThisScope,
"PropertyDefinition > *.value": enterThisScope,
"PropertyDefinition > *.value:exit": exitThisScope,
StaticBlock: enterThisScope,
"StaticBlock:exit": exitThisScope,

@@ -281,3 +285,4 @@ ThisExpression(node) {

if (!funcInfo.strict && funcInfo.defaultThis) {
// `this` at the top level of scripts always refers to the global object
if (funcInfo.isTopLevelOfScript || (!funcInfo.strict && funcInfo.defaultThis)) {

@@ -284,0 +289,0 @@ // `this.eval` is possible built-in `eval`.

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow reassigning exceptions in `catch` clauses",
description: "Disallow reassigning exceptions in `catch` clauses",
recommended: true,
url: "https://eslint.org/docs/rules/no-ex-assign"
url: "https://eslint.org/docs/latest/rules/no-ex-assign"
},

@@ -35,2 +35,4 @@

const sourceCode = context.sourceCode;
/**

@@ -49,3 +51,3 @@ * Finds and reports references that are non initializer and writable.

CatchClause(node) {
context.getDeclaredVariables(node).forEach(checkVariable);
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}

@@ -52,0 +54,0 @@ };

@@ -25,5 +25,5 @@ /**

docs: {
description: "disallow extending native types",
description: "Disallow extending native types",
recommended: false,
url: "https://eslint.org/docs/rules/no-extend-native"
url: "https://eslint.org/docs/latest/rules/no-extend-native"
},

@@ -55,2 +55,3 @@

const config = context.options[0] || {};
const sourceCode = context.sourceCode;
const exceptions = new Set(config.exceptions || []);

@@ -164,4 +165,4 @@ const modifiedBuiltins = new Set(

"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);

@@ -168,0 +169,0 @@ modifiedBuiltins.forEach(builtin => {

@@ -29,5 +29,5 @@ /**

docs: {
description: "disallow unnecessary calls to `.bind()`",
description: "Disallow unnecessary calls to `.bind()`",
recommended: false,
url: "https://eslint.org/docs/rules/no-extra-bind"
url: "https://eslint.org/docs/latest/rules/no-extra-bind"
},

@@ -44,3 +44,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let scopeInfo = null;

@@ -47,0 +47,0 @@

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

const astUtils = require("./utils/ast-utils");
const eslintUtils = require("eslint-utils");
const eslintUtils = require("@eslint-community/eslint-utils");

@@ -28,5 +28,5 @@ const precedence = astUtils.getPrecedence;

docs: {
description: "disallow unnecessary boolean casts",
description: "Disallow unnecessary boolean casts",
recommended: true,
url: "https://eslint.org/docs/rules/no-extra-boolean-cast"
url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast"
},

@@ -53,6 +53,6 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
// Node types which have a test which will coerce values to booleans.
const BOOLEAN_NODE_TYPES = [
const BOOLEAN_NODE_TYPES = new Set([
"IfStatement",

@@ -63,3 +63,3 @@ "DoWhileStatement",

"ForStatement"
];
]);

@@ -102,3 +102,3 @@ /**

(BOOLEAN_NODE_TYPES.indexOf(node.parent.type) !== -1 &&
(BOOLEAN_NODE_TYPES.has(node.parent.type) &&
node === node.parent.test) ||

@@ -196,3 +196,3 @@

/* istanbul ignore next */
/* c8 ignore next */
default:

@@ -199,0 +199,0 @@ throw new Error(`Unexpected parent type: ${parent.type}`);

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow unnecessary labels",
description: "Disallow unnecessary labels",
recommended: false,
url: "https://eslint.org/docs/rules/no-extra-label"
url: "https://eslint.org/docs/latest/rules/no-extra-label"
},

@@ -39,3 +39,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let scopeInfo = null;

@@ -42,0 +42,0 @@

/**
* @fileoverview Disallow parenthesising higher precedence subexpressions.
* @author Michael Ficarra
* @deprecated in ESLint v8.53.0
*/

@@ -11,3 +12,3 @@ "use strict";

const { isParenthesized: isParenthesizedRaw } = require("eslint-utils");
const { isParenthesized: isParenthesizedRaw } = require("@eslint-community/eslint-utils");
const astUtils = require("./utils/ast-utils.js");

@@ -18,8 +19,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow unnecessary parentheses",
description: "Disallow unnecessary parentheses",
recommended: false,
url: "https://eslint.org/docs/rules/no-extra-parens"
url: "https://eslint.org/docs/latest/rules/no-extra-parens"
},

@@ -51,2 +54,3 @@

conditionalAssign: { type: "boolean" },
ternaryOperandBinaryExpressions: { type: "boolean" },
nestedBinaryExpressions: { type: "boolean" },

@@ -58,3 +62,4 @@ returnAssign: { type: "boolean" },

enforceForNewInMemberExpressions: { type: "boolean" },
enforceForFunctionPrototypeMethods: { type: "boolean" }
enforceForFunctionPrototypeMethods: { type: "boolean" },
allowParensAfterCommentPattern: { type: "string" }
},

@@ -76,3 +81,3 @@ additionalProperties: false

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -83,2 +88,3 @@ const tokensToIgnore = new WeakSet();

const EXCEPT_COND_ASSIGN = ALL_NODES && context.options[1] && context.options[1].conditionalAssign === false;
const EXCEPT_COND_TERNARY = ALL_NODES && context.options[1] && context.options[1].ternaryOperandBinaryExpressions === false;
const NESTED_BINARY = ALL_NODES && context.options[1] && context.options[1].nestedBinaryExpressions === false;

@@ -95,2 +101,3 @@ const EXCEPT_RETURN_ASSIGN = ALL_NODES && context.options[1] && context.options[1].returnAssign === false;

context.options[1].enforceForFunctionPrototypeMethods === false;
const ALLOW_PARENS_AFTER_COMMENT_PATTERN = ALL_NODES && context.options[1] && context.options[1].allowParensAfterCommentPattern;

@@ -395,2 +402,26 @@ const PRECEDENCE_OF_ASSIGNMENT_EXPR = precedence({ type: "AssignmentExpression" });

/**
* Checks if a node is fixable.
* A node is fixable if removing a single pair of surrounding parentheses does not turn it
* into a directive after fixing other nodes.
* Almost all nodes are fixable, except if all of the following conditions are met:
* The node is a string Literal
* It has a single pair of parentheses
* It is the only child of an ExpressionStatement
* @param {ASTNode} node The node to evaluate.
* @returns {boolean} Whether or not the node is fixable.
* @private
*/
function isFixable(node) {
// if it's not a string literal it can be autofixed
if (node.type !== "Literal" || typeof node.value !== "string") {
return true;
}
if (isParenthesisedTwice(node)) {
return true;
}
return !astUtils.isTopLevelExpressionStatement(node.parent);
}
/**
* Report the node

@@ -413,2 +444,15 @@ * @param {ASTNode} node node to evaluate

}
if (ALLOW_PARENS_AFTER_COMMENT_PATTERN) {
const commentsBeforeLeftParenToken = sourceCode.getCommentsBefore(leftParenToken);
const totalCommentsBeforeLeftParenTokenCount = commentsBeforeLeftParenToken.length;
const ignorePattern = new RegExp(ALLOW_PARENS_AFTER_COMMENT_PATTERN, "u");
if (
totalCommentsBeforeLeftParenTokenCount > 0 &&
ignorePattern.test(commentsBeforeLeftParenToken[totalCommentsBeforeLeftParenTokenCount - 1].value)
) {
return;
}
}
}

@@ -426,10 +470,12 @@

messageId: "unexpected",
fix(fixer) {
const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
fix: isFixable(node)
? fixer => {
const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
return fixer.replaceTextRange([
leftParenToken.range[0],
rightParenToken.range[1]
], (requiresLeadingSpace(node) ? " " : "") + parenthesizedSource + (requiresTrailingSpace(node) ? " " : ""));
}
return fixer.replaceTextRange([
leftParenToken.range[0],
rightParenToken.range[1]
], (requiresLeadingSpace(node) ? " " : "") + parenthesizedSource + (requiresTrailingSpace(node) ? " " : ""));
}
: null
});

@@ -647,6 +693,6 @@ }

/* istanbul ignore if */
/* c8 ignore start */
if (currentNode === null) {
throw new Error("Nodes are not in the ancestor-descendant relationship.");
}
}/* c8 ignore stop */

@@ -765,2 +811,34 @@ path.push(currentNode);

/**
* Checks if the left-hand side of an assignment is an identifier, the operator is one of
* `=`, `&&=`, `||=` or `??=` and the right-hand side is an anonymous class or function.
*
* As per https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation, an
* assignment involving one of the operators `=`, `&&=`, `||=` or `??=` where the right-hand
* side is an anonymous class or function and the left-hand side is an *unparenthesized*
* identifier has different semantics than other assignments.
* Specifically, when an expression like `foo = function () {}` is evaluated, `foo.name`
* will be set to the string "foo", i.e. the identifier name. The same thing does not happen
* when evaluating `(foo) = function () {}`.
* Since the parenthesizing of the identifier in the left-hand side is significant in this
* special case, the parentheses, if present, should not be flagged as unnecessary.
* @param {ASTNode} node an AssignmentExpression node.
* @returns {boolean} `true` if the left-hand side of the assignment is an identifier, the
* operator is one of `=`, `&&=`, `||=` or `??=` and the right-hand side is an anonymous
* class or function; otherwise, `false`.
*/
function isAnonymousFunctionAssignmentException({ left, operator, right }) {
if (left.type === "Identifier" && ["=", "&&=", "||=", "??="].includes(operator)) {
const rhsType = right.type;
if (rhsType === "ArrowFunctionExpression") {
return true;
}
if ((rhsType === "FunctionExpression" || rhsType === "ClassExpression") && !right.id) {
return true;
}
}
return false;
}
return {

@@ -804,3 +882,4 @@ ArrayExpression(node) {

AssignmentExpression(node) {
if (canBeAssignmentTarget(node.left) && hasExcessParens(node.left)) {
if (canBeAssignmentTarget(node.left) && hasExcessParens(node.left) &&
(!isAnonymousFunctionAssignmentException(node) || isParenthesisedTwice(node.left))) {
report(node.left);

@@ -828,3 +907,7 @@ }

}
const availableTypes = new Set(["BinaryExpression", "LogicalExpression"]);
if (
!(EXCEPT_COND_TERNARY && availableTypes.has(node.test.type)) &&
!isCondAssignException(node) &&

@@ -836,7 +919,11 @@ hasExcessParensWithPrecedence(node.test, precedence({ type: "LogicalExpression", operator: "||" }))

if (hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
if (
!(EXCEPT_COND_TERNARY && availableTypes.has(node.consequent.type)) &&
hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
report(node.consequent);
}
if (hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
if (
!(EXCEPT_COND_TERNARY && availableTypes.has(node.alternate.type)) &&
hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
report(node.alternate);

@@ -843,0 +930,0 @@ }

/**
* @fileoverview Rule to flag use of unnecessary semicolons
* @author Nicholas C. Zakas
* @deprecated in ESLint v8.53.0
*/

@@ -22,8 +23,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "disallow unnecessary semicolons",
description: "Disallow unnecessary semicolons",
recommended: true,
url: "https://eslint.org/docs/rules/no-extra-semi"
url: "https://eslint.org/docs/latest/rules/no-extra-semi"
},

@@ -40,5 +43,22 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
/**
* Checks if a node or token is fixable.
* A node is fixable if it can be removed without turning a subsequent statement into a directive after fixing other nodes.
* @param {Token} nodeOrToken The node or token to check.
* @returns {boolean} Whether or not the node is fixable.
*/
function isFixable(nodeOrToken) {
const nextToken = sourceCode.getTokenAfter(nodeOrToken);
if (!nextToken || nextToken.type !== "String") {
return true;
}
const stringNode = sourceCode.getNodeByRangeIndex(nextToken.range[0]);
return !astUtils.isTopLevelExpressionStatement(stringNode.parent);
}
/**
* Reports an unnecessary semicolon error.

@@ -52,13 +72,14 @@ * @param {Node|Token} nodeOrToken A node or a token to be reported.

messageId: "unexpected",
fix(fixer) {
fix: isFixable(nodeOrToken)
? fixer =>
/*
* Expand the replacement range to include the surrounding
* tokens to avoid conflicting with semi.
* https://github.com/eslint/eslint/issues/7928
*/
return new FixTracker(fixer, context.getSourceCode())
.retainSurroundingTokens(nodeOrToken)
.remove(nodeOrToken);
}
/*
* Expand the replacement range to include the surrounding
* tokens to avoid conflicting with semi.
* https://github.com/eslint/eslint/issues/7928
*/
new FixTracker(fixer, context.sourceCode)
.retainSurroundingTokens(nodeOrToken)
.remove(nodeOrToken)
: null
});

@@ -104,3 +125,3 @@ }

if (allowedParentTypes.indexOf(parent.type) === -1) {
if (!allowedParentTypes.includes(parent.type)) {
report(node);

@@ -107,0 +128,0 @@ }

@@ -8,2 +8,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { directivesPattern } = require("../shared/directives");
//------------------------------------------------------------------------------
// Helpers

@@ -15,2 +21,28 @@ //------------------------------------------------------------------------------

/**
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}
/**
* Checks whether or not a given comment string is really a fallthrough comment and not an ESLint directive.
* @param {string} comment The comment string to check.
* @param {RegExp} fallthroughCommentPattern The regular expression used for checking for fallthrough comments.
* @returns {boolean} `true` if the comment string is truly a fallthrough comment.
*/
function isFallThroughComment(comment, fallthroughCommentPattern) {
return fallthroughCommentPattern.test(comment) && !directivesPattern.test(comment.trim());
}
/**
* Checks whether or not a given case has a fallthrough comment.

@@ -24,3 +56,3 @@ * @param {ASTNode} caseWhichFallsThrough SwitchCase node which falls through.

function hasFallthroughComment(caseWhichFallsThrough, subsequentCase, context, fallthroughCommentPattern) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -31,3 +63,3 @@ if (caseWhichFallsThrough.consequent.length === 1 && caseWhichFallsThrough.consequent[0].type === "BlockStatement") {

if (commentInBlock && fallthroughCommentPattern.test(commentInBlock.value)) {
if (commentInBlock && isFallThroughComment(commentInBlock.value, fallthroughCommentPattern)) {
return true;

@@ -39,15 +71,6 @@ }

return Boolean(comment && fallthroughCommentPattern.test(comment.value));
return Boolean(comment && isFallThroughComment(comment.value, fallthroughCommentPattern));
}
/**
* Checks whether or not a given code path segment is reachable.
* @param {CodePathSegment} segment A CodePathSegment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
return segment.reachable;
}
/**
* Checks whether a node and a token are separated by blank lines

@@ -72,5 +95,5 @@ * @param {ASTNode} node The node to check

docs: {
description: "disallow fallthrough of `case` statements",
description: "Disallow fallthrough of `case` statements",
recommended: true,
url: "https://eslint.org/docs/rules/no-fallthrough"
url: "https://eslint.org/docs/latest/rules/no-fallthrough"
},

@@ -85,2 +108,6 @@

default: ""
},
allowEmptyCase: {
type: "boolean",
default: false
}

@@ -99,4 +126,6 @@ },

const options = context.options[0] || {};
let currentCodePath = null;
const sourceCode = context.getSourceCode();
const codePathSegments = [];
let currentCodePathSegments = new Set();
const sourceCode = context.sourceCode;
const allowEmptyCase = options.allowEmptyCase || false;

@@ -115,11 +144,30 @@ /*

}
return {
return {
onCodePathStart(codePath) {
currentCodePath = codePath;
onCodePathStart() {
codePathSegments.push(currentCodePathSegments);
currentCodePathSegments = new Set();
},
onCodePathEnd() {
currentCodePath = currentCodePath.upper;
currentCodePathSegments = codePathSegments.pop();
},
onUnreachableCodePathSegmentStart(segment) {
currentCodePathSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
onCodePathSegmentStart(segment) {
currentCodePathSegments.add(segment);
},
onCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
SwitchCase(node) {

@@ -131,3 +179,4 @@

*/
if (fallthroughCase && !hasFallthroughComment(fallthroughCase, node, context, fallthroughCommentPattern)) {
if (fallthroughCase && (!hasFallthroughComment(fallthroughCase, node, context, fallthroughCommentPattern))) {
context.report({

@@ -149,4 +198,4 @@ messageId: node.test ? "case" : "default",

*/
if (currentCodePath.currentSegments.some(isReachable) &&
(node.consequent.length > 0 || hasBlankLinesBetween(node, nextToken)) &&
if (isAnySegmentReachable(currentCodePathSegments) &&
(node.consequent.length > 0 || (!allowEmptyCase && hasBlankLinesBetween(node, nextToken))) &&
node.parent.cases[node.parent.cases.length - 1] !== node) {

@@ -153,0 +202,0 @@ fallthroughCase = node;

/**
* @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal
* @author James Allardice
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "disallow leading or trailing decimal points in numeric literals",
description: "Disallow leading or trailing decimal points in numeric literals",
recommended: false,
url: "https://eslint.org/docs/rules/no-floating-decimal"
url: "https://eslint.org/docs/latest/rules/no-floating-decimal"
},

@@ -39,3 +42,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -42,0 +45,0 @@ return {

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow reassigning `function` declarations",
description: "Disallow reassigning `function` declarations",
recommended: true,
url: "https://eslint.org/docs/rules/no-func-assign"
url: "https://eslint.org/docs/latest/rules/no-func-assign"
},

@@ -35,2 +35,4 @@

const sourceCode = context.sourceCode;
/**

@@ -70,3 +72,3 @@ * Reports a reference if is non initializer and writable.

function checkForFunction(node) {
context.getDeclaredVariables(node).forEach(checkVariable);
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}

@@ -73,0 +75,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow assignments to native objects or read-only global variables",
description: "Disallow assignments to native objects or read-only global variables",
recommended: true,
url: "https://eslint.org/docs/rules/no-global-assign"
url: "https://eslint.org/docs/latest/rules/no-global-assign"
},

@@ -45,2 +45,3 @@

const config = context.options[0];
const sourceCode = context.sourceCode;
const exceptions = (config && config.exceptions) || [];

@@ -83,3 +84,3 @@

function checkVariable(variable) {
if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) {
if (variable.writeable === false && !exceptions.includes(variable.name)) {
variable.references.forEach(checkReference);

@@ -90,4 +91,4 @@ }

return {
Program() {
const globalScope = context.getScope();
Program(node) {
const globalScope = sourceCode.getScope(node);

@@ -94,0 +95,0 @@ globalScope.variables.forEach(checkVariable);

@@ -33,5 +33,5 @@ /**

/**
* Checks whether or not a node is a double logical nigating.
* Checks whether or not a node is a double logical negating.
* @param {ASTNode} node An UnaryExpression node to check.
* @returns {boolean} Whether or not the node is a double logical nigating.
* @returns {boolean} Whether or not the node is a double logical negating.
*/

@@ -76,2 +76,20 @@ function isDoubleLogicalNegating(node) {

/**
* Checks whether the given node logically represents multiplication by a fraction of `1`.
* For example, `a * 1` in `a * 1 / b` is technically multiplication by `1`, but the
* whole expression can be logically interpreted as `a * (1 / b)` rather than `(a * 1) / b`.
* @param {BinaryExpression} node A BinaryExpression node to check.
* @param {SourceCode} sourceCode The source code object.
* @returns {boolean} Whether or not the node is a multiplying by a fraction of `1`.
*/
function isMultiplyByFractionOfOne(node, sourceCode) {
return node.type === "BinaryExpression" &&
node.operator === "*" &&
(node.right.type === "Literal" && node.right.value === 1) &&
node.parent.type === "BinaryExpression" &&
node.parent.operator === "/" &&
node.parent.left === node &&
!astUtils.isParenthesised(sourceCode, node);
}
/**
* Checks whether the result of a node is numeric or not

@@ -178,5 +196,5 @@ * @param {ASTNode} node The node to test

docs: {
description: "disallow shorthand type conversions",
description: "Disallow shorthand type conversions",
recommended: false,
url: "https://eslint.org/docs/rules/no-implicit-coercion"
url: "https://eslint.org/docs/latest/rules/no-implicit-coercion"
},

@@ -223,3 +241,3 @@

const options = parseOptions(context.options[0] || {});
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -264,3 +282,3 @@ /**

// !!foo
operatorAllowed = options.allow.indexOf("!!") >= 0;
operatorAllowed = options.allow.includes("!!");
if (!operatorAllowed && options.boolean && isDoubleLogicalNegating(node)) {

@@ -273,3 +291,3 @@ const recommendation = `Boolean(${sourceCode.getText(node.argument.argument)})`;

// ~foo.indexOf(bar)
operatorAllowed = options.allow.indexOf("~") >= 0;
operatorAllowed = options.allow.includes("~");
if (!operatorAllowed && options.boolean && isBinaryNegatingOfIndexOf(node)) {

@@ -285,3 +303,3 @@

// +foo
operatorAllowed = options.allow.indexOf("+") >= 0;
operatorAllowed = options.allow.includes("+");
if (!operatorAllowed && options.number && node.operator === "+" && !isNumeric(node.argument)) {

@@ -299,4 +317,5 @@ const recommendation = `Number(${sourceCode.getText(node.argument)})`;

// 1 * foo
operatorAllowed = options.allow.indexOf("*") >= 0;
const nonNumericOperand = !operatorAllowed && options.number && isMultiplyByOne(node) && getNonNumericOperand(node);
operatorAllowed = options.allow.includes("*");
const nonNumericOperand = !operatorAllowed && options.number && isMultiplyByOne(node) && !isMultiplyByFractionOfOne(node, sourceCode) &&
getNonNumericOperand(node);

@@ -310,3 +329,3 @@ if (nonNumericOperand) {

// "" + foo
operatorAllowed = options.allow.indexOf("+") >= 0;
operatorAllowed = options.allow.includes("+");
if (!operatorAllowed && options.string && isConcatWithEmptyString(node)) {

@@ -322,3 +341,3 @@ const recommendation = `String(${sourceCode.getText(getNonEmptyOperand(node))})`;

// foo += ""
const operatorAllowed = options.allow.indexOf("+") >= 0;
const operatorAllowed = options.allow.includes("+");

@@ -325,0 +344,0 @@ if (!operatorAllowed && options.string && isAppendEmptyString(node)) {

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow declarations in the global scope",
description: "Disallow declarations in the global scope",
recommended: false,
url: "https://eslint.org/docs/rules/no-implicit-globals"
url: "https://eslint.org/docs/latest/rules/no-implicit-globals"
},

@@ -47,2 +47,3 @@

const checkLexicalBindings = context.options[0] && context.options[0].lexicalBindings === true;
const sourceCode = context.sourceCode;

@@ -67,4 +68,4 @@ /**

return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);

@@ -83,2 +84,7 @@ scope.variables.forEach(variable => {

// Variables exported by "exported" block comments
if (variable.eslintExported) {
return;
}
variable.defs.forEach(def => {

@@ -85,0 +91,0 @@ const defNode = def.node;

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

const astUtils = require("./utils/ast-utils");
const { getStaticValue } = require("eslint-utils");
const { getStaticValue } = require("@eslint-community/eslint-utils");

@@ -26,5 +26,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow the use of `eval()`-like methods",
description: "Disallow the use of `eval()`-like methods",
recommended: false,
url: "https://eslint.org/docs/rules/no-implied-eval"
url: "https://eslint.org/docs/latest/rules/no-implied-eval"
},

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

const EVAL_LIKE_FUNC_PATTERN = /^(?:set(?:Interval|Timeout)|execScript)$/u;
const sourceCode = context.sourceCode;

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

const staticValue = getStaticValue(firstArgument, context.getScope());
const staticValue = getStaticValue(firstArgument, sourceCode.getScope(node));
const isStaticString = staticValue && typeof staticValue.value === "string";

@@ -124,4 +125,4 @@ const isString = isStaticString || isEvaluatedString(firstArgument);

},
"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);

@@ -128,0 +129,0 @@ GLOBAL_CANDIDATES

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

const { findVariable } = require("eslint-utils");
const { findVariable } = require("@eslint-community/eslint-utils");
const astUtils = require("./utils/ast-utils");

@@ -184,5 +184,5 @@

docs: {
description: "disallow assigning to imported bindings",
description: "Disallow assigning to imported bindings",
recommended: true,
url: "https://eslint.org/docs/rules/no-import-assign"
url: "https://eslint.org/docs/latest/rules/no-import-assign"
},

@@ -199,7 +199,9 @@

create(context) {
const sourceCode = context.sourceCode;
return {
ImportDeclaration(node) {
const scope = context.getScope();
const scope = sourceCode.getScope(node);
for (const variable of context.getDeclaredVariables(node)) {
for (const variable of sourceCode.getDeclaredVariables(node)) {
const shouldCheckMembers = variable.defs.some(

@@ -206,0 +208,0 @@ d => d.node.type === "ImportNamespaceSpecifier"

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow inline comments after code",
description: "Disallow inline comments after code",
recommended: false,
url: "https://eslint.org/docs/rules/no-inline-comments"
url: "https://eslint.org/docs/latest/rules/no-inline-comments"
},

@@ -43,3 +43,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = context.options[0];

@@ -46,0 +46,0 @@ let customIgnoreRegExp;

@@ -51,5 +51,5 @@ /**

docs: {
description: "disallow variable or `function` declarations in nested blocks",
description: "Disallow variable or `function` declarations in nested blocks",
recommended: true,
url: "https://eslint.org/docs/rules/no-inner-declarations"
url: "https://eslint.org/docs/latest/rules/no-inner-declarations"
},

@@ -56,0 +56,0 @@

@@ -11,5 +11,5 @@ /**

const RegExpValidator = require("regexpp").RegExpValidator;
const RegExpValidator = require("@eslint-community/regexpp").RegExpValidator;
const validator = new RegExpValidator();
const validFlags = /[dgimsuy]/gu;
const validFlags = /[dgimsuvy]/gu;
const undefined1 = void 0;

@@ -27,5 +27,5 @@

docs: {
description: "disallow invalid regular expression strings in `RegExp` constructors",
description: "Disallow invalid regular expression strings in `RegExp` constructors",
recommended: true,
url: "https://eslint.org/docs/rules/no-invalid-regexp"
url: "https://eslint.org/docs/latest/rules/no-invalid-regexp"
},

@@ -65,2 +65,16 @@

/**
* Reports error with the provided message.
* @param {ASTNode} node The node holding the invalid RegExp
* @param {string} message The message to report.
* @returns {void}
*/
function report(node, message) {
context.report({
node,
messageId: "regexMessage",
data: { message }
});
}
/**
* Check if node is a string

@@ -100,8 +114,10 @@ * @param {ASTNode} node node to evaluate

* @param {string} pattern The RegExp pattern to validate.
* @param {boolean} uFlag The Unicode flag.
* @param {Object} flags The RegExp flags to validate.
* @param {boolean} [flags.unicode] The Unicode flag.
* @param {boolean} [flags.unicodeSets] The UnicodeSets flag.
* @returns {string|null} The syntax error.
*/
function validateRegExpPattern(pattern, uFlag) {
function validateRegExpPattern(pattern, flags) {
try {
validator.validatePattern(pattern, undefined1, undefined1, uFlag);
validator.validatePattern(pattern, undefined1, undefined1, flags);
return null;

@@ -115,12 +131,24 @@ } catch (err) {

* Check syntax error in a given flags.
* @param {string} flags The RegExp flags to validate.
* @param {string|null} flags The RegExp flags to validate.
* @returns {string|null} The syntax error.
*/
function validateRegExpFlags(flags) {
if (!flags) {
return null;
}
try {
validator.validateFlags(flags);
return null;
} catch {
return `Invalid flags supplied to RegExp constructor '${flags}'`;
}
/*
* `regexpp` checks the combination of `u` and `v` flags when parsing `Pattern` according to `ecma262`,
* but this rule may check only the flag when the pattern is unidentifiable, so check it here.
* https://tc39.es/ecma262/multipage/text-processing.html#sec-parsepattern
*/
if (flags.includes("u") && flags.includes("v")) {
return "Regex 'u' and 'v' flags cannot be used together";
}
return null;
}

@@ -130,6 +158,6 @@

"CallExpression, NewExpression"(node) {
if (node.callee.type !== "Identifier" || node.callee.name !== "RegExp" || !isString(node.arguments[0])) {
if (node.callee.type !== "Identifier" || node.callee.name !== "RegExp") {
return;
}
const pattern = node.arguments[0].value;
let flags = getFlags(node);

@@ -141,20 +169,29 @@

const message =
(
flags && validateRegExpFlags(flags)
) ||
(
let message = validateRegExpFlags(flags);
// If flags are unknown, report the regex only if its pattern is invalid both with and without the "u" flag
flags === null
? validateRegExpPattern(pattern, true) && validateRegExpPattern(pattern, false)
: validateRegExpPattern(pattern, flags.includes("u"))
);
if (message) {
report(node, message);
return;
}
if (!isString(node.arguments[0])) {
return;
}
const pattern = node.arguments[0].value;
message = (
// If flags are unknown, report the regex only if its pattern is invalid both with and without the "u" flag
flags === null
? (
validateRegExpPattern(pattern, { unicode: true, unicodeSets: false }) &&
validateRegExpPattern(pattern, { unicode: false, unicodeSets: true }) &&
validateRegExpPattern(pattern, { unicode: false, unicodeSets: false })
)
: validateRegExpPattern(pattern, { unicode: flags.includes("u"), unicodeSets: flags.includes("v") })
);
if (message) {
context.report({
node,
messageId: "regexMessage",
data: { message }
});
report(node, message);
}

@@ -161,0 +198,0 @@ }

/**
* @fileoverview A rule to disallow `this` keywords outside of classes or class-like objects.
* @fileoverview A rule to disallow `this` keywords in contexts where the value of `this` is `undefined`.
* @author Toru Nagashima

@@ -15,2 +15,17 @@ */

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Determines if the given code path is a code path with lexical `this` binding.
* That is, if `this` within the code path refers to `this` of surrounding code path.
* @param {CodePath} codePath Code path.
* @param {ASTNode} node Node that started the code path.
* @returns {boolean} `true` if it is a code path with lexical `this` binding.
*/
function isCodePathWithLexicalThis(codePath, node) {
return codePath.origin === "function" && node.type === "ArrowFunctionExpression";
}
//------------------------------------------------------------------------------
// Rule Definition

@@ -25,5 +40,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow `this` keywords outside of classes or class-like objects",
description: "Disallow use of `this` in contexts where the value of `this` is `undefined`",
recommended: false,
url: "https://eslint.org/docs/rules/no-invalid-this"
url: "https://eslint.org/docs/latest/rules/no-invalid-this"
},

@@ -53,3 +68,3 @@

const stack = [],
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -78,67 +93,49 @@ /**

/**
* Pushs new checking context into the stack.
*
* The checking context is not initialized yet.
* Because most functions don't have `this` keyword.
* When `this` keyword was found, the checking context is initialized.
* @param {ASTNode} node A function node that was entered.
* @returns {void}
*/
function enterFunction(node) {
return {
// `this` can be invalid only under strict mode.
stack.push({
init: !context.getScope().isStrict,
node,
valid: true
});
}
onCodePathStart(codePath, node) {
if (isCodePathWithLexicalThis(codePath, node)) {
return;
}
/**
* Pops the current checking context from the stack.
* @returns {void}
*/
function exitFunction() {
stack.pop();
}
if (codePath.origin === "program") {
const scope = sourceCode.getScope(node);
const features = context.parserOptions.ecmaFeatures || {};
return {
// `this` at the top level of scripts always refers to the global object
stack.push({
init: true,
node,
valid: !(
node.sourceType === "module" ||
(features.globalReturn && scope.childScopes[0].isStrict)
)
});
/*
* `this` is invalid only under strict mode.
* Modules is always strict mode.
*/
Program(node) {
const scope = context.getScope(),
features = context.parserOptions.ecmaFeatures || {};
return;
}
/*
* `init: false` means that `valid` isn't determined yet.
* Most functions don't use `this`, and the calculation for `valid`
* is relatively costly, so we'll calculate it lazily when the first
* `this` within the function is traversed. A special case are non-strict
* functions, because `this` refers to the global object and therefore is
* always valid, so we can set `init: true` right away.
*/
stack.push({
init: true,
init: !sourceCode.getScope(node).isStrict,
node,
valid: !(
scope.isStrict ||
node.sourceType === "module" ||
(features.globalReturn && scope.childScopes[0].isStrict)
)
valid: true
});
},
"Program:exit"() {
onCodePathEnd(codePath, node) {
if (isCodePathWithLexicalThis(codePath, node)) {
return;
}
stack.pop();
},
FunctionDeclaration: enterFunction,
"FunctionDeclaration:exit": exitFunction,
FunctionExpression: enterFunction,
"FunctionExpression:exit": exitFunction,
// Field initializers are implicit functions.
"PropertyDefinition > *.value": enterFunction,
"PropertyDefinition > *.value:exit": exitFunction,
// Class static blocks are implicit functions.
StaticBlock: enterFunction,
"StaticBlock:exit": exitFunction,
// Reports if `this` of the current context is invalid.

@@ -145,0 +142,0 @@ ThisExpression(node) {

@@ -34,5 +34,5 @@ /**

docs: {
description: "disallow irregular whitespace",
description: "Disallow irregular whitespace",
recommended: true,
url: "https://eslint.org/docs/rules/no-irregular-whitespace"
url: "https://eslint.org/docs/latest/rules/no-irregular-whitespace"
},

@@ -59,2 +59,6 @@

default: false
},
skipJSXText: {
type: "boolean",
default: false
}

@@ -82,4 +86,5 @@ },

const skipTemplates = !!options.skipTemplates;
const skipJSXText = !!options.skipJSXText;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const commentNodes = sourceCode.getAllComments();

@@ -106,3 +111,3 @@

/**
* Checks identifier or literal nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
* Checks literal nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
* @param {ASTNode} node to check for matching errors.

@@ -112,3 +117,3 @@ * @returns {void}

*/
function removeInvalidNodeErrorsInIdentifierOrLiteral(node) {
function removeInvalidNodeErrorsInLiteral(node) {
const shouldCheckStrings = skipStrings && (typeof node.value === "string");

@@ -153,2 +158,14 @@ const shouldCheckRegExps = skipRegExps && Boolean(node.regex);

/**
* Checks JSX nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors
* @param {ASTNode} node to check for matching errors.
* @returns {void}
* @private
*/
function removeInvalidNodeErrorsInJSXText(node) {
if (ALL_IRREGULARS.test(node.raw)) {
removeWhitespaceError(node);
}
}
/**
* Checks the program source for irregular whitespace

@@ -246,5 +263,5 @@ * @param {ASTNode} node The program node

nodes.Identifier = removeInvalidNodeErrorsInIdentifierOrLiteral;
nodes.Literal = removeInvalidNodeErrorsInIdentifierOrLiteral;
nodes.Literal = removeInvalidNodeErrorsInLiteral;
nodes.TemplateElement = skipTemplates ? removeInvalidNodeErrorsInTemplateLiteral : noop;
nodes.JSXText = skipJSXText ? removeInvalidNodeErrorsInJSXText : noop;
nodes["Program:exit"] = function() {

@@ -251,0 +268,0 @@ if (skipComments) {

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow the use of the `__iterator__` property",
description: "Disallow the use of the `__iterator__` property",
recommended: false,
url: "https://eslint.org/docs/rules/no-iterator"
url: "https://eslint.org/docs/latest/rules/no-iterator"
},

@@ -29,0 +29,0 @@

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow labels that share a name with a variable",
description: "Disallow labels that share a name with a variable",
recommended: false,
url: "https://eslint.org/docs/rules/no-label-var"
url: "https://eslint.org/docs/latest/rules/no-label-var"
},

@@ -38,2 +38,3 @@

create(context) {
const sourceCode = context.sourceCode;

@@ -64,3 +65,3 @@ //--------------------------------------------------------------------------

// Fetch the innermost scope.
const scope = context.getScope();
const scope = sourceCode.getScope(node);

@@ -67,0 +68,0 @@ /*

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow labeled statements",
description: "Disallow labeled statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-labels"
url: "https://eslint.org/docs/latest/rules/no-labels"
},

@@ -102,3 +102,3 @@

/* istanbul ignore next: syntax error */
/* c8 ignore next */
return "other";

@@ -105,0 +105,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow unnecessary nested blocks",
description: "Disallow unnecessary nested blocks",
recommended: false,
url: "https://eslint.org/docs/rules/no-lone-blocks"
url: "https://eslint.org/docs/latest/rules/no-lone-blocks"
},

@@ -37,2 +37,3 @@

let ruleDef;
const sourceCode = context.sourceCode;

@@ -72,5 +73,6 @@ /**

* and "marks it" as valid if any.
* @param {ASTNode} node The current node to check.
* @returns {void}
*/
function markLoneBlock() {
function markLoneBlock(node) {
if (loneBlocks.length === 0) {

@@ -80,3 +82,3 @@ return;

const block = context.getAncestors().pop();
const block = node.parent;

@@ -98,3 +100,3 @@ if (loneBlocks[loneBlocks.length - 1] === block) {

// ES6: report blocks without block-level bindings, or that's only child of another block
if (context.parserOptions.ecmaVersion >= 6) {
if (context.languageOptions.ecmaVersion >= 2015) {
ruleDef = {

@@ -124,9 +126,9 @@ BlockStatement(node) {

if (node.kind === "let" || node.kind === "const") {
markLoneBlock();
markLoneBlock(node);
}
};
ruleDef.FunctionDeclaration = function() {
if (context.getScope().isStrict) {
markLoneBlock();
ruleDef.FunctionDeclaration = function(node) {
if (sourceCode.getScope(node).isStrict) {
markLoneBlock(node);
}

@@ -133,0 +135,0 @@ };

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow `if` statements as the only statement in `else` blocks",
description: "Disallow `if` statements as the only statement in `else` blocks",
recommended: false,
url: "https://eslint.org/docs/rules/no-lonely-if"
url: "https://eslint.org/docs/latest/rules/no-lonely-if"
},

@@ -32,9 +32,8 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
return {
IfStatement(node) {
const ancestors = context.getAncestors(),
parent = ancestors.pop(),
grandparent = ancestors.pop();
const parent = node.parent,
grandparent = parent.parent;

@@ -41,0 +40,0 @@ if (parent && parent.type === "BlockStatement" &&

@@ -128,3 +128,3 @@ /**

*
* It's safeafe if the reference matches one of the following condition.
* It's safe if the reference matches one of the following condition.
* - is readonly.

@@ -158,5 +158,5 @@ * - doesn't exist inside a local function and after the border.

docs: {
description: "disallow function declarations that contain unsafe references inside loop statements",
description: "Disallow function declarations that contain unsafe references inside loop statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-loop-func"
url: "https://eslint.org/docs/latest/rules/no-loop-func"
},

@@ -173,2 +173,4 @@

const sourceCode = context.sourceCode;
/**

@@ -189,4 +191,4 @@ * Reports functions which match the following condition:

const references = context.getScope().through;
const unsafeRefs = references.filter(r => !isSafe(loopNode, r)).map(r => r.identifier.name);
const references = sourceCode.getScope(node).through;
const unsafeRefs = references.filter(r => r.resolved && !isSafe(loopNode, r)).map(r => r.identifier.name);

@@ -193,0 +195,0 @@ if (unsafeRefs.length > 0) {

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow literal numbers that lose precision",
description: "Disallow literal numbers that lose precision",
recommended: true,
url: "https://eslint.org/docs/rules/no-loss-of-precision"
url: "https://eslint.org/docs/latest/rules/no-loss-of-precision"
},

@@ -87,3 +87,3 @@ schema: [],

function addDecimalPointToNumber(stringNumber) {
return `${stringNumber.slice(0, 1)}.${stringNumber.slice(1)}`;
return `${stringNumber[0]}.${stringNumber.slice(1)}`;
}

@@ -97,3 +97,8 @@

function removeLeadingZeros(numberAsString) {
return numberAsString.replace(/^0*/u, "");
for (let i = 0; i < numberAsString.length; i++) {
if (numberAsString[i] !== "0") {
return numberAsString.slice(i);
}
}
return numberAsString;
}

@@ -107,7 +112,12 @@

function removeTrailingZeros(numberAsString) {
return numberAsString.replace(/0*$/u, "");
for (let i = numberAsString.length - 1; i >= 0; i--) {
if (numberAsString[i] !== "0") {
return numberAsString.slice(0, i + 1);
}
}
return numberAsString;
}
/**
* 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

@@ -127,3 +137,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

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

if (trimmedFloat.startsWith(".")) {
const decimalDigits = trimmedFloat.split(".").pop();
const decimalDigits = trimmedFloat.slice(1);
const significantDigits = removeLeadingZeros(decimalDigits);

@@ -153,3 +163,2 @@

/**

@@ -170,3 +179,2 @@ * Converts a base ten number to proper scientific notation

return `${normalizedCoefficient}e${magnitude}`;
}

@@ -173,0 +181,0 @@

@@ -35,5 +35,5 @@ /**

docs: {
description: "disallow magic numbers",
description: "Disallow magic numbers",
recommended: false,
url: "https://eslint.org/docs/rules/no-magic-numbers"
url: "https://eslint.org/docs/latest/rules/no-magic-numbers"
},

@@ -69,2 +69,6 @@

default: false
},
ignoreClassFieldInitialValues: {
type: "boolean",
default: false
}

@@ -85,5 +89,6 @@ },

enforceConst = !!config.enforceConst,
ignore = (config.ignore || []).map(normalizeIgnoreValue),
ignore = new Set((config.ignore || []).map(normalizeIgnoreValue)),
ignoreArrayIndexes = !!config.ignoreArrayIndexes,
ignoreDefaultValues = !!config.ignoreDefaultValues;
ignoreDefaultValues = !!config.ignoreDefaultValues,
ignoreClassFieldInitialValues = !!config.ignoreClassFieldInitialValues;

@@ -98,3 +103,3 @@ const okTypes = detectObjects ? [] : ["ObjectExpression", "Property", "AssignmentExpression"];

function isIgnoredValue(value) {
return ignore.indexOf(value) !== -1;
return ignore.has(value);
}

@@ -114,2 +119,13 @@

/**
* Returns whether the number is the initial value of a class field.
* @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node
* @returns {boolean} true if the number is the initial value of a class field.
*/
function isClassFieldInitialValue(fullNumberNode) {
const parent = fullNumberNode.parent;
return parent.type === "PropertyDefinition" && parent.value === fullNumberNode;
}
/**
* Returns whether the given node is used as a radix within parseInt() or Number.parseInt()

@@ -202,2 +218,3 @@ * @param {ASTNode} fullNumberNode `Literal` or `UnaryExpression` full number node

(ignoreDefaultValues && isDefaultValue(fullNumberNode)) ||
(ignoreClassFieldInitialValues && isClassFieldInitialValue(fullNumberNode)) ||
isParseIntRadix(fullNumberNode) ||

@@ -218,3 +235,3 @@ isJSXNumber(fullNumberNode) ||

} else if (
okTypes.indexOf(parent.type) === -1 ||
!okTypes.includes(parent.type) ||
(parent.type === "AssignmentExpression" && parent.left.type === "Identifier")

@@ -221,0 +238,0 @@ ) {

@@ -6,5 +6,7 @@ /**

const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
const { RegExpParser, visitRegExpAST } = require("regexpp");
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("@eslint-community/eslint-utils");
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurrogatePair } = require("./utils/unicode");
const astUtils = require("./utils/ast-utils.js");
const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");

@@ -16,2 +18,7 @@ //------------------------------------------------------------------------------

/**
* @typedef {import('@eslint-community/regexpp').AST.Character} Character
* @typedef {import('@eslint-community/regexpp').AST.CharacterClassElement} CharacterClassElement
*/
/**
* Iterate character sequences of a given nodes.

@@ -21,6 +28,8 @@ *

* so this function reverts CharacterClassRange syntax and restore the sequence.
* @param {regexpp.AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
* @returns {IterableIterator<number[]>} The list of character sequences.
* @param {CharacterClassElement[]} nodes The node list to iterate character sequences.
* @returns {IterableIterator<Character[]>} The list of character sequences.
*/
function *iterateCharacterSequence(nodes) {
/** @type {Character[]} */
let seq = [];

@@ -31,12 +40,15 @@

case "Character":
seq.push(node.value);
seq.push(node);
break;
case "CharacterClassRange":
seq.push(node.min.value);
seq.push(node.min);
yield seq;
seq = [node.max.value];
seq = [node.max];
break;
case "CharacterSet":
case "CharacterClass": // [[]] nesting character class
case "ClassStringDisjunction": // \q{...}
case "ExpressionCharacterClass": // [A--B]
if (seq.length > 0) {

@@ -57,12 +69,54 @@ yield seq;

/**
* Checks whether the given character node is a Unicode code point escape or not.
* @param {Character} char the character node to check.
* @returns {boolean} `true` if the character node is a Unicode code point escape.
*/
function isUnicodeCodePointEscape(char) {
return /^\\u\{[\da-f]+\}$/iu.test(char.raw);
}
/**
* Each function returns `true` if it detects that kind of problem.
* @type {Record<string, (chars: Character[]) => boolean>}
*/
const hasCharacterSequence = {
surrogatePairWithoutUFlag(chars) {
return chars.some((c, i) => i !== 0 && isSurrogatePair(chars[i - 1], c));
return chars.some((c, i) => {
if (i === 0) {
return false;
}
const c1 = chars[i - 1];
return (
isSurrogatePair(c1.value, c.value) &&
!isUnicodeCodePointEscape(c1) &&
!isUnicodeCodePointEscape(c)
);
});
},
surrogatePair(chars) {
return chars.some((c, i) => {
if (i === 0) {
return false;
}
const c1 = chars[i - 1];
return (
isSurrogatePair(c1.value, c.value) &&
(
isUnicodeCodePointEscape(c1) ||
isUnicodeCodePointEscape(c)
)
);
});
},
combiningClass(chars) {
return chars.some((c, i) => (
i !== 0 &&
isCombiningCharacter(c) &&
!isCombiningCharacter(chars[i - 1])
isCombiningCharacter(c.value) &&
!isCombiningCharacter(chars[i - 1].value)
));

@@ -74,4 +128,4 @@ },

i !== 0 &&
isEmojiModifier(c) &&
!isEmojiModifier(chars[i - 1])
isEmojiModifier(c.value) &&
!isEmojiModifier(chars[i - 1].value)
));

@@ -83,4 +137,4 @@ },

i !== 0 &&
isRegionalIndicatorSymbol(c) &&
isRegionalIndicatorSymbol(chars[i - 1])
isRegionalIndicatorSymbol(c.value) &&
isRegionalIndicatorSymbol(chars[i - 1].value)
));

@@ -95,5 +149,5 @@ },

i !== lastIndex &&
c === 0x200d &&
chars[i - 1] !== 0x200d &&
chars[i + 1] !== 0x200d
c.value === 0x200d &&
chars[i - 1].value !== 0x200d &&
chars[i + 1].value !== 0x200d
));

@@ -115,7 +169,9 @@ }

docs: {
description: "disallow characters which are made with multiple code points in character class syntax",
description: "Disallow characters which are made with multiple code points in character class syntax",
recommended: true,
url: "https://eslint.org/docs/rules/no-misleading-character-class"
url: "https://eslint.org/docs/latest/rules/no-misleading-character-class"
},
hasSuggestions: true,
schema: [],

@@ -125,9 +181,12 @@

surrogatePairWithoutUFlag: "Unexpected surrogate pair in character class. Use 'u' flag.",
surrogatePair: "Unexpected surrogate pair in character class.",
combiningClass: "Unexpected combined character in character class.",
emojiModifier: "Unexpected modified Emoji in character class.",
regionalIndicatorSymbol: "Unexpected national flag in character class.",
zwj: "Unexpected joined character sequence in character class."
zwj: "Unexpected joined character sequence in character class.",
suggestUnicodeFlag: "Add unicode 'u' flag to regex."
}
},
create(context) {
const sourceCode = context.sourceCode;
const parser = new RegExpParser();

@@ -140,13 +199,6 @@

* @param {string} flags The flags of the regular expression.
* @param {Function} unicodeFixer Fixer for missing "u" flag.
* @returns {void}
*/
function verify(node, pattern, flags) {
const has = {
surrogatePairWithoutUFlag: false,
combiningClass: false,
variationSelector: false,
emojiModifier: false,
regionalIndicatorSymbol: false,
zwj: false
};
function verify(node, pattern, flags, unicodeFixer) {
let patternNode;

@@ -159,3 +211,6 @@

pattern.length,
flags.includes("u")
{
unicode: flags.includes("u"),
unicodeSets: flags.includes("v")
}
);

@@ -168,2 +223,4 @@ } catch {

const foundKinds = new Set();
visitRegExpAST(patternNode, {

@@ -173,3 +230,5 @@ onCharacterClassEnter(ccNode) {

for (const kind of kinds) {
has[kind] = has[kind] || hasCharacterSequence[kind](chars);
if (hasCharacterSequence[kind](chars)) {
foundKinds.add(kind);
}
}

@@ -180,6 +239,17 @@ }

for (const kind of kinds) {
if (has[kind]) {
context.report({ node, messageId: kind });
for (const kind of foundKinds) {
let suggest;
if (kind === "surrogatePairWithoutUFlag") {
suggest = [{
messageId: "suggestUnicodeFlag",
fix: unicodeFixer
}];
}
context.report({
node,
messageId: kind,
suggest
});
}

@@ -190,6 +260,12 @@ }

"Literal[regex]"(node) {
verify(node, node.regex.pattern, node.regex.flags);
verify(node, node.regex.pattern, node.regex.flags, fixer => {
if (!isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, node.regex.pattern)) {
return null;
}
return fixer.insertTextAfter(node, "u");
});
},
"Program"() {
const scope = context.getScope();
"Program"(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -202,6 +278,6 @@

*/
for (const { node } of tracker.iterateGlobalReferences({
for (const { node: refNode } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true }
})) {
const [patternNode, flagsNode] = node.arguments;
const [patternNode, flagsNode] = refNode.arguments;
const pattern = getStringIfConstant(patternNode, scope);

@@ -211,3 +287,27 @@ const flags = getStringIfConstant(flagsNode, scope);

if (typeof pattern === "string") {
verify(node, pattern, flags || "");
verify(refNode, pattern, flags || "", fixer => {
if (!isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, pattern)) {
return null;
}
if (refNode.arguments.length === 1) {
const penultimateToken = sourceCode.getLastToken(refNode, { skip: 1 }); // skip closing parenthesis
return fixer.insertTextAfter(
penultimateToken,
astUtils.isCommaToken(penultimateToken)
? ' "u",'
: ', "u"'
);
}
if ((flagsNode.type === "Literal" && typeof flagsNode.value === "string") || flagsNode.type === "TemplateLiteral") {
const range = [flagsNode.range[0], flagsNode.range[1] - 1];
return fixer.insertTextAfterRange(range, "u");
}
return null;
});
}

@@ -214,0 +314,0 @@ }

/**
* @fileoverview Rule to disallow mixed binary operators.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -67,3 +68,3 @@

function includesBothInAGroup(groups, left, right) {
return groups.some(group => group.indexOf(left) !== -1 && group.indexOf(right) !== -1);
return groups.some(group => group.includes(left) && group.includes(right));
}

@@ -89,8 +90,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "disallow mixed binary operators",
description: "Disallow mixed binary operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-mixed-operators"
url: "https://eslint.org/docs/latest/rules/no-mixed-operators"
},

@@ -127,3 +130,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = normalizeOptions(context.options[0]);

@@ -130,0 +133,0 @@

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow `require` calls to be mixed with regular variable declarations",
description: "Disallow `require` calls to be mixed with regular variable declarations",
recommended: false,
url: "https://eslint.org/docs/rules/no-mixed-requires"
url: "https://eslint.org/docs/latest/rules/no-mixed-requires"
},

@@ -164,3 +164,3 @@

if (BUILTIN_MODULES.indexOf(arg.value) !== -1) {
if (BUILTIN_MODULES.includes(arg.value)) {

@@ -167,0 +167,0 @@ // "var fs = require('fs');"

/**
* @fileoverview Disallow mixed spaces and tabs for indentation
* @author Jary Niebur
* @deprecated in ESLint v8.53.0
*/

@@ -14,8 +15,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow mixed spaces and tabs for indentation",
description: "Disallow mixed spaces and tabs for indentation",
recommended: true,
url: "https://eslint.org/docs/rules/no-mixed-spaces-and-tabs"
url: "https://eslint.org/docs/latest/rules/no-mixed-spaces-and-tabs"
},

@@ -35,3 +38,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -38,0 +41,0 @@ let smartTabs;

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow use of chained assignment expressions",
description: "Disallow use of chained assignment expressions",
recommended: false,
url: "https://eslint.org/docs/rules/no-multi-assign"
url: "https://eslint.org/docs/latest/rules/no-multi-assign"
},

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

/**
* @fileoverview Disallow use of multiple spaces.
* @author Nicholas C. Zakas
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow multiple spaces",
description: "Disallow multiple spaces",
recommended: false,
url: "https://eslint.org/docs/rules/no-multi-spaces"
url: "https://eslint.org/docs/latest/rules/no-multi-spaces"
},

@@ -56,7 +59,7 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = context.options[0] || {};
const ignoreEOLComments = options.ignoreEOLComments;
const exceptions = Object.assign({ Property: true }, options.exceptions);
const hasExceptions = Object.keys(exceptions).filter(key => exceptions[key]).length > 0;
const hasExceptions = Object.keys(exceptions).some(key => exceptions[key]);

@@ -63,0 +66,0 @@ /**

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow multiline strings",
description: "Disallow multiline strings",
recommended: false,
url: "https://eslint.org/docs/rules/no-multi-str"
url: "https://eslint.org/docs/latest/rules/no-multi-str"
},

@@ -29,0 +29,0 @@

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

* @author Greg Cochard
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow multiple empty lines",
description: "Disallow multiple empty lines",
recommended: false,
url: "https://eslint.org/docs/rules/no-multiple-empty-lines"
url: "https://eslint.org/docs/latest/rules/no-multiple-empty-lines"
},

@@ -69,3 +72,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -72,0 +75,0 @@ // Swallow the final newline, as some editors add it automatically and we don't want it to cause an issue

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow assignments to native objects or read-only global variables",
description: "Disallow assignments to native objects or read-only global variables",
recommended: false,
url: "https://eslint.org/docs/rules/no-native-reassign"
url: "https://eslint.org/docs/latest/rules/no-native-reassign"
},

@@ -51,2 +51,3 @@

const exceptions = (config && config.exceptions) || [];
const sourceCode = context.sourceCode;

@@ -86,3 +87,3 @@ /**

function checkVariable(variable) {
if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) {
if (variable.writeable === false && !exceptions.includes(variable.name)) {
variable.references.forEach(checkReference);

@@ -93,4 +94,4 @@ }

return {
Program() {
const globalScope = context.getScope();
Program(node) {
const globalScope = sourceCode.getScope(node);

@@ -97,0 +98,0 @@ globalScope.variables.forEach(checkVariable);

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow negated conditions",
description: "Disallow negated conditions",
recommended: false,
url: "https://eslint.org/docs/rules/no-negated-condition"
url: "https://eslint.org/docs/latest/rules/no-negated-condition"
},

@@ -22,0 +22,0 @@

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow negating the left operand in `in` expressions",
description: "Disallow negating the left operand in `in` expressions",
recommended: false,
url: "https://eslint.org/docs/rules/no-negated-in-lhs"
url: "https://eslint.org/docs/latest/rules/no-negated-in-lhs"
},

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

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow nested ternary expressions",
description: "Disallow nested ternary expressions",
recommended: false,
url: "https://eslint.org/docs/rules/no-nested-ternary"
url: "https://eslint.org/docs/latest/rules/no-nested-ternary"
},

@@ -23,0 +23,0 @@

@@ -30,5 +30,5 @@ /**

docs: {
description: "disallow `new` operators with the `Function` object",
description: "Disallow `new` operators with the `Function` object",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-func"
url: "https://eslint.org/docs/latest/rules/no-new-func"
},

@@ -44,6 +44,7 @@

create(context) {
const sourceCode = context.sourceCode;
return {
"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);
const variable = globalScope.set.get("Function");

@@ -53,8 +54,8 @@

variable.references.forEach(ref => {
const node = ref.identifier;
const { parent } = node;
const idNode = ref.identifier;
const { parent } = idNode;
let evalNode;
if (parent) {
if (node === parent.callee && (
if (idNode === parent.callee && (
parent.type === "NewExpression" ||

@@ -66,3 +67,3 @@ parent.type === "CallExpression"

parent.type === "MemberExpression" &&
node === parent.object &&
idNode === parent.object &&
callMethods.has(astUtils.getStaticPropertyName(parent))

@@ -69,0 +70,0 @@ ) {

/**
* @fileoverview A rule to disallow calls to the Object constructor
* @author Matt DuVall <http://www.mattduvall.com/>
* @deprecated in ESLint v8.50.0
*/

@@ -24,11 +25,17 @@

docs: {
description: "disallow `Object` constructors",
description: "Disallow `Object` constructors",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-object"
url: "https://eslint.org/docs/latest/rules/no-new-object"
},
deprecated: true,
replacedBy: [
"no-object-constructor"
],
schema: [],
messages: {
preferLiteral: "The object literal notation {} is preferrable."
preferLiteral: "The object literal notation {} is preferable."
}

@@ -38,6 +45,9 @@ },

create(context) {
const sourceCode = context.sourceCode;
return {
NewExpression(node) {
const variable = astUtils.getVariableByName(
context.getScope(),
sourceCode.getScope(node),
node.callee.name

@@ -44,0 +54,0 @@ );

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow `new` operators with calls to `require`",
description: "Disallow `new` operators with calls to `require`",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-require"
url: "https://eslint.org/docs/latest/rules/no-new-require"
},

@@ -28,0 +28,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow `new` operators with the `Symbol` object",
description: "Disallow `new` operators with the `Symbol` object",
recommended: true,
url: "https://eslint.org/docs/rules/no-new-symbol"
url: "https://eslint.org/docs/latest/rules/no-new-symbol"
},

@@ -33,5 +33,7 @@

const sourceCode = context.sourceCode;
return {
"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);
const variable = globalScope.set.get("Symbol");

@@ -41,8 +43,8 @@

variable.references.forEach(ref => {
const node = ref.identifier;
const parent = node.parent;
const idNode = ref.identifier;
const parent = idNode.parent;
if (parent && parent.type === "NewExpression" && parent.callee === node) {
if (parent && parent.type === "NewExpression" && parent.callee === idNode) {
context.report({
node,
node: idNode,
messageId: "noNewSymbol"

@@ -49,0 +51,0 @@ });

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { getVariableByName } = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,5 +25,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
description: "Disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-wrappers"
url: "https://eslint.org/docs/latest/rules/no-new-wrappers"
},

@@ -33,2 +39,3 @@

create(context) {
const { sourceCode } = context;

@@ -39,9 +46,14 @@ return {

const wrapperObjects = ["String", "Number", "Boolean"];
const { name } = node.callee;
if (wrapperObjects.indexOf(node.callee.name) > -1) {
context.report({
node,
messageId: "noConstructor",
data: { fn: node.callee.name }
});
if (wrapperObjects.includes(name)) {
const variable = getVariableByName(sourceCode.getScope(node), name);
if (variable && variable.identifiers.length === 0) {
context.report({
node,
messageId: "noConstructor",
data: { fn: name }
});
}
}

@@ -48,0 +60,0 @@ }

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow `new` operators outside of assignments or comparisons",
description: "Disallow `new` operators outside of assignments or comparisons",
recommended: false,
url: "https://eslint.org/docs/rules/no-new"
url: "https://eslint.org/docs/latest/rules/no-new"
},

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

@@ -33,5 +33,5 @@ /**

docs: {
description: "disallow `\\8` and `\\9` escape sequences in string literals",
description: "Disallow `\\8` and `\\9` escape sequences in string literals",
recommended: true,
url: "https://eslint.org/docs/rules/no-nonoctal-decimal-escape"
url: "https://eslint.org/docs/latest/rules/no-nonoctal-decimal-escape"
},

@@ -53,3 +53,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -56,0 +56,0 @@ /**

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

const { CALL, CONSTRUCT, ReferenceTracker } = require("eslint-utils");
const { CALL, CONSTRUCT, ReferenceTracker } = require("@eslint-community/eslint-utils");
const getPropertyName = require("./utils/ast-utils").getStaticPropertyName;

@@ -20,3 +20,3 @@

const nonCallableGlobals = ["Atomics", "JSON", "Math", "Reflect"];
const nonCallableGlobals = ["Atomics", "JSON", "Math", "Reflect", "Intl"];

@@ -48,5 +48,5 @@ /**

docs: {
description: "disallow calling global object properties as functions",
description: "Disallow calling global object properties as functions",
recommended: true,
url: "https://eslint.org/docs/rules/no-obj-calls"
url: "https://eslint.org/docs/latest/rules/no-obj-calls"
},

@@ -64,5 +64,7 @@

const sourceCode = context.sourceCode;
return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -78,8 +80,8 @@ const traceMap = {};

for (const { node, path } of tracker.iterateGlobalReferences(traceMap)) {
const name = getReportNodeName(node.callee);
for (const { node: refNode, path } of tracker.iterateGlobalReferences(traceMap)) {
const name = getReportNodeName(refNode.callee);
const ref = path[0];
const messageId = name === ref ? "unexpectedCall" : "unexpectedRefCall";
context.report({ node, messageId, data: { name, ref } });
context.report({ node: refNode, messageId, data: { name, ref } });
}

@@ -86,0 +88,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow octal escape sequences in string literals",
description: "Disallow octal escape sequences in string literals",
recommended: false,
url: "https://eslint.org/docs/rules/no-octal-escape"
url: "https://eslint.org/docs/latest/rules/no-octal-escape"
},

@@ -23,0 +23,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow octal literals",
description: "Disallow octal literals",
recommended: true,
url: "https://eslint.org/docs/rules/no-octal"
url: "https://eslint.org/docs/latest/rules/no-octal"
},

@@ -27,3 +27,3 @@

messages: {
noOcatal: "Octal literals should not be used."
noOctal: "Octal literals should not be used."
}

@@ -40,3 +40,3 @@ },

node,
messageId: "noOcatal"
messageId: "noOctal"
});

@@ -43,0 +43,0 @@ }

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow reassigning `function` parameters",
description: "Disallow reassigning `function` parameters",
recommended: false,
url: "https://eslint.org/docs/rules/no-param-reassign"
url: "https://eslint.org/docs/latest/rules/no-param-reassign"
},

@@ -74,2 +74,3 @@

const ignoredPropertyAssignmentsForRegex = context.options[0] && context.options[0].ignorePropertyModificationsForRegex || [];
const sourceCode = context.sourceCode;

@@ -219,3 +220,3 @@ /**

function checkForFunction(node) {
context.getDeclaredVariables(node).forEach(checkVariable);
sourceCode.getDeclaredVariables(node).forEach(checkVariable);
}

@@ -222,0 +223,0 @@

@@ -22,5 +22,5 @@ /**

docs: {
description: "disallow string concatenation with `__dirname` and `__filename`",
description: "Disallow string concatenation with `__dirname` and `__filename`",
recommended: false,
url: "https://eslint.org/docs/rules/no-path-concat"
url: "https://eslint.org/docs/latest/rules/no-path-concat"
},

@@ -27,0 +27,0 @@

@@ -54,5 +54,5 @@ /**

docs: {
description: "disallow the unary operators `++` and `--`",
description: "Disallow the unary operators `++` and `--`",
recommended: false,
url: "https://eslint.org/docs/rules/no-plusplus"
url: "https://eslint.org/docs/latest/rules/no-plusplus"
},

@@ -59,0 +59,0 @@

@@ -22,5 +22,5 @@ /**

docs: {
description: "disallow the use of `process.env`",
description: "Disallow the use of `process.env`",
recommended: false,
url: "https://eslint.org/docs/rules/no-process-env"
url: "https://eslint.org/docs/latest/rules/no-process-env"
},

@@ -27,0 +27,0 @@

@@ -22,5 +22,5 @@ /**

docs: {
description: "disallow the use of `process.exit()`",
description: "Disallow the use of `process.exit()`",
recommended: false,
url: "https://eslint.org/docs/rules/no-process-exit"
url: "https://eslint.org/docs/latest/rules/no-process-exit"
},

@@ -27,0 +27,0 @@

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

const { findVariable } = require("eslint-utils");
const { findVariable } = require("@eslint-community/eslint-utils");
const astUtils = require("./utils/ast-utils");

@@ -63,2 +64,74 @@ //------------------------------------------------------------------------------

/**
* Checks if the given node is a void expression.
* @param {ASTNode} node The node to check.
* @returns {boolean} - `true` if the node is a void expression
*/
function expressionIsVoid(node) {
return node.type === "UnaryExpression" && node.operator === "void";
}
/**
* Fixes the linting error by prepending "void " to the given node
* @param {Object} sourceCode context given by context.sourceCode
* @param {ASTNode} node The node to fix.
* @param {Object} fixer The fixer object provided by ESLint.
* @returns {Array<Object>} - An array of fix objects to apply to the node.
*/
function voidPrependFixer(sourceCode, node, fixer) {
const requiresParens =
// prepending `void ` will fail if the node has a lower precedence than void
astUtils.getPrecedence(node) < astUtils.getPrecedence({ type: "UnaryExpression", operator: "void" }) &&
// check if there are parentheses around the node to avoid redundant parentheses
!astUtils.isParenthesised(sourceCode, node);
// avoid parentheses issues
const returnOrArrowToken = sourceCode.getTokenBefore(
node,
node.parent.type === "ArrowFunctionExpression"
? astUtils.isArrowToken
// isReturnToken
: token => token.type === "Keyword" && token.value === "return"
);
const firstToken = sourceCode.getTokenAfter(returnOrArrowToken);
const prependSpace =
// is return token, as => allows void to be adjacent
returnOrArrowToken.value === "return" &&
// If two tokens (return and "(") are adjacent
returnOrArrowToken.range[1] === firstToken.range[0];
return [
fixer.insertTextBefore(firstToken, `${prependSpace ? " " : ""}void ${requiresParens ? "(" : ""}`),
fixer.insertTextAfter(node, requiresParens ? ")" : "")
];
}
/**
* Fixes the linting error by `wrapping {}` around the given node's body.
* @param {Object} sourceCode context given by context.sourceCode
* @param {ASTNode} node The node to fix.
* @param {Object} fixer The fixer object provided by ESLint.
* @returns {Array<Object>} - An array of fix objects to apply to the node.
*/
function curlyWrapFixer(sourceCode, node, fixer) {
// https://github.com/eslint/eslint/pull/17282#issuecomment-1592795923
const arrowToken = sourceCode.getTokenBefore(node.body, astUtils.isArrowToken);
const firstToken = sourceCode.getTokenAfter(arrowToken);
const lastToken = sourceCode.getLastToken(node);
return [
fixer.insertTextBefore(firstToken, "{"),
fixer.insertTextAfter(lastToken, "}")
];
}
//------------------------------------------------------------------------------

@@ -74,11 +147,28 @@ // Rule Definition

docs: {
description: "disallow returning values from Promise executor functions",
description: "Disallow returning values from Promise executor functions",
recommended: false,
url: "https://eslint.org/docs/rules/no-promise-executor-return"
url: "https://eslint.org/docs/latest/rules/no-promise-executor-return"
},
schema: [],
hasSuggestions: true,
schema: [{
type: "object",
properties: {
allowVoid: {
type: "boolean",
default: false
}
},
additionalProperties: false
}],
messages: {
returnsValue: "Return values from promise executor functions cannot be read."
returnsValue: "Return values from promise executor functions cannot be read.",
// arrow and function suggestions
prependVoid: "Prepend `void` to the expression.",
// only arrow suggestions
wrapBraces: "Wrap the expression in `{}`."
}

@@ -90,12 +180,7 @@ },

let funcInfo = null;
const sourceCode = context.sourceCode;
const {
allowVoid = false
} = context.options[0] || {};
/**
* Reports the given node.
* @param {ASTNode} node Node to report.
* @returns {void}
*/
function report(node) {
context.report({ node, messageId: "returnsValue" });
}
return {

@@ -106,7 +191,39 @@

upper: funcInfo,
shouldCheck: functionTypesToCheck.has(node.type) && isPromiseExecutor(node, context.getScope())
shouldCheck:
functionTypesToCheck.has(node.type) &&
isPromiseExecutor(node, sourceCode.getScope(node))
};
if (funcInfo.shouldCheck && node.type === "ArrowFunctionExpression" && node.expression) {
report(node.body);
if (// Is a Promise executor
funcInfo.shouldCheck &&
node.type === "ArrowFunctionExpression" &&
node.expression &&
// Except void
!(allowVoid && expressionIsVoid(node.body))
) {
const suggest = [];
// prevent useless refactors
if (allowVoid) {
suggest.push({
messageId: "prependVoid",
fix(fixer) {
return voidPrependFixer(sourceCode, node.body, fixer);
}
});
}
suggest.push({
messageId: "wrapBraces",
fix(fixer) {
return curlyWrapFixer(sourceCode, node, fixer);
}
});
context.report({
node: node.body,
messageId: "returnsValue",
suggest
});
}

@@ -120,5 +237,27 @@ },

ReturnStatement(node) {
if (funcInfo.shouldCheck && node.argument) {
report(node);
if (!(funcInfo.shouldCheck && node.argument)) {
return;
}
// node is `return <expression>`
if (!allowVoid) {
context.report({ node, messageId: "returnsValue" });
return;
}
if (expressionIsVoid(node.argument)) {
return;
}
// allowVoid && !expressionIsVoid
context.report({
node,
messageId: "returnsValue",
suggest: [{
messageId: "prependVoid",
fix(fixer) {
return voidPrependFixer(sourceCode, node.argument, fixer);
}
}]
});
}

@@ -125,0 +264,0 @@ };

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow the use of the `__proto__` property",
description: "Disallow the use of the `__proto__` property",
recommended: false,
url: "https://eslint.org/docs/rules/no-proto"
url: "https://eslint.org/docs/latest/rules/no-proto"
},

@@ -29,0 +29,0 @@

@@ -14,2 +14,33 @@ /**

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Returns true if the node or any of the objects
* to the left of it in the member/call chain is optional.
*
* e.g. `a?.b`, `a?.b.c`, `a?.()`, `a()?.()`
* @param {ASTNode} node The expression to check
* @returns {boolean} `true` if there is a short-circuiting optional `?.`
* in the same option chain to the left of this call or member expression,
* or the node itself is an optional call or member `?.`.
*/
function isAfterOptional(node) {
let leftNode;
if (node.type === "MemberExpression") {
leftNode = node.object;
} else if (node.type === "CallExpression") {
leftNode = node.callee;
} else {
return false;
}
if (node.optional) {
return true;
}
return isAfterOptional(leftNode);
}
//------------------------------------------------------------------------------
// Rule Definition

@@ -24,11 +55,14 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow calling some `Object.prototype` methods directly on objects",
description: "Disallow calling some `Object.prototype` methods directly on objects",
recommended: true,
url: "https://eslint.org/docs/rules/no-prototype-builtins"
url: "https://eslint.org/docs/latest/rules/no-prototype-builtins"
},
hasSuggestions: true,
schema: [],
messages: {
prototypeBuildIn: "Do not access Object.prototype method '{{prop}}' from target object."
prototypeBuildIn: "Do not access Object.prototype method '{{prop}}' from target object.",
callObjectPrototype: "Call Object.prototype.{{prop}} explicitly."
}

@@ -38,7 +72,7 @@ },

create(context) {
const DISALLOWED_PROPS = [
const DISALLOWED_PROPS = new Set([
"hasOwnProperty",
"isPrototypeOf",
"propertyIsEnumerable"
];
]);

@@ -60,3 +94,3 @@ /**

if (propName !== null && DISALLOWED_PROPS.indexOf(propName) > -1) {
if (propName !== null && DISALLOWED_PROPS.has(propName)) {
context.report({

@@ -66,3 +100,57 @@ messageId: "prototypeBuildIn",

data: { prop: propName },
node
node,
suggest: [
{
messageId: "callObjectPrototype",
data: { prop: propName },
fix(fixer) {
const sourceCode = context.sourceCode;
/*
* A call after an optional chain (e.g. a?.b.hasOwnProperty(c))
* must be fixed manually because the call can be short-circuited
*/
if (isAfterOptional(node)) {
return null;
}
/*
* A call on a ChainExpression (e.g. (a?.hasOwnProperty)(c)) will trigger
* no-unsafe-optional-chaining which should be fixed before this suggestion
*/
if (node.callee.type === "ChainExpression") {
return null;
}
const objectVariable = astUtils.getVariableByName(sourceCode.getScope(node), "Object");
/*
* We can't use Object if the global Object was shadowed,
* or Object does not exist in the global scope for some reason
*/
if (!objectVariable || objectVariable.scope.type !== "global" || objectVariable.defs.length > 0) {
return null;
}
let objectText = sourceCode.getText(callee.object);
if (astUtils.getPrecedence(callee.object) <= astUtils.getPrecedence({ type: "SequenceExpression" })) {
objectText = `(${objectText})`;
}
const openParenToken = sourceCode.getTokenAfter(
node.callee,
astUtils.isOpeningParenToken
);
const isEmptyParameters = node.arguments.length === 0;
const delim = isEmptyParameters ? "" : ", ";
const fixes = [
fixer.replaceText(callee, `Object.prototype.${propName}.call`),
fixer.insertTextAfter(openParenToken, objectText + delim)
];
return fixes;
}
}
]
});

@@ -69,0 +157,0 @@ }

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow variable redeclaration",
description: "Disallow variable redeclaration",
recommended: true,
url: "https://eslint.org/docs/rules/no-redeclare"
url: "https://eslint.org/docs/latest/rules/no-redeclare"
},

@@ -54,3 +54,3 @@

};
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -134,3 +134,3 @@ /**

function checkForBlock(node) {
const scope = context.getScope();
const scope = sourceCode.getScope(node);

@@ -147,4 +147,4 @@ /*

return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);

@@ -151,0 +151,0 @@ findVariablesInScope(scope);

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

const astUtils = require("./utils/ast-utils");
const regexpp = require("regexpp");
const regexpp = require("@eslint-community/regexpp");

@@ -43,5 +43,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow multiple spaces in regular expressions",
description: "Disallow multiple spaces in regular expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-regex-spaces"
url: "https://eslint.org/docs/latest/rules/no-regex-spaces"
},

@@ -59,2 +59,4 @@

const sourceCode = context.sourceCode;
/**

@@ -81,3 +83,3 @@ * Validate regular expression

try {
regExpAST = regExpParser.parsePattern(pattern, 0, pattern.length, flags.includes("u"));
regExpAST = regExpParser.parsePattern(pattern, 0, pattern.length, { unicode: flags.includes("u"), unicodeSets: flags.includes("v") });
} catch {

@@ -156,7 +158,6 @@

function checkFunction(node) {
const scope = context.getScope();
const scope = sourceCode.getScope(node);
const regExpVar = astUtils.getVariableByName(scope, "RegExp");
const shadowed = regExpVar && regExpVar.defs.length > 0;
const patternNode = node.arguments[0];
const flagsNode = node.arguments[1];

@@ -167,4 +168,20 @@ if (node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(patternNode) && !shadowed) {

const rawPatternStartRange = patternNode.range[0] + 1;
const flags = isString(flagsNode) ? flagsNode.value : "";
let flags;
if (node.arguments.length < 2) {
// It has no flags.
flags = "";
} else {
const flagsNode = node.arguments[1];
if (isString(flagsNode)) {
flags = flagsNode.value;
} else {
// The flags cannot be determined.
return;
}
}
checkRegex(

@@ -171,0 +188,0 @@ node,

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,23 +25,73 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow specified names in exports",
description: "Disallow specified names in exports",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-exports"
url: "https://eslint.org/docs/latest/rules/no-restricted-exports"
},
schema: [{
type: "object",
properties: {
restrictedNamedExports: {
type: "array",
items: {
type: "string"
anyOf: [
{
type: "object",
properties: {
restrictedNamedExports: {
type: "array",
items: {
type: "string"
},
uniqueItems: true
}
},
uniqueItems: true
additionalProperties: false
},
{
type: "object",
properties: {
restrictedNamedExports: {
type: "array",
items: {
type: "string",
pattern: "^(?!default$)"
},
uniqueItems: true
},
restrictDefaultExports: {
type: "object",
properties: {
// Allow/Disallow `export default foo; export default 42; export default function foo() {}` format
direct: {
type: "boolean"
},
// Allow/Disallow `export { foo as default };` declarations
named: {
type: "boolean"
},
// Allow/Disallow `export { default } from "mod"; export { default as default } from "mod";` declarations
defaultFrom: {
type: "boolean"
},
// Allow/Disallow `export { foo as default } from "mod";` declarations
namedFrom: {
type: "boolean"
},
// Allow/Disallow `export * as default from "mod"`; declarations
namespaceFrom: {
type: "boolean"
}
},
additionalProperties: false
}
},
additionalProperties: false
}
},
additionalProperties: false
]
}],
messages: {
restrictedNamed: "'{{name}}' is restricted from being used as an exported name."
restrictedNamed: "'{{name}}' is restricted from being used as an exported name.",
restrictedDefault: "Exporting 'default' is restricted."
}

@@ -47,10 +103,12 @@ },

const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports);
const restrictDefaultExports = context.options[0] && context.options[0].restrictDefaultExports;
const sourceCode = context.sourceCode;
/**
* Checks and reports given exported identifier.
* @param {ASTNode} node exported `Identifier` node to check.
* Checks and reports given exported name.
* @param {ASTNode} node exported `Identifier` or string `Literal` node to check.
* @returns {void}
*/
function checkExportedName(node) {
const name = node.name;
const name = astUtils.getModuleExportName(node);

@@ -63,3 +121,39 @@ if (restrictedNames.has(name)) {

});
return;
}
if (name === "default") {
if (node.parent.type === "ExportAllDeclaration") {
if (restrictDefaultExports && restrictDefaultExports.namespaceFrom) {
context.report({
node,
messageId: "restrictedDefault"
});
}
} else { // ExportSpecifier
const isSourceSpecified = !!node.parent.parent.source;
const specifierLocalName = astUtils.getModuleExportName(node.parent.local);
if (!isSourceSpecified && restrictDefaultExports && restrictDefaultExports.named) {
context.report({
node,
messageId: "restrictedDefault"
});
return;
}
if (isSourceSpecified && restrictDefaultExports) {
if (
(specifierLocalName === "default" && restrictDefaultExports.defaultFrom) ||
(specifierLocalName !== "default" && restrictDefaultExports.namedFrom)
) {
context.report({
node,
messageId: "restrictedDefault"
});
}
}
}
}
}

@@ -74,2 +168,11 @@

ExportDefaultDeclaration(node) {
if (restrictDefaultExports && restrictDefaultExports.direct) {
context.report({
node,
messageId: "restrictedDefault"
});
}
},
ExportNamedDeclaration(node) {

@@ -82,3 +185,3 @@ const declaration = node.declaration;

} else if (declaration.type === "VariableDeclaration") {
context.getDeclaredVariables(declaration)
sourceCode.getDeclaredVariables(declaration)
.map(v => v.defs.find(d => d.parent === declaration))

@@ -85,0 +188,0 @@ .map(d => d.name) // Identifier nodes

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow specified global variables",
description: "Disallow specified global variables",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-globals"
url: "https://eslint.org/docs/latest/rules/no-restricted-globals"
},

@@ -54,2 +54,4 @@

const sourceCode = context.sourceCode;
// If no globals are restricted, we don't need to do anything

@@ -104,4 +106,4 @@ if (context.options.length === 0) {

return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);

@@ -108,0 +110,0 @@ // Report variables declared elsewhere (ex: variables defined as "global" by eslint)

@@ -8,2 +8,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -56,2 +62,10 @@ //------------------------------------------------------------------------------

properties: {
importNames: {
type: "array",
items: {
type: "string"
},
minItems: 1,
uniqueItems: true
},
group: {

@@ -68,2 +82,5 @@ type: "array",

minLength: 1
},
caseSensitive: {
type: "boolean"
}

@@ -85,5 +102,5 @@ },

docs: {
description: "disallow specified modules when loaded by `import`",
description: "Disallow specified modules when loaded by `import`",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-imports"
url: "https://eslint.org/docs/latest/rules/no-restricted-imports"
},

@@ -100,2 +117,10 @@

patternAndImportName: "'{{importName}}' import from '{{importSource}}' is restricted from being used by a pattern.",
// eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
patternAndImportNameWithCustomMessage: "'{{importName}}' import from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}",
patternAndEverything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern.",
// eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
patternAndEverythingWithCustomMessage: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted from being used by a pattern. {{customMessage}}",
everything: "* import is invalid because '{{importNames}}' from '{{importSource}}' is restricted.",

@@ -130,3 +155,3 @@ // eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = Array.isArray(context.options) ? context.options : [];

@@ -151,7 +176,16 @@ const isPathAndPatternsObject =

// Handle patterns too, either as strings or groups
const restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || [];
const restrictedPatternGroups = restrictedPatterns.length > 0 && typeof restrictedPatterns[0] === "string"
? [{ matcher: ignore().add(restrictedPatterns) }]
: restrictedPatterns.map(({ group, message }) => ({ matcher: ignore().add(group), customMessage: message }));
let restrictedPatterns = (isPathAndPatternsObject ? options[0].patterns : []) || [];
// standardize to array of objects if we have an array of strings
if (restrictedPatterns.length > 0 && typeof restrictedPatterns[0] === "string") {
restrictedPatterns = [{ group: restrictedPatterns }];
}
// relative paths are supported for this rule
const restrictedPatternGroups = restrictedPatterns.map(({ group, message, caseSensitive, importNames }) => ({
matcher: ignore({ allowRelativePaths: true, ignorecase: !caseSensitive }).add(group),
customMessage: message,
importNames
}));
// if no imports are restricted we don't need to check

@@ -227,16 +261,64 @@ if (Object.keys(restrictedPaths).length === 0 && restrictedPatternGroups.length === 0) {

* @param {node} node representing the restricted path reference
* @param {Object} group contains a Ignore instance for paths, and the customMessage to show if it fails
* @param {Object} group contains an Ignore instance for paths, the customMessage to show on failure,
* and any restricted import names that have been specified in the config
* @param {Map<string,Object[]>} importNames Map of import names that are being imported
* @returns {void}
* @private
*/
function reportPathForPatterns(node, group) {
function reportPathForPatterns(node, group, importNames) {
const importSource = node.source.value.trim();
context.report({
node,
messageId: group.customMessage ? "patternWithCustomMessage" : "patterns",
data: {
importSource,
customMessage: group.customMessage
const customMessage = group.customMessage;
const restrictedImportNames = group.importNames;
/*
* If we are not restricting to any specific import names and just the pattern itself,
* report the error and move on
*/
if (!restrictedImportNames) {
context.report({
node,
messageId: customMessage ? "patternWithCustomMessage" : "patterns",
data: {
importSource,
customMessage
}
});
return;
}
if (importNames.has("*")) {
const specifierData = importNames.get("*")[0];
context.report({
node,
messageId: customMessage ? "patternAndEverythingWithCustomMessage" : "patternAndEverything",
loc: specifierData.loc,
data: {
importSource,
importNames: restrictedImportNames,
customMessage
}
});
}
restrictedImportNames.forEach(importName => {
if (!importNames.has(importName)) {
return;
}
const specifiers = importNames.get(importName);
specifiers.forEach(specifier => {
context.report({
node,
messageId: customMessage ? "patternAndImportNameWithCustomMessage" : "patternAndImportName",
loc: specifier.loc,
data: {
importSource,
customMessage,
importName
}
});
});
});

@@ -280,8 +362,8 @@ }

} else if (specifier.imported) {
name = specifier.imported.name;
name = astUtils.getModuleExportName(specifier.imported);
} else if (specifier.local) {
name = specifier.local.name;
name = astUtils.getModuleExportName(specifier.local);
}
if (name) {
if (typeof name === "string") {
if (importNames.has(name)) {

@@ -299,3 +381,3 @@ importNames.get(name).push(specifierData);

if (isRestrictedPattern(importSource, group)) {
reportPathForPatterns(node, group);
reportPathForPatterns(node, group, importNames);
}

@@ -302,0 +384,0 @@ });

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -53,5 +59,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow specified modules when loaded by `require`",
description: "Disallow specified modules when loaded by `require`",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-modules"
url: "https://eslint.org/docs/latest/rules/no-restricted-modules"
},

@@ -108,3 +114,4 @@

const ig = ignore().add(restrictedPatterns);
// relative paths are supported for this rule
const ig = ignore({ allowRelativePaths: true }).add(restrictedPatterns);

@@ -122,11 +129,2 @@

/**
* Function to check if a node is a static string template literal.
* @param {ASTNode} node The node to check.
* @returns {boolean} If the node is a string template literal.
*/
function isStaticTemplateLiteral(node) {
return node && node.type === "TemplateLiteral" && node.expressions.length === 0;
}
/**
* Function to check if a node is a require call.

@@ -150,3 +148,3 @@ * @param {ASTNode} node The node to check.

if (isStaticTemplateLiteral(node)) {
if (astUtils.isStaticTemplateLiteral(node)) {
return node.quasis[0].value.cooked.trim();

@@ -153,0 +151,0 @@ }

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow certain properties on certain objects",
description: "Disallow certain properties on certain objects",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-properties"
url: "https://eslint.org/docs/latest/rules/no-restricted-properties"
},

@@ -25,0 +25,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow specified syntax",
description: "Disallow specified syntax",
recommended: false,
url: "https://eslint.org/docs/rules/no-restricted-syntax"
url: "https://eslint.org/docs/latest/rules/no-restricted-syntax"
},

@@ -22,0 +22,0 @@

@@ -29,5 +29,5 @@ /**

docs: {
description: "disallow assignment operators in `return` statements",
description: "Disallow assignment operators in `return` statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-return-assign"
url: "https://eslint.org/docs/latest/rules/no-return-assign"
},

@@ -49,3 +49,3 @@

const always = (context.options[0] || "except-parens") !== "except-parens";
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -52,0 +52,0 @@ return {

/**
* @fileoverview Disallows unnecessary `return await`
* @author Jordan Harband
* @deprecated in ESLint v8.46.0
*/

@@ -16,10 +17,11 @@ "use strict";

meta: {
hasSuggestions: true,
type: "suggestion",
docs: {
description: "disallow unnecessary `return await`",
description: "Disallow unnecessary `return await`",
recommended: false,
url: "https://eslint.org/docs/rules/no-return-await"
url: "https://eslint.org/docs/latest/rules/no-return-await"
},

@@ -29,2 +31,6 @@

deprecated: true,
replacedBy: [],
schema: [

@@ -34,2 +40,3 @@ ],

messages: {
removeAwait: "Remove redundant `await`.",
redundantUseOfAwait: "Redundant use of `await` on a return value."

@@ -48,5 +55,30 @@ }

context.report({
node: context.getSourceCode().getFirstToken(node),
node: context.sourceCode.getFirstToken(node),
loc: node.loc,
messageId: "redundantUseOfAwait"
messageId: "redundantUseOfAwait",
suggest: [
{
messageId: "removeAwait",
fix(fixer) {
const sourceCode = context.sourceCode;
const [awaitToken, tokenAfterAwait] = sourceCode.getFirstTokens(node, 2);
const areAwaitAndAwaitedExpressionOnTheSameLine = awaitToken.loc.start.line === tokenAfterAwait.loc.start.line;
if (!areAwaitAndAwaitedExpressionOnTheSameLine) {
return null;
}
const [startOfAwait, endOfAwait] = awaitToken.range;
const characterAfterAwait = sourceCode.text[endOfAwait];
const trimLength = characterAfterAwait === " " ? 1 : 0;
const range = [startOfAwait, endOfAwait + trimLength];
return fixer.removeRange(range);
}
}
]
});

@@ -53,0 +85,0 @@ }

@@ -21,5 +21,5 @@ /**

docs: {
description: "disallow `javascript:` urls",
description: "Disallow `javascript:` urls",
recommended: false,
url: "https://eslint.org/docs/rules/no-script-url"
url: "https://eslint.org/docs/latest/rules/no-script-url"
},

@@ -26,0 +26,0 @@

@@ -133,5 +133,5 @@ /**

docs: {
description: "disallow assignments where both sides are exactly the same",
description: "Disallow assignments where both sides are exactly the same",
recommended: true,
url: "https://eslint.org/docs/rules/no-self-assign"
url: "https://eslint.org/docs/latest/rules/no-self-assign"
},

@@ -158,3 +158,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const [{ props = true } = {}] = context.options;

@@ -179,3 +179,3 @@

AssignmentExpression(node) {
if (node.operator === "=") {
if (["=", "&&=", "||=", "??="].includes(node.operator)) {
eachSelfAssignment(node.left, node.right, props, report);

@@ -182,0 +182,0 @@ }

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow comparisons where both sides are exactly the same",
description: "Disallow comparisons where both sides are exactly the same",
recommended: false,
url: "https://eslint.org/docs/rules/no-self-compare"
url: "https://eslint.org/docs/latest/rules/no-self-compare"
},

@@ -33,3 +33,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -36,0 +36,0 @@ /**

@@ -32,5 +32,5 @@ /**

docs: {
description: "disallow comma operators",
description: "Disallow comma operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-sequences"
url: "https://eslint.org/docs/latest/rules/no-sequences"
},

@@ -55,3 +55,3 @@

const options = Object.assign({}, DEFAULT_OPTIONS, context.options[0]);
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -58,0 +58,0 @@ /**

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

const astUtils = require("./utils/ast-utils");
const { findVariable } = require("eslint-utils");
const { findVariable } = require("@eslint-community/eslint-utils");

@@ -146,5 +146,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow returning values from setters",
description: "Disallow returning values from setters",
recommended: true,
url: "https://eslint.org/docs/rules/no-setter-return"
url: "https://eslint.org/docs/latest/rules/no-setter-return"
},

@@ -161,2 +161,3 @@

let funcInfo = null;
const sourceCode = context.sourceCode;

@@ -169,3 +170,3 @@ /**

function enterFunction(node) {
const outerScope = getOuterScope(context.getScope());
const outerScope = getOuterScope(sourceCode.getScope(node));

@@ -172,0 +173,0 @@ funcInfo = {

@@ -30,5 +30,5 @@ /**

docs: {
description: "disallow identifiers from shadowing restricted names",
description: "Disallow identifiers from shadowing restricted names",
recommended: true,
url: "https://eslint.org/docs/rules/no-shadow-restricted-names"
url: "https://eslint.org/docs/latest/rules/no-shadow-restricted-names"
},

@@ -47,6 +47,7 @@

const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]);
const sourceCode = context.sourceCode;
return {
"VariableDeclaration, :function, CatchClause"(node) {
for (const variable of context.getDeclaredVariables(node)) {
for (const variable of sourceCode.getDeclaredVariables(node)) {
if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) {

@@ -53,0 +54,0 @@ context.report({

@@ -15,2 +15,11 @@ /**

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const FUNC_EXPR_NODE_TYPES = new Set(["ArrowFunctionExpression", "FunctionExpression"]);
const CALL_EXPR_NODE_TYPE = new Set(["CallExpression"]);
const FOR_IN_OF_TYPE = /^For(?:In|Of)Statement$/u;
const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/u;
//------------------------------------------------------------------------------
// Rule Definition

@@ -25,5 +34,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow variable declarations from shadowing variables declared in the outer scope",
description: "Disallow variable declarations from shadowing variables declared in the outer scope",
recommended: false,
url: "https://eslint.org/docs/rules/no-shadow"
url: "https://eslint.org/docs/latest/rules/no-shadow"
},

@@ -42,3 +51,4 @@

}
}
},
ignoreOnInitialization: { type: "boolean", default: false }
},

@@ -60,6 +70,107 @@ additionalProperties: false

hoist: (context.options[0] && context.options[0].hoist) || "functions",
allow: (context.options[0] && context.options[0].allow) || []
allow: (context.options[0] && context.options[0].allow) || [],
ignoreOnInitialization: context.options[0] && context.options[0].ignoreOnInitialization
};
const sourceCode = context.sourceCode;
/**
* Checks whether or not a given location is inside of the range of a given node.
* @param {ASTNode} node An node to check.
* @param {number} location A location to check.
* @returns {boolean} `true` if the location is inside of the range of the node.
*/
function isInRange(node, location) {
return node && node.range[0] <= location && location <= node.range[1];
}
/**
* Searches from the current node through its ancestry to find a matching node.
* @param {ASTNode} node a node to get.
* @param {(node: ASTNode) => boolean} match a callback that checks whether or not the node verifies its condition or not.
* @returns {ASTNode|null} the matching node.
*/
function findSelfOrAncestor(node, match) {
let currentNode = node;
while (currentNode && !match(currentNode)) {
currentNode = currentNode.parent;
}
return currentNode;
}
/**
* Finds function's outer scope.
* @param {Scope} scope Function's own scope.
* @returns {Scope} Function's outer scope.
*/
function getOuterScope(scope) {
const upper = scope.upper;
if (upper.type === "function-expression-name") {
return upper.upper;
}
return upper;
}
/**
* Checks if a variable and a shadowedVariable have the same init pattern ancestor.
* @param {Object} variable a variable to check.
* @param {Object} shadowedVariable a shadowedVariable to check.
* @returns {boolean} Whether or not the variable and the shadowedVariable have the same init pattern ancestor.
*/
function isInitPatternNode(variable, shadowedVariable) {
const outerDef = shadowedVariable.defs[0];
if (!outerDef) {
return false;
}
const { variableScope } = variable.scope;
if (!(FUNC_EXPR_NODE_TYPES.has(variableScope.block.type) && getOuterScope(variableScope) === shadowedVariable.scope)) {
return false;
}
const fun = variableScope.block;
const { parent } = fun;
const callExpression = findSelfOrAncestor(
parent,
node => CALL_EXPR_NODE_TYPE.has(node.type)
);
if (!callExpression) {
return false;
}
let node = outerDef.name;
const location = callExpression.range[1];
while (node) {
if (node.type === "VariableDeclarator") {
if (isInRange(node.init, location)) {
return true;
}
if (FOR_IN_OF_TYPE.test(node.parent.parent.type) &&
isInRange(node.parent.parent.right, location)
) {
return true;
}
break;
} else if (node.type === "AssignmentPattern") {
if (isInRange(node.right, location)) {
return true;
}
} else if (SENTINEL_TYPE.test(node.type)) {
break;
}
node = node.parent;
}
return false;
}
/**
* Check if variable name is allowed.

@@ -70,3 +181,3 @@ * @param {ASTNode} variable The variable to check.

function isAllowed(variable) {
return options.allow.indexOf(variable.name) !== -1;
return options.allow.includes(variable.name);
}

@@ -107,7 +218,7 @@

outer &&
inner &&
outer[0] < inner[0] &&
inner[1] < outer[1] &&
((innerDef.type === "FunctionName" && innerDef.node.type === "FunctionExpression") || innerDef.node.type === "ClassExpression") &&
outerScope === innerScope.upper
inner &&
outer[0] < inner[0] &&
inner[1] < outer[1] &&
((innerDef.type === "FunctionName" && innerDef.node.type === "FunctionExpression") || innerDef.node.type === "ClassExpression") &&
outerScope === innerScope.upper
);

@@ -163,7 +274,7 @@ }

inner &&
outer &&
inner[1] < outer[0] &&
outer &&
inner[1] < outer[0] &&
// Excepts FunctionDeclaration if is {"hoist":"function"}.
(options.hoist !== "functions" || !outerDef || outerDef.node.type !== "FunctionDeclaration")
// Excepts FunctionDeclaration if is {"hoist":"function"}.
(options.hoist !== "functions" || !outerDef || outerDef.node.type !== "FunctionDeclaration")
);

@@ -185,4 +296,4 @@ }

if (variable.identifiers.length === 0 ||
isDuplicatedClassNameVariable(variable) ||
isAllowed(variable)
isDuplicatedClassNameVariable(variable) ||
isAllowed(variable)
) {

@@ -196,5 +307,6 @@ continue;

if (shadowed &&
(shadowed.identifiers.length > 0 || (options.builtinGlobals && "writeable" in shadowed)) &&
!isOnInitializer(variable, shadowed) &&
!(options.hoist !== "all" && isInTdz(variable, shadowed))
(shadowed.identifiers.length > 0 || (options.builtinGlobals && "writeable" in shadowed)) &&
!isOnInitializer(variable, shadowed) &&
!(options.ignoreOnInitialization && isInitPatternNode(variable, shadowed)) &&
!(options.hoist !== "all" && isInTdz(variable, shadowed))
) {

@@ -219,4 +331,4 @@ const location = getDeclaredLocation(shadowed);

return {
"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);
const stack = globalScope.childScopes.slice();

@@ -223,0 +335,0 @@

@@ -19,5 +19,5 @@ /**

docs: {
description: "disallow spacing between function identifiers and their applications (deprecated)",
description: "Disallow spacing between function identifiers and their applications (deprecated)",
recommended: false,
url: "https://eslint.org/docs/rules/no-spaced-func"
url: "https://eslint.org/docs/latest/rules/no-spaced-func"
},

@@ -39,3 +39,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -42,0 +42,0 @@ /**

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow sparse arrays",
description: "Disallow sparse arrays",
recommended: true,
url: "https://eslint.org/docs/rules/no-sparse-arrays"
url: "https://eslint.org/docs/latest/rules/no-sparse-arrays"
},

@@ -41,3 +41,3 @@

const emptySpot = node.elements.indexOf(null) > -1;
const emptySpot = node.elements.includes(null);

@@ -44,0 +44,0 @@ if (emptySpot) {

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow synchronous methods",
description: "Disallow synchronous methods",
recommended: false,
url: "https://eslint.org/docs/rules/no-sync"
url: "https://eslint.org/docs/latest/rules/no-sync"
},

@@ -28,0 +28,0 @@

/**
* @fileoverview Rule to check for tabs inside a file
* @author Gyandeep Singh
* @deprecated in ESLint v8.53.0
*/

@@ -22,8 +23,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow all tabs",
description: "Disallow all tabs",
recommended: false,
url: "https://eslint.org/docs/rules/no-tabs"
url: "https://eslint.org/docs/latest/rules/no-tabs"
},

@@ -47,3 +50,3 @@ schema: [{

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;

@@ -50,0 +53,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow template literal placeholder syntax in regular strings",
description: "Disallow template literal placeholder syntax in regular strings",
recommended: false,
url: "https://eslint.org/docs/rules/no-template-curly-in-string"
url: "https://eslint.org/docs/latest/rules/no-template-curly-in-string"
},

@@ -22,0 +22,0 @@

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow ternary operators",
description: "Disallow ternary operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-ternary"
url: "https://eslint.org/docs/latest/rules/no-ternary"
},

@@ -23,0 +23,0 @@

@@ -43,5 +43,5 @@ /**

docs: {
description: "disallow `this`/`super` before calling `super()` in constructors",
description: "Disallow `this`/`super` before calling `super()` in constructors",
recommended: true,
url: "https://eslint.org/docs/rules/no-this-before-super"
url: "https://eslint.org/docs/latest/rules/no-this-before-super"
},

@@ -95,2 +95,17 @@

/**
* Determines if every segment in a set has been called.
* @param {Set<CodePathSegment>} segments The segments to search.
* @returns {boolean} True if every segment has been called; false otherwise.
*/
function isEverySegmentCalled(segments) {
for (const segment of segments) {
if (!isCalled(segment)) {
return false;
}
}
return true;
}
/**
* Checks whether or not this is before `super()` is called.

@@ -102,3 +117,3 @@ * @returns {boolean} `true` if this is before `super()` is called.

isInConstructorOfDerivedClass() &&
!funcInfo.codePath.currentSegments.every(isCalled)
!isEverySegmentCalled(funcInfo.currentSegments)
);

@@ -114,7 +129,5 @@ }

function setInvalid(node) {
const segments = funcInfo.codePath.currentSegments;
const segments = funcInfo.currentSegments;
for (let i = 0; i < segments.length; ++i) {
const segment = segments[i];
for (const segment of segments) {
if (segment.reachable) {

@@ -131,7 +144,5 @@ segInfoMap[segment.id].invalidNodes.push(node);

function setSuperCalled() {
const segments = funcInfo.codePath.currentSegments;
const segments = funcInfo.currentSegments;
for (let i = 0; i < segments.length; ++i) {
const segment = segments[i];
for (const segment of segments) {
if (segment.reachable) {

@@ -164,3 +175,4 @@ segInfoMap[segment.id].superCalled = true;

),
codePath
codePath,
currentSegments: new Set()
};

@@ -172,3 +184,4 @@ } else {

hasExtends: false,
codePath
codePath,
currentSegments: new Set()
};

@@ -221,2 +234,4 @@ }

onCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
if (!isInConstructorOfDerivedClass()) {

@@ -236,2 +251,14 @@ return;

onUnreachableCodePathSegmentStart(segment) {
funcInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
funcInfo.currentSegments.delete(segment);
},
/**

@@ -238,0 +265,0 @@ * Update information of the code path segment when a code path was

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow throwing literals as exceptions",
description: "Disallow throwing literals as exceptions",
recommended: false,
url: "https://eslint.org/docs/rules/no-throw-literal"
url: "https://eslint.org/docs/latest/rules/no-throw-literal"
},

@@ -25,0 +25,0 @@

/**
* @fileoverview Disallow trailing spaces at the end of lines.
* @author Nodeca Team <https://github.com/nodeca>
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow trailing whitespace at the end of lines",
description: "Disallow trailing whitespace at the end of lines",
recommended: false,
url: "https://eslint.org/docs/rules/no-trailing-spaces"
url: "https://eslint.org/docs/latest/rules/no-trailing-spaces"
},

@@ -54,3 +57,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -57,0 +60,0 @@ const BLANK_CLASS = "[ \t\u00a0\u2000-\u200b\u3000]",

@@ -20,5 +20,5 @@ /**

docs: {
description: "disallow initializing variables to `undefined`",
description: "Disallow initializing variables to `undefined`",
recommended: false,
url: "https://eslint.org/docs/rules/no-undef-init"
url: "https://eslint.org/docs/latest/rules/no-undef-init"
},

@@ -36,3 +36,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -44,3 +44,3 @@ return {

init = node.init && node.init.name,
scope = context.getScope(),
scope = sourceCode.getScope(node),
undefinedVar = astUtils.getVariableByName(scope, "undefined"),

@@ -47,0 +47,0 @@ shadowed = undefinedVar && undefinedVar.defs.length > 0,

@@ -32,5 +32,5 @@ /**

docs: {
description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments",
description: "Disallow the use of undeclared variables unless mentioned in `/*global */` comments",
recommended: true,
url: "https://eslint.org/docs/rules/no-undef"
url: "https://eslint.org/docs/latest/rules/no-undef"
},

@@ -58,6 +58,7 @@

const considerTypeOf = options && options.typeof === true || false;
const sourceCode = context.sourceCode;
return {
"Program:exit"(/* node */) {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);

@@ -64,0 +65,0 @@ globalScope.through.forEach(ref => {

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow the use of `undefined` as an identifier",
description: "Disallow the use of `undefined` as an identifier",
recommended: false,
url: "https://eslint.org/docs/rules/no-undefined"
url: "https://eslint.org/docs/latest/rules/no-undefined"
},

@@ -32,2 +32,4 @@

const sourceCode = context.sourceCode;
/**

@@ -71,4 +73,4 @@ * Report an invalid "undefined" identifier node.

return {
"Program:exit"() {
const globalScope = context.getScope();
"Program:exit"(node) {
const globalScope = sourceCode.getScope(node);

@@ -75,0 +77,0 @@ const stack = [globalScope];

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow dangling underscores in identifiers",
description: "Disallow dangling underscores in identifiers",
recommended: false,
url: "https://eslint.org/docs/rules/no-underscore-dangle"
url: "https://eslint.org/docs/latest/rules/no-underscore-dangle"
},

@@ -53,2 +53,14 @@

default: true
},
enforceInClassFields: {
type: "boolean",
default: false
},
allowInArrayDestructuring: {
type: "boolean",
default: true
},
allowInObjectDestructuring: {
type: "boolean",
default: true
}

@@ -73,3 +85,7 @@ },

const enforceInMethodNames = typeof options.enforceInMethodNames !== "undefined" ? options.enforceInMethodNames : false;
const enforceInClassFields = typeof options.enforceInClassFields !== "undefined" ? options.enforceInClassFields : false;
const allowFunctionParams = typeof options.allowFunctionParams !== "undefined" ? options.allowFunctionParams : true;
const allowInArrayDestructuring = typeof options.allowInArrayDestructuring !== "undefined" ? options.allowInArrayDestructuring : true;
const allowInObjectDestructuring = typeof options.allowInObjectDestructuring !== "undefined" ? options.allowInObjectDestructuring : true;
const sourceCode = context.sourceCode;

@@ -87,3 +103,3 @@ //-------------------------------------------------------------------------

function isAllowed(identifier) {
return ALLOWED_VARIABLES.some(ident => ident === identifier);
return ALLOWED_VARIABLES.includes(identifier);
}

@@ -197,2 +213,3 @@

/**

@@ -205,14 +222,28 @@ * Check if variable expression has a dangling underscore

function checkForDanglingUnderscoreInVariableExpression(node) {
const identifier = node.id.name;
sourceCode.getDeclaredVariables(node).forEach(variable => {
const definition = variable.defs.find(def => def.node === node);
const identifierNode = definition.name;
const identifier = identifierNode.name;
let parent = identifierNode.parent;
if (typeof identifier !== "undefined" && hasDanglingUnderscore(identifier) &&
!isSpecialCaseIdentifierInVariableExpression(identifier) && !isAllowed(identifier)) {
context.report({
node,
messageId: "unexpectedUnderscore",
data: {
identifier
}
});
}
while (!["VariableDeclarator", "ArrayPattern", "ObjectPattern"].includes(parent.type)) {
parent = parent.parent;
}
if (
hasDanglingUnderscore(identifier) &&
!isSpecialCaseIdentifierInVariableExpression(identifier) &&
!isAllowed(identifier) &&
!(allowInArrayDestructuring && parent.type === "ArrayPattern") &&
!(allowInObjectDestructuring && parent.type === "ObjectPattern")
) {
context.report({
node,
messageId: "unexpectedUnderscore",
data: {
identifier
}
});
}
});
}

@@ -270,2 +301,26 @@

/**
* Check if a class field has a dangling underscore
* @param {ASTNode} node node to evaluate
* @returns {void}
* @private
*/
function checkForDanglingUnderscoreInClassField(node) {
const identifier = node.key.name;
if (typeof identifier !== "undefined" && hasDanglingUnderscore(identifier) &&
enforceInClassFields &&
!isAllowed(identifier)) {
context.report({
node,
messageId: "unexpectedUnderscore",
data: {
identifier: node.key.type === "PrivateIdentifier"
? `#${identifier}`
: identifier
}
});
}
}
//--------------------------------------------------------------------------

@@ -280,3 +335,3 @@ // Public API

MethodDefinition: checkForDanglingUnderscoreInMethod,
PropertyDefinition: checkForDanglingUnderscoreInMethod,
PropertyDefinition: checkForDanglingUnderscoreInClassField,
Property: checkForDanglingUnderscoreInMethod,

@@ -283,0 +338,0 @@ FunctionExpression: checkForDanglingUnderscoreInFunction,

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow confusing multiline expressions",
description: "Disallow confusing multiline expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-unexpected-multiline"
url: "https://eslint.org/docs/latest/rules/no-unexpected-multiline"
},

@@ -42,3 +42,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -45,0 +45,0 @@ /**

@@ -165,5 +165,5 @@ /**

docs: {
description: "disallow unmodified loop conditions",
description: "Disallow unmodified loop conditions",
recommended: false,
url: "https://eslint.org/docs/rules/no-unmodified-loop-condition"
url: "https://eslint.org/docs/latest/rules/no-unmodified-loop-condition"
},

@@ -179,3 +179,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let groupMap = null;

@@ -345,4 +345,4 @@

return {
"Program:exit"() {
const queue = [context.getScope()];
"Program:exit"(node) {
const queue = [sourceCode.getScope(node)];

@@ -349,0 +349,0 @@ groupMap = new Map();

@@ -32,5 +32,5 @@ /**

docs: {
description: "disallow ternary operators when simpler alternatives exist",
description: "Disallow ternary operators when simpler alternatives exist",
recommended: false,
url: "https://eslint.org/docs/rules/no-unneeded-ternary"
url: "https://eslint.org/docs/latest/rules/no-unneeded-ternary"
},

@@ -62,3 +62,3 @@

const defaultAssignment = options.defaultAssignment !== false;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -149,3 +149,3 @@ /**

messageId: "unnecessaryConditionalAssignment",
fix: fixer => {
fix(fixer) {
const shouldParenthesizeAlternate =

@@ -152,0 +152,0 @@ (

@@ -15,2 +15,18 @@ /**

/**
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}
/**
* Determines whether the given node is the first node in the code path to which a loop statement

@@ -63,5 +79,5 @@ * 'loops' for the next iteration.

docs: {
description: "disallow loops with a body that allows only one iteration",
description: "Disallow loops with a body that allows only one iteration",
recommended: false,
url: "https://eslint.org/docs/rules/no-unreachable-loop"
url: "https://eslint.org/docs/latest/rules/no-unreachable-loop"
},

@@ -95,25 +111,32 @@

let currentCodePath = null;
const codePathSegments = [];
let currentCodePathSegments = new Set();
return {
onCodePathStart(codePath) {
currentCodePath = codePath;
onCodePathStart() {
codePathSegments.push(currentCodePathSegments);
currentCodePathSegments = new Set();
},
onCodePathEnd() {
currentCodePath = currentCodePath.upper;
currentCodePathSegments = codePathSegments.pop();
},
[loopSelector](node) {
onUnreachableCodePathSegmentStart(segment) {
currentCodePathSegments.add(segment);
},
/**
* Ignore unreachable loop statements to avoid unnecessary complexity in the implementation, or false positives otherwise.
* For unreachable segments, the code path analysis does not raise events required for this implementation.
*/
if (currentCodePath.currentSegments.some(segment => segment.reachable)) {
loopsToReport.add(node);
}
onUnreachableCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
onCodePathSegmentStart(segment, node) {
currentCodePathSegments.add(segment);
if (isLoopingTarget(node)) {

@@ -146,2 +169,14 @@ const loop = node.parent;

[loopSelector](node) {
/**
* Ignore unreachable loop statements to avoid unnecessary complexity in the implementation, or false positives otherwise.
* For unreachable segments, the code path analysis does not raise events required for this implementation.
*/
if (isAnySegmentReachable(currentCodePathSegments)) {
loopsToReport.add(node);
}
},
"Program:exit"() {

@@ -148,0 +183,0 @@ loopsToReport.forEach(

@@ -27,8 +27,15 @@ /**

/**
* Checks whether or not a given code path segment is unreachable.
* @param {CodePathSegment} segment A CodePathSegment to check.
* @returns {boolean} `true` if the segment is unreachable.
* Checks all segments in a set and returns true if all are unreachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if all segments are unreachable; false otherwise.
*/
function isUnreachable(segment) {
return !segment.reachable;
function areAllSegmentsUnreachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return false;
}
}
return true;
}

@@ -115,5 +122,5 @@

docs: {
description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
description: "Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
recommended: true,
url: "https://eslint.org/docs/rules/no-unreachable"
url: "https://eslint.org/docs/latest/rules/no-unreachable"
},

@@ -129,3 +136,2 @@

create(context) {
let currentCodePath = null;

@@ -136,4 +142,10 @@ /** @type {ConstructorInfo | null} */

/** @type {ConsecutiveRange} */
const range = new ConsecutiveRange(context.getSourceCode());
const range = new ConsecutiveRange(context.sourceCode);
/** @type {Array<Set<CodePathSegment>>} */
const codePathSegments = [];
/** @type {Set<CodePathSegment>} */
let currentCodePathSegments = new Set();
/**

@@ -147,3 +159,3 @@ * Reports a given node if it's unreachable.

if (node && (node.type === "PropertyDefinition" || currentCodePath.currentSegments.every(isUnreachable))) {
if (node && (node.type === "PropertyDefinition" || areAllSegmentsUnreachable(currentCodePathSegments))) {

@@ -189,10 +201,27 @@ // Store this statement to distinguish consecutive statements.

// Manages the current code path.
onCodePathStart(codePath) {
currentCodePath = codePath;
onCodePathStart() {
codePathSegments.push(currentCodePathSegments);
currentCodePathSegments = new Set();
},
onCodePathEnd() {
currentCodePath = currentCodePath.upper;
currentCodePathSegments = codePathSegments.pop();
},
onUnreachableCodePathSegmentStart(segment) {
currentCodePathSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
currentCodePathSegments.delete(segment);
},
onCodePathSegmentStart(segment) {
currentCodePathSegments.add(segment);
},
// Registers for all statement nodes (excludes FunctionDeclaration).

@@ -199,0 +228,0 @@ BlockStatement: reportIfUnreachable,

@@ -27,5 +27,5 @@ /**

docs: {
description: "disallow control flow statements in `finally` blocks",
description: "Disallow control flow statements in `finally` blocks",
recommended: true,
url: "https://eslint.org/docs/rules/no-unsafe-finally"
url: "https://eslint.org/docs/latest/rules/no-unsafe-finally"
},

@@ -32,0 +32,0 @@

@@ -55,5 +55,5 @@ /**

docs: {
description: "disallow negating the left operand of relational operators",
description: "Disallow negating the left operand of relational operators",
recommended: true,
url: "https://eslint.org/docs/rules/no-unsafe-negation"
url: "https://eslint.org/docs/latest/rules/no-unsafe-negation"
},

@@ -86,3 +86,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = context.options[0] || {};

@@ -89,0 +89,0 @@ const enforceForOrderingRelations = options.enforceForOrderingRelations === true;

@@ -27,5 +27,5 @@ /**

docs: {
description: "disallow use of optional chaining in contexts where the `undefined` value is not allowed",
description: "Disallow use of optional chaining in contexts where the `undefined` value is not allowed",
recommended: true,
url: "https://eslint.org/docs/rules/no-unsafe-optional-chaining"
url: "https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining"
},

@@ -32,0 +32,0 @@ schema: [{

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

const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------

@@ -34,5 +36,5 @@ // Rule Definition

docs: {
description: "disallow unused expressions",
description: "Disallow unused expressions",
recommended: false,
url: "https://eslint.org/docs/rules/no-unused-expressions"
url: "https://eslint.org/docs/latest/rules/no-unused-expressions"
},

@@ -114,8 +116,5 @@

* @param {ASTNode} node any node
* @param {ASTNode[]} ancestors the given node's ancestors
* @returns {boolean} whether the given node is considered a directive in its current position
*/
function isDirective(node, ancestors) {
const parent = ancestors[ancestors.length - 1],
grandparent = ancestors[ancestors.length - 2];
function isDirective(node) {

@@ -128,5 +127,3 @@ /**

*/
return (parent.type === "Program" || parent.type === "BlockStatement" &&
(/Function/u.test(grandparent.type))) &&
directives(parent).indexOf(node) >= 0;
return astUtils.isTopLevelExpressionStatement(node) && directives(node.parent).includes(node);
}

@@ -187,3 +184,3 @@

ExpressionStatement(node) {
if (Checker.isDisallowed(node.expression) && !isDirective(node, context.getAncestors())) {
if (Checker.isDisallowed(node.expression) && !isDirective(node)) {
context.report({ node, messageId: "unusedExpression" });

@@ -190,0 +187,0 @@ }

@@ -9,2 +9,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -19,5 +25,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow unused labels",
description: "Disallow unused labels",
recommended: true,
url: "https://eslint.org/docs/rules/no-unused-labels"
url: "https://eslint.org/docs/latest/rules/no-unused-labels"
},

@@ -35,3 +41,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let scopeInfo = null;

@@ -53,2 +59,41 @@

/**
* Checks if a `LabeledStatement` node is fixable.
* For a node to be fixable, there must be no comments between the label and the body.
* Furthermore, is must be possible to remove the label without turning the body statement into a
* directive after other fixes are applied.
* @param {ASTNode} node The node to evaluate.
* @returns {boolean} Whether or not the node is fixable.
*/
function isFixable(node) {
/*
* Only perform a fix if there are no comments between the label and the body. This will be the case
* when there is exactly one token/comment (the ":") between the label and the body.
*/
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) !==
sourceCode.getTokenBefore(node.body, { includeComments: true })) {
return false;
}
// Looking for the node's deepest ancestor which is not a `LabeledStatement`.
let ancestor = node.parent;
while (ancestor.type === "LabeledStatement") {
ancestor = ancestor.parent;
}
if (ancestor.type === "Program" ||
(ancestor.type === "BlockStatement" && astUtils.isFunction(ancestor.parent))) {
const { body } = node;
if (body.type === "ExpressionStatement" &&
((body.expression.type === "Literal" && typeof body.expression.value === "string") ||
astUtils.isStaticTemplateLiteral(body.expression))) {
return false; // potential directive
}
}
return true;
}
/**
* Removes the top of the stack.

@@ -65,15 +110,3 @@ * At the same time, this reports the label if it's never used.

data: node.label,
fix(fixer) {
/*
* Only perform a fix if there are no comments between the label and the body. This will be the case
* when there is exactly one token/comment (the ":") between the label and the body.
*/
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) ===
sourceCode.getTokenBefore(node.body, { includeComments: true })) {
return fixer.removeRange([node.range[0], node.body.range[0]]);
}
return null;
}
fix: isFixable(node) ? fixer => fixer.removeRange([node.range[0], node.body.range[0]]) : null
});

@@ -80,0 +113,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow unused private class members",
description: "Disallow unused private class members",
recommended: false,
url: "https://eslint.org/docs/rules/no-unused-private-class-members"
url: "https://eslint.org/docs/latest/rules/no-unused-private-class-members"
},

@@ -23,0 +23,0 @@

@@ -36,5 +36,5 @@ /**

docs: {
description: "disallow unused variables",
description: "Disallow unused variables",
recommended: true,
url: "https://eslint.org/docs/rules/no-unused-vars"
url: "https://eslint.org/docs/latest/rules/no-unused-vars"
},

@@ -71,2 +71,5 @@

type: "string"
},
destructuredArrayIgnorePattern: {
type: "string"
}

@@ -86,3 +89,3 @@ },

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -120,2 +123,6 @@ const REST_PROPERTY_TYPE = /^(?:RestElement|(?:Experimental)?RestProperty)$/u;

}
if (firstOption.destructuredArrayIgnorePattern) {
config.destructuredArrayIgnorePattern = new RegExp(firstOption.destructuredArrayIgnorePattern, "u");
}
}

@@ -162,4 +169,11 @@ }

function getAssignedMessageData(unusedVar) {
const additional = config.varsIgnorePattern ? `. Allowed unused vars must match ${config.varsIgnorePattern.toString()}` : "";
const def = unusedVar.defs[0];
let additional = "";
if (config.destructuredArrayIgnorePattern && def && def.name.parent.type === "ArrayPattern") {
additional = `. Allowed unused elements of array destructuring patterns must match ${config.destructuredArrayIgnorePattern.toString()}`;
} else if (config.varsIgnorePattern) {
additional = `. Allowed unused vars must match ${config.varsIgnorePattern.toString()}`;
}
return {

@@ -253,3 +267,3 @@ varName: unusedVar.name,

while (scope) {
if (nodes.indexOf(scope.block) >= 0) {
if (nodes.includes(scope.block)) {
return true;

@@ -461,3 +475,4 @@ }

parent.left === id &&
isUnusedExpression(parent)
isUnusedExpression(parent) &&
!astUtils.isLogicalAssignmentOperator(parent.operator)
) ||

@@ -480,3 +495,3 @@ (

/**
* Determine if an identifier is used either in for-in loops.
* Determine if an identifier is used either in for-in or for-of loops.
* @param {Reference} ref The reference to check.

@@ -486,3 +501,3 @@ * @returns {boolean} whether reference is used in the for-in loops

*/
function isForInRef(ref) {
function isForInOfRef(ref) {
let target = ref.identifier.parent;

@@ -496,3 +511,3 @@

if (target.type !== "ForInStatement") {
if (target.type !== "ForInStatement" && target.type !== "ForOfStatement") {
return false;

@@ -530,3 +545,3 @@ }

return variable.references.some(ref => {
if (isForInRef(ref)) {
if (isForInOfRef(ref)) {
return true;

@@ -555,3 +570,3 @@ }

const def = variable.defs[0];
const params = context.getDeclaredVariables(def.node);
const params = sourceCode.getDeclaredVariables(def.node);
const posteriorParams = params.slice(params.indexOf(variable) + 1);

@@ -599,3 +614,16 @@

const type = def.type;
const refUsedInArrayPatterns = variable.references.some(ref => ref.identifier.parent.type === "ArrayPattern");
// skip elements of array destructuring patterns
if (
(
def.name.parent.type === "ArrayPattern" ||
refUsedInArrayPatterns
) &&
config.destructuredArrayIgnorePattern &&
config.destructuredArrayIgnorePattern.test(def.name.name)
) {
continue;
}
// skip catch variables

@@ -662,3 +690,3 @@ if (type === "CatchClause") {

"Program:exit"(programNode) {
const unusedVars = collectUnusedVariables(context.getScope(), []);
const unusedVars = collectUnusedVariables(sourceCode.getScope(programNode), []);

@@ -665,0 +693,0 @@ for (let i = 0, l = unusedVars.length; i < l; ++i) {

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

let variables = true;
let allowNamedExports = false;

@@ -32,5 +33,6 @@ if (typeof options === "string") {

variables = options.variables !== false;
allowNamedExports = !!options.allowNamedExports;
}
return { functions, classes, variables };
return { functions, classes, variables, allowNamedExports };
}

@@ -71,3 +73,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.

@@ -230,5 +232,5 @@ * @param {eslint-scope.Scope} scope A scope to check.

docs: {
description: "disallow the use of variables before they are defined",
description: "Disallow the use of variables before they are defined",
recommended: false,
url: "https://eslint.org/docs/rules/no-use-before-define"
url: "https://eslint.org/docs/latest/rules/no-use-before-define"
},

@@ -247,3 +249,4 @@

classes: { type: "boolean" },
variables: { type: "boolean" }
variables: { type: "boolean" },
allowNamedExports: { type: "boolean" }
},

@@ -263,2 +266,3 @@ additionalProperties: false

const options = parseOptions(context.options[0]);
const sourceCode = context.sourceCode;

@@ -282,2 +286,12 @@ /**

const { identifier } = reference;
if (
options.allowNamedExports &&
identifier.parent.type === "ExportSpecifier" &&
identifier.parent.local === identifier
) {
return false;
}
const variable = reference.resolved;

@@ -336,4 +350,4 @@

return {
Program() {
checkReferencesInScope(context.getScope());
Program(node) {
checkReferencesInScope(sourceCode.getScope(node));
}

@@ -340,0 +354,0 @@ };

@@ -12,4 +12,4 @@ /**

const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("eslint-utils");
const { RegExpParser, visitRegExpAST } = require("regexpp");
const { CALL, CONSTRUCT, ReferenceTracker, getStringIfConstant } = require("@eslint-community/eslint-utils");
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");

@@ -68,5 +68,5 @@ //------------------------------------------------------------------------------

docs: {
description: "disallow useless backreferences in regular expressions",
description: "Disallow useless backreferences in regular expressions",
recommended: true,
url: "https://eslint.org/docs/rules/no-useless-backreference"
url: "https://eslint.org/docs/latest/rules/no-useless-backreference"
},

@@ -87,2 +87,4 @@

const sourceCode = context.sourceCode;
/**

@@ -99,3 +101,3 @@ * Checks and reports useless backreferences in the given regular expression.

try {
regExpAST = parser.parsePattern(pattern, 0, pattern.length, flags.includes("u"));
regExpAST = parser.parsePattern(pattern, 0, pattern.length, { unicode: flags.includes("u"), unicodeSets: flags.includes("v") });
} catch {

@@ -174,4 +176,4 @@

},
Program() {
const scope = context.getScope(),
Program(node) {
const scope = sourceCode.getScope(node),
tracker = new ReferenceTracker(scope),

@@ -185,4 +187,4 @@ traceMap = {

for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
const [patternNode, flagsNode] = node.arguments,
for (const { node: refNode } of tracker.iterateGlobalReferences(traceMap)) {
const [patternNode, flagsNode] = refNode.arguments,
pattern = getStringIfConstant(patternNode, scope),

@@ -192,3 +194,3 @@ flags = getStringIfConstant(flagsNode, scope);

if (typeof pattern === "string") {
checkRegex(node, pattern, flags || "");
checkRegex(refNode, pattern, flags || "");
}

@@ -195,0 +197,0 @@ }

@@ -58,5 +58,5 @@ /**

docs: {
description: "disallow unnecessary calls to `.call()` and `.apply()`",
description: "Disallow unnecessary calls to `.call()` and `.apply()`",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-call"
url: "https://eslint.org/docs/latest/rules/no-useless-call"
},

@@ -72,3 +72,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -75,0 +75,0 @@ return {

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow unnecessary `catch` clauses",
description: "Disallow unnecessary `catch` clauses",
recommended: true,
url: "https://eslint.org/docs/rules/no-useless-catch"
url: "https://eslint.org/docs/latest/rules/no-useless-catch"
},

@@ -23,0 +23,0 @@

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

/* istanbul ignore next */
/* c8 ignore next */
default:

@@ -95,5 +95,5 @@ throw new Error(`Unexpected node type: ${node.type}`);

docs: {
description: "disallow unnecessary computed property keys in objects and classes",
description: "Disallow unnecessary computed property keys in objects and classes",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-computed-key"
url: "https://eslint.org/docs/latest/rules/no-useless-computed-key"
},

@@ -118,3 +118,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const enforceForClassMembers = context.options[0] && context.options[0].enforceForClassMembers;

@@ -121,0 +121,0 @@

@@ -73,5 +73,5 @@ /**

docs: {
description: "disallow unnecessary concatenation of literals or template literals",
description: "Disallow unnecessary concatenation of literals or template literals",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-concat"
url: "https://eslint.org/docs/latest/rules/no-useless-concat"
},

@@ -87,3 +87,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -90,0 +90,0 @@ return {

@@ -141,5 +141,5 @@ /**

docs: {
description: "disallow unnecessary constructors",
description: "Disallow unnecessary constructors",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-constructor"
url: "https://eslint.org/docs/latest/rules/no-useless-constructor"
},

@@ -146,0 +146,0 @@

@@ -9,3 +9,8 @@ /**

const astUtils = require("./utils/ast-utils");
const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
/**
* @typedef {import('@eslint-community/regexpp').AST.CharacterClass} CharacterClass
* @typedef {import('@eslint-community/regexpp').AST.ExpressionCharacterClass} ExpressionCharacterClass
*/
//------------------------------------------------------------------------------

@@ -32,52 +37,14 @@ // Rule Definition

/**
* Parses a regular expression into a list of characters with character class info.
* @param {string} regExpText The raw text used to create the regular expression
* @returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
* @example
*
* parseRegExp("a\\b[cd-]");
*
* // returns:
* [
* { text: "a", index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false },
* { text: "b", index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false },
* { text: "c", index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false },
* { text: "d", index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false },
* { text: "-", index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false }
* ];
*
/*
* Set of characters that require escaping in character classes in `unicodeSets` mode.
* ( ) [ ] { } / - \ | are ClassSetSyntaxCharacter
*/
function parseRegExp(regExpText) {
const charList = [];
const REGEX_CLASSSET_CHARACTER_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set("q/[{}|()-"));
regExpText.split("").reduce((state, char, index) => {
if (!state.escapeNextChar) {
if (char === "\\") {
return Object.assign(state, { escapeNextChar: true });
}
if (char === "[" && !state.inCharClass) {
return Object.assign(state, { inCharClass: true, startingCharClass: true });
}
if (char === "]" && state.inCharClass) {
if (charList.length && charList[charList.length - 1].inCharClass) {
charList[charList.length - 1].endsCharClass = true;
}
return Object.assign(state, { inCharClass: false, startingCharClass: false });
}
}
charList.push({
text: char,
index,
escaped: state.escapeNextChar,
inCharClass: state.inCharClass,
startsCharClass: state.startingCharClass,
endsCharClass: false
});
return Object.assign(state, { escapeNextChar: false, startingCharClass: false });
}, { escapeNextChar: false, inCharClass: false, startingCharClass: false });
/*
* A single character set of ClassSetReservedDoublePunctuator.
* && !! ## $$ %% ** ++ ,, .. :: ;; << == >> ?? @@ ^^ `` ~~ are ClassSetReservedDoublePunctuator
*/
const REGEX_CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR = new Set("!#$%&*+,.:;<=>?@^`~");
return charList;
}
/** @type {import('../shared/types').Rule} */

@@ -89,5 +56,5 @@ module.exports = {

docs: {
description: "disallow unnecessary escape characters",
description: "Disallow unnecessary escape characters",
recommended: true,
url: "https://eslint.org/docs/rules/no-useless-escape"
url: "https://eslint.org/docs/latest/rules/no-useless-escape"
},

@@ -100,2 +67,3 @@

removeEscape: "Remove the `\\`. This maintains the current functionality.",
removeEscapeDoNotKeepSemantics: "Remove the `\\` if it was inserted by mistake.",
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."

@@ -108,3 +76,4 @@ },

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const parser = new RegExpParser();

@@ -116,5 +85,6 @@ /**

* @param {string} character The uselessly escaped character (not including the backslash)
* @param {boolean} [disableEscapeBackslashSuggest] `true` if escapeBackslash suggestion should be turned off.
* @returns {void}
*/
function report(node, startOffset, character) {
function report(node, startOffset, character, disableEscapeBackslashSuggest) {
const rangeStart = node.range[0] + startOffset;

@@ -134,3 +104,6 @@ const range = [rangeStart, rangeStart + 1];

{
messageId: "removeEscape",
// Removing unnecessary `\` characters in a directive is not guaranteed to maintain functionality.
messageId: astUtils.isDirective(node.parent)
? "removeEscapeDoNotKeepSemantics" : "removeEscape",
fix(fixer) {

@@ -140,8 +113,12 @@ return fixer.removeRange(range);

},
{
messageId: "escapeBackslash",
fix(fixer) {
return fixer.insertTextBeforeRange(range, "\\");
}
}
...disableEscapeBackslashSuggest
? []
: [
{
messageId: "escapeBackslash",
fix(fixer) {
return fixer.insertTextBeforeRange(range, "\\");
}
}
]
]

@@ -190,2 +167,129 @@ });

/**
* Checks if the escape character in given regexp is unnecessary.
* @private
* @param {ASTNode} node node to validate.
* @returns {void}
*/
function validateRegExp(node) {
const { pattern, flags } = node.regex;
let patternNode;
const unicode = flags.includes("u");
const unicodeSets = flags.includes("v");
try {
patternNode = parser.parsePattern(pattern, 0, pattern.length, { unicode, unicodeSets });
} catch {
// Ignore regular expressions with syntax errors
return;
}
/** @type {(CharacterClass | ExpressionCharacterClass)[]} */
const characterClassStack = [];
visitRegExpAST(patternNode, {
onCharacterClassEnter: characterClassNode => characterClassStack.unshift(characterClassNode),
onCharacterClassLeave: () => characterClassStack.shift(),
onExpressionCharacterClassEnter: characterClassNode => characterClassStack.unshift(characterClassNode),
onExpressionCharacterClassLeave: () => characterClassStack.shift(),
onCharacterEnter(characterNode) {
if (!characterNode.raw.startsWith("\\")) {
// It's not an escaped character.
return;
}
const escapedChar = characterNode.raw.slice(1);
if (escapedChar !== String.fromCodePoint(characterNode.value)) {
// It's a valid escape.
return;
}
let allowedEscapes;
if (characterClassStack.length) {
allowedEscapes = unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : REGEX_GENERAL_ESCAPES;
} else {
allowedEscapes = REGEX_NON_CHARCLASS_ESCAPES;
}
if (allowedEscapes.has(escapedChar)) {
return;
}
const reportedIndex = characterNode.start + 1;
let disableEscapeBackslashSuggest = false;
if (characterClassStack.length) {
const characterClassNode = characterClassStack[0];
if (escapedChar === "^") {
/*
* The '^' character is also a special case; it must always be escaped outside of character classes, but
* it only needs to be escaped in character classes if it's at the beginning of the character class. To
* account for this, consider it to be a valid escape character outside of character classes, and filter
* out '^' characters that appear at the start of a character class.
*/
if (characterClassNode.start + 1 === characterNode.start) {
return;
}
}
if (!unicodeSets) {
if (escapedChar === "-") {
/*
* The '-' character is a special case, because it's only valid to escape it if it's in a character
* class, and is not at either edge of the character class. To account for this, don't consider '-'
* characters to be valid in general, and filter out '-' characters that appear in the middle of a
* character class.
*/
if (characterClassNode.start + 1 !== characterNode.start && characterNode.end !== characterClassNode.end - 1) {
return;
}
}
} else { // unicodeSets mode
if (REGEX_CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR.has(escapedChar)) {
// Escaping is valid if it is a ClassSetReservedDoublePunctuator.
if (pattern[characterNode.end] === escapedChar) {
return;
}
if (pattern[characterNode.start - 1] === escapedChar) {
if (escapedChar !== "^") {
return;
}
// If the previous character is a `negate` caret(`^`), escape to caret is unnecessary.
if (!characterClassNode.negate) {
return;
}
const negateCaretIndex = characterClassNode.start + 1;
if (negateCaretIndex < characterNode.start - 1) {
return;
}
}
}
if (characterNode.parent.type === "ClassIntersection" || characterNode.parent.type === "ClassSubtraction") {
disableEscapeBackslashSuggest = true;
}
}
}
report(
node,
reportedIndex,
escapedChar,
disableEscapeBackslashSuggest
);
}
});
}
/**
* Checks if a node has an escape.

@@ -228,28 +332,3 @@ * @param {ASTNode} node node to check.

} else if (node.regex) {
parseRegExp(node.regex.pattern)
/*
* The '-' character is a special case, because it's only valid to escape it if it's in a character
* class, and is not at either edge of the character class. To account for this, don't consider '-'
* characters to be valid in general, and filter out '-' characters that appear in the middle of a
* character class.
*/
.filter(charInfo => !(charInfo.text === "-" && charInfo.inCharClass && !charInfo.startsCharClass && !charInfo.endsCharClass))
/*
* The '^' character is also a special case; it must always be escaped outside of character classes, but
* it only needs to be escaped in character classes if it's at the beginning of the character class. To
* account for this, consider it to be a valid escape character outside of character classes, and filter
* out '^' characters that appear at the start of a character class.
*/
.filter(charInfo => !(charInfo.text === "^" && charInfo.startsCharClass))
// Filter out characters that aren't escaped.
.filter(charInfo => charInfo.escaped)
// Filter out characters that are valid to escape, based on their position in the regular expression.
.filter(charInfo => !(charInfo.inCharClass ? REGEX_GENERAL_ESCAPES : REGEX_NON_CHARCLASS_ESCAPES).has(charInfo.text))
// Report all the remaining characters.
.forEach(charInfo => report(node, charInfo.index, charInfo.text));
validateRegExp(node);
}

@@ -256,0 +335,0 @@

@@ -24,5 +24,5 @@ /**

docs: {
description: "disallow renaming import, export, and destructured assignments to the same name",
description: "Disallow renaming import, export, and destructured assignments to the same name",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-rename"
url: "https://eslint.org/docs/latest/rules/no-useless-rename"
},

@@ -50,3 +50,3 @@

create(context) {
const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
options = context.options[0] || {},

@@ -137,4 +137,6 @@ ignoreDestructuring = options.ignoreDestructuring === true,

if (node.imported.name === node.local.name &&
node.imported.range[0] !== node.local.range[0]) {
if (
node.imported.range[0] !== node.local.range[0] &&
astUtils.getModuleExportName(node.imported) === node.local.name
) {
reportError(node, node.imported, "Import");

@@ -154,4 +156,6 @@ }

if (node.local.name === node.exported.name &&
node.local.range[0] !== node.exported.range[0]) {
if (
node.local.range[0] !== node.exported.range[0] &&
astUtils.getModuleExportName(node.local) === astUtils.getModuleExportName(node.exported)
) {
reportError(node, node.local, "Export");

@@ -158,0 +162,0 @@ }

@@ -60,2 +60,18 @@ /**

/**
* Checks all segments in a set and returns true if any are reachable.
* @param {Set<CodePathSegment>} segments The segments to check.
* @returns {boolean} True if any segment is reachable; false otherwise.
*/
function isAnySegmentReachable(segments) {
for (const segment of segments) {
if (segment.reachable) {
return true;
}
}
return false;
}
//------------------------------------------------------------------------------

@@ -71,5 +87,5 @@ // Rule Definition

docs: {
description: "disallow redundant return statements",
description: "Disallow redundant return statements",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-return"
url: "https://eslint.org/docs/latest/rules/no-useless-return"
},

@@ -87,4 +103,3 @@

const segmentInfoMap = new WeakMap();
const usedUnreachableSegments = new WeakSet();
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let scopeInfo = null;

@@ -158,5 +173,6 @@

* @param {CodePathSegment} segment The segment to get return statements.
* @param {Set<CodePathSegment>} usedUnreachableSegments A set of segments that have already been traversed in this call.
* @returns {void}
*/
function markReturnStatementsOnSegmentAsUsed(segment) {
function markReturnStatementsOnSegmentAsUsed(segment, usedUnreachableSegments) {
if (!segment.reachable) {

@@ -167,3 +183,3 @@ usedUnreachableSegments.add(segment);

.filter(prevSegment => !usedUnreachableSegments.has(prevSegment))
.forEach(markReturnStatementsOnSegmentAsUsed);
.forEach(prevSegment => markReturnStatementsOnSegmentAsUsed(prevSegment, usedUnreachableSegments));
return;

@@ -174,6 +190,25 @@ }

for (const node of info.uselessReturns) {
info.uselessReturns = info.uselessReturns.filter(node => {
if (scopeInfo.traversedTryBlockStatements && scopeInfo.traversedTryBlockStatements.length > 0) {
const returnInitialRange = node.range[0];
const returnFinalRange = node.range[1];
const areBlocksInRange = scopeInfo.traversedTryBlockStatements.some(tryBlockStatement => {
const blockInitialRange = tryBlockStatement.range[0];
const blockFinalRange = tryBlockStatement.range[1];
return (
returnInitialRange >= blockInitialRange &&
returnFinalRange <= blockFinalRange
);
});
if (areBlocksInRange) {
return true;
}
}
remove(scopeInfo.uselessReturns, node);
}
info.uselessReturns = [];
return false;
});
}

@@ -195,5 +230,4 @@

scopeInfo
.codePath
.currentSegments
.forEach(markReturnStatementsOnSegmentAsUsed);
.forEach(segment => markReturnStatementsOnSegmentAsUsed(segment, new Set()));
}

@@ -207,3 +241,3 @@

// Makes and pushs a new scope information.
// Makes and pushes a new scope information.
onCodePathStart(codePath) {

@@ -213,3 +247,5 @@ scopeInfo = {

uselessReturns: [],
codePath
traversedTryBlockStatements: [],
codePath,
currentSegments: new Set()
};

@@ -251,2 +287,5 @@ },

onCodePathSegmentStart(segment) {
scopeInfo.currentSegments.add(segment);
const info = {

@@ -261,2 +300,14 @@ uselessReturns: getUselessReturns([], segment.allPrevSegments),

onUnreachableCodePathSegmentStart(segment) {
scopeInfo.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
scopeInfo.currentSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
scopeInfo.currentSegments.delete(segment);
},
// Adds ReturnStatement node to check whether it's useless or not.

@@ -273,3 +324,3 @@ ReturnStatement(node) {

// Ignore `return` statements in unreachable places (https://github.com/eslint/eslint/issues/11647).
!scopeInfo.codePath.currentSegments.some(s => s.reachable)
!isAnySegmentReachable(scopeInfo.currentSegments)
) {

@@ -279,3 +330,3 @@ return;

for (const segment of scopeInfo.codePath.currentSegments) {
for (const segment of scopeInfo.currentSegments) {
const info = segmentInfoMap.get(segment);

@@ -291,2 +342,10 @@

"TryStatement > BlockStatement.block:exit"(node) {
scopeInfo.traversedTryBlockStatements.push(node);
},
"TryStatement:exit"() {
scopeInfo.traversedTryBlockStatements.pop();
},
/*

@@ -293,0 +352,0 @@ * Registers for all statement nodes except FunctionDeclaration, BlockStatement, BreakStatement.

@@ -93,3 +93,3 @@ /**

/* istanbul ignore next : unreachable */
/* c8 ignore next */
return null;

@@ -163,3 +163,3 @@ }

(defaultValue !== null && start >= defaultStart && end <= defaultEnd) ||
(start >= initStart && end <= initEnd)
(!astUtils.isFunction(node) && start >= initStart && end <= initEnd)
);

@@ -190,5 +190,5 @@ });

docs: {
description: "require `let` or `const` instead of `var`",
description: "Require `let` or `const` instead of `var`",
recommended: false,
url: "https://eslint.org/docs/rules/no-var"
url: "https://eslint.org/docs/latest/rules/no-var"
},

@@ -205,3 +205,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -217,3 +217,3 @@ /**

}
const variables = context.getDeclaredVariables(declarator);
const variables = sourceCode.getDeclaredVariables(declarator);

@@ -276,3 +276,3 @@ return variables.some(hasReferenceInTDZ(declarator.init));

function canFix(node) {
const variables = context.getDeclaredVariables(node);
const variables = sourceCode.getDeclaredVariables(node);
const scopeNode = getScopeNode(node);

@@ -279,0 +279,0 @@

@@ -17,5 +17,5 @@ /**

docs: {
description: "disallow `void` operators",
description: "Disallow `void` operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-void"
url: "https://eslint.org/docs/latest/rules/no-void"
},

@@ -22,0 +22,0 @@

@@ -23,5 +23,5 @@ /**

docs: {
description: "disallow specified warning terms in comments",
description: "Disallow specified warning terms in comments",
recommended: false,
url: "https://eslint.org/docs/rules/no-warning-comments"
url: "https://eslint.org/docs/latest/rules/no-warning-comments"
},

@@ -41,2 +41,11 @@

enum: ["start", "anywhere"]
},
decoration: {
type: "array",
items: {
type: "string",
pattern: "^\\S$"
},
minItems: 1,
uniqueItems: true
}

@@ -54,6 +63,7 @@ },

create(context) {
const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
configuration = context.options[0] || {},
warningTerms = configuration.terms || ["todo", "fixme", "xxx"],
location = configuration.location || "start",
decoration = [...configuration.decoration || []].join(""),
selfConfigRegEx = /\bno-warning-comments\b/u;

@@ -70,55 +80,50 @@

const escaped = escapeRegExp(term);
const wordBoundary = "\\b";
const eitherOrWordBoundary = `|${wordBoundary}`;
let prefix;
const escapedDecoration = escapeRegExp(decoration);
/*
* If the term ends in a word character (a-z0-9_), ensure a word
* boundary at the end, so that substrings do not get falsely
* matched. eg "todo" in a string such as "mastodon".
* If the term ends in a non-word character, then \b won't match on
* the boundary to the next non-word character, which would likely
* be a space. For example `/\bFIX!\b/.test('FIX! blah') === false`.
* In these cases, use no bounding match. Same applies for the
* prefix, handled below.
* When matching at the start, ignore leading whitespace, and
* there's no need to worry about word boundaries.
*
* These expressions for the prefix and suffix are designed as follows:
* ^ handles any terms at the beginning of a comment.
* e.g. terms ["TODO"] matches `//TODO something`
* $ handles any terms at the end of a comment
* e.g. terms ["TODO"] matches `// something TODO`
* \b handles terms preceded/followed by word boundary
* e.g. terms: ["!FIX", "FIX!"] matches `// FIX!something` or `// something!FIX`
* terms: ["FIX"] matches `// FIX!` or `// !FIX`, but not `// fixed or affix`
*
* For location start:
* [\s]* handles optional leading spaces
* e.g. terms ["TODO"] matches `// TODO something`
* [\s\*]* (where "\*" is the escaped string of decoration)
* handles optional leading spaces or decoration characters (for "start" location only)
* e.g. terms ["TODO"] matches `/**** TODO something ... `
*/
const suffix = /\w$/u.test(term) ? "\\b" : "";
const wordBoundary = "\\b";
let prefix = "";
if (location === "start") {
/*
* When matching at the start, ignore leading whitespace, and
* there's no need to worry about word boundaries.
*/
prefix = "^\\s*";
prefix = `^[\\s${escapedDecoration}]*`;
} else if (/^\w/u.test(term)) {
prefix = wordBoundary;
} else {
prefix = "";
}
if (location === "start") {
const suffix = /\w$/u.test(term) ? wordBoundary : "";
const flags = "iu"; // Case-insensitive with Unicode case folding.
/*
* For location "start" the regex should be
* ^\s*TERM\b. This checks the word boundary
* at the beginning of the comment.
*/
return new RegExp(prefix + escaped + suffix, "iu");
}
/*
* For location "anywhere" the regex should be
* \bTERM\b|\bTERM\b, this checks the entire comment
* for the term.
* For location "start", the typical regex is:
* /^[\s]*ESCAPED_TERM\b/iu.
* Or if decoration characters are specified (e.g. "*"), then any of
* those characters may appear in any order at the start:
* /^[\s\*]*ESCAPED_TERM\b/iu.
*
* For location "anywhere" the typical regex is
* /\bESCAPED_TERM\b/iu
*
* If it starts or ends with non-word character, the prefix and suffix are empty, respectively.
*/
return new RegExp(
prefix +
escaped +
suffix +
eitherOrWordBoundary +
term +
wordBoundary,
"iu"
);
return new RegExp(`${prefix}${escaped}${suffix}`, flags);
}

@@ -125,0 +130,0 @@

/**
* @fileoverview Rule to disallow whitespace before properties
* @author Kai Cataldo
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "disallow whitespace before properties",
description: "Disallow whitespace before properties",
recommended: false,
url: "https://eslint.org/docs/rules/no-whitespace-before-property"
url: "https://eslint.org/docs/latest/rules/no-whitespace-before-property"
},

@@ -38,3 +41,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -41,0 +44,0 @@ //--------------------------------------------------------------------------

@@ -18,5 +18,5 @@ /**

docs: {
description: "disallow `with` statements",
description: "Disallow `with` statements",
recommended: true,
url: "https://eslint.org/docs/rules/no-with"
url: "https://eslint.org/docs/latest/rules/no-with"
},

@@ -23,0 +23,0 @@

/**
* @fileoverview enforce the location of single-line statements
* @author Teddy Katz
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce the location of single-line statements",
description: "Enforce the location of single-line statements",
recommended: false,
url: "https://eslint.org/docs/rules/nonblock-statement-body-position"
url: "https://eslint.org/docs/latest/rules/nonblock-statement-body-position"
},

@@ -53,3 +56,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -56,0 +59,0 @@ //----------------------------------------------------------------------

/**
* @fileoverview Rule to require or disallow line breaks inside braces.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -150,8 +151,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent line breaks after opening and before closing braces",
description: "Enforce consistent line breaks after opening and before closing braces",
recommended: false,
url: "https://eslint.org/docs/rules/object-curly-newline"
url: "https://eslint.org/docs/latest/rules/object-curly-newline"
},

@@ -189,3 +192,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const normalizedOptions = normalizeOptions(context.options[0]);

@@ -192,0 +195,0 @@

/**
* @fileoverview Disallows or enforces spaces inside of object literals.
* @author Jamund Ferguson
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing inside braces",
description: "Enforce consistent spacing inside braces",
recommended: false,
url: "https://eslint.org/docs/rules/object-curly-spacing"
url: "https://eslint.org/docs/latest/rules/object-curly-spacing"
},

@@ -55,3 +58,3 @@

const spaced = context.options[0] === "always",
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -86,3 +89,3 @@ /**

function reportNoBeginningSpace(node, token) {
const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true });
const nextToken = context.sourceCode.getTokenAfter(token, { includeComments: true });

@@ -109,3 +112,3 @@ context.report({

function reportNoEndingSpace(node, token) {
const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true });
const previousToken = context.sourceCode.getTokenBefore(token, { includeComments: true });

@@ -112,0 +115,0 @@ context.report({

/**
* @fileoverview Rule to enforce placing object properties on separate lines.
* @author Vitor Balocco
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce placing object properties on separate lines",
description: "Enforce placing object properties on separate lines",
recommended: false,
url: "https://eslint.org/docs/rules/object-property-newline"
url: "https://eslint.org/docs/latest/rules/object-property-newline"
},

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

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -60,0 +63,0 @@ return {

@@ -31,5 +31,5 @@ /**

docs: {
description: "require or disallow method and property shorthand syntax for object literals",
description: "Require or disallow method and property shorthand syntax for object literals",
recommended: false,
url: "https://eslint.org/docs/rules/object-shorthand"
url: "https://eslint.org/docs/latest/rules/object-shorthand"
},

@@ -82,2 +82,5 @@

},
methodsIgnorePattern: {
type: "string"
},
avoidQuotes: {

@@ -120,5 +123,8 @@ type: "boolean"

const IGNORE_CONSTRUCTORS = PARAMS.ignoreConstructors;
const METHODS_IGNORE_PATTERN = PARAMS.methodsIgnorePattern
? new RegExp(PARAMS.methodsIgnorePattern, "u")
: null;
const AVOID_QUOTES = PARAMS.avoidQuotes;
const AVOID_EXPLICIT_RETURN_ARROWS = !!PARAMS.avoidExplicitReturnArrows;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -354,7 +360,8 @@ //--------------------------------------------------------------------------

* Also, this marks all `arguments` identifiers so that they can be detected later.
* @param {ASTNode} node The node representing the function.
* @returns {void}
*/
function enterFunction() {
function enterFunction(node) {
lexicalScopeStack.unshift(new Set());
context.getScope().variables.filter(variable => variable.name === "arguments").forEach(variable => {
sourceCode.getScope(node).variables.filter(variable => variable.name === "arguments").forEach(variable => {
variable.references.map(ref => ref.identifier).forEach(identifier => argumentsIdentifiers.add(identifier));

@@ -464,2 +471,11 @@ });

}
if (METHODS_IGNORE_PATTERN) {
const propertyName = astUtils.getStaticPropertyName(node);
if (propertyName !== null && METHODS_IGNORE_PATTERN.test(propertyName)) {
return;
}
}
if (AVOID_QUOTES && isStringLiteral(node.key)) {

@@ -466,0 +482,0 @@ return;

/**
* @fileoverview Rule to check multiple var declarations per line
* @author Alberto Rodríguez
* @deprecated in ESLint v8.53.0
*/

@@ -14,8 +15,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "require or disallow newlines around variable declarations",
description: "Require or disallow newlines around variable declarations",
recommended: false,
url: "https://eslint.org/docs/rules/one-var-declaration-per-line"
url: "https://eslint.org/docs/latest/rules/one-var-declaration-per-line"
},

@@ -22,0 +25,0 @@

@@ -37,5 +37,5 @@ /**

docs: {
description: "enforce variables to be declared either together or separately in functions",
description: "Enforce variables to be declared either together or separately in functions",
recommended: false,
url: "https://eslint.org/docs/rules/one-var"
url: "https://eslint.org/docs/latest/rules/one-var"
},

@@ -125,3 +125,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -128,0 +128,0 @@ //--------------------------------------------------------------------------

@@ -25,3 +25,3 @@ /**

function isCommutativeOperatorWithShorthand(operator) {
return ["*", "&", "^", "|"].indexOf(operator) >= 0;
return ["*", "&", "^", "|"].includes(operator);
}

@@ -37,3 +37,3 @@

function isNonCommutativeOperatorWithShorthand(operator) {
return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].indexOf(operator) >= 0;
return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].includes(operator);
}

@@ -68,5 +68,5 @@

docs: {
description: "require or disallow assignment operator shorthand where possible",
description: "Require or disallow assignment operator shorthand where possible",
recommended: false,
url: "https://eslint.org/docs/rules/operator-assignment"
url: "https://eslint.org/docs/latest/rules/operator-assignment"
},

@@ -82,4 +82,4 @@

messages: {
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}=).",
unexpected: "Unexpected operator assignment ({{operator}}=) shorthand."
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}).",
unexpected: "Unexpected operator assignment ({{operator}}) shorthand."
}

@@ -90,3 +90,3 @@ },

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

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

if (isCommutativeOperatorWithShorthand(operator) || isNonCommutativeOperatorWithShorthand(operator)) {
const replacementOperator = `${operator}=`;
if (astUtils.isSameReference(left, expr.left, true)) {

@@ -122,3 +124,3 @@ context.report({

messageId: "replaced",
data: { operator },
data: { operator: replacementOperator },
fix(fixer) {

@@ -136,3 +138,3 @@ if (canBeFixed(left) && canBeFixed(expr.left)) {

return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
return fixer.replaceText(node, `${leftText}${replacementOperator}${rightText}`);
}

@@ -152,3 +154,3 @@ return null;

messageId: "replaced",
data: { operator }
data: { operator: replacementOperator }
});

@@ -155,0 +157,0 @@ }

/**
* @fileoverview Operator linebreak - enforces operator linebreak style of two types: after and before
* @author Benoît Zugmeyer
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent linebreak style for operators",
description: "Enforce consistent linebreak style for operators",
recommended: false,
url: "https://eslint.org/docs/rules/operator-linebreak"
url: "https://eslint.org/docs/latest/rules/operator-linebreak"
},

@@ -73,3 +76,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -76,0 +79,0 @@ //--------------------------------------------------------------------------

/**
* @fileoverview A rule to ensure blank lines within blocks.
* @author Mathias Schreck <https://github.com/lo1tuma>
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow padding within blocks",
description: "Require or disallow padding within blocks",
recommended: false,
url: "https://eslint.org/docs/rules/padded-blocks"
url: "https://eslint.org/docs/latest/rules/padded-blocks"
},

@@ -100,3 +103,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -191,3 +194,3 @@ /**

/* istanbul ignore next */
/* c8 ignore next */
default:

@@ -194,0 +197,0 @@ throw new Error("unreachable");

/**
* @fileoverview Rule to require or disallow newlines between statements
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -134,45 +135,2 @@

/**
* Check whether the given node is a directive or not.
* @param {ASTNode} node The node to check.
* @param {SourceCode} sourceCode The source code object to get tokens.
* @returns {boolean} `true` if the node is a directive.
*/
function isDirective(node, sourceCode) {
return (
node.type === "ExpressionStatement" &&
(
node.parent.type === "Program" ||
(
node.parent.type === "BlockStatement" &&
astUtils.isFunction(node.parent.parent)
)
) &&
node.expression.type === "Literal" &&
typeof node.expression.value === "string" &&
!astUtils.isParenthesised(sourceCode, node.expression)
);
}
/**
* Check whether the given node is a part of directive prologue or not.
* @param {ASTNode} node The node to check.
* @param {SourceCode} sourceCode The source code object to get tokens.
* @returns {boolean} `true` if the node is a part of directive prologue.
*/
function isDirectivePrologue(node, sourceCode) {
if (isDirective(node, sourceCode)) {
for (const sibling of node.parent.body) {
if (sibling === node) {
break;
}
if (!isDirective(sibling, sourceCode)) {
return false;
}
}
return true;
}
return false;
}
/**
* Gets the actual last token.

@@ -257,3 +215,3 @@ *

const end = nextToken.range[0];
const text = context.getSourceCode().text
const text = context.sourceCode.text
.slice(start, end)

@@ -289,3 +247,3 @@ .replace(PADDING_LINE_SEQUENCE, replacerToRemovePaddingLines);

fix(fixer) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let prevToken = getActualLastToken(sourceCode, prevNode);

@@ -372,8 +330,6 @@ const nextToken = sourceCode.getFirstTokenBetween(

directive: {
test: isDirectivePrologue
test: astUtils.isDirective
},
expression: {
test: (node, sourceCode) =>
node.type === "ExpressionStatement" &&
!isDirectivePrologue(node, sourceCode)
test: node => node.type === "ExpressionStatement" && !astUtils.isDirective(node)
},

@@ -389,6 +345,6 @@ iife: {

"multiline-expression": {
test: (node, sourceCode) =>
test: node =>
node.loc.start.line !== node.loc.end.line &&
node.type === "ExpressionStatement" &&
!isDirectivePrologue(node, sourceCode)
!astUtils.isDirective(node)
},

@@ -436,8 +392,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow padding lines between statements",
description: "Require or disallow padding lines between statements",
recommended: false,
url: "https://eslint.org/docs/rules/padding-line-between-statements"
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements"
},

@@ -459,4 +417,3 @@

minItems: 1,
uniqueItems: true,
additionalItems: false
uniqueItems: true
}

@@ -476,4 +433,3 @@ ]

required: ["blankLine", "prev", "next"]
},
additionalItems: false
}
},

@@ -488,3 +444,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const configureList = context.options || [];

@@ -491,0 +447,0 @@ let scopeInfo = null;

@@ -56,3 +56,3 @@ /**

/* istanbul ignore next */
/* c8 ignore next */
return null;

@@ -130,3 +130,3 @@ }

/* istanbul ignore next */
/* c8 ignore next */
throw new Error("unreachable");

@@ -156,5 +156,5 @@ }

docs: {
description: "require using arrow functions for callbacks",
description: "Require using arrow functions for callbacks",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-arrow-callback"
url: "https://eslint.org/docs/latest/rules/prefer-arrow-callback"
},

@@ -191,3 +191,3 @@

const allowNamedFunctions = options.allowNamedFunctions;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -270,3 +270,3 @@ /*

// Skip recursive functions.
const nameVar = context.getDeclaredVariables(node)[0];
const nameVar = sourceCode.getDeclaredVariables(node)[0];

@@ -278,3 +278,3 @@ if (isFunctionName(nameVar) && nameVar.references.length > 0) {

// Skip if it's using arguments.
const variable = getVariableOfArguments(context.getScope());
const variable = getVariableOfArguments(sourceCode.getScope(node));

@@ -344,2 +344,3 @@ if (variable && variable.references.length > 0) {

const leftParenToken = sourceCode.getTokenAfter(functionToken, astUtils.isOpeningParenToken);
const tokenBeforeBody = sourceCode.getTokenBefore(node.body);

@@ -358,3 +359,3 @@ if (sourceCode.commentsExistBetween(functionToken, leftParenToken)) {

}
yield fixer.insertTextBefore(node.body, "=> ");
yield fixer.insertTextAfter(tokenBeforeBody, " =>");

@@ -361,0 +362,0 @@ // Get the node that will become the new arrow function.

@@ -63,3 +63,3 @@ /**

if (initScope.through.find(ref => ref.resolved && ref.resolved.name === name)) {
if (initScope.through.some(ref => ref.resolved && ref.resolved.name === name)) {
return true;

@@ -336,5 +336,5 @@ }

docs: {
description: "require `const` declarations for variables that are never reassigned after declared",
description: "Require `const` declarations for variables that are never reassigned after declared",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-const"
url: "https://eslint.org/docs/latest/rules/prefer-const"
},

@@ -361,3 +361,3 @@

const options = context.options[0] || {};
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const shouldMatchAnyDestructuredVariable = options.destructuring !== "all";

@@ -452,3 +452,15 @@ const ignoreReadBeforeAssign = options.ignoreReadBeforeAssign === true;

shouldFix = shouldFix && (reportCount === varDeclParent.declarations.length);
let totalDeclarationsCount = 0;
varDeclParent.declarations.forEach(declaration => {
if (declaration.id.type === "ObjectPattern") {
totalDeclarationsCount += declaration.id.properties.length;
} else if (declaration.id.type === "ArrayPattern") {
totalDeclarationsCount += declaration.id.elements.length;
} else {
totalDeclarationsCount += 1;
}
});
shouldFix = shouldFix && (reportCount === totalDeclarationsCount);
}

@@ -488,3 +500,3 @@ }

if (node.kind === "let" && !isInitOfForStatement(node)) {
variables.push(...context.getDeclaredVariables(node));
variables.push(...sourceCode.getDeclaredVariables(node));
}

@@ -491,0 +503,0 @@ }

@@ -29,5 +29,5 @@ /**

docs: {
description: "require destructuring from arrays and/or objects",
description: "Require destructuring from arrays and/or objects",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-destructuring"
url: "https://eslint.org/docs/latest/rules/prefer-destructuring"
},

@@ -194,3 +194,3 @@

const rightNode = node.init;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -197,0 +197,0 @@ // Don't fix if that would remove any comments. Only comments inside `rightNode.object` can be preserved.

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

const astUtils = require("./utils/ast-utils");
const { CALL, ReferenceTracker } = require("eslint-utils");
const { CALL, ReferenceTracker } = require("@eslint-community/eslint-utils");

@@ -59,2 +59,3 @@ //------------------------------------------------------------------------------

const parentPrecedence = astUtils.getPrecedence(parent);
const needsParens = (

@@ -64,3 +65,3 @@ parent.type === "ClassDeclaration" ||

parent.type.endsWith("Expression") &&
astUtils.getPrecedence(parent) >= PRECEDENCE_OF_EXPONENTIATION_EXPR &&
(parentPrecedence === -1 || parentPrecedence >= PRECEDENCE_OF_EXPONENTIATION_EXPR) &&
!(parent.type === "BinaryExpression" && parent.operator === "**" && parent.right === node) &&

@@ -96,5 +97,5 @@ !((parent.type === "CallExpression" || parent.type === "NewExpression") && parent.arguments.includes(node)) &&

docs: {
description: "disallow the use of `Math.pow` in favor of the `**` operator",
description: "Disallow the use of `Math.pow` in favor of the `**` operator",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-exponentiation-operator"
url: "https://eslint.org/docs/latest/rules/prefer-exponentiation-operator"
},

@@ -111,3 +112,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -180,4 +181,4 @@ /**

return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -190,4 +191,4 @@ const trackMap = {

for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
report(node);
for (const { node: refNode } of tracker.iterateGlobalReferences(trackMap)) {
report(refNode);
}

@@ -194,0 +195,0 @@ }

@@ -17,4 +17,4 @@ /**

getStringIfConstant
} = require("eslint-utils");
const regexpp = require("regexpp");
} = require("@eslint-community/eslint-utils");
const regexpp = require("@eslint-community/regexpp");

@@ -27,2 +27,57 @@ //------------------------------------------------------------------------------

/**
* Creates fixer suggestions for the regex, if statically determinable.
* @param {number} groupStart Starting index of the regex group.
* @param {string} pattern The regular expression pattern to be checked.
* @param {string} rawText Source text of the regexNode.
* @param {ASTNode} regexNode AST node which contains the regular expression.
* @returns {Array<SuggestionResult>} Fixer suggestions for the regex, if statically determinable.
*/
function suggestIfPossible(groupStart, pattern, rawText, regexNode) {
switch (regexNode.type) {
case "Literal":
if (typeof regexNode.value === "string" && rawText.includes("\\")) {
return null;
}
break;
case "TemplateLiteral":
if (regexNode.expressions.length || rawText.slice(1, -1) !== pattern) {
return null;
}
break;
default:
return null;
}
const start = regexNode.range[0] + groupStart + 2;
return [
{
fix(fixer) {
const existingTemps = pattern.match(/temp\d+/gu) || [];
const highestTempCount = existingTemps.reduce(
(previous, next) =>
Math.max(previous, Number(next.slice("temp".length))),
0
);
return fixer.insertTextBeforeRange(
[start, start],
`?<temp${highestTempCount + 1}>`
);
},
messageId: "addGroupName"
},
{
fix(fixer) {
return fixer.insertTextBeforeRange(
[start, start],
"?:"
);
},
messageId: "addNonCapture"
}
];
}
//------------------------------------------------------------------------------

@@ -38,10 +93,14 @@ // Rule Definition

docs: {
description: "enforce using named capture group in regular expression",
description: "Enforce using named capture group in regular expression",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-named-capture-group"
url: "https://eslint.org/docs/latest/rules/prefer-named-capture-group"
},
hasSuggestions: true,
schema: [],
messages: {
addGroupName: "Add name to capture group.",
addNonCapture: "Convert group to non-capturing.",
required: "Capture group '{{group}}' should be converted to a named or non-capturing group."

@@ -52,15 +111,20 @@ }

create(context) {
const sourceCode = context.sourceCode;
/**
* Function to check regular expression.
* @param {string} pattern The regular expression pattern to be check.
* @param {ASTNode} node AST node which contains regular expression.
* @param {boolean} uFlag Flag indicates whether unicode mode is enabled or not.
* @param {string} pattern The regular expression pattern to be checked.
* @param {ASTNode} node AST node which contains the regular expression or a call/new expression.
* @param {ASTNode} regexNode AST node which contains the regular expression.
* @param {string|null} flags The regular expression flags to be checked.
* @returns {void}
*/
function checkRegex(pattern, node, uFlag) {
function checkRegex(pattern, node, regexNode, flags) {
let ast;
try {
ast = parser.parsePattern(pattern, 0, pattern.length, uFlag);
ast = parser.parsePattern(pattern, 0, pattern.length, {
unicode: Boolean(flags && flags.includes("u")),
unicodeSets: Boolean(flags && flags.includes("v"))
});
} catch {

@@ -75,2 +139,5 @@

if (!group.name) {
const rawText = sourceCode.getText(regexNode);
const suggest = suggestIfPossible(group.start, pattern, rawText, regexNode);
context.report({

@@ -81,3 +148,4 @@ node,

group: group.raw
}
},
suggest
});

@@ -92,7 +160,7 @@ }

if (node.regex) {
checkRegex(node.regex.pattern, node, node.regex.flags.includes("u"));
checkRegex(node.regex.pattern, node, node, node.regex.flags);
}
},
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -106,8 +174,8 @@ const traceMap = {

for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
const regex = getStringIfConstant(node.arguments[0]);
const flags = getStringIfConstant(node.arguments[1]);
for (const { node: refNode } of tracker.iterateGlobalReferences(traceMap)) {
const regex = getStringIfConstant(refNode.arguments[0]);
const flags = getStringIfConstant(refNode.arguments[1]);
if (regex) {
checkRegex(regex, node, flags && flags.includes("u"));
checkRegex(regex, refNode, refNode.arguments[0], flags);
}

@@ -114,0 +182,0 @@ }

@@ -48,5 +48,5 @@ /**

docs: {
description: "disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
description: "Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-numeric-literals"
url: "https://eslint.org/docs/latest/rules/prefer-numeric-literals"
},

@@ -64,3 +64,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -67,0 +67,0 @@ //----------------------------------------------------------------------

/**
* @fileoverview Prefers object spread property over Object.assign
* @author Sharmila Jesupaul
* See LICENSE file in root directory for full license.
*/

@@ -9,3 +8,3 @@

const { CALL, ReferenceTracker } = require("eslint-utils");
const { CALL, ReferenceTracker } = require("@eslint-community/eslint-utils");
const {

@@ -251,5 +250,5 @@ isCommaToken,

description:
"disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.",
"Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-object-spread"
url: "https://eslint.org/docs/latest/rules/prefer-object-spread"
},

@@ -267,7 +266,7 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -281,18 +280,18 @@ const trackMap = {

// Iterate all calls of `Object.assign` (only of the global variable `Object`).
for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
for (const { node: refNode } of tracker.iterateGlobalReferences(trackMap)) {
if (
node.arguments.length >= 1 &&
node.arguments[0].type === "ObjectExpression" &&
!hasArraySpread(node) &&
refNode.arguments.length >= 1 &&
refNode.arguments[0].type === "ObjectExpression" &&
!hasArraySpread(refNode) &&
!(
node.arguments.length > 1 &&
hasArgumentsWithAccessors(node)
refNode.arguments.length > 1 &&
hasArgumentsWithAccessors(refNode)
)
) {
const messageId = node.arguments.length === 1
const messageId = refNode.arguments.length === 1
? "useLiteralMessage"
: "useSpreadMessage";
const fix = defineFixer(node, sourceCode);
const fix = defineFixer(refNode, sourceCode);
context.report({ node, messageId, fix });
context.report({ node: refNode, messageId, fix });
}

@@ -299,0 +298,0 @@ }

@@ -19,5 +19,5 @@ /**

docs: {
description: "require using Error objects as Promise rejection reasons",
description: "Require using Error objects as Promise rejection reasons",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-promise-reject-errors"
url: "https://eslint.org/docs/latest/rules/prefer-promise-reject-errors"
},

@@ -45,2 +45,3 @@

const ALLOW_EMPTY_REJECT = context.options.length && context.options[0].allowEmptyReject;
const sourceCode = context.sourceCode;

@@ -105,3 +106,3 @@ //----------------------------------------------------------------------

) {
context.getDeclaredVariables(node.arguments[0])
sourceCode.getDeclaredVariables(node.arguments[0])

@@ -108,0 +109,0 @@ /*

@@ -18,5 +18,5 @@ /**

docs: {
description: "require `Reflect` methods where applicable",
description: "Require `Reflect` methods where applicable",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-reflect"
url: "https://eslint.org/docs/latest/rules/prefer-reflect"
},

@@ -110,3 +110,3 @@

const hasReflectSubstitute = Object.prototype.hasOwnProperty.call(reflectSubstitutes, methodName);
const userConfiguredException = exceptions.indexOf(methodName) !== -1;
const userConfiguredException = exceptions.includes(methodName);

@@ -120,3 +120,3 @@ if (hasReflectSubstitute && !isReflectCall && !userConfiguredException) {

const targetsIdentifier = node.argument.type === "Identifier";
const userConfiguredException = exceptions.indexOf("delete") !== -1;
const userConfiguredException = exceptions.includes("delete");

@@ -123,0 +123,0 @@ if (isDeleteOperator && !targetsIdentifier && !userConfiguredException) {

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

const astUtils = require("./utils/ast-utils");
const { CALL, CONSTRUCT, ReferenceTracker, findVariable } = require("eslint-utils");
const { CALL, CONSTRUCT, ReferenceTracker, findVariable } = require("@eslint-community/eslint-utils");
const { RegExpValidator, visitRegExpAST, RegExpParser } = require("@eslint-community/regexpp");
const { canTokensBeAdjacent } = require("./utils/ast-utils");
const { REGEXPP_LATEST_ECMA_VERSION } = require("./utils/regular-expressions");

@@ -38,10 +41,66 @@ //------------------------------------------------------------------------------

/**
* Determines whether the given node is a template literal without expressions.
* @param {ASTNode} node Node to check.
* @returns {boolean} True if the node is a template literal without expressions.
*/
function isStaticTemplateLiteral(node) {
return node.type === "TemplateLiteral" && node.expressions.length === 0;
}
const validPrecedingTokens = new Set([
"(",
";",
"[",
",",
"=",
"+",
"*",
"-",
"?",
"~",
"%",
"**",
"!",
"typeof",
"instanceof",
"&&",
"||",
"??",
"return",
"...",
"delete",
"void",
"in",
"<",
">",
"<=",
">=",
"==",
"===",
"!=",
"!==",
"<<",
">>",
">>>",
"&",
"|",
"^",
":",
"{",
"=>",
"*=",
"<<=",
">>=",
">>>=",
"^=",
"|=",
"&=",
"??=",
"||=",
"&&=",
"**=",
"+=",
"-=",
"/=",
"%=",
"/",
"do",
"break",
"continue",
"debugger",
"case",
"throw"
]);

@@ -59,7 +118,9 @@

docs: {
description: "disallow use of the `RegExp` constructor in favor of regular expression literals",
description: "Disallow use of the `RegExp` constructor in favor of regular expression literals",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-regex-literals"
url: "https://eslint.org/docs/latest/rules/prefer-regex-literals"
},
hasSuggestions: true,
schema: [

@@ -80,2 +141,5 @@ {

unexpectedRegExp: "Use a regular expression literal instead of the 'RegExp' constructor.",
replaceWithLiteral: "Replace with an equivalent regular expression literal.",
replaceWithLiteralAndFlags: "Replace with an equivalent regular expression literal with flags '{{ flags }}'.",
replaceWithIntendedLiteralAndFlags: "Replace with a regular expression literal with flags '{{ flags }}'.",
unexpectedRedundantRegExp: "Regular expression literal is unnecessarily wrapped within a 'RegExp' constructor.",

@@ -88,2 +152,3 @@ unexpectedRedundantRegExpWithFlags: "Use regular expression literal with flags instead of the 'RegExp' constructor."

const [{ disallowRedundantWrapping = false } = {}] = context.options;
const sourceCode = context.sourceCode;

@@ -96,3 +161,3 @@ /**

function isGlobalReference(node) {
const scope = context.getScope();
const scope = sourceCode.getScope(node);
const variable = findVariable(scope, node);

@@ -113,6 +178,27 @@

isGlobalReference(astUtils.skipChainExpression(node.tag).object) &&
isStaticTemplateLiteral(node.quasi);
astUtils.isStaticTemplateLiteral(node.quasi);
}
/**
* Gets the value of a string
* @param {ASTNode} node The node to get the string of.
* @returns {string|null} The value of the node.
*/
function getStringValue(node) {
if (isStringLiteral(node)) {
return node.value;
}
if (astUtils.isStaticTemplateLiteral(node)) {
return node.quasis[0].value.cooked;
}
if (isStringRawTaggedStaticTemplateLiteral(node)) {
return node.quasi.quasis[0].value.raw;
}
return null;
}
/**
* Determines whether the given node is considered to be a static string by the logic of this rule.

@@ -124,3 +210,3 @@ * @param {ASTNode} node Node to check.

return isStringLiteral(node) ||
isStaticTemplateLiteral(node) ||
astUtils.isStaticTemplateLiteral(node) ||
isStringRawTaggedStaticTemplateLiteral(node);

@@ -163,5 +249,134 @@ }

/**
* Returns a ecmaVersion compatible for regexpp.
* @param {number} ecmaVersion The ecmaVersion to convert.
* @returns {import("@eslint-community/regexpp/ecma-versions").EcmaVersion} The resulting ecmaVersion compatible for regexpp.
*/
function getRegexppEcmaVersion(ecmaVersion) {
if (ecmaVersion <= 5) {
return 5;
}
return Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION);
}
const regexppEcmaVersion = getRegexppEcmaVersion(context.languageOptions.ecmaVersion);
/**
* Makes a character escaped or else returns null.
* @param {string} character The character to escape.
* @returns {string} The resulting escaped character.
*/
function resolveEscapes(character) {
switch (character) {
case "\n":
case "\\\n":
return "\\n";
case "\r":
case "\\\r":
return "\\r";
case "\t":
case "\\\t":
return "\\t";
case "\v":
case "\\\v":
return "\\v";
case "\f":
case "\\\f":
return "\\f";
case "/":
return "\\/";
default:
return null;
}
}
/**
* Checks whether the given regex and flags are valid for the ecma version or not.
* @param {string} pattern The regex pattern to check.
* @param {string | undefined} flags The regex flags to check.
* @returns {boolean} True if the given regex pattern and flags are valid for the ecma version.
*/
function isValidRegexForEcmaVersion(pattern, flags) {
const validator = new RegExpValidator({ ecmaVersion: regexppEcmaVersion });
try {
validator.validatePattern(pattern, 0, pattern.length, {
unicode: flags ? flags.includes("u") : false,
unicodeSets: flags ? flags.includes("v") : false
});
if (flags) {
validator.validateFlags(flags);
}
return true;
} catch {
return false;
}
}
/**
* Checks whether two given regex flags contain the same flags or not.
* @param {string} flagsA The regex flags.
* @param {string} flagsB The regex flags.
* @returns {boolean} True if two regex flags contain same flags.
*/
function areFlagsEqual(flagsA, flagsB) {
return [...flagsA].sort().join("") === [...flagsB].sort().join("");
}
/**
* Merges two regex flags.
* @param {string} flagsA The regex flags.
* @param {string} flagsB The regex flags.
* @returns {string} The merged regex flags.
*/
function mergeRegexFlags(flagsA, flagsB) {
const flagsSet = new Set([
...flagsA,
...flagsB
]);
return [...flagsSet].join("");
}
/**
* Checks whether a give node can be fixed to the given regex pattern and flags.
* @param {ASTNode} node The node to check.
* @param {string} pattern The regex pattern to check.
* @param {string} flags The regex flags
* @returns {boolean} True if a node can be fixed to the given regex pattern and flags.
*/
function canFixTo(node, pattern, flags) {
const tokenBefore = sourceCode.getTokenBefore(node);
return sourceCode.getCommentsInside(node).length === 0 &&
(!tokenBefore || validPrecedingTokens.has(tokenBefore.value)) &&
isValidRegexForEcmaVersion(pattern, flags);
}
/**
* Returns a safe output code considering the before and after tokens.
* @param {ASTNode} node The regex node.
* @param {string} newRegExpValue The new regex expression value.
* @returns {string} The output code.
*/
function getSafeOutput(node, newRegExpValue) {
const tokenBefore = sourceCode.getTokenBefore(node);
const tokenAfter = sourceCode.getTokenAfter(node);
return (tokenBefore && !canTokensBeAdjacent(tokenBefore, newRegExpValue) && tokenBefore.range[1] === node.range[0] ? " " : "") +
newRegExpValue +
(tokenAfter && !canTokensBeAdjacent(newRegExpValue, tokenAfter) && node.range[1] === tokenAfter.range[0] ? " " : "");
}
return {
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -175,11 +390,123 @@ const traceMap = {

for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
if (disallowRedundantWrapping && isUnnecessarilyWrappedRegexLiteral(node)) {
if (node.arguments.length === 2) {
context.report({ node, messageId: "unexpectedRedundantRegExpWithFlags" });
for (const { node: refNode } of tracker.iterateGlobalReferences(traceMap)) {
if (disallowRedundantWrapping && isUnnecessarilyWrappedRegexLiteral(refNode)) {
const regexNode = refNode.arguments[0];
if (refNode.arguments.length === 2) {
const suggests = [];
const argFlags = getStringValue(refNode.arguments[1]) || "";
if (canFixTo(refNode, regexNode.regex.pattern, argFlags)) {
suggests.push({
messageId: "replaceWithLiteralAndFlags",
pattern: regexNode.regex.pattern,
flags: argFlags
});
}
const literalFlags = regexNode.regex.flags || "";
const mergedFlags = mergeRegexFlags(literalFlags, argFlags);
if (
!areFlagsEqual(mergedFlags, argFlags) &&
canFixTo(refNode, regexNode.regex.pattern, mergedFlags)
) {
suggests.push({
messageId: "replaceWithIntendedLiteralAndFlags",
pattern: regexNode.regex.pattern,
flags: mergedFlags
});
}
context.report({
node: refNode,
messageId: "unexpectedRedundantRegExpWithFlags",
suggest: suggests.map(({ flags, pattern, messageId }) => ({
messageId,
data: {
flags
},
fix(fixer) {
return fixer.replaceText(refNode, getSafeOutput(refNode, `/${pattern}/${flags}`));
}
}))
});
} else {
context.report({ node, messageId: "unexpectedRedundantRegExp" });
const outputs = [];
if (canFixTo(refNode, regexNode.regex.pattern, regexNode.regex.flags)) {
outputs.push(sourceCode.getText(regexNode));
}
context.report({
node: refNode,
messageId: "unexpectedRedundantRegExp",
suggest: outputs.map(output => ({
messageId: "replaceWithLiteral",
fix(fixer) {
return fixer.replaceText(
refNode,
getSafeOutput(refNode, output)
);
}
}))
});
}
} else if (hasOnlyStaticStringArguments(node)) {
context.report({ node, messageId: "unexpectedRegExp" });
} else if (hasOnlyStaticStringArguments(refNode)) {
let regexContent = getStringValue(refNode.arguments[0]);
let noFix = false;
let flags;
if (refNode.arguments[1]) {
flags = getStringValue(refNode.arguments[1]);
}
if (!canFixTo(refNode, regexContent, flags)) {
noFix = true;
}
if (!/^[-a-zA-Z0-9\\[\](){} \t\r\n\v\f!@#$%^&*+^_=/~`.><?,'"|:;]*$/u.test(regexContent)) {
noFix = true;
}
if (regexContent && !noFix) {
let charIncrease = 0;
const ast = new RegExpParser({ ecmaVersion: regexppEcmaVersion }).parsePattern(regexContent, 0, regexContent.length, {
unicode: flags ? flags.includes("u") : false,
unicodeSets: flags ? flags.includes("v") : false
});
visitRegExpAST(ast, {
onCharacterEnter(characterNode) {
const escaped = resolveEscapes(characterNode.raw);
if (escaped) {
regexContent =
regexContent.slice(0, characterNode.start + charIncrease) +
escaped +
regexContent.slice(characterNode.end + charIncrease);
if (characterNode.raw.length === 1) {
charIncrease += 1;
}
}
}
});
}
const newRegExpValue = `/${regexContent || "(?:)"}/${flags || ""}`;
context.report({
node: refNode,
messageId: "unexpectedRegExp",
suggest: noFix ? [] : [{
messageId: "replaceWithLiteral",
fix(fixer) {
return fixer.replaceText(refNode, getSafeOutput(refNode, newRegExpValue));
}
}]
});
}

@@ -186,0 +513,0 @@ }

@@ -33,3 +33,3 @@ /**

/* istanbul ignore next : unreachable */
/* c8 ignore next */
return null;

@@ -69,5 +69,5 @@ }

docs: {
description: "require rest parameters instead of `arguments`",
description: "Require rest parameters instead of `arguments`",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-rest-params"
url: "https://eslint.org/docs/latest/rules/prefer-rest-params"
},

@@ -84,2 +84,4 @@

const sourceCode = context.sourceCode;
/**

@@ -100,6 +102,7 @@ * Reports a given reference.

* Reports references of the implicit `arguments` variable if exist.
* @param {ASTNode} node The node representing the function.
* @returns {void}
*/
function checkForArguments() {
const argumentsVar = getVariableOfArguments(context.getScope());
function checkForArguments(node) {
const argumentsVar = getVariableOfArguments(sourceCode.getScope(node));

@@ -106,0 +109,0 @@ if (argumentsVar) {

@@ -52,5 +52,5 @@ /**

docs: {
description: "require spread operators instead of `.apply()`",
description: "Require spread operators instead of `.apply()`",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-spread"
url: "https://eslint.org/docs/latest/rules/prefer-spread"
},

@@ -67,3 +67,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -70,0 +70,0 @@ return {

@@ -131,5 +131,5 @@ /**

docs: {
description: "require template literals instead of string concatenation",
description: "Require template literals instead of string concatenation",
recommended: false,
url: "https://eslint.org/docs/rules/prefer-template"
url: "https://eslint.org/docs/latest/rules/prefer-template"
},

@@ -146,3 +146,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let done = Object.create(null);

@@ -193,3 +193,3 @@

if (isConcatenation(currentNode) && hasStringLiteral(currentNode) && hasNonStringLiteral(currentNode)) {
if (isConcatenation(currentNode) && hasStringLiteral(currentNode)) {
const plusSign = sourceCode.getFirstTokenBetween(currentNode.left, currentNode.right, token => token.value === "+");

@@ -196,0 +196,0 @@ const textBeforePlus = getTextBetween(currentNode.left, plusSign);

/**
* @fileoverview Rule to flag non-quoted property names in object literals.
* @author Mathias Bynens <http://mathiasbynens.be/>
* @deprecated in ESLint v8.53.0
*/

@@ -22,8 +23,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "require quotes around object literal property names",
description: "Require quotes around object literal property names",
recommended: false,
url: "https://eslint.org/docs/rules/quote-props"
url: "https://eslint.org/docs/latest/rules/quote-props"
},

@@ -90,3 +93,3 @@

sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -100,3 +103,3 @@

function isKeyword(tokenStr) {
return keywords.indexOf(tokenStr) >= 0;
return keywords.includes(tokenStr);
}

@@ -114,3 +117,3 @@

return tokens.length === 1 && tokens[0].start === 0 && tokens[0].end === rawKey.length &&
(["Identifier", "Keyword", "Null", "Boolean"].indexOf(tokens[0].type) >= 0 ||
(["Identifier", "Keyword", "Null", "Boolean"].includes(tokens[0].type) ||
(tokens[0].type === "Numeric" && !skipNumberLiterals && String(+tokens[0].value) === tokens[0].value));

@@ -117,0 +120,0 @@ }

/**
* @fileoverview A rule to choose between single and double quote marks
* @author Matt DuVall <http://www.mattduvall.com/>, Brandon Payton
* @deprecated in ESLint v8.53.0
*/

@@ -80,8 +81,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce the consistent use of either backticks, double, or single quotes",
description: "Enforce the consistent use of either backticks, double, or single quotes",
recommended: false,
url: "https://eslint.org/docs/rules/quotes"
url: "https://eslint.org/docs/latest/rules/quotes"
},

@@ -127,3 +130,3 @@

allowTemplateLiterals = options && options.allowTemplateLiterals === true,
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;
let avoidEscape = options && options.avoidEscape === true;

@@ -162,3 +165,4 @@

* Checks whether or not a given node is a directive.
* The directive is a `ExpressionStatement` which has only a string literal.
* The directive is a `ExpressionStatement` which has only a string literal not surrounded by
* parentheses.
* @param {ASTNode} node A node to check.

@@ -172,3 +176,4 @@ * @returns {boolean} Whether or not the node is a directive.

node.expression.type === "Literal" &&
typeof node.expression.value === "string"
typeof node.expression.value === "string" &&
!astUtils.isParenthesised(sourceCode, node.expression)
);

@@ -178,14 +183,13 @@ }

/**
* Checks whether or not a given node is a part of directive prologues.
* See also: http://www.ecma-international.org/ecma-262/6.0/#sec-directive-prologues-and-the-use-strict-directive
* Checks whether a specified node is either part of, or immediately follows a (possibly empty) directive prologue.
* @see {@link http://www.ecma-international.org/ecma-262/6.0/#sec-directive-prologues-and-the-use-strict-directive}
* @param {ASTNode} node A node to check.
* @returns {boolean} Whether or not the node is a part of directive prologues.
* @returns {boolean} Whether a specified node is either part of, or immediately follows a (possibly empty) directive prologue.
* @private
*/
function isPartOfDirectivePrologue(node) {
const block = node.parent.parent;
if (block.type !== "Program" && (block.type !== "BlockStatement" || !astUtils.isFunction(block.parent))) {
function isExpressionInOrJustAfterDirectivePrologue(node) {
if (!astUtils.isTopLevelExpressionStatement(node.parent)) {
return false;
}
const block = node.parent.parent;

@@ -220,3 +224,3 @@ // Check the node is at a prologue.

case "ExpressionStatement":
return isPartOfDirectivePrologue(node);
return !astUtils.isParenthesised(sourceCode, node) && isExpressionInOrJustAfterDirectivePrologue(node);

@@ -232,5 +236,16 @@ // LiteralPropertyName.

case "ExportNamedDeclaration":
case "ExportAllDeclaration":
return parent.source === node;
// ModuleExportName or ModuleSpecifier.
case "ExportAllDeclaration":
return parent.exported === node || parent.source === node;
// ModuleExportName.
case "ImportSpecifier":
return parent.imported === node;
// ModuleExportName.
case "ExportSpecifier":
return parent.local === node || parent.exported === node;
// Others don't allow.

@@ -282,3 +297,3 @@ default:

if (!isValid && avoidEscape) {
isValid = astUtils.isSurroundedBy(rawVal, settings.alternateQuote) && rawVal.indexOf(settings.quote) >= 0;
isValid = astUtils.isSurroundedBy(rawVal, settings.alternateQuote) && rawVal.includes(settings.quote);
}

@@ -328,8 +343,7 @@

fix(fixer) {
if (isPartOfDirectivePrologue(node)) {
if (astUtils.isTopLevelExpressionStatement(node.parent) && !astUtils.isParenthesised(sourceCode, node)) {
/*
* TemplateLiterals in a directive prologue aren't actually directives, but if they're
* in the directive prologue, then fixing them might turn them into directives and change
* the behavior of the code.
* TemplateLiterals aren't actually directives, but fixing them might turn
* them into directives and change the behavior of the code.
*/

@@ -336,0 +350,0 @@ return null;

@@ -83,5 +83,5 @@ /**

docs: {
description: "enforce the consistent use of the radix argument when using `parseInt()`",
description: "Enforce the consistent use of the radix argument when using `parseInt()`",
recommended: false,
url: "https://eslint.org/docs/rules/radix"
url: "https://eslint.org/docs/latest/rules/radix"
},

@@ -108,2 +108,3 @@

const mode = context.options[0] || MODE_ALWAYS;
const sourceCode = context.sourceCode;

@@ -136,3 +137,2 @@ /**

fix(fixer) {
const sourceCode = context.getSourceCode();
const tokens = sourceCode.getTokens(node);

@@ -168,4 +168,4 @@ const lastToken = tokens[tokens.length - 1]; // Parenthesis.

return {
"Program:exit"() {
const scope = context.getScope();
"Program:exit"(node) {
const scope = sourceCode.getScope(node);
let variable;

@@ -177,6 +177,6 @@

variable.references.forEach(reference => {
const node = reference.identifier;
const idNode = reference.identifier;
if (astUtils.isCallee(node)) {
checkArguments(node.parent);
if (astUtils.isCallee(idNode)) {
checkArguments(idNode.parent);
}

@@ -190,8 +190,8 @@ });

variable.references.forEach(reference => {
const node = reference.identifier.parent;
const maybeCallee = node.parent.type === "ChainExpression"
? node.parent
: node;
const parentNode = reference.identifier.parent;
const maybeCallee = parentNode.parent.type === "ChainExpression"
? parentNode.parent
: parentNode;
if (isParseIntMethod(node) && astUtils.isCallee(maybeCallee)) {
if (isParseIntMethod(parentNode) && astUtils.isCallee(maybeCallee)) {
checkArguments(maybeCallee.parent);

@@ -198,0 +198,0 @@ }

@@ -174,5 +174,5 @@ /**

docs: {
description: "disallow assignments that can lead to race conditions due to usage of `await` or `yield`",
description: "Disallow assignments that can lead to race conditions due to usage of `await` or `yield`",
recommended: false,
url: "https://eslint.org/docs/rules/require-atomic-updates"
url: "https://eslint.org/docs/latest/rules/require-atomic-updates"
},

@@ -202,3 +202,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const assignmentReferences = new Map();

@@ -209,4 +209,4 @@ const segmentInfo = new SegmentInfo();

return {
onCodePathStart(codePath) {
const scope = context.getScope();
onCodePathStart(codePath, node) {
const scope = sourceCode.getScope(node);
const shouldVerify =

@@ -219,3 +219,4 @@ scope.type === "function" &&

codePath,
referenceMap: shouldVerify ? createReferenceMap(scope) : null
referenceMap: shouldVerify ? createReferenceMap(scope) : null,
currentSegments: new Set()
};

@@ -230,7 +231,21 @@ },

segmentInfo.initialize(segment);
stack.currentSegments.add(segment);
},
onUnreachableCodePathSegmentStart(segment) {
stack.currentSegments.add(segment);
},
onUnreachableCodePathSegmentEnd(segment) {
stack.currentSegments.delete(segment);
},
onCodePathSegmentEnd(segment) {
stack.currentSegments.delete(segment);
},
// Handle references to prepare verification.
Identifier(node) {
const { codePath, referenceMap } = stack;
const { referenceMap } = stack;
const reference = referenceMap && referenceMap.get(node);

@@ -248,3 +263,3 @@

if (reference.isRead() && !(writeExpr && writeExpr.parent.operator === "=")) {
segmentInfo.markAsRead(codePath.currentSegments, variable);
segmentInfo.markAsRead(stack.currentSegments, variable);
}

@@ -276,6 +291,5 @@

":expression:exit"(node) {
const { codePath, referenceMap } = stack;
// referenceMap exists if this is in a resumable function scope.
if (!referenceMap) {
if (!stack.referenceMap) {
return;

@@ -286,3 +300,3 @@ }

if (node.type === "AwaitExpression" || node.type === "YieldExpression") {
segmentInfo.makeOutdated(codePath.currentSegments);
segmentInfo.makeOutdated(stack.currentSegments);
}

@@ -299,3 +313,3 @@

if (segmentInfo.isOutdated(codePath.currentSegments, variable)) {
if (segmentInfo.isOutdated(stack.currentSegments, variable)) {
if (node.parent.left === reference.identifier) {

@@ -302,0 +316,0 @@ context.report({

@@ -37,5 +37,5 @@ /**

docs: {
description: "disallow async functions which have no `await` expression",
description: "Disallow async functions which have no `await` expression",
recommended: false,
url: "https://eslint.org/docs/rules/require-await"
url: "https://eslint.org/docs/latest/rules/require-await"
},

@@ -51,3 +51,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
let scopeInfo = null;

@@ -54,0 +54,0 @@

@@ -14,5 +14,5 @@ /**

docs: {
description: "require JSDoc comments",
description: "Require JSDoc comments",
recommended: false,
url: "https://eslint.org/docs/rules/require-jsdoc"
url: "https://eslint.org/docs/latest/rules/require-jsdoc"
},

@@ -65,3 +65,3 @@

create(context) {
const source = context.getSourceCode();
const source = context.sourceCode;
const DEFAULT_OPTIONS = {

@@ -68,0 +68,0 @@ FunctionDeclaration: true,

@@ -17,3 +17,5 @@ /**

getStringIfConstant
} = require("eslint-utils");
} = require("@eslint-community/eslint-utils");
const astUtils = require("./utils/ast-utils.js");
const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");

@@ -30,8 +32,11 @@ //------------------------------------------------------------------------------

docs: {
description: "enforce the use of `u` flag on RegExp",
description: "Enforce the use of `u` or `v` flag on RegExp",
recommended: false,
url: "https://eslint.org/docs/rules/require-unicode-regexp"
url: "https://eslint.org/docs/latest/rules/require-unicode-regexp"
},
hasSuggestions: true,
messages: {
addUFlag: "Add the 'u' flag.",
requireUFlag: "Use the 'u' flag."

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

create(context) {
const sourceCode = context.sourceCode;
return {

@@ -49,9 +57,22 @@ "Literal[regex]"(node) {

if (!flags.includes("u")) {
context.report({ node, messageId: "requireUFlag" });
if (!flags.includes("u") && !flags.includes("v")) {
context.report({
messageId: "requireUFlag",
node,
suggest: isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, node.regex.pattern)
? [
{
fix(fixer) {
return fixer.insertTextAfter(node, "u");
},
messageId: "addUFlag"
}
]
: null
});
}
},
Program() {
const scope = context.getScope();
Program(node) {
const scope = sourceCode.getScope(node);
const tracker = new ReferenceTracker(scope);

@@ -62,8 +83,47 @@ const trackMap = {

for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
const flagsNode = node.arguments[1];
for (const { node: refNode } of tracker.iterateGlobalReferences(trackMap)) {
const [patternNode, flagsNode] = refNode.arguments;
if (patternNode && patternNode.type === "SpreadElement") {
continue;
}
const pattern = getStringIfConstant(patternNode, scope);
const flags = getStringIfConstant(flagsNode, scope);
if (!flagsNode || (typeof flags === "string" && !flags.includes("u"))) {
context.report({ node, messageId: "requireUFlag" });
if (!flagsNode || (typeof flags === "string" && !flags.includes("u") && !flags.includes("v"))) {
context.report({
messageId: "requireUFlag",
node: refNode,
suggest: typeof pattern === "string" && isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, pattern)
? [
{
fix(fixer) {
if (flagsNode) {
if ((flagsNode.type === "Literal" && typeof flagsNode.value === "string") || flagsNode.type === "TemplateLiteral") {
const flagsNodeText = sourceCode.getText(flagsNode);
return fixer.replaceText(flagsNode, [
flagsNodeText.slice(0, flagsNodeText.length - 1),
flagsNodeText.slice(flagsNodeText.length - 1)
].join("u"));
}
// We intentionally don't suggest concatenating + "u" to non-literals
return null;
}
const penultimateToken = sourceCode.getLastToken(refNode, { skip: 1 }); // skip closing parenthesis
return fixer.insertTextAfter(
penultimateToken,
astUtils.isCommaToken(penultimateToken)
? ' "u",'
: ', "u"'
);
},
messageId: "addUFlag"
}
]
: null
});
}

@@ -70,0 +130,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "require generator functions to contain `yield`",
description: "Require generator functions to contain `yield`",
recommended: true,
url: "https://eslint.org/docs/rules/require-yield"
url: "https://eslint.org/docs/latest/rules/require-yield"
},

@@ -72,3 +72,2 @@

/* istanbul ignore else */
if (stack.length > 0) {

@@ -75,0 +74,0 @@ stack[stack.length - 1] += 1;

/**
* @fileoverview Enforce spacing between rest and spread operators and their expressions.
* @author Kai Cataldo
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce spacing between rest and spread operators and their expressions",
description: "Enforce spacing between rest and spread operators and their expressions",
recommended: false,
url: "https://eslint.org/docs/rules/rest-spread-spacing"
url: "https://eslint.org/docs/latest/rules/rest-spread-spacing"
},

@@ -39,3 +42,3 @@

create(context) {
const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
alwaysSpace = context.options[0] === "always";

@@ -42,0 +45,0 @@

/**
* @fileoverview Validates spacing before and after semicolon
* @author Mathias Schreck
* @deprecated in ESLint v8.53.0
*/

@@ -17,8 +18,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before and after semicolons",
description: "Enforce consistent spacing before and after semicolons",
recommended: false,
url: "https://eslint.org/docs/rules/semi-spacing"
url: "https://eslint.org/docs/latest/rules/semi-spacing"
},

@@ -56,3 +59,3 @@

const config = context.options[0],
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;
let requireSpaceBefore = false,

@@ -59,0 +62,0 @@ requireSpaceAfter = true;

/**
* @fileoverview Rule to enforce location of semicolons.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -73,8 +74,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce location of semicolons",
description: "Enforce location of semicolons",
recommended: false,
url: "https://eslint.org/docs/rules/semi-style"
url: "https://eslint.org/docs/latest/rules/semi-style"
},

@@ -91,3 +94,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const option = context.options[0] || "last";

@@ -94,0 +97,0 @@

/**
* @fileoverview Rule to flag missing semicolons.
* @author Nicholas C. Zakas
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow semicolons instead of ASI",
description: "Require or disallow semicolons instead of ASI",
recommended: false,
url: "https://eslint.org/docs/rules/semi"
url: "https://eslint.org/docs/latest/rules/semi"
},

@@ -62,3 +65,4 @@

properties: {
omitLastInOneLineBlock: { type: "boolean" }
omitLastInOneLineBlock: { type: "boolean" },
omitLastInOneLineClassBody: { type: "boolean" }
},

@@ -88,4 +92,5 @@ additionalProperties: false

const exceptOneLine = Boolean(options && options.omitLastInOneLineBlock);
const exceptOneLineClassBody = Boolean(options && options.omitLastInOneLineClassBody);
const beforeStatementContinuationChars = options && options.beforeStatementContinuationChars || "any";
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -341,2 +346,23 @@ //--------------------------------------------------------------------------

/**
* Checks a node to see if it's the last item in a one-liner `ClassBody` node.
* ClassBody is a one-liner if its braces (and consequently everything between them) are on the same line.
* @param {ASTNode} node The node to check.
* @returns {boolean} whether the node is the last item in a one-liner ClassBody.
*/
function isLastInOneLinerClassBody(node) {
const parent = node.parent;
const nextToken = sourceCode.getTokenAfter(node);
if (!nextToken || nextToken.value !== "}") {
return false;
}
if (parent.type === "ClassBody") {
return parent.loc.start.line === parent.loc.end.line;
}
return false;
}
/**
* Checks a node to see if it's followed by a semicolon.

@@ -361,6 +387,8 @@ * @param {ASTNode} node The node to check.

const oneLinerBlock = (exceptOneLine && isLastInOneLinerBlock(node));
const oneLinerClassBody = (exceptOneLineClassBody && isLastInOneLinerClassBody(node));
const oneLinerBlockOrClassBody = oneLinerBlock || oneLinerClassBody;
if (isSemi && oneLinerBlock) {
if (isSemi && oneLinerBlockOrClassBody) {
report(node, true);
} else if (!isSemi && !oneLinerBlock) {
} else if (!isSemi && !oneLinerBlockOrClassBody) {
report(node);

@@ -367,0 +395,0 @@ }

@@ -18,5 +18,5 @@ /**

docs: {
description: "enforce sorted import declarations within modules",
description: "Enforce sorted import declarations within modules",
recommended: false,
url: "https://eslint.org/docs/rules/sort-imports"
url: "https://eslint.org/docs/latest/rules/sort-imports"
},

@@ -75,3 +75,3 @@

allowSeparatedGroups = configuration.allowSeparatedGroups || false,
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;
let previousDeclaration = null;

@@ -78,0 +78,0 @@

@@ -84,5 +84,5 @@ /**

docs: {
description: "require object keys to be sorted",
description: "Require object keys to be sorted",
recommended: false,
url: "https://eslint.org/docs/rules/sort-keys"
url: "https://eslint.org/docs/latest/rules/sort-keys"
},

@@ -109,2 +109,6 @@

default: 2
},
allowLineSeparatedGroups: {
type: "boolean",
default: false
}

@@ -129,2 +133,3 @@ },

const minKeys = options && options.minKeys;
const allowLineSeparatedGroups = options && options.allowLineSeparatedGroups || false;
const isValidOrder = isValidOrders[

@@ -136,2 +141,3 @@ order + (insensitive ? "I" : "") + (natural ? "N" : "")

let stack = null;
const sourceCode = context.sourceCode;

@@ -142,2 +148,4 @@ return {

upper: stack,
prevNode: null,
prevBlankLine: false,
prevName: null,

@@ -167,2 +175,32 @@ numKeys: node.properties.length

// Get tokens between current node and previous node
const tokens = stack.prevNode && sourceCode
.getTokensBetween(stack.prevNode, node, { includeComments: true });
let isBlankLineBetweenNodes = stack.prevBlankLine;
if (tokens) {
// check blank line between tokens
tokens.forEach((token, index) => {
const previousToken = tokens[index - 1];
if (previousToken && (token.loc.start.line - previousToken.loc.end.line > 1)) {
isBlankLineBetweenNodes = true;
}
});
// check blank line between the current node and the last token
if (!isBlankLineBetweenNodes && (node.loc.start.line - tokens[tokens.length - 1].loc.end.line > 1)) {
isBlankLineBetweenNodes = true;
}
// check blank line between the first token and the previous node
if (!isBlankLineBetweenNodes && (tokens[0].loc.start.line - stack.prevNode.loc.end.line > 1)) {
isBlankLineBetweenNodes = true;
}
}
stack.prevNode = node;
if (thisName !== null) {

@@ -172,2 +210,7 @@ stack.prevName = thisName;

if (allowLineSeparatedGroups && isBlankLineBetweenNodes) {
stack.prevBlankLine = thisName === null;
return;
}
if (prevName === null || thisName === null || numKeys < minKeys) {

@@ -174,0 +217,0 @@ return;

@@ -18,5 +18,5 @@ /**

docs: {
description: "require variables within the same declaration block to be sorted",
description: "Require variables within the same declaration block to be sorted",
recommended: false,
url: "https://eslint.org/docs/rules/sort-vars"
url: "https://eslint.org/docs/latest/rules/sort-vars"
},

@@ -48,3 +48,3 @@

ignoreCase = configuration.ignoreCase || false,
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;

@@ -51,0 +51,0 @@ return {

/**
* @fileoverview A rule to ensure whitespace before blocks.
* @author Mathias Schreck <https://github.com/lo1tuma>
* @deprecated in ESLint v8.53.0
*/

@@ -40,8 +41,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before blocks",
description: "Enforce consistent spacing before blocks",
recommended: false,
url: "https://eslint.org/docs/rules/space-before-blocks"
url: "https://eslint.org/docs/latest/rules/space-before-blocks"
},

@@ -84,3 +87,3 @@

const config = context.options[0],
sourceCode = context.getSourceCode();
sourceCode = context.sourceCode;
let alwaysFunctions = true,

@@ -87,0 +90,0 @@ alwaysKeywords = true,

/**
* @fileoverview Rule to validate spacing before function paren.
* @author Mathias Schreck <https://github.com/lo1tuma>
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before `function` definition opening parenthesis",
description: "Enforce consistent spacing before `function` definition opening parenthesis",
recommended: false,
url: "https://eslint.org/docs/rules/space-before-function-paren"
url: "https://eslint.org/docs/latest/rules/space-before-function-paren"
},

@@ -63,3 +66,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const baseConfig = typeof context.options[0] === "string" ? context.options[0] : "always";

@@ -66,0 +69,0 @@ const overrideConfig = typeof context.options[0] === "object" ? context.options[0] : {};

/**
* @fileoverview Disallows or enforces spaces inside of parentheses.
* @author Jonathan Rajavuori
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing inside parentheses",
description: "Enforce consistent spacing inside parentheses",
recommended: false,
url: "https://eslint.org/docs/rules/space-in-parens"
url: "https://eslint.org/docs/latest/rules/space-in-parens"
},

@@ -106,3 +109,3 @@

//--------------------------------------------------------------------------
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -109,0 +112,0 @@ /**

/**
* @fileoverview Require spaces around infix operators
* @author Michael Ficarra
* @deprecated in ESLint v8.53.0
*/

@@ -16,8 +17,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require spacing around infix operators",
description: "Require spacing around infix operators",
recommended: false,
url: "https://eslint.org/docs/rules/space-infix-ops"
url: "https://eslint.org/docs/latest/rules/space-infix-ops"
},

@@ -47,3 +50,3 @@

const int32Hint = context.options[0] ? context.options[0].int32Hint === true : false;
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -50,0 +53,0 @@ /**

/**
* @fileoverview This rule should require or disallow spaces before or after unary operations.
* @author Marcin Kumorek
* @deprecated in ESLint v8.53.0
*/

@@ -20,8 +21,10 @@ "use strict";

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce consistent spacing before or after unary operators",
description: "Enforce consistent spacing before or after unary operators",
recommended: false,
url: "https://eslint.org/docs/rules/space-unary-ops"
url: "https://eslint.org/docs/latest/rules/space-unary-ops"
},

@@ -66,3 +69,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -69,0 +72,0 @@ //--------------------------------------------------------------------------

/**
* @fileoverview Source code for spaced-comments rule
* @author Gyandeep Singh
* @deprecated in ESLint v8.53.0
*/

@@ -42,3 +43,3 @@ "use strict";

// `*` is a marker for JSDoc comments.
if (markers.indexOf("*") === -1) {
if (!markers.includes("*")) {
return markers.concat("*");

@@ -153,8 +154,10 @@ }

meta: {
deprecated: true,
replacedBy: [],
type: "suggestion",
docs: {
description: "enforce consistent spacing after the `//` or `/*` in a comment",
description: "Enforce consistent spacing after the `//` or `/*` in a comment",
recommended: false,
url: "https://eslint.org/docs/rules/spaced-comment"
url: "https://eslint.org/docs/latest/rules/spaced-comment"
},

@@ -240,3 +243,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -243,0 +246,0 @@ // Unless the first option is never, require a space

@@ -72,5 +72,5 @@ /**

docs: {
description: "require or disallow strict mode directives",
description: "Require or disallow strict mode directives",
recommended: false,
url: "https://eslint.org/docs/rules/strict"
url: "https://eslint.org/docs/latest/rules/strict"
},

@@ -109,3 +109,3 @@

} else if (mode === "safe") {
mode = ecmaFeatures.globalReturn ? "global" : "function";
mode = ecmaFeatures.globalReturn || context.languageOptions.sourceType === "commonjs" ? "global" : "function";
}

@@ -112,0 +112,0 @@

/**
* @fileoverview Rule to enforce spacing around colons of switch statements.
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "enforce spacing around colons of switch statements",
description: "Enforce spacing around colons of switch statements",
recommended: false,
url: "https://eslint.org/docs/rules/switch-colon-spacing"
url: "https://eslint.org/docs/latest/rules/switch-colon-spacing"
},

@@ -50,3 +53,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const options = context.options[0] || {};

@@ -53,0 +56,0 @@ const beforeSpacing = options.before === true; // false by default

@@ -25,5 +25,5 @@ /**

docs: {
description: "require symbol descriptions",
description: "Require symbol descriptions",
recommended: false,
url: "https://eslint.org/docs/rules/symbol-description"
url: "https://eslint.org/docs/latest/rules/symbol-description"
},

@@ -39,2 +39,4 @@ fixable: null,

const sourceCode = context.sourceCode;
/**

@@ -56,4 +58,4 @@ * Reports if node does not conform the rule in case rule is set to

return {
"Program:exit"() {
const scope = context.getScope();
"Program:exit"(node) {
const scope = sourceCode.getScope(node);
const variable = astUtils.getVariableByName(scope, "Symbol");

@@ -63,6 +65,6 @@

variable.references.forEach(reference => {
const node = reference.identifier;
const idNode = reference.identifier;
if (astUtils.isCallee(node)) {
checkArgument(node.parent);
if (astUtils.isCallee(idNode)) {
checkArgument(idNode.parent);
}

@@ -69,0 +71,0 @@ });

/**
* @fileoverview Rule to enforce spacing around embedded expressions of template strings
* @author Toru Nagashima
* @deprecated in ESLint v8.53.0
*/

@@ -21,8 +22,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow spacing around embedded expressions of template strings",
description: "Require or disallow spacing around embedded expressions of template strings",
recommended: false,
url: "https://eslint.org/docs/rules/template-curly-spacing"
url: "https://eslint.org/docs/latest/rules/template-curly-spacing"
},

@@ -44,3 +47,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;
const always = context.options[0] === "always";

@@ -47,0 +50,0 @@

/**
* @fileoverview Rule to check spacing between template tags and their literals
* @author Jonathan Wilsson
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow spacing between template tags and their literals",
description: "Require or disallow spacing between template tags and their literals",
recommended: false,
url: "https://eslint.org/docs/rules/template-tag-spacing"
url: "https://eslint.org/docs/latest/rules/template-tag-spacing"
},

@@ -37,3 +40,3 @@

const never = context.options[0] !== "always";
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -40,0 +43,0 @@ /**

@@ -17,5 +17,5 @@ /**

docs: {
description: "require or disallow Unicode byte order mark (BOM)",
description: "Require or disallow Unicode byte order mark (BOM)",
recommended: false,
url: "https://eslint.org/docs/rules/unicode-bom"
url: "https://eslint.org/docs/latest/rules/unicode-bom"
},

@@ -46,3 +46,3 @@

const sourceCode = context.getSourceCode(),
const sourceCode = context.sourceCode,
location = { column: 0, line: 1 },

@@ -49,0 +49,0 @@ requireBOM = context.options[0] || "never";

@@ -40,5 +40,5 @@ /**

docs: {
description: "require calls to `isNaN()` when checking for `NaN`",
description: "Require calls to `isNaN()` when checking for `NaN`",
recommended: true,
url: "https://eslint.org/docs/rules/use-isnan"
url: "https://eslint.org/docs/latest/rules/use-isnan"
},

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

@@ -24,5 +24,5 @@ /**

docs: {
description: "enforce valid JSDoc comments",
description: "Enforce valid JSDoc comments",
recommended: false,
url: "https://eslint.org/docs/rules/valid-jsdoc"
url: "https://eslint.org/docs/latest/rules/valid-jsdoc"
},

@@ -100,3 +100,3 @@

prefer = options.prefer || {},
sourceCode = context.getSourceCode(),
sourceCode = context.sourceCode,

@@ -410,3 +410,3 @@ // these both default to true, so you have to explicitly make them false

});
} else if (param.name.indexOf(".") === -1) {
} else if (!param.name.includes(".")) {
paramTagsByName[param.name] = param;

@@ -413,0 +413,0 @@ }

@@ -8,2 +8,8 @@ /**

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition

@@ -18,7 +24,9 @@ //------------------------------------------------------------------------------

docs: {
description: "enforce comparing `typeof` expressions against valid strings",
description: "Enforce comparing `typeof` expressions against valid strings",
recommended: true,
url: "https://eslint.org/docs/rules/valid-typeof"
url: "https://eslint.org/docs/latest/rules/valid-typeof"
},
hasSuggestions: true,
schema: [

@@ -38,3 +46,4 @@ {

invalidValue: "Invalid typeof comparison value.",
notString: "Typeof comparisons should be to string literals."
notString: "Typeof comparisons should be to string literals.",
suggestString: 'Use `"{{type}}"` instead of `{{type}}`.'
}

@@ -45,8 +54,23 @@ },

const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"],
OPERATORS = ["==", "===", "!=", "!=="];
const VALID_TYPES = new Set(["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"]),
OPERATORS = new Set(["==", "===", "!=", "!=="]);
const sourceCode = context.sourceCode;
const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
let globalScope;
/**
* Checks whether the given node represents a reference to a global variable that is not declared in the source code.
* These identifiers will be allowed, as it is assumed that user has no control over the names of external global variables.
* @param {ASTNode} node `Identifier` node to check.
* @returns {boolean} `true` if the node is a reference to a global variable.
*/
function isReferenceToGlobalVariable(node) {
const variable = globalScope.set.get(node.name);
return variable && variable.defs.length === 0 &&
variable.references.some(ref => ref.identifier === node);
}
/**
* Determines whether a node is a typeof expression.

@@ -66,15 +90,33 @@ * @param {ASTNode} node The node

Program(node) {
globalScope = sourceCode.getScope(node);
},
UnaryExpression(node) {
if (isTypeofExpression(node)) {
const parent = context.getAncestors().pop();
const { parent } = node;
if (parent.type === "BinaryExpression" && OPERATORS.indexOf(parent.operator) !== -1) {
if (parent.type === "BinaryExpression" && OPERATORS.has(parent.operator)) {
const sibling = parent.left === node ? parent.right : parent.left;
if (sibling.type === "Literal" || sibling.type === "TemplateLiteral" && !sibling.expressions.length) {
if (sibling.type === "Literal" || astUtils.isStaticTemplateLiteral(sibling)) {
const value = sibling.type === "Literal" ? sibling.value : sibling.quasis[0].value.cooked;
if (VALID_TYPES.indexOf(value) === -1) {
if (!VALID_TYPES.has(value)) {
context.report({ node: sibling, messageId: "invalidValue" });
}
} else if (sibling.type === "Identifier" && sibling.name === "undefined" && isReferenceToGlobalVariable(sibling)) {
context.report({
node: sibling,
messageId: requireStringLiterals ? "notString" : "invalidValue",
suggest: [
{
messageId: "suggestString",
data: { type: "undefined" },
fix(fixer) {
return fixer.replaceText(sibling, '"undefined"');
}
}
]
});
} else if (requireStringLiterals && !isTypeofExpression(sibling)) {

@@ -81,0 +123,0 @@ context.report({ node: sibling, messageId: "notString" });

@@ -18,5 +18,5 @@ /**

docs: {
description: "require `var` declarations be placed at the top of their containing scope",
description: "Require `var` declarations be placed at the top of their containing scope",
recommended: false,
url: "https://eslint.org/docs/rules/vars-on-top"
url: "https://eslint.org/docs/latest/rules/vars-on-top"
},

@@ -23,0 +23,0 @@

/**
* @fileoverview Rule to flag when IIFE is not wrapped in parens
* @author Ilya Volodin
* @deprecated in ESLint v8.53.0
*/

@@ -13,3 +14,3 @@

const astUtils = require("./utils/ast-utils");
const eslintUtils = require("eslint-utils");
const eslintUtils = require("@eslint-community/eslint-utils");

@@ -44,8 +45,10 @@ //----------------------------------------------------------------------

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require parentheses around immediate `function` invocations",
description: "Require parentheses around immediate `function` invocations",
recommended: false,
url: "https://eslint.org/docs/rules/wrap-iife"
url: "https://eslint.org/docs/latest/rules/wrap-iife"
},

@@ -82,3 +85,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -85,0 +88,0 @@ /**

/**
* @fileoverview Rule to flag when regex literals are not wrapped in parens
* @author Matt DuVall <http://www.mattduvall.com>
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require parenthesis around regex literals",
description: "Require parenthesis around regex literals",
recommended: false,
url: "https://eslint.org/docs/rules/wrap-regex"
url: "https://eslint.org/docs/latest/rules/wrap-regex"
},

@@ -33,3 +36,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -45,6 +48,5 @@ return {

const afterToken = sourceCode.getTokenAfter(node);
const ancestors = context.getAncestors();
const grandparent = ancestors[ancestors.length - 1];
const { parent } = node;
if (grandparent.type === "MemberExpression" && grandparent.object === node &&
if (parent.type === "MemberExpression" && parent.object === node &&
!(beforeToken && beforeToken.value === "(" && afterToken && afterToken.value === ")")) {

@@ -51,0 +53,0 @@ context.report({

/**
* @fileoverview Rule to check the spacing around the * in yield* expressions.
* @author Bryan Smith
* @deprecated in ESLint v8.53.0
*/

@@ -15,8 +16,10 @@

meta: {
deprecated: true,
replacedBy: [],
type: "layout",
docs: {
description: "require or disallow spacing around the `*` in `yield*` expressions",
description: "Require or disallow spacing around the `*` in `yield*` expressions",
recommended: false,
url: "https://eslint.org/docs/rules/yield-star-spacing"
url: "https://eslint.org/docs/latest/rules/yield-star-spacing"
},

@@ -52,3 +55,3 @@

create(context) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -55,0 +58,0 @@ const mode = (function(option) {

@@ -42,3 +42,3 @@ /**

function isRangeTestOperator(operator) {
return ["<", "<="].indexOf(operator) >= 0;
return ["<", "<="].includes(operator);
}

@@ -63,11 +63,2 @@

/**
* Determines whether a node is a Template Literal which can be determined statically.
* @param {ASTNode} node Node to test
* @returns {boolean} True if the node is a Template Literal without expression.
*/
function isStaticTemplateLiteral(node) {
return node.type === "TemplateLiteral" && node.expressions.length === 0;
}
/**
* Determines whether a non-Literal node should be treated as a single Literal node.

@@ -78,3 +69,3 @@ * @param {ASTNode} node Node to test

function looksLikeLiteral(node) {
return isNegativeNumericLiteral(node) || isStaticTemplateLiteral(node);
return isNegativeNumericLiteral(node) || astUtils.isStaticTemplateLiteral(node);
}

@@ -106,3 +97,3 @@

if (isStaticTemplateLiteral(node)) {
if (astUtils.isStaticTemplateLiteral(node)) {
return {

@@ -128,5 +119,5 @@ type: "Literal",

docs: {
description: 'require or disallow "Yoda" conditions',
description: 'Require or disallow "Yoda" conditions',
recommended: false,
url: "https://eslint.org/docs/rules/yoda"
url: "https://eslint.org/docs/latest/rules/yoda"
},

@@ -170,3 +161,3 @@

const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode;

@@ -352,3 +343,3 @@ /**

isComparisonOperator(node.operator) &&
!(exceptRange && isRangeTest(context.getAncestors().pop()))
!(exceptRange && isRangeTest(node.parent))
) {

@@ -355,0 +346,0 @@ context.report({

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

ESLINT_LEGACY_ECMAFEATURES:
"The 'ecmaFeatures' config file property is deprecated and has no effect.",
ESLINT_PERSONAL_CONFIG_LOAD:
"'~/.eslintrc.*' config files have been deprecated. " +
"Please use a config file per project or the '--config' option.",
ESLINT_PERSONAL_CONFIG_SUPPRESS:
"'~/.eslintrc.*' config files have been deprecated. " +
"Please remove it or add 'root:true' to the config files in your " +
"projects in order to avoid loading '~/.eslintrc.*' accidentally."
"The 'ecmaFeatures' config file property is deprecated and has no effect."
};

@@ -30,0 +23,0 @@

@@ -10,3 +10,3 @@ /**

/* istanbul ignore next */
/* c8 ignore next */
module.exports = {

@@ -13,0 +13,0 @@

@@ -100,3 +100,3 @@ /**

const npmBinArgs = ["bin", "-g"];
const npmLsArgs = ["ls", "--depth=0", "--json", "eslint"];
const npmLsArgs = ["ls", "--depth=0", "--json", pkg];

@@ -103,0 +103,0 @@ if (global) {

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

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const Graphemer = require("graphemer").default;
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
// eslint-disable-next-line no-control-regex -- intentionally including control characters
const ASCII_REGEX = /^[\u0000-\u007f]*$/u;
/** @type {Graphemer | undefined} */
let splitter;
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
/**

@@ -21,4 +41,22 @@ * Converts the first letter of a string to uppercase.

/**
* Counts graphemes in a given string.
* @param {string} value A string to count graphemes.
* @returns {number} The number of graphemes in `value`.
*/
function getGraphemeCount(value) {
if (ASCII_REGEX.test(value)) {
return value.length;
}
if (!splitter) {
splitter = new Graphemer();
}
return splitter.countGraphemes(value);
}
module.exports = {
upperCaseFirst
upperCaseFirst,
getGraphemeCount
};

@@ -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 @@ */

@@ -24,3 +24,3 @@ /**

* @property {EcmaFeatures} [ecmaFeatures] The optional features.
* @property {3|5|6|7|8|9|10|11|12|13|2015|2016|2017|2018|2019|2020|2021|2022} [ecmaVersion] The ECMAScript version (or revision number).
* @property {3|5|6|7|8|9|10|11|12|13|14|15|2015|2016|2017|2018|2019|2020|2021|2022|2023|2024} [ecmaVersion] The ECMAScript version (or revision number).
* @property {"script"|"module"} [sourceType] The source code type.

@@ -100,6 +100,8 @@ * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3.

* @property {number} [endLine] The 1-based line number of the end location.
* @property {boolean} fatal If `true` then this is a fatal error.
* @property {boolean} [fatal] If `true` then this is a fatal error.
* @property {{range:[number,number], text:string}} [fix] Information for autofix.
* @property {number|undefined} line The 1-based line number.
* @property {string} message The error message.
* @property {string} [messageId] The ID of the message in the rule's meta.
* @property {(string|null)} nodeType Type of node
* @property {string|null} ruleId The ID of the rule which makes this message.

@@ -111,2 +113,19 @@ * @property {0|1|2} severity The severity of this message.

/**
* @typedef {Object} SuppressedLintMessage
* @property {number|undefined} column The 1-based column number.
* @property {number} [endColumn] The 1-based column number of the end location.
* @property {number} [endLine] The 1-based line number of the end location.
* @property {boolean} [fatal] If `true` then this is a fatal error.
* @property {{range:[number,number], text:string}} [fix] Information for autofix.
* @property {number|undefined} line The 1-based line number.
* @property {string} message The error message.
* @property {string} [messageId] The ID of the message in the rule's meta.
* @property {(string|null)} nodeType Type of node
* @property {string|null} ruleId The ID of the rule which makes this message.
* @property {0|1|2} severity The severity of this message.
* @property {Array<{kind: string, justification: string}>} suppressions The suppression info.
* @property {Array<{desc?: string, messageId?: string, fix: {range: [number, number], text: string}}>} [suggestions] Information for suggestions.
*/
/**
* @typedef {Object} SuggestionResult

@@ -127,3 +146,2 @@ * @property {string} desc A short description.

* @typedef {Object} RuleMetaDocs
* @property {string} category The category of the rule.
* @property {string} description The description of the rule.

@@ -139,2 +157,3 @@ * @property {boolean} recommended If `true` then the rule is included in `eslint:recommended` preset.

* @property {"code"|"whitespace"} [fixable] The autofix type.
* @property {boolean} [hasSuggestions] If `true` then the rule provides suggestions.
* @property {Record<string,string>} [messages] The messages the rule reports.

@@ -166,1 +185,38 @@ * @property {string[]} [replacedBy] The IDs of the alternative rules.

*/
/**
* A linting result.
* @typedef {Object} LintResult
* @property {string} filePath The path to the file that was linted.
* @property {LintMessage[]} messages All of the messages for the result.
* @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
* @property {number} errorCount Number of errors for the result.
* @property {number} fatalErrorCount Number of fatal errors for the result.
* @property {number} warningCount Number of warnings for the result.
* @property {number} fixableErrorCount Number of fixable errors for the result.
* @property {number} fixableWarningCount Number of fixable warnings for the result.
* @property {string} [source] The source code of the file that was linted.
* @property {string} [output] The source code of the file that was linted, with as many fixes applied as possible.
* @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules.
*/
/**
* 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, maxWarningsExceeded?: MaxWarningsExceeded, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
* @returns {string | Promise<string>} Formatted text.
*/

@@ -12,11 +12,27 @@ /**

const
{ isCommentToken } = require("eslint-utils"),
{ isCommentToken } = require("@eslint-community/eslint-utils"),
TokenStore = require("./token-store"),
astUtils = require("../shared/ast-utils"),
Traverser = require("../shared/traverser");
Traverser = require("../shared/traverser"),
globals = require("../../conf/globals"),
{
directivesPattern
} = require("../shared/directives"),
/* eslint-disable-next-line n/no-restricted-require -- Too messy to figure out right now. */
ConfigCommentParser = require("../linter/config-comment-parser"),
eslintScope = require("eslint-scope");
//------------------------------------------------------------------------------
// Type Definitions
//------------------------------------------------------------------------------
/** @typedef {import("eslint-scope").Variable} Variable */
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
const commentParser = new ConfigCommentParser();
/**

@@ -48,2 +64,25 @@ * Validates that the given AST has the required information.

/**
* Retrieves globals for the given ecmaVersion.
* @param {number} ecmaVersion The version to retrieve globals for.
* @returns {Object} The globals for the given ecmaVersion.
*/
function getGlobalsForEcmaVersion(ecmaVersion) {
switch (ecmaVersion) {
case 3:
return globals.es3;
case 5:
return globals.es5;
default:
if (ecmaVersion < 2015) {
return globals[`es${ecmaVersion + 2009}`];
}
return globals[`es${ecmaVersion}`];
}
}
/**
* Check to see if its a ES6 export declaration.

@@ -83,2 +122,32 @@ * @param {ASTNode} astNode An AST node.

/**
* Normalizes a value for a global in a config
* @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in
* a global directive comment
* @returns {("readable"|"writeable"|"off")} The value normalized as a string
* @throws Error if global value is invalid
*/
function normalizeConfigGlobal(configuredValue) {
switch (configuredValue) {
case "off":
return "off";
case true:
case "true":
case "writeable":
case "writable":
return "writable";
case null:
case false:
case "false":
case "readable":
case "readonly":
return "readonly";
default:
throw new Error(`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`);
}
}
/**
* Determines if two nodes or tokens overlap.

@@ -145,2 +214,112 @@ * @param {ASTNode|Token} first The first node or token to check.

//-----------------------------------------------------------------------------
// Directive Comments
//-----------------------------------------------------------------------------
/**
* Extract the directive and the justification from a given directive comment and trim them.
* @param {string} value The comment text to extract.
* @returns {{directivePart: string, justificationPart: string}} The extracted directive and justification.
*/
function extractDirectiveComment(value) {
const match = /\s-{2,}\s/u.exec(value);
if (!match) {
return { directivePart: value.trim(), justificationPart: "" };
}
const directive = value.slice(0, match.index).trim();
const justification = value.slice(match.index + match[0].length).trim();
return { directivePart: directive, justificationPart: justification };
}
/**
* Ensures that variables representing built-in properties of the Global Object,
* and any globals declared by special block comments, are present in the global
* scope.
* @param {Scope} globalScope The global scope.
* @param {Object|undefined} configGlobals The globals declared in configuration
* @param {Object|undefined} inlineGlobals The globals declared in the source code
* @returns {void}
*/
function addDeclaredGlobals(globalScope, configGlobals = {}, inlineGlobals = {}) {
// Define configured global variables.
for (const id of new Set([...Object.keys(configGlobals), ...Object.keys(inlineGlobals)])) {
/*
* `normalizeConfigGlobal` will throw an error if a configured global value is invalid. However, these errors would
* typically be caught when validating a config anyway (validity for inline global comments is checked separately).
*/
const configValue = configGlobals[id] === void 0 ? void 0 : normalizeConfigGlobal(configGlobals[id]);
const commentValue = inlineGlobals[id] && inlineGlobals[id].value;
const value = commentValue || configValue;
const sourceComments = inlineGlobals[id] && inlineGlobals[id].comments;
if (value === "off") {
continue;
}
let variable = globalScope.set.get(id);
if (!variable) {
variable = new eslintScope.Variable(id, globalScope);
globalScope.variables.push(variable);
globalScope.set.set(id, variable);
}
variable.eslintImplicitGlobalSetting = configValue;
variable.eslintExplicitGlobal = sourceComments !== void 0;
variable.eslintExplicitGlobalComments = sourceComments;
variable.writeable = (value === "writable");
}
/*
* "through" contains all references which definitions cannot be found.
* Since we augment the global scope using configuration, we need to update
* references and remove the ones that were added by configuration.
*/
globalScope.through = globalScope.through.filter(reference => {
const name = reference.identifier.name;
const variable = globalScope.set.get(name);
if (variable) {
/*
* Links the variable and the reference.
* And this reference is removed from `Scope#through`.
*/
reference.resolved = variable;
variable.references.push(reference);
return false;
}
return true;
});
}
/**
* Sets the given variable names as exported so they won't be triggered by
* the `no-unused-vars` rule.
* @param {eslint.Scope} globalScope The global scope to define exports in.
* @param {Record<string,string>} variables An object whose keys are the variable
* names to export.
* @returns {void}
*/
function markExportedVariables(globalScope, variables) {
Object.keys(variables).forEach(name => {
const variable = globalScope.set.get(name);
if (variable) {
variable.eslintUsed = true;
variable.eslintExported = true;
}
});
}
//------------------------------------------------------------------------------

@@ -150,2 +329,4 @@ // Public Interface

const caches = Symbol("caches");
/**

@@ -184,2 +365,11 @@ * Represents parsed source code.

/**
* General purpose caching for the class.
*/
this[caches] = new Map([
["scopes", new WeakMap()],
["vars", new Map()],
["configNodes", void 0]
]);
/**
* The flag to indicate that the source code has Unicode BOM.

@@ -260,3 +450,3 @@ * @type {boolean}

// don't allow modification of this object
// don't allow further modification of this object
Object.freeze(this);

@@ -598,4 +788,297 @@ Object.freeze(this.lines);

}
/**
* Gets the scope for the given node
* @param {ASTNode} currentNode The node to get the scope of
* @returns {eslint-scope.Scope} The scope information for this node
* @throws {TypeError} If the `currentNode` argument is missing.
*/
getScope(currentNode) {
if (!currentNode) {
throw new TypeError("Missing required argument: node.");
}
// check cache first
const cache = this[caches].get("scopes");
const cachedScope = cache.get(currentNode);
if (cachedScope) {
return cachedScope;
}
// On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
const inner = currentNode.type !== "Program";
for (let node = currentNode; node; node = node.parent) {
const scope = this.scopeManager.acquire(node, inner);
if (scope) {
if (scope.type === "function-expression-name") {
cache.set(currentNode, scope.childScopes[0]);
return scope.childScopes[0];
}
cache.set(currentNode, scope);
return scope;
}
}
cache.set(currentNode, this.scopeManager.scopes[0]);
return this.scopeManager.scopes[0];
}
/**
* Get the variables that `node` defines.
* This is a convenience method that passes through
* to the same method on the `scopeManager`.
* @param {ASTNode} node The node for which the variables are obtained.
* @returns {Array<Variable>} An array of variable nodes representing
* the variables that `node` defines.
*/
getDeclaredVariables(node) {
return this.scopeManager.getDeclaredVariables(node);
}
/* eslint-disable class-methods-use-this -- node is owned by SourceCode */
/**
* Gets all the ancestors of a given node
* @param {ASTNode} node The node
* @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting
* from the root node at index 0 and going inwards to the parent node.
* @throws {TypeError} When `node` is missing.
*/
getAncestors(node) {
if (!node) {
throw new TypeError("Missing required argument: node.");
}
const ancestorsStartingAtParent = [];
for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
ancestorsStartingAtParent.push(ancestor);
}
return ancestorsStartingAtParent.reverse();
}
/* eslint-enable class-methods-use-this -- node is owned by SourceCode */
/**
* Marks a variable as used in the current scope
* @param {string} name The name of the variable to mark as used.
* @param {ASTNode} [refNode] The closest node to the variable reference.
* @returns {boolean} True if the variable was found and marked as used, false if not.
*/
markVariableAsUsed(name, refNode = this.ast) {
const currentScope = this.getScope(refNode);
let initialScope = currentScope;
/*
* When we are in an ESM or CommonJS module, we need to start searching
* from the top-level scope, not the global scope. For ESM the top-level
* scope is the module scope; for CommonJS the top-level scope is the
* outer function scope.
*
* Without this check, we might miss a variable declared with `var` at
* the top-level because it won't exist in the global scope.
*/
if (
currentScope.type === "global" &&
currentScope.childScopes.length > 0 &&
// top-level scopes refer to a `Program` node
currentScope.childScopes[0].block === this.ast
) {
initialScope = currentScope.childScopes[0];
}
for (let scope = initialScope; scope; scope = scope.upper) {
const variable = scope.variables.find(scopeVar => scopeVar.name === name);
if (variable) {
variable.eslintUsed = true;
return true;
}
}
return false;
}
/**
* Returns an array of all inline configuration nodes found in the
* source code.
* @returns {Array<Token>} An array of all inline configuration nodes.
*/
getInlineConfigNodes() {
// check the cache first
let configNodes = this[caches].get("configNodes");
if (configNodes) {
return configNodes;
}
// calculate fresh config nodes
configNodes = this.ast.comments.filter(comment => {
// shebang comments are never directives
if (comment.type === "Shebang") {
return false;
}
const { directivePart } = extractDirectiveComment(comment.value);
const directiveMatch = directivesPattern.exec(directivePart);
if (!directiveMatch) {
return false;
}
// only certain comment types are supported as line comments
return comment.type !== "Line" || !!/^eslint-disable-(next-)?line$/u.test(directiveMatch[1]);
});
this[caches].set("configNodes", configNodes);
return configNodes;
}
/**
* Applies language options sent in from the core.
* @param {Object} languageOptions The language options for this run.
* @returns {void}
*/
applyLanguageOptions(languageOptions) {
/*
* Add configured globals and language globals
*
* Using Object.assign instead of object spread for performance reasons
* https://github.com/eslint/eslint/issues/16302
*/
const configGlobals = Object.assign(
{},
getGlobalsForEcmaVersion(languageOptions.ecmaVersion),
languageOptions.sourceType === "commonjs" ? globals.commonjs : void 0,
languageOptions.globals
);
const varsCache = this[caches].get("vars");
varsCache.set("configGlobals", configGlobals);
}
/**
* Applies configuration found inside of the source code. This method is only
* called when ESLint is running with inline configuration allowed.
* @returns {{problems:Array<Problem>,configs:{config:FlatConfigArray,node:ASTNode}}} Information
* that ESLint needs to further process the inline configuration.
*/
applyInlineConfig() {
const problems = [];
const configs = [];
const exportedVariables = {};
const inlineGlobals = Object.create(null);
this.getInlineConfigNodes().forEach(comment => {
const { directivePart } = extractDirectiveComment(comment.value);
const match = directivesPattern.exec(directivePart);
const directiveText = match[1];
const directiveValue = directivePart.slice(match.index + directiveText.length);
switch (directiveText) {
case "exported":
Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
case "globals":
case "global":
for (const [id, { value }] of Object.entries(commentParser.parseStringConfig(directiveValue, comment))) {
let normalizedValue;
try {
normalizedValue = normalizeConfigGlobal(value);
} catch (err) {
problems.push({
ruleId: null,
loc: comment.loc,
message: err.message
});
continue;
}
if (inlineGlobals[id]) {
inlineGlobals[id].comments.push(comment);
inlineGlobals[id].value = normalizedValue;
} else {
inlineGlobals[id] = {
comments: [comment],
value: normalizedValue
};
}
}
break;
case "eslint": {
const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
if (parseResult.success) {
configs.push({
config: {
rules: parseResult.config
},
node: comment
});
} else {
problems.push(parseResult.error);
}
break;
}
// no default
}
});
// save all the new variables for later
const varsCache = this[caches].get("vars");
varsCache.set("inlineGlobals", inlineGlobals);
varsCache.set("exportedVariables", exportedVariables);
return {
configs,
problems
};
}
/**
* Called by ESLint core to indicate that it has finished providing
* information. We now add in all the missing variables and ensure that
* state-changing methods cannot be called by rules.
* @returns {void}
*/
finalize() {
// Step 1: ensure that all of the necessary variables are up to date
const varsCache = this[caches].get("vars");
const globalScope = this.scopeManager.scopes[0];
const configGlobals = varsCache.get("configGlobals");
const inlineGlobals = varsCache.get("inlineGlobals");
const exportedVariables = varsCache.get("exportedVariables");
addDeclaredGlobals(globalScope, configGlobals, inlineGlobals);
if (exportedVariables) {
markExportedVariables(globalScope, exportedVariables);
}
}
}
module.exports = SourceCode;

@@ -72,3 +72,3 @@ /**

*/
/* istanbul ignore next */
/* c8 ignore next */
moveNext() { // eslint-disable-line class-methods-use-this -- Unused

@@ -75,0 +75,0 @@ throw new Error("Not implemented.");

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

const assert = require("assert");
const { isCommentToken } = require("eslint-utils");
const { isCommentToken } = require("@eslint-community/eslint-utils");
const cursors = require("./cursors");

@@ -15,0 +15,0 @@ const ForwardTokenCursor = require("./forward-token-cursor");

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

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Gets `token.range[0]` from the given token.
* @param {Node|Token|Comment} token The token to get.
* @returns {number} The start location.
* @private
*/
function getStartLocation(token) {
return token.range[0];
}
//------------------------------------------------------------------------------
// Exports

@@ -34,5 +20,24 @@ //------------------------------------------------------------------------------

exports.search = function search(tokens, location) {
const index = tokens.findIndex(el => location <= getStartLocation(el));
for (let minIndex = 0, maxIndex = tokens.length - 1; minIndex <= maxIndex;) {
return index === -1 ? tokens.length : index;
/*
* Calculate the index in the middle between minIndex and maxIndex.
* `| 0` is used to round a fractional value down to the nearest integer: this is similar to
* using `Math.trunc()` or `Math.floor()`, but performance tests have shown this method to
* be faster.
*/
const index = (minIndex + maxIndex) / 2 | 0;
const token = tokens[index];
const tokenStartLocation = token.range[0];
if (location <= tokenStartLocation) {
if (index === minIndex) {
return index;
}
maxIndex = index;
} else {
minIndex = index + 1;
}
}
return tokens.length;
};

@@ -54,4 +59,9 @@

const index = indexMap[startLoc - 1];
const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
const token = tokens[index];
// If the mapped index is out of bounds, the returned cursor index will point after the end of the tokens array.
if (!token) {
return tokens.length;
}
/*

@@ -61,3 +71,3 @@ * For the map of "comment's location -> token's index", it points the next token of a comment.

*/
if (token && token.range[0] >= startLoc) {
if (token.range[0] >= startLoc) {
return index;

@@ -84,4 +94,9 @@ }

const index = indexMap[endLoc - 1];
const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
const token = tokens[index];
// If the mapped index is out of bounds, the returned cursor index will point before the end of the tokens array.
if (!token) {
return tokens.length - 1;
}
/*

@@ -91,3 +106,3 @@ * For the map of "comment's location -> token's index", it points the next token of a comment.

*/
if (token && token.range[1] > endLoc) {
if (token.range[1] > endLoc) {
return index - 1;

@@ -94,0 +109,0 @@ }

@@ -15,2 +15,5 @@ /**

const { FileEnumerator } = require("./cli-engine/file-enumerator");
const { FlatESLint, shouldUseFlatConfig } = require("./eslint/flat-eslint");
const FlatRuleTester = require("./rule-tester/flat-rule-tester");
const { ESLint } = require("./eslint/eslint");

@@ -23,3 +26,7 @@ //-----------------------------------------------------------------------------

builtinRules: require("./rules"),
FileEnumerator
FlatESLint,
shouldUseFlatConfig,
FlatRuleTester,
FileEnumerator,
LegacyESLint: ESLint
};

@@ -15,3 +15,3 @@ "use strict";

* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.
`.trimLeft();
`.trimStart();
};

@@ -12,3 +12,3 @@ "use strict";

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
`.trimLeft();
`.trimStart();
};

@@ -10,3 +10,3 @@ "use strict";

${message}
`.trimLeft();
`.trimStart();
};

@@ -9,3 +9,3 @@ "use strict";

Please check for typing mistakes in the pattern.
`.trimLeft();
`.trimStart();
};

@@ -9,8 +9,8 @@ "use strict";

eslint --init
npm init @eslint/config
ESLint looked for configuration files in ${directoryPath} and its ancestors. If it found none, it then looked in your home directory.
If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
`.trimLeft();
If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat
`.trimStart();
};

@@ -15,3 +15,3 @@ "use strict";

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
`.trimLeft();
`.trimStart();
};

@@ -18,3 +18,3 @@ "use strict";

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
`.trimLeft();
`.trimStart();
};

@@ -6,4 +6,4 @@ "use strict";

The '--print-config' CLI option requires a path to a source code file rather than a directory.
See also: https://eslint.org/docs/user-guide/command-line-interface#--print-config
`.trimLeft();
See also: https://eslint.org/docs/latest/use/command-line-interface#--print-config
`.trimStart();
};

@@ -10,3 +10,3 @@ "use strict";

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
`.trimLeft();
`.trimStart();
};
{
"name": "eslint",
"version": "8.4.1",
"version": "8.54.0",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",

@@ -16,15 +16,19 @@ "description": "An AST-based pattern checker for JavaScript.",

"scripts": {
"build:docs:update-links": "node tools/fetch-docs-links.js",
"build:site": "node Makefile.js gensite",
"build:webpack": "node Makefile.js webpack",
"build:readme": "node tools/update-readme.js",
"lint": "node Makefile.js lint",
"lint:docs:js": "node Makefile.js lintDocsJS",
"lint:fix": "node Makefile.js lint -- fix",
"lint:fix:docs:js": "node Makefile.js lintDocsJS -- fix",
"release:generate:alpha": "node Makefile.js generatePrerelease -- alpha",
"release:generate:beta": "node Makefile.js generatePrerelease -- beta",
"release:generate:latest": "node Makefile.js generateRelease",
"release:generate:rc": "node Makefile.js generatePrerelease -- rc",
"release:publish": "node Makefile.js publishRelease",
"test": "node Makefile.js test",
"test:cli": "mocha",
"lint": "node Makefile.js lint",
"fix": "node Makefile.js lint -- fix",
"fuzz": "node Makefile.js fuzz",
"generate-release": "node Makefile.js generateRelease",
"generate-alpharelease": "node Makefile.js generatePrerelease -- alpha",
"generate-betarelease": "node Makefile.js generatePrerelease -- beta",
"generate-rcrelease": "node Makefile.js generatePrerelease -- rc",
"publish-release": "node Makefile.js publishRelease",
"gensite": "node Makefile.js gensite",
"webpack": "node Makefile.js webpack",
"perf": "node Makefile.js perf"
"test:fuzz": "node Makefile.js fuzz",
"test:performance": "node Makefile.js perf"
},

@@ -36,3 +40,12 @@ "gitHooks": {

"*.js": "eslint --fix",
"*.md": "markdownlint"
"*.md": "markdownlint --fix",
"lib/rules/*.js": [
"node tools/update-eslint-all.js",
"git add packages/js/src/configs/eslint-all.js"
],
"docs/src/rules/*.md": [
"node tools/fetch-docs-links.js",
"git add docs/src/_data/further_reading_links.json"
],
"docs/**/*.svg": "npx svgo -r --multipass"
},

@@ -52,5 +65,11 @@ "files": [

"dependencies": {
"@eslint/eslintrc": "^1.0.5",
"@humanwhocodes/config-array": "^0.9.2",
"ajv": "^6.10.0",
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
"@eslint/eslintrc": "^2.1.3",
"@eslint/js": "8.54.0",
"@humanwhocodes/config-array": "^0.11.13",
"@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8",
"@ungap/structured-clone": "^1.2.0",
"ajv": "^6.12.4",
"chalk": "^4.0.0",

@@ -60,19 +79,18 @@ "cross-spawn": "^7.0.2",

"doctrine": "^3.0.0",
"enquirer": "^2.3.5",
"escape-string-regexp": "^4.0.0",
"eslint-scope": "^7.1.0",
"eslint-utils": "^3.0.0",
"eslint-visitor-keys": "^3.1.0",
"espree": "^9.2.0",
"esquery": "^1.4.0",
"eslint-scope": "^7.2.2",
"eslint-visitor-keys": "^3.4.3",
"espree": "^9.6.1",
"esquery": "^1.4.2",
"esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3",
"file-entry-cache": "^6.0.1",
"functional-red-black-tree": "^1.0.1",
"glob-parent": "^6.0.1",
"globals": "^13.6.0",
"ignore": "^4.0.6",
"import-fresh": "^3.0.0",
"find-up": "^5.0.0",
"glob-parent": "^6.0.2",
"globals": "^13.19.0",
"graphemer": "^1.4.0",
"ignore": "^5.2.0",
"imurmurhash": "^0.1.4",
"is-glob": "^4.0.0",
"is-path-inside": "^3.0.3",
"js-yaml": "^4.1.0",

@@ -82,12 +100,7 @@ "json-stable-stringify-without-jsonify": "^1.0.1",

"lodash.merge": "^4.6.2",
"minimatch": "^3.0.4",
"minimatch": "^3.1.2",
"natural-compare": "^1.4.0",
"optionator": "^0.9.1",
"progress": "^2.0.0",
"regexpp": "^3.2.0",
"semver": "^7.2.1",
"optionator": "^0.9.3",
"strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0",
"text-table": "^0.2.0",
"v8-compile-cache": "^2.0.3"
"text-table": "^0.2.0"
},

@@ -97,3 +110,9 @@ "devDependencies": {

"@babel/preset-env": "^7.4.3",
"@wdio/browser-runner": "^8.14.6",
"@wdio/cli": "^8.14.6",
"@wdio/concise-reporter": "^8.14.0",
"@wdio/globals": "^8.14.6",
"@wdio/mocha-framework": "^8.14.0",
"babel-loader": "^8.0.5",
"c8": "^7.12.0",
"chai": "^4.0.1",

@@ -103,3 +122,2 @@ "cheerio": "^0.22.0",

"core-js": "^3.1.3",
"dateformat": "^4.5.1",
"ejs": "^3.0.2",

@@ -109,22 +127,27 @@ "eslint": "file:.",

"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^4.0.1",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-internal-rules": "file:tools/internal-rules",
"eslint-plugin-jsdoc": "^37.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-jsdoc": "^46.2.5",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-unicorn": "^42.0.0",
"eslint-release": "^3.2.0",
"eslump": "^3.0.0",
"esprima": "^4.0.1",
"fast-glob": "^3.2.11",
"fs-teardown": "^0.1.3",
"glob": "^7.1.6",
"jsdoc": "^3.5.5",
"karma": "^6.1.1",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-webpack": "^5.0.0",
"got": "^11.8.3",
"gray-matter": "^4.0.3",
"lint-staged": "^11.0.0",
"load-perf": "^0.2.0",
"markdownlint": "^0.24.0",
"markdownlint-cli": "^0.30.0",
"markdownlint": "^0.31.1",
"markdownlint-cli": "^0.37.0",
"marked": "^4.0.8",
"memfs": "^3.0.1",
"metascraper": "^5.25.7",
"metascraper-description": "^5.25.7",
"metascraper-image": "^5.29.3",
"metascraper-logo": "^5.25.7",
"metascraper-logo-favicon": "^5.25.7",
"metascraper-title": "^5.25.7",
"mocha": "^8.3.2",

@@ -134,10 +157,13 @@ "mocha-junit-reporter": "^2.0.0",

"npm-license": "^0.3.3",
"nyc": "^15.0.1",
"pirates": "^4.0.5",
"progress": "^2.0.3",
"proxyquire": "^2.0.1",
"puppeteer": "^9.1.1",
"recast": "^0.20.4",
"regenerator-runtime": "^0.13.2",
"recast": "^0.23.0",
"regenerator-runtime": "^0.14.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"semver": "^7.5.3",
"shelljs": "^0.8.2",
"sinon": "^11.0.0",
"temp": "^0.9.0",
"vite-plugin-commonjs": "^0.10.0",
"webdriverio": "^8.14.6",
"webpack": "^5.23.0",

@@ -144,0 +170,0 @@ "webpack-cli": "^4.5.0",

@@ -13,10 +13,10 @@ [![npm version](https://img.shields.io/npm/v/eslint.svg)](https://www.npmjs.com/package/eslint)

[Website](https://eslint.org) |
[Configuring](https://eslint.org/docs/user-guide/configuring) |
[Configure ESLint](https://eslint.org/docs/latest/use/configure) |
[Rules](https://eslint.org/docs/rules/) |
[Contributing](https://eslint.org/docs/developer-guide/contributing) |
[Reporting Bugs](https://eslint.org/docs/developer-guide/contributing/reporting-bugs) |
[Contribute to ESLint](https://eslint.org/docs/latest/contribute) |
[Report Bugs](https://eslint.org/docs/latest/contribute/report-bugs) |
[Code of Conduct](https://eslint.org/conduct) |
[Twitter](https://twitter.com/geteslint) |
[Mailing List](https://groups.google.com/group/eslint) |
[Chat Room](https://eslint.org/chat)
[Discord](https://eslint.org/chat) |
[Mastodon](https://fosstodon.org/@eslint)

@@ -35,3 +35,3 @@ ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:

4. [Filing Issues](#filing-issues)
5. [Frequently Asked Questions](#faq)
5. [Frequently Asked Questions](#frequently-asked-questions)
6. [Releases](#releases)

@@ -46,27 +46,21 @@ 7. [Security Policy](#security-policy)

## <a name="installation-and-usage"></a>Installation and Usage
## Installation and Usage
Prerequisites: [Node.js](https://nodejs.org/) (`^12.22.0`, `^14.17.0`, or `>=16.0.0`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
You can install ESLint using npm:
You can install and configure ESLint using this command:
```sh
$ npm install eslint --save-dev
```shell
npm init @eslint/config
```
You should then set up a configuration file:
```sh
$ ./node_modules/.bin/eslint --init
```
After that, you can run ESLint on any file or directory like this:
```sh
$ ./node_modules/.bin/eslint yourfile.js
```shell
./node_modules/.bin/eslint yourfile.js
```
## <a name="configuration"></a>Configuration
## Configuration
After running `eslint --init`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:
After running `npm init @eslint/config`, you'll have an `.eslintrc` file in your directory. In it, you'll see some rules configured like this:

@@ -88,18 +82,18 @@ ```json

The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](https://eslint.org/docs/user-guide/configuring)).
The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](https://eslint.org/docs/latest/use/configure)).
## <a name="code-of-conduct"></a>Code of Conduct
## Code of Conduct
ESLint adheres to the [JS Foundation Code of Conduct](https://eslint.org/conduct).
## <a name="filing-issues"></a>Filing Issues
## Filing Issues
Before filing an issue, please be sure to read the guidelines for what you're reporting:
* [Bug Report](https://eslint.org/docs/developer-guide/contributing/reporting-bugs)
* [Propose a New Rule](https://eslint.org/docs/developer-guide/contributing/new-rules)
* [Proposing a Rule Change](https://eslint.org/docs/developer-guide/contributing/rule-changes)
* [Request a Change](https://eslint.org/docs/developer-guide/contributing/changes)
* [Bug Report](https://eslint.org/docs/latest/contribute/report-bugs)
* [Propose a New Rule](https://eslint.org/docs/latest/contribute/propose-new-rule)
* [Proposing a Rule Change](https://eslint.org/docs/latest/contribute/propose-rule-change)
* [Request a Change](https://eslint.org/docs/latest/contribute/request-change)
## <a name="faq"></a>Frequently Asked Questions
## Frequently Asked Questions

@@ -110,3 +104,3 @@ ### I'm using JSCS, should I migrate to ESLint?

We have prepared a [migration guide](https://eslint.org/docs/user-guide/migrating-from-jscs) to help you convert your JSCS settings to an ESLint configuration.
We have prepared a [migration guide](https://eslint.org/docs/latest/use/migrating-from-jscs) to help you convert your JSCS settings to an ESLint configuration.

@@ -127,7 +121,7 @@ We are now at or near 100% compatibility with JSCS. If you try ESLint and believe we are not yet compatible with a JSCS rule/configuration, please create an issue (mentioning that it is a JSCS compatibility issue) and we will evaluate it as per our normal process.

Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/user-guide/configuring)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/latest/use/configure)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
### What ECMAScript versions does ESLint support?
ESLint has full support for ECMAScript 3, 5 (default), 2015, 2016, 2017, 2018, 2019, 2020, 2021 and 2022. You can set your desired ECMAScript syntax (and other settings, like global variables or your target environments) through [configuration](https://eslint.org/docs/user-guide/configuring).
ESLint has full support for ECMAScript 3, 5 (default), 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, and 2023. You can set your desired ECMAScript syntax (and other settings, like global variables or your target environments) through [configuration](https://eslint.org/docs/latest/use/configure).

@@ -138,9 +132,9 @@ ### What about experimental features?

In other cases (including if rules need to warn on more or fewer cases due to new syntax, rather than just not crashing), we recommend you use other parsers and/or rule plugins. If you are using Babel, you can use the [babel-eslint](https://github.com/babel/babel-eslint) parser and [eslint-plugin-babel](https://github.com/babel/eslint-plugin-babel) to use any option available in Babel.
In other cases (including if rules need to warn on more or fewer cases due to new syntax, rather than just not crashing), we recommend you use other parsers and/or rule plugins. If you are using Babel, you can use [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) and [@babel/eslint-plugin](https://www.npmjs.com/package/@babel/eslint-plugin) to use any option available in Babel.
Once a language feature has been adopted into the ECMAScript standard (stage 4 according to the [TC39 process](https://tc39.github.io/process-document/)), we will accept issues and pull requests related to the new feature, subject to our [contributing guidelines](https://eslint.org/docs/developer-guide/contributing). Until then, please use the appropriate parser and plugin(s) for your experimental feature.
Once a language feature has been adopted into the ECMAScript standard (stage 4 according to the [TC39 process](https://tc39.github.io/process-document/)), we will accept issues and pull requests related to the new feature, subject to our [contributing guidelines](https://eslint.org/docs/latest/contribute). Until then, please use the appropriate parser and plugin(s) for your experimental feature.
### Where to ask for help?
Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://eslint.org/chat).
Open a [discussion](https://github.com/eslint/eslint/discussions) or stop by our [Discord server](https://eslint.org/chat).

@@ -157,11 +151,11 @@ ### Why doesn't ESLint lock dependency versions?

## <a name="releases"></a>Releases
## Releases
We have scheduled releases every two weeks on Friday or Saturday. You can follow a [release issue](https://github.com/eslint/eslint/issues?q=is%3Aopen+is%3Aissue+label%3Arelease) for updates about the scheduling of any particular release.
## <a name="security-policy"></a>Security Policy
## Security Policy
ESLint takes security seriously. We work hard to ensure that ESLint is safe for everyone and that security issues are addressed quickly and responsibly. Read the full [security policy](https://github.com/eslint/.github/blob/master/SECURITY.md).
## <a name="semantic-versioning-policy"></a>Semantic Versioning Policy
## Semantic Versioning Policy

@@ -199,3 +193,3 @@ ESLint follows [semantic versioning](https://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:

## <a name="stylistic-rule-updates"></a>Stylistic Rule Updates
## Stylistic Rule Updates

@@ -209,7 +203,7 @@ Stylistic rules are frozen according to [our policy](https://eslint.org/blog/2020/05/changes-to-rules-policies) on how we evaluate new rules and rule changes.

## <a name="license"></a>License
## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_large)
## <a name="team"></a>Team
## Team

@@ -232,7 +226,2 @@ These folks keep the project moving and are resources for help.

</td><td align="center" valign="top" width="11%">
<a href="https://github.com/btmills">
<img src="https://github.com/btmills.png?s=75" width="75" height="75"><br />
Brandon Mills
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/mdjermanovic">

@@ -249,7 +238,2 @@ <img src="https://github.com/mdjermanovic.png?s=75" width="75" height="75"><br />

<table><tbody><tr><td align="center" valign="top" width="11%">
<a href="https://github.com/mysticatea">
<img src="https://github.com/mysticatea.png?s=75" width="75" height="75"><br />
Toru Nagashima
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/aladdin-add">

@@ -259,2 +243,7 @@ <img src="https://github.com/aladdin-add.png?s=75" width="75" height="75"><br />

</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/snitin315">
<img src="https://github.com/snitin315.png?s=75" width="75" height="75"><br />
Nitin Kumar
</a>
</td></tr></tbody></table>

@@ -267,7 +256,2 @@

<table><tbody><tr><td align="center" valign="top" width="11%">
<a href="https://github.com/brettz9">
<img src="https://github.com/brettz9.png?s=75" width="75" height="75"><br />
Brett Zamir
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/bmish">

@@ -278,21 +262,37 @@ <img src="https://github.com/bmish.png?s=75" width="75" height="75"><br />

</td><td align="center" valign="top" width="11%">
<a href="https://github.com/g-plane">
<img src="https://github.com/g-plane.png?s=75" width="75" height="75"><br />
Pig Fang
<a href="https://github.com/fasttime">
<img src="https://github.com/fasttime.png?s=75" width="75" height="75"><br />
Francesco Trotta
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/anikethsaha">
<img src="https://github.com/anikethsaha.png?s=75" width="75" height="75"><br />
Anix
<a href="https://github.com/ota-meshi">
<img src="https://github.com/ota-meshi.png?s=75" width="75" height="75"><br />
Yosuke Ota
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/yeonjuan">
<img src="https://github.com/yeonjuan.png?s=75" width="75" height="75"><br />
YeonJuan
<a href="https://github.com/Tanujkanti4441">
<img src="https://github.com/Tanujkanti4441.png?s=75" width="75" height="75"><br />
Tanuj Kanti
</a>
</td></tr></tbody></table>
### Website Team
Team members who focus specifically on eslint.org
<table><tbody><tr><td align="center" valign="top" width="11%">
<a href="https://github.com/amareshsm">
<img src="https://github.com/amareshsm.png?s=75" width="75" height="75"><br />
Amaresh S M
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/snitin315">
<img src="https://github.com/snitin315.png?s=75" width="75" height="75"><br />
Nitin Kumar
<a href="https://github.com/harish-sethuraman">
<img src="https://github.com/harish-sethuraman.png?s=75" width="75" height="75"><br />
Strek
</a>
</td><td align="center" valign="top" width="11%">
<a href="https://github.com/kecrily">
<img src="https://github.com/kecrily.png?s=75" width="75" height="75"><br />
Percy Ma
</a>
</td></tr></tbody></table>

@@ -302,3 +302,3 @@

## <a name="sponsors"></a>Sponsors
## Sponsors

@@ -310,9 +310,9 @@ The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://opencollective.com/eslint) to get your logo on our README and website.

<h3>Platinum Sponsors</h3>
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
<p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://coinbase.com"><img src="https://avatars.githubusercontent.com/u/1885080?v=4" alt="Coinbase" height="96"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://sumatosoft.com/"><img src="https://images.opencollective.com/sumatosoft1/cab6013/logo.png" alt="SumatoSoft" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a> <a href="https://www.practiceignition.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" height="32"></a></p>
<p><a href="#"><img src="https://images.opencollective.com/2021-frameworks-fund/logo.png" alt="Chrome Frameworks Fund" height="undefined"></a> <a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
<p><a href="https://engineering.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://transloadit.com/"><img src="https://avatars.githubusercontent.com/u/125754?v=4" alt="Transloadit" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p>
<!--sponsorsend-->
## <a name="technology-sponsors"></a>Technology Sponsors
## Technology Sponsors

@@ -319,0 +319,0 @@ * Site search ([eslint.org](https://eslint.org)) is sponsored by [Algolia](https://www.algolia.com)

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

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

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

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