Update Bot

This commit is contained in:
2026-03-15 11:58:43 +01:00
parent b67c111ffc
commit cd99275933
560 changed files with 23173 additions and 55113 deletions

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -35,7 +35,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -78,7 +78,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -68,7 +68,6 @@ module.exports = {
},
create(context) {
const sourceCode = context.sourceCode;
const option = context.options[0];
let threshold = THRESHOLD_DEFAULT;
let VARIANT = "classic";
@@ -172,21 +171,17 @@ module.exports = {
if (complexity > threshold) {
let name;
let loc = node.loc;
if (codePath.origin === "class-field-initializer") {
name = "class field initializer";
} else if (codePath.origin === "class-static-block") {
name = "class static block";
loc = sourceCode.getFirstToken(node).loc;
} else {
name = astUtils.getFunctionNameWithKind(node);
loc = astUtils.getFunctionHeadLoc(node, sourceCode);
}
context.report({
node,
loc,
messageId: "complex",
data: {
name: upperCaseFirst(name),

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -46,10 +46,7 @@ module.exports = {
*/
function report(node) {
context.report({
loc: {
start: node.loc.start,
end: sourceCode.getTokenBefore(node.body).loc.end,
},
node,
messageId: "incorrectDirection",
});
}

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:
@@ -105,7 +105,7 @@ module.exports = {
* Check if open space is present in a function name
* @param {ASTNode} node node to evaluate
* @param {Token} leftToken The last token of the callee. This may be the closing parenthesis that encloses the callee.
* @param {Token} rightToken The first token of the arguments. this is the opening parenthesis that encloses the arguments.
* @param {Token} rightToken Tha first token of the arguments. this is the opening parenthesis that encloses the arguments.
* @returns {void}
* @private
*/

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -33,7 +33,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -60,7 +60,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -101,7 +101,7 @@ module.exports = {
message: "The rule was renamed.",
url: "https://eslint.org/blog/2020/07/eslint-v7.5.0-released/#deprecating-id-blacklist",
deprecatedSince: "7.5.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -35,7 +35,6 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "4.0.0",
availableUntil: "11.0.0",
replacedBy: [
{
message:

View File

@@ -512,7 +512,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -44,7 +44,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -151,7 +151,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -82,7 +82,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "9.3.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -31,7 +31,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -60,7 +60,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -56,7 +56,7 @@ module.exports = {
message: "The rule was replaced with a more general rule.",
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
deprecatedSince: "4.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message: "The new rule moved to a plugin.",

View File

@@ -37,7 +37,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -71,7 +71,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "9.3.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -27,7 +27,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -42,7 +42,7 @@ module.exports = {
message: "The rule was replaced with a more general rule.",
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
deprecatedSince: "4.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message: "The new rule moved to a plugin.",

View File

@@ -30,7 +30,7 @@ module.exports = {
message: "The rule was replaced with a more general rule.",
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
deprecatedSince: "4.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message: "The new rule moved to a plugin.",

View File

@@ -20,7 +20,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -32,7 +32,7 @@ module.exports = {
message: "This rule was renamed.",
url: "https://eslint.org/blog/2018/07/eslint-v5.1.0-released/",
deprecatedSince: "5.1.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -33,7 +33,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -5,12 +5,6 @@
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@@ -64,15 +58,10 @@ module.exports = {
// Checks and reports duplications.
const defs = variable.defs.filter(isParameter);
const loc = {
start: astUtils.getOpeningParenOfParams(node, sourceCode)
.loc.start,
end: sourceCode.getTokenBefore(node.body).loc.end,
};
if (defs.length >= 2) {
context.report({
loc,
node,
messageId: "unexpected",
data: { name: variable.name },
});

View File

@@ -106,7 +106,7 @@ module.exports = {
if (isDuplicate) {
context.report({
loc: node.key.loc,
node,
messageId: "unexpected",
data: { name },
});

View File

@@ -21,7 +21,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -24,7 +24,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -5,212 +5,6 @@
"use strict";
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/** Class representing a number in scientific notation. */
class ScientificNotation {
/** @type {string} The digits of the coefficient. A decimal point is implied after the first digit. */
coefficient;
/** @type {number} The order of magnitude. */
magnitude;
constructor(coefficient, magnitude) {
this.coefficient = coefficient;
this.magnitude = magnitude;
}
/* c8 ignore start -- debug only */
toString() {
return `${this.coefficient[0]}${this.coefficient.length > 1 ? `.${this.coefficient.slice(1)}` : ""}e${this.magnitude}`;
}
/* c8 ignore stop */
}
/**
* Returns whether the node is number literal
* @param {Node} node the node literal being evaluated
* @returns {boolean} true if the node is a number literal
*/
function isNumber(node) {
return typeof node.value === "number";
}
/**
* Gets the source code of the given number literal. Removes `_` numeric separators from the result.
* @param {Node} node the number `Literal` node
* @returns {string} raw source code of the literal, without numeric separators
*/
function getRaw(node) {
return node.raw.replace(/_/gu, "");
}
/**
* Checks whether the number is base ten
* @param {ASTNode} node the node being evaluated
* @returns {boolean} true if the node is in base ten
*/
function isBaseTen(node) {
const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"];
return (
prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
!/^0[0-7]+$/u.test(node.raw)
);
}
/**
* Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function notBaseTenLosesPrecision(node) {
const rawString = getRaw(node).toUpperCase();
let base;
if (rawString.startsWith("0B")) {
base = 2;
} else if (rawString.startsWith("0X")) {
base = 16;
} else {
base = 8;
}
return !rawString.endsWith(node.value.toString(base).toUpperCase());
}
/**
* Returns the number stripped of leading zeros
* @param {string} numberAsString the string representation of the number
* @returns {string} the stripped string
*/
function removeLeadingZeros(numberAsString) {
for (let i = 0; i < numberAsString.length; i++) {
if (numberAsString[i] !== "0") {
return numberAsString.slice(i);
}
}
return numberAsString;
}
/**
* Returns the number stripped of trailing zeros
* @param {string} numberAsString the string representation of the number
* @returns {string} the stripped string
*/
function removeTrailingZeros(numberAsString) {
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 an object containing the integer's coefficient and order of magnitude
* @param {string} stringInteger the string representation of the integer being converted
* @returns {ScientificNotation} the object containing the integer's coefficient and order of magnitude
*/
function normalizeInteger(stringInteger) {
const trimmedInteger = removeLeadingZeros(stringInteger);
const significantDigits = removeTrailingZeros(trimmedInteger);
return new ScientificNotation(significantDigits, trimmedInteger.length - 1);
}
/**
* Converts a float to an object containing the float's coefficient and order of magnitude
* @param {string} stringFloat the string representation of the float being converted
* @returns {ScientificNotation} the object containing the float's coefficient and order of magnitude
*/
function normalizeFloat(stringFloat) {
const trimmedFloat = removeLeadingZeros(stringFloat);
const indexOfDecimalPoint = trimmedFloat.indexOf(".");
switch (indexOfDecimalPoint) {
case 0: {
const significantDigits = removeLeadingZeros(trimmedFloat.slice(1));
return new ScientificNotation(
significantDigits,
significantDigits.length - trimmedFloat.length,
);
}
case -1:
return new ScientificNotation(
trimmedFloat,
trimmedFloat.length - 1,
);
default:
return new ScientificNotation(
trimmedFloat.replace(".", ""),
indexOfDecimalPoint - 1,
);
}
}
/**
* Converts a base ten number to proper scientific notation
* @param {string} stringNumber the string representation of the base ten number to be converted
* @param {boolean} parseAsFloat if true, the coefficient will be always parsed as a float, regardless of whether a decimal point is present
* @returns {ScientificNotation} the object containing the number's coefficient and order of magnitude
*/
function convertNumberToScientificNotation(stringNumber, parseAsFloat) {
const splitNumber = stringNumber.split("e");
const originalCoefficient = splitNumber[0];
const normalizedNumber =
parseAsFloat || stringNumber.includes(".")
? normalizeFloat(originalCoefficient)
: normalizeInteger(originalCoefficient);
if (splitNumber.length > 1) {
normalizedNumber.magnitude += parseInt(splitNumber[1], 10);
}
return normalizedNumber;
}
/**
* Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function baseTenLosesPrecision(node) {
const rawNumber = getRaw(node).toLowerCase();
const normalizedRawNumber = convertNumberToScientificNotation(
rawNumber,
false,
);
const requestedPrecision = normalizedRawNumber.coefficient.length;
if (requestedPrecision > 100) {
return true;
}
const storedNumber = node.value.toPrecision(requestedPrecision);
const normalizedStoredNumber = convertNumberToScientificNotation(
storedNumber,
true,
);
return (
normalizedRawNumber.magnitude !== normalizedStoredNumber.magnitude ||
normalizedRawNumber.coefficient !== normalizedStoredNumber.coefficient
);
}
/**
* Checks that the user-intended number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function losesPrecision(node) {
return isBaseTen(node)
? baseTenLosesPrecision(node)
: notBaseTenLosesPrecision(node);
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@@ -235,6 +29,217 @@ module.exports = {
},
create(context) {
/**
* Returns whether the node is number literal
* @param {Node} node the node literal being evaluated
* @returns {boolean} true if the node is a number literal
*/
function isNumber(node) {
return typeof node.value === "number";
}
/**
* Gets the source code of the given number literal. Removes `_` numeric separators from the result.
* @param {Node} node the number `Literal` node
* @returns {string} raw source code of the literal, without numeric separators
*/
function getRaw(node) {
return node.raw.replace(/_/gu, "");
}
/**
* Checks whether the number is base ten
* @param {ASTNode} node the node being evaluated
* @returns {boolean} true if the node is in base ten
*/
function isBaseTen(node) {
const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"];
return (
prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
!/^0[0-7]+$/u.test(node.raw)
);
}
/**
* Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function notBaseTenLosesPrecision(node) {
const rawString = getRaw(node).toUpperCase();
let base;
if (rawString.startsWith("0B")) {
base = 2;
} else if (rawString.startsWith("0X")) {
base = 16;
} else {
base = 8;
}
return !rawString.endsWith(node.value.toString(base).toUpperCase());
}
/**
* Adds a decimal point to the numeric string at index 1
* @param {string} stringNumber the numeric string without any decimal point
* @returns {string} the numeric string with a decimal point in the proper place
*/
function addDecimalPointToNumber(stringNumber) {
return `${stringNumber[0]}.${stringNumber.slice(1)}`;
}
/**
* Returns the number stripped of leading zeros
* @param {string} numberAsString the string representation of the number
* @returns {string} the stripped string
*/
function removeLeadingZeros(numberAsString) {
for (let i = 0; i < numberAsString.length; i++) {
if (numberAsString[i] !== "0") {
return numberAsString.slice(i);
}
}
return numberAsString;
}
/**
* Returns the number stripped of trailing zeros
* @param {string} numberAsString the string representation of the number
* @returns {string} the stripped string
*/
function removeTrailingZeros(numberAsString) {
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 an object containing the integer's coefficient and order of magnitude
* @param {string} stringInteger the string representation of the integer being converted
* @returns {Object} the object containing the integer's coefficient and order of magnitude
*/
function normalizeInteger(stringInteger) {
const significantDigits = removeTrailingZeros(
removeLeadingZeros(stringInteger),
);
return {
magnitude: stringInteger.startsWith("0")
? stringInteger.length - 2
: stringInteger.length - 1,
coefficient: addDecimalPointToNumber(significantDigits),
};
}
/**
*
* 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
* @returns {Object} the object containing the integer's coefficient and order of magnitude
*/
function normalizeFloat(stringFloat) {
const trimmedFloat = removeLeadingZeros(stringFloat);
if (trimmedFloat.startsWith(".")) {
const decimalDigits = trimmedFloat.slice(1);
const significantDigits = removeLeadingZeros(decimalDigits);
return {
magnitude:
significantDigits.length - decimalDigits.length - 1,
coefficient: addDecimalPointToNumber(significantDigits),
};
}
return {
magnitude: trimmedFloat.indexOf(".") - 1,
coefficient: addDecimalPointToNumber(
trimmedFloat.replace(".", ""),
),
};
}
/**
* Converts a base ten number to proper scientific notation
* @param {string} stringNumber the string representation of the base ten number to be converted
* @returns {string} the number converted to scientific notation
*/
function convertNumberToScientificNotation(stringNumber) {
const splitNumber = stringNumber.replace("E", "e").split("e");
const originalCoefficient = splitNumber[0];
const normalizedNumber = stringNumber.includes(".")
? normalizeFloat(originalCoefficient)
: normalizeInteger(originalCoefficient);
const normalizedCoefficient = normalizedNumber.coefficient;
const magnitude =
splitNumber.length > 1
? parseInt(splitNumber[1], 10) + normalizedNumber.magnitude
: normalizedNumber.magnitude;
return `${normalizedCoefficient}e${magnitude}`;
}
/**
* Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function baseTenLosesPrecision(node) {
const rawNumber = getRaw(node).toLowerCase();
/*
* If trailing zeros equal the exponent, this is a valid representation
* like "9.00e2" where 00 = 2 (meaning 9.00 * 10^2 = 900)
* https://github.com/eslint/eslint/issues/19957
*/
if (rawNumber.includes(".") && rawNumber.includes("e")) {
const parts = rawNumber.split("e");
const coefficient = parts[0];
const exponent = parseInt(parts[1], 10);
// Count trailing zeros after decimal
const decimalParts = coefficient.split(".");
if (decimalParts.length === 2) {
const decimalPart = decimalParts[1];
const trailingZeros = decimalPart.match(/0*$/u)[0].length;
if (trailingZeros === exponent) {
return false;
}
}
}
const normalizedRawNumber =
convertNumberToScientificNotation(rawNumber);
const requestedPrecision = normalizedRawNumber
.split("e")[0]
.replace(".", "").length;
if (requestedPrecision > 100) {
return true;
}
const storedNumber = node.value.toPrecision(requestedPrecision);
const normalizedStoredNumber =
convertNumberToScientificNotation(storedNumber);
return normalizedRawNumber !== normalizedStoredNumber;
}
/**
* Checks that the user-intended number equals the actual number after is has been converted to the Number type
* @param {Node} node the node being evaluated
* @returns {boolean} true if they do not match
*/
function losesPrecision(node) {
return isBaseTen(node)
? baseTenLosesPrecision(node)
: notBaseTenLosesPrecision(node);
}
return {
Literal(node) {
if (node.value && isNumber(node) && losesPrecision(node)) {

View File

@@ -90,7 +90,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -26,7 +26,7 @@ module.exports = {
message: "Renamed rule.",
url: "https://eslint.org/blog/2016/08/eslint-v3.3.0-released/#deprecated-rules",
deprecatedSince: "3.3.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -26,7 +26,7 @@ module.exports = {
message: "Renamed rule.",
url: "https://eslint.org/blog/2016/08/eslint-v3.3.0-released/#deprecated-rules",
deprecatedSince: "3.3.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -32,7 +32,7 @@ module.exports = {
"The new rule flags more situations where object literal syntax can be used, and it does not report a problem when the `Object` constructor is invoked with an argument.",
url: "https://eslint.org/blog/2023/09/eslint-v8.50.0-released/",
deprecatedSince: "8.50.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -25,7 +25,7 @@ module.exports = {
message: "The rule was replaced with a more general rule.",
url: "https://eslint.org/docs/latest/use/migrate-to-9.0.0#eslint-recommended",
deprecatedSince: "9.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
rule: {

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -41,11 +41,6 @@ const arrayOfStringsOrObjects = {
type: "string",
},
},
allowTypeImports: {
type: "boolean",
description:
"Whether to allow type-only imports for a path.",
},
},
additionalProperties: false,
required: ["name"],
@@ -110,11 +105,6 @@ const arrayOfStringsOrObjectPatterns = {
caseSensitive: {
type: "boolean",
},
allowTypeImports: {
type: "boolean",
description:
"Whether to allow type-only imports for a pattern.",
},
},
additionalProperties: false,
not: {
@@ -147,8 +137,6 @@ const arrayOfStringsOrObjectPatterns = {
module.exports = {
meta: {
type: "suggestion",
dialects: ["typescript", "javascript"],
language: "javascript",
docs: {
description: "Disallow specified modules when loaded by `import`",
@@ -273,7 +261,6 @@ module.exports = {
message: importSource.message,
importNames: importSource.importNames,
allowImportNames: importSource.allowImportNames,
allowTypeImports: importSource.allowTypeImports,
});
}
return memo;
@@ -304,7 +291,6 @@ module.exports = {
importNamePattern,
allowImportNames,
allowImportNamePattern,
allowTypeImports,
}) => ({
...(group
? {
@@ -327,7 +313,6 @@ module.exports = {
importNamePattern,
allowImportNames,
allowImportNamePattern,
allowTypeImports,
}),
);
@@ -339,48 +324,6 @@ module.exports = {
return {};
}
/**
* Check if the node is a type-only import
* @param {ASTNode} node The node to check
* @returns {boolean} Whether the node is a type-only import
*/
function isTypeOnlyImport(node) {
return (
node.importKind === "type" ||
(node.specifiers?.length > 0 &&
node.specifiers.every(
specifier => specifier.importKind === "type",
))
);
}
/**
* Check if a specifier is type-only
* @param {ASTNode} specifier The specifier to check
* @returns {boolean} Whether the specifier is type-only
*/
function isTypeOnlySpecifier(specifier) {
return (
specifier.importKind === "type" ||
specifier.exportKind === "type"
);
}
/**
* Check if the node is a type-only export
* @param {ASTNode} node The node to check
* @returns {boolean} Whether the node is a type-only export
*/
function isTypeOnlyExport(node) {
return (
node.exportKind === "type" ||
(node.specifiers?.length > 0 &&
node.specifiers.every(
specifier => specifier.exportKind === "type",
))
);
}
/**
* Report a restricted path.
* @param {string} importSource path of the import
@@ -401,28 +344,6 @@ module.exports = {
restrictedPathEntry.importNames;
const allowedImportNames =
restrictedPathEntry.allowImportNames;
const allowTypeImports =
restrictedPathEntry.allowTypeImports;
// Skip if this is a type-only import and it's allowed for this specific entry
if (
allowTypeImports &&
(node.type === "ImportDeclaration" ||
node.type === "TSImportEqualsDeclaration") &&
isTypeOnlyImport(node)
) {
return;
}
// Skip if this is a type-only export and it's allowed for this specific entry
if (
allowTypeImports &&
(node.type === "ExportNamedDeclaration" ||
node.type === "ExportAllDeclaration") &&
isTypeOnlyExport(node)
) {
return;
}
if (!restrictedImportNames && !allowedImportNames) {
context.report({
@@ -479,14 +400,6 @@ module.exports = {
restrictedImportNames.includes(importName)
) {
specifiers.forEach(specifier => {
// Skip if this is a type-only import specifier and type imports are allowed
if (
allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}
context.report({
node,
messageId: customMessage
@@ -507,14 +420,6 @@ module.exports = {
!allowedImportNames.includes(importName)
) {
specifiers.forEach(specifier => {
// Skip if this is a type-only import specifier and type imports are allowed
if (
allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}
context.report({
node,
loc: specifier.loc,
@@ -541,30 +446,11 @@ module.exports = {
* @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
* @param {string} importSource the import source string
* @returns {void}
* @private
*/
function reportPathForPatterns(node, group, importNames, importSource) {
// Skip if this is a type-only import and it's allowed
if (
group.allowTypeImports &&
(node.type === "ImportDeclaration" ||
node.type === "TSImportEqualsDeclaration") &&
isTypeOnlyImport(node)
) {
return;
}
// Skip if this is a type-only export and it's allowed
if (
group.allowTypeImports &&
(node.type === "ExportNamedDeclaration" ||
node.type === "ExportAllDeclaration") &&
isTypeOnlyExport(node)
) {
return;
}
function reportPathForPatterns(node, group, importNames) {
const importSource = node.source.value.trim();
const customMessage = group.customMessage;
const restrictedImportNames = group.importNames;
@@ -667,14 +553,6 @@ module.exports = {
restrictedImportNamePattern.test(importName))
) {
specifiers.forEach(specifier => {
// Skip if this is a type-only import specifier and type imports are allowed
if (
group.allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}
context.report({
node,
messageId: customMessage
@@ -695,14 +573,6 @@ module.exports = {
!allowedImportNames.includes(importName)
) {
specifiers.forEach(specifier => {
// Skip if this is a type-only import specifier and type imports are allowed
if (
group.allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}
context.report({
node,
messageId: customMessage
@@ -722,14 +592,6 @@ module.exports = {
!allowedImportNamePattern.test(importName)
) {
specifiers.forEach(specifier => {
// Skip if this is a type-only import specifier and type imports are allowed
if (
group.allowTypeImports &&
isTypeOnlySpecifier(specifier.specifier)
) {
return;
}
context.report({
node,
messageId: customMessage
@@ -778,7 +640,7 @@ module.exports = {
} else if (node.specifiers) {
for (const specifier of node.specifiers) {
let name;
const specifierData = { loc: specifier.loc, specifier };
const specifierData = { loc: specifier.loc };
if (specifier.type === "ImportDefaultSpecifier") {
name = "default";
@@ -803,12 +665,7 @@ module.exports = {
checkRestrictedPathAndReport(importSource, importNames, node);
restrictedPatternGroups.forEach(group => {
if (isRestrictedPattern(importSource, group)) {
reportPathForPatterns(
node,
group,
importNames,
importSource,
);
reportPathForPatterns(node, group, importNames);
}
});
}
@@ -821,30 +678,6 @@ module.exports = {
}
},
ExportAllDeclaration: checkNode,
// Add support for TypeScript import equals declarations
TSImportEqualsDeclaration(node) {
if (node.moduleReference.type === "TSExternalModuleReference") {
const importSource = node.moduleReference.expression.value;
const importNames = new Map();
// Use existing logic with the actual node
checkRestrictedPathAndReport(
importSource,
importNames,
node,
);
restrictedPatternGroups.forEach(group => {
if (isRestrictedPattern(importSource, group)) {
reportPathForPatterns(
node,
group,
importNames,
importSource,
);
}
});
}
},
};
},
};

View File

@@ -52,7 +52,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -26,7 +26,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2016/08/eslint-v3.3.0-released/#deprecated-rules",
deprecatedSince: "3.3.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Node.js rules were moved out of ESLint core.",
url: "https://eslint.org/docs/latest/use/migrating-to-7.0.0#deprecate-node-rules",
deprecatedSince: "7.0.0",
availableUntil: "11.0.0",
availableUntil: null,
replacedBy: [
{
message:

View File

@@ -24,7 +24,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -30,7 +30,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -162,7 +162,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,86 +19,6 @@ const OPTIONS = {
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
const CTOR_PREFIX_REGEX = /[^_$0-9]/u;
const JSDOC_COMMENT_REGEX = /^\s*\*/u;
/**
* Determines if the first character of the name is a capital letter.
* @param {string} name The name of the node to evaluate.
* @returns {boolean} True if the first character of the property name is a capital letter, false if not.
* @private
*/
function isConstructor(name) {
const match = CTOR_PREFIX_REGEX.exec(name);
// Not a constructor if name has no characters apart from '_', '$' and digits e.g. '_', '$$', '_8'
if (!match) {
return false;
}
const firstChar = name.charAt(match.index);
return firstChar === firstChar.toUpperCase();
}
/**
* Determines if the property can have a shorthand form.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the property can have a shorthand form
* @private
*/
function canHaveShorthand(property) {
return (
property.kind !== "set" &&
property.kind !== "get" &&
property.type !== "SpreadElement" &&
property.type !== "SpreadProperty" &&
property.type !== "ExperimentalSpreadProperty"
);
}
/**
* Checks whether a node is a string literal.
* @param {ASTNode} node Any AST node.
* @returns {boolean} `true` if it is a string literal.
*/
function isStringLiteral(node) {
return node.type === "Literal" && typeof node.value === "string";
}
/**
* Determines if the property is a shorthand or not.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the property is considered shorthand, false if not.
* @private
*/
function isShorthand(property) {
// property.method is true when `{a(){}}`.
return property.shorthand || property.method;
}
/**
* Determines if the property's key and method or value are named equally.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the key and value are named equally, false if not.
* @private
*/
function isRedundant(property) {
const value = property.value;
if (value.type === "FunctionExpression") {
return !value.id; // Only anonymous should be shorthand method.
}
if (value.type === "Identifier") {
return astUtils.getStaticPropertyName(property) === value.name;
}
return false;
}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@@ -219,6 +139,86 @@ module.exports = {
const AVOID_EXPLICIT_RETURN_ARROWS = !!PARAMS.avoidExplicitReturnArrows;
const sourceCode = context.sourceCode;
//--------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------
const CTOR_PREFIX_REGEX = /[^_$0-9]/u;
/**
* Determines if the first character of the name is a capital letter.
* @param {string} name The name of the node to evaluate.
* @returns {boolean} True if the first character of the property name is a capital letter, false if not.
* @private
*/
function isConstructor(name) {
const match = CTOR_PREFIX_REGEX.exec(name);
// Not a constructor if name has no characters apart from '_', '$' and digits e.g. '_', '$$', '_8'
if (!match) {
return false;
}
const firstChar = name.charAt(match.index);
return firstChar === firstChar.toUpperCase();
}
/**
* Determines if the property can have a shorthand form.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the property can have a shorthand form
* @private
*/
function canHaveShorthand(property) {
return (
property.kind !== "set" &&
property.kind !== "get" &&
property.type !== "SpreadElement" &&
property.type !== "SpreadProperty" &&
property.type !== "ExperimentalSpreadProperty"
);
}
/**
* Checks whether a node is a string literal.
* @param {ASTNode} node Any AST node.
* @returns {boolean} `true` if it is a string literal.
*/
function isStringLiteral(node) {
return node.type === "Literal" && typeof node.value === "string";
}
/**
* Determines if the property is a shorthand or not.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the property is considered shorthand, false if not.
* @private
*/
function isShorthand(property) {
// property.method is true when `{a(){}}`.
return property.shorthand || property.method;
}
/**
* Determines if the property's key and method or value are named equally.
* @param {ASTNode} property Property AST node
* @returns {boolean} True if the key and value are named equally, false if not.
* @private
*/
function isRedundant(property) {
const value = property.value;
if (value.type === "FunctionExpression") {
return !value.id; // Only anonymous should be shorthand method.
}
if (value.type === "Identifier") {
return astUtils.getStaticPropertyName(property) === value.name;
}
return false;
}
/**
* Ensures that an object's properties are consistently shorthand, or not shorthand at all.
* @param {ASTNode} node Property AST node
@@ -582,19 +582,6 @@ module.exports = {
node.key.name === node.value.name &&
APPLY_TO_PROPS
) {
// Skip if there are JSDoc comments inside the property (e.g., JSDoc type annotations)
const comments = sourceCode.getCommentsInside(node);
if (
comments.some(
comment =>
comment.type === "Block" &&
JSDOC_COMMENT_REGEX.test(comment.value) &&
comment.value.includes("@type"),
)
) {
return;
}
// {x: x} should be written as {x}
context.report({
node,
@@ -619,18 +606,6 @@ module.exports = {
return;
}
const comments = sourceCode.getCommentsInside(node);
if (
comments.some(
comment =>
comment.type === "Block" &&
comment.value.startsWith("*") &&
comment.value.includes("@type"),
)
) {
return;
}
// {"x": x} should be written as {x}
context.report({
node,

View File

@@ -16,7 +16,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -393,7 +393,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -82,7 +82,11 @@ function getErrorCause(throwStatement) {
}
const causeProperties = errorOptions.properties.filter(
prop => astUtils.getStaticPropertyName(prop) === "cause",
prop =>
prop.type === "Property" &&
prop.key.type === "Identifier" &&
prop.key.name === "cause" &&
!prop.computed, // It is hard to accurately identify the value of computed props
);
const causeProperty = causeProperties.at(-1);

View File

@@ -24,7 +24,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -101,7 +101,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -19,7 +19,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -89,7 +89,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -42,7 +42,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -18,7 +18,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -22,7 +22,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -147,7 +147,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -23,7 +23,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -2729,5 +2729,4 @@ module.exports = {
isStartOfExpressionStatement,
needsPrecedingSemicolon,
isImportAttributeKey,
getOpeningParenOfParams,
};

View File

@@ -44,7 +44,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message:

View File

@@ -17,7 +17,7 @@ module.exports = {
message: "Formatting rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "11.0.0",
availableUntil: "10.0.0",
replacedBy: [
{
message: