refactor start

This commit is contained in:
Spectre 2025-02-18 11:19:45 +01:00
parent bd49791e06
commit e46d25f0b7
16699 changed files with 2 additions and 1484887 deletions

View file

@ -1,31 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow accessor properties.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-accessor-properties.html",
},
fixable: null,
messages: {
forbidden: "ES5 accessor properties are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Property[kind='get'], Property[kind='set'], MethodDefinition[kind='get'], MethodDefinition[kind='set']"(
node,
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,34 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow arbitrary module namespace names.",
category: "ES2022",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-arbitrary-module-namespace-names.html",
},
fixable: null,
messages: {
forbidden: "ES2022 arbitrary module namespace names are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ExportAllDeclaration > Literal.exported, ExportSpecifier > Literal.local, ExportSpecifier > Literal.exported, ImportSpecifier > Literal.imported"(
node,
) {
context.report({
node,
messageId: "forbidden",
})
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.from` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-from.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
from: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.isArray` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-isarray.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
isArray: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.of` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-of.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
of: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.copyWithin` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-copywithin.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["copyWithin"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.entries` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-entries.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["entries"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.every` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-every.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["every"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.fill` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-fill.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["fill"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.filter` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-filter.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["filter"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.find` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-find.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["find"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.findIndex` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-findindex.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["findIndex"],
})
},
}

View file

@ -1,47 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `Array.prototype.{findLast,findLastIndex}` methods.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-findlast-findlastindex.html",
},
fixable: null,
messages: {
forbidden: "ES2023 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["findLast", "findLastIndex"],
Int8Array: ["findLast", "findLastIndex"],
Uint8Array: ["findLast", "findLastIndex"],
Uint8ClampedArray: ["findLast", "findLastIndex"],
Int16Array: ["findLast", "findLastIndex"],
Uint16Array: ["findLast", "findLastIndex"],
Int32Array: ["findLast", "findLastIndex"],
Uint32Array: ["findLast", "findLastIndex"],
Float32Array: ["findLast", "findLastIndex"],
Float64Array: ["findLast", "findLastIndex"],
BigInt64Array: ["findLast", "findLastIndex"],
BigUint64Array: ["findLast", "findLastIndex"],
})
},
}

View file

@ -1,40 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `Array.prototype.{flat,flatMap}` method.",
category: "ES2019",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-flat.html",
},
fixable: null,
messages: {
forbidden: "ES2019 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["flat", "flatMap"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.forEach` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-foreach.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["forEach"],
})
},
}

View file

@ -1,50 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.includes` method.",
category: "ES2016",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-includes.html",
},
fixable: null,
messages: {
forbidden: "ES2016 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["includes"],
Int8Array: ["includes"],
Uint8Array: ["includes"],
Uint8ClampedArray: ["includes"],
Int16Array: ["includes"],
Uint16Array: ["includes"],
Int32Array: ["includes"],
Uint32Array: ["includes"],
Float32Array: ["includes"],
Float64Array: ["includes"],
BigInt64Array: ["includes"],
BigUint64Array: ["includes"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.indexOf` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-indexof.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["indexOf"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.keys` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-keys.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["keys"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.lastIndexOf` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-lastindexof.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["lastIndexOf"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.map` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-map.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["map"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.reduce` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-reduce.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["reduce"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.reduceRight` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-reduceright.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["reduceRight"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.some` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-some.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["some"],
})
},
}

View file

@ -1,46 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.toReversed` method.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-toreversed.html",
},
fixable: null,
messages: {
forbidden: "ES2023 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["toReversed"],
Int8Array: ["toReversed"],
Uint8Array: ["toReversed"],
Uint8ClampedArray: ["toReversed"],
Int16Array: ["toReversed"],
Uint16Array: ["toReversed"],
Int32Array: ["toReversed"],
Uint32Array: ["toReversed"],
Float32Array: ["toReversed"],
Float64Array: ["toReversed"],
BigInt64Array: ["toReversed"],
BigUint64Array: ["toReversed"],
})
},
}

View file

@ -1,46 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.toSorted` method.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-tosorted.html",
},
fixable: null,
messages: {
forbidden: "ES2023 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["toSorted"],
Int8Array: ["toSorted"],
Uint8Array: ["toSorted"],
Uint8ClampedArray: ["toSorted"],
Int16Array: ["toSorted"],
Uint16Array: ["toSorted"],
Int32Array: ["toSorted"],
Uint32Array: ["toSorted"],
Float32Array: ["toSorted"],
Float64Array: ["toSorted"],
BigInt64Array: ["toSorted"],
BigUint64Array: ["toSorted"],
})
},
}

View file

@ -1,35 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.toSpliced` method.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-tospliced.html",
},
fixable: null,
messages: {
forbidden: "ES2023 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["toSpliced"],
})
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.values` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-values.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["values"],
})
},
}

View file

@ -1,46 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.prototype.with` method.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-with.html",
},
fixable: null,
messages: {
forbidden: "ES2023 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["with"],
Int8Array: ["with"],
Uint8Array: ["with"],
Uint8ClampedArray: ["with"],
Int16Array: ["with"],
Uint16Array: ["with"],
Int32Array: ["with"],
Uint32Array: ["with"],
Float32Array: ["with"],
Float64Array: ["with"],
BigInt64Array: ["with"],
BigUint64Array: ["with"],
})
},
}

View file

@ -1,52 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `{Array,String}.prototype.at()` methods.",
category: "ES2022",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-string-prototype-at.html",
},
fixable: null,
messages: {
forbidden: "ES2022 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["at"],
String: ["at"],
Int8Array: ["at"],
Uint8Array: ["at"],
Uint8ClampedArray: ["at"],
Int16Array: ["at"],
Uint16Array: ["at"],
Int32Array: ["at"],
Uint32Array: ["at"],
Float32Array: ["at"],
Float64Array: ["at"],
BigInt64Array: ["at"],
BigUint64Array: ["at"],
})
},
}

View file

@ -1,51 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `ArrayBuffer.prototype.transfer` method.",
category: "ES2024",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-arraybuffer-prototype-transfer.html",
},
fixable: null,
messages: {
forbidden: "ES2024 '{{name}}' method is forbidden.",
forbiddenForDetached:
"ES2024 'ArrayBuffer.prototype.detached' property is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(
context,
{
ArrayBuffer: ["detached", "transfer", "transferToFixedLength"],
},
{
createReport({ propertyName }) {
return {
messageId:
propertyName === "detached"
? "forbiddenForDetached"
: "forbidden",
}
},
},
)
},
}

View file

@ -1,132 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
isArrowToken,
isParenthesized,
} = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow arrow function expressions.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-arrow-functions.html",
},
fixable: "code",
messages: {
forbidden: "ES2015 arrow function expressions are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = getSourceCode(context)
/**
* ArrowFunctionExpression to FunctionExpression
* @param {Node} node ArrowFunctionExpression Node
* @param {boolean} hasThis `true` if the function has `this`.
* @returns {string} function expression text
*/
function toFunctionExpression(node, hasThis) {
const params = node.params
const paramText = params.length
? sourceCode.text.slice(
params[0].range[0],
params[params.length - 1].range[1],
)
: ""
const arrowToken = sourceCode.getTokenBefore(
node.body,
isArrowToken,
)
const preText = sourceCode.text.slice(
arrowToken.range[1],
node.body.range[0],
)
const bodyText = sourceCode.text
.slice(arrowToken.range[1], node.range[1])
.trim()
let resultText =
/*eslint-disable prettier/prettier */
node.body.type === "BlockStatement" ? (
`function(${paramText}) ${bodyText}`
) : preText.includes("\n") ? (
`function(${paramText}) { return (${bodyText}) }`
) : (
`function(${paramText}) { return ${bodyText} }`
)
/*eslint-enable prettier/prettier */
if (node.async) {
resultText = `async ${resultText}`
}
if (hasThis) {
resultText += ".bind(this)"
}
if (
node.parent.type === "ExpressionStatement" &&
!isParenthesized(node, sourceCode)
) {
resultText = `(${resultText})`
}
return resultText
}
/**
* Report that ArrowFunctionExpression is being used
* @param {Node} node ArrowFunctionExpression Node
* @param {boolean} hasThis Whether `this` is referenced in` function` scope
* @param {boolean} hasSuper Whether `super` is referenced in` function` scope
* @returns {void}
*/
function report(node, hasThis, hasSuper) {
context.report({
node,
messageId: "forbidden",
fix(fixer) {
if (hasSuper) {
return undefined
}
return fixer.replaceText(
node,
toFunctionExpression(node, hasThis),
)
},
})
}
let stack = { upper: null, hasThis: false, hasSuper: false }
return {
":function"() {
stack = { upper: stack, hasThis: false, hasSuper: false }
},
":function:exit"(node) {
const { hasThis, hasSuper } = stack
stack = stack.upper
if (node.type === "ArrowFunctionExpression") {
report(node, hasThis, hasSuper)
stack.hasThis = stack.hasThis || hasThis
stack.hasSuper = stack.hasSuper || hasSuper
}
},
ThisExpression() {
stack.hasThis = true
},
Super() {
stack.hasSuper = true
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow async function declarations.",
category: "ES2017",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-async-functions.html",
},
fixable: null,
messages: {
forbidden: "ES2017 async function declarations are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":function[async=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,32 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow async iteration.",
category: "ES2018",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-async-iteration.html",
},
fixable: null,
messages: {
forbidden: "ES2018 async iteration is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":function[async=true][generator=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
"ForOfStatement[await=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Atomics.waitAsync` method.",
category: "ES2024",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-atomics-waitasync.html",
},
fixable: null,
messages: {
forbidden: "ES2024 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Atomics: {
waitAsync: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,44 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Atomics` class.",
category: "ES2017",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-atomics.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Atomics: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,50 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow `bigint` syntax and built-ins",
category: "ES2020",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-bigint.html",
},
fixable: null,
messages: {
forbidden: "ES2020 BigInt is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
Literal(node) {
if (node.bigint != null) {
context.report({ messageId: "forbidden", node })
}
},
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
const references = tracker.iterateGlobalReferences({
BigInt: { [ReferenceTracker.READ]: true },
BigInt64Array: { [ReferenceTracker.READ]: true },
BigUint64Array: { [ReferenceTracker.READ]: true },
})
for (const { node } of references) {
context.report({ messageId: "forbidden", node })
}
},
}
},
}

View file

@ -1,33 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const Pattern = /^0[bB]/u
module.exports = {
meta: {
docs: {
description: "disallow binary numeric literals.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-binary-numeric-literals.html",
},
fixable: null,
messages: {
forbidden: "ES2015 binary numeric literals are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
Literal(node) {
if (typeof node.value === "number" && Pattern.test(node.raw)) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow block-scoped function declarations.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-block-scoped-functions.html",
},
fixable: null,
messages: {
forbidden: "ES2015 block-scoped functions are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":not(:function) > BlockStatement > FunctionDeclaration"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,31 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow block-scoped variable declarations.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-block-scoped-variables.html",
},
fixable: null,
messages: {
forbidden: "ES2015 block-scoped variables are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"VariableDeclaration[kind='const'], VariableDeclaration[kind='let']"(
node,
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,113 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
getFunctionNameWithKind,
getPropertyName,
} = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
/**
* Get the name and kind of the given PropertyDefinition node.
* @param {PropertyDefinition} node - The PropertyDefinition node to get.
* @param {SourceCode} sourceCode The source code object to get the code of computed property keys.
* @returns {string} The name and kind of the PropertyDefinition node.
*/
function getFieldNameWithKind(node, sourceCode) {
const tokens = []
if (node.static) {
tokens.push("static")
}
if (node.key.type === "PrivateIdentifier") {
tokens.push("private")
}
tokens.push("field")
if (node.key.type === "PrivateIdentifier") {
tokens.push(`#${node.key.name}`)
} else {
const name = getPropertyName(node)
if (name) {
tokens.push(`'${name}'`)
} else if (sourceCode) {
const keyText = sourceCode.getText(node.key)
if (!keyText.includes("\n")) {
tokens.push(`[${keyText}]`)
}
}
}
return tokens.join(" ")
}
module.exports = {
meta: {
docs: {
description: "disallow class fields.",
category: "ES2022",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-class-fields.html",
},
fixable: null,
messages: {
forbidden: "ES2022 {{nameWithKind}} is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
PropertyDefinition(node) {
if (node.declare || node.parent.parent.declare) {
return
}
context.report({
node: node.key,
messageId: "forbidden",
data: {
nameWithKind: getFieldNameWithKind(
node,
getSourceCode(context),
),
},
})
},
"MethodDefinition:exit"(node) {
if (node.key.type !== "PrivateIdentifier") {
return
}
context.report({
node: node.key,
messageId: "forbidden",
data: {
nameWithKind: getFunctionNameWithKind(
node.value,
getSourceCode(context),
),
},
})
},
":not(PropertyDefinition, MethodDefinition) > PrivateIdentifier"(
node,
) {
const parent = node.parent
context.report({
node,
messageId: "forbidden",
data: {
nameWithKind:
parent.parent.type === "CallExpression" &&
parent.parent.callee === parent
? `private method call #${node.name}()`
: `private access #${node.name}`,
},
})
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow class static block.",
category: "ES2022",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-class-static-block.html",
},
fixable: null,
messages: {
forbidden: "ES2022 class static block is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
StaticBlock(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow class declarations.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-classes.html",
},
fixable: null,
messages: {
forbidden: "ES2015 class declarations are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ClassDeclaration, ClassExpression"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow computed properties.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-computed-properties.html",
},
fixable: null,
messages: {
forbidden: "ES2015 computed properties are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":matches(Property, MethodDefinition)[computed=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Date.now` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-date-now.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Date: {
now: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `Date.prototype.{getYear,setYear}` methods.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-date-prototype-getyear-setyear.html",
},
fixable: null,
messages: {
forbidden: "Annex B feature '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Date: ["getYear", "setYear"],
})
},
}

View file

@ -1,63 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Date.prototype.toGMTString` method.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-date-prototype-togmtstring.html",
},
fixable: "code",
messages: {
forbidden: "Annex B feature '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
hasSuggestions: true,
},
create(context) {
return definePrototypeMethodHandler(
context,
{
Date: ["toGMTString"],
},
{
createReport({ objectTypeResult, node }) {
if (node.computed) {
return null
}
if (objectTypeResult !== true) {
return {
suggest: [
{
desc: "Replace with 'toUTCString'",
fix,
},
],
}
}
return {
fix,
}
function fix(fixer) {
return fixer.replaceText(node.property, "toUTCString")
}
},
},
)
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow default parameters.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-default-parameters.html",
},
fixable: null,
messages: {
forbidden: "ES2015 default parameters are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":function > AssignmentPattern"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,31 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow destructuring.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-destructuring.html",
},
fixable: null,
messages: {
forbidden: "ES2015 destructuring is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":matches(:function, AssignmentExpression, VariableDeclarator, :function > :matches(AssignmentPattern, RestElement), ForInStatement, ForOfStatement) > :matches(ArrayPattern, ObjectPattern)"(
node,
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow `import()` syntax",
category: "ES2020",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-dynamic-import.html",
},
fixable: null,
messages: {
forbidden: "ES2020 'import()' syntax is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
ImportExpression(node) {
context.report({ messageId: "forbidden", node })
},
}
},
}

View file

@ -1,193 +0,0 @@
/**
* @author Sosuke Suzuki <https://github.com/sosukesuzuki>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
CONSTRUCT,
READ,
ReferenceTracker,
getPropertyName,
} = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
/**
* @typedef {import("estree").Node} Node
* @typedef {import("estree").ClassExpression | import("estree").ClassDeclaration} ClassNode
* @typedef {import("estree").CallExpression} CallExpression
*/
const errorConstructorNames = [
"Error",
"EvalError",
"RangeError",
"ReferenceError",
"SyntaxError",
"TypeError",
"URIError",
"AggregateError",
]
const errorsTraceMap = {}
for (const errorConstructorName of errorConstructorNames) {
errorsTraceMap[errorConstructorName] = { [CONSTRUCT]: true, [READ]: true }
}
/**
* @param {Node} node
* @returns {boolean}
*/
function isSuperCall(node) {
return node.type === "CallExpression" && node.callee.type === "Super"
}
/**
* @param {Node|undefined} node
* @returns {boolean}
*/
function isSpreadElement(node) {
return node && node.type === "SpreadElement"
}
/**
* @param {Node} node
* @returns {ClassNode | null}
*/
function findClassFromAncestors(node) {
if (node.type !== "ClassExpression" && node.type !== "ClassDeclaration") {
return findClassFromAncestors(node.parent)
}
if (!node) {
return null
}
return node
}
module.exports = {
meta: {
docs: {
description: "disallow Error Cause.",
category: "ES2022",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-error-cause.html",
},
fixable: null,
messages: {
forbidden: "ES2022 Error Cause is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = getSourceCode(context)
/** @type {Array<{ classNode: ClassNode, superCallNode: CallExpression }>} */
const maybeErrorSubclasses = []
/** @type {Array<{ classNode: ClassNode, superCallNode: CallExpression }>} */
const maybeAggregateErrorSubclasses = []
/**
* Checks if the received node is a constructor call with cause option.
* e.g. `new Error("message", { cause: foo })`, `super("message", { cause: foo })`
*
* @param {Node} node
* @param {boolean} isAggregateError
* @returns {boolean}
*/
function isConstructCallWithCauseOption(node, isAggregateError) {
if (node.type !== "NewExpression" && !isSuperCall(node)) {
return false
}
const optionsArgIndex = isAggregateError ? 2 : 1
for (let index = 0; index < optionsArgIndex; index++) {
if (isSpreadElement(node.arguments[index])) {
return false
}
}
const optionsArg = node.arguments[optionsArgIndex]
if (!optionsArg || optionsArg.type !== "ObjectExpression") {
return false
}
return optionsArg.properties.some((property) => {
if (property.type !== "Property") {
return false
}
// new Error("msg", { cause: foo })
return (
getPropertyName(property, sourceCode.getScope(node)) ===
"cause"
)
})
}
/**
* @param {Node} node
* @param {isAggregateError} boolean
* @return {Node | null}
*/
function getReportedNode(node, isAggregateError) {
const errorSubclasses = isAggregateError
? maybeAggregateErrorSubclasses
: maybeErrorSubclasses
if (errorSubclasses.length > 0) {
for (const { classNode, superCallNode } of errorSubclasses) {
if (classNode.superClass === node) {
return superCallNode
}
}
}
if (isConstructCallWithCauseOption(node, isAggregateError)) {
return node
}
return null
}
return {
Super(node) {
const superCallNode = node.parent
function findErrorSubclasses(isAggregateError) {
const errorSubclasses = isAggregateError
? maybeAggregateErrorSubclasses
: maybeErrorSubclasses
if (
isConstructCallWithCauseOption(
superCallNode,
isAggregateError,
)
) {
const classNode = findClassFromAncestors(superCallNode)
if (classNode && classNode.superClass) {
errorSubclasses.push({ classNode, superCallNode })
}
}
}
findErrorSubclasses(/* isAggregateError */ false)
findErrorSubclasses(/* isAggregateError */ true)
},
"Program:exit"(program) {
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences(
errorsTraceMap,
)) {
const reportedNode = getReportedNode(
node,
path.join(",") === "AggregateError",
)
if (reportedNode) {
context.report({
node: reportedNode,
messageId: "forbidden",
})
}
}
},
}
},
}

View file

@ -1,41 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow `escape` and `unescape`",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-escape-unescape.html",
},
fixable: null,
messages: {
forbidden: "Annex B feature '{{name}}' is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
escape: { [READ]: true },
unescape: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,31 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow exponential operators.",
category: "ES2016",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-exponential-operators.html",
},
fixable: null,
messages: {
forbidden: "ES2016 exponential operators are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"AssignmentExpression[operator='**='], BinaryExpression[operator='**']"(
node,
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow `export * as ns`.",
category: "ES2020",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-export-ns-from.html",
},
fixable: null,
messages: {
forbidden: "ES2020 'export * as ns' are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ExportAllDeclaration[exported!=null]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow `for-of` statements.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-for-of-loops.html",
},
fixable: null,
messages: {
forbidden: "ES2015 'for-of' statements are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
ForOfStatement(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,38 +0,0 @@
"use strict"
module.exports = {
meta: {
docs: {
description:
"disallow function declarations in if statement clauses without using blocks.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-function-declarations-in-if-statement-clauses-without-block.html",
},
fixable: "code",
messages: {
forbidden:
"Annex B feature the function declarations in if statement clauses without using blocks are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"IfStatement > FunctionDeclaration.consequent, IfStatement > FunctionDeclaration.alternate"(
node,
) {
context.report({
node,
messageId: "forbidden",
fix(fixer) {
return [
fixer.insertTextBefore(node, "{"),
fixer.insertTextAfter(node, "}"),
]
},
})
},
}
},
}

View file

@ -1,39 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description: "disallow the `Function.prototype.bind` method.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-function-prototype-bind.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Function: ["bind"],
})
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow generator function declarations.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-generators.html",
},
fixable: null,
messages: {
forbidden: "ES2015 generator function declarations are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":function[generator=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,44 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `globalThis` variable",
category: "ES2020",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-global-this.html",
},
fixable: null,
messages: {
forbidden: "ES2020 '{{name}}' variable is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
globalThis: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,33 +0,0 @@
"use strict"
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow Hashbang comments.",
category: "ES2023",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-hashbang.html",
},
fixable: null,
messages: {
forbidden: "ES2023 Hashbang comments are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
Program() {
const firstComment = getSourceCode(context).ast.comments[0]
if (firstComment && firstComment.type === "Shebang") {
context.report({
node: firstComment,
messageId: "forbidden",
})
}
},
}
},
}

View file

@ -1,29 +0,0 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow `import.meta` meta property.",
category: "ES2020",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-import-meta.html",
},
fixable: null,
messages: {
forbidden: "ES2020 'import.meta' meta property is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"MetaProperty[meta.name='import'][property.name='meta']"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,28 +0,0 @@
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow initializers in for-in heads.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-initializers-in-for-in.html",
},
fixable: null,
messages: {
forbidden:
"Annex B feature the initializers in for-in heads are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ForInStatement > VariableDeclaration.left > VariableDeclarator.declarations > *.init"(
node,
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `Intl.DateTimeFormat.prototype.formatRange` method.",
category: "ES2021-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-datetimeformat-prototype-formatrange.html",
},
fixable: null,
messages: {
forbidden: "ES2021 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.DateTimeFormat": ["formatRange"],
})
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `DateTimeFormat.prototype.formatToParts` method.",
category: "ES2017-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-datetimeformat-prototype-formattoparts.html",
},
fixable: null,
messages: {
forbidden: "ES2017 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.DateTimeFormat": ["formatToParts"],
})
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.DisplayNames` object.",
category: "ES2021-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-displaynames.html",
},
fixable: null,
messages: {
forbidden: "ES2021 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
DisplayNames: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.getCanonicalLocales` method.",
category: "ES2016-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-getcanonicallocales.html",
},
fixable: null,
messages: {
forbidden: "ES2016 Intl API '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
getCanonicalLocales: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.ListFormat` object.",
category: "ES2021-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-listformat.html",
},
fixable: null,
messages: {
forbidden: "ES2021 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
ListFormat: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.Locale` object.",
category: "ES2020-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-locale.html",
},
fixable: null,
messages: {
forbidden: "ES2020 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
Locale: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `NumberFormat.prototype.formatRange` method.",
category: "ES2023-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-numberformat-prototype-formatrange.html",
},
fixable: null,
messages: {
forbidden: "ES2023 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.NumberFormat": ["formatRange"],
})
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `NumberFormat.prototype.formatRangeToParts` method.",
category: "ES2023-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-numberformat-prototype-formatrangetoparts.html",
},
fixable: null,
messages: {
forbidden: "ES2023 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.NumberFormat": ["formatRangeToParts"],
})
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `NumberFormat.prototype.formatToParts` method.",
category: "ES2018-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-numberformat-prototype-formattoparts.html",
},
fixable: null,
messages: {
forbidden: "ES2018 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.NumberFormat": ["formatToParts"],
})
},
}

View file

@ -1,36 +0,0 @@
"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `PluralRules.prototype.selectRange` method.",
category: "ES2023-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-pluralrules-prototype-selectrange.html",
},
fixable: null,
messages: {
forbidden: "ES2023 Intl API '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
"Intl.PluralRules": ["selectRange"],
})
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.PluralRules` object.",
category: "ES2018-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-pluralrules.html",
},
fixable: null,
messages: {
forbidden: "ES2018 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
PluralRules: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.RelativeTimeFormat` object.",
category: "ES2020-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-relativetimeformat.html",
},
fixable: null,
messages: {
forbidden: "ES2020 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
RelativeTimeFormat: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.Segmenter` object.",
category: "ES2022-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-segmenter.html",
},
fixable: null,
messages: {
forbidden: "ES2022 Intl API '{{name}}' object is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
Segmenter: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,42 +0,0 @@
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Intl.supportedValuesOf` method.",
category: "ES2022-Intl-API",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-intl-supportedvaluesof.html",
},
fixable: null,
messages: {
forbidden: "ES2022 Intl API '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Intl: {
supportedValuesOf: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,55 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { getSourceCode } = require("eslint-compat-utils")
const { definePatternSearchGenerator } = require("../utils")
const iterateTargetChars = definePatternSearchGenerator(/[\u2028\u2029]/gu)
module.exports = {
meta: {
docs: {
description: "disallow `\\u2028` and `\\u2029` in string literals.",
category: "ES2019",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-json-superset.html",
},
fixable: "code",
messages: {
forbidden: "ES2019 '\\u{{code}}' in string literals is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = getSourceCode(context)
return {
Literal(node) {
if (typeof node.value !== "string") {
return
}
const offset = node.range[0]
for (const { index } of iterateTargetChars(node.raw)) {
const code = node.raw.codePointAt(index).toString(16)
const loc = sourceCode.getLocFromIndex(offset + index)
context.report({
node,
loc,
messageId: "forbidden",
data: { code },
fix(fixer) {
return fixer.replaceTextRange(
[offset + index, offset + index + 1],
`\\u${code}`,
)
},
})
}
},
}
},
}

View file

@ -1,44 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `JSON` class.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-json.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
JSON: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,107 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
// https://www-archive.mozilla.org/js/language/E262-3.pdf
const keywords = new Set([
"abstract",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"double",
"else",
"enum",
"export",
"extends",
"false",
"final",
"finally",
"float",
"for",
"function",
"goto",
"if",
"implements",
"import",
"in",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"typeof",
"var",
"void",
"volatile",
"while",
"with",
])
module.exports = {
meta: {
docs: {
description: "disallow reserved words as property names.",
category: "ES5",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-keyword-properties.html",
},
fixable: null,
messages: {
forbidden: "ES5 reserved words as property names are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
Property(node) {
if (
!node.computed &&
node.key.type === "Identifier" &&
keywords.has(node.key.name)
) {
context.report({ node, messageId: "forbidden" })
}
},
MemberExpression(node) {
if (
!node.computed &&
node.property.type === "Identifier" &&
keywords.has(node.property.name)
) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}

View file

@ -1,26 +0,0 @@
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow labelled function declarations.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-labelled-function-declarations.html",
},
fixable: null,
messages: {
forbidden:
"Annex B feature the labelled function declarations are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"LabeledStatement > FunctionDeclaration.body"(node) {
context.report({ node: node.parent, messageId: "forbidden" })
},
}
},
}

View file

@ -1,99 +0,0 @@
"use strict"
const {
getPropertyName,
findVariable,
} = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
const LEGACY_ACCESSOR_METHODS = new Set([
"__defineGetter__",
"__defineSetter__",
"__lookupGetter__",
"__lookupSetter__",
])
module.exports = {
meta: {
docs: {
description: "disallow legacy `Object.prototype` accessor methods.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-legacy-object-prototype-accessor-methods.html",
},
fixable: null,
messages: {
forbidden: "LEGACY '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const reported = new Set()
function report(name, node) {
if (reported.has(node)) {
return
}
reported.add(node)
context.report({
node,
messageId: "forbidden",
data: {
name,
},
})
}
return {
MemberExpression(node) {
const name = getPropertyName(node)
if (!LEGACY_ACCESSOR_METHODS.has(name)) {
return
}
report(name, node.property)
},
Identifier(node) {
const name = node.name
if (!LEGACY_ACCESSOR_METHODS.has(name)) {
return
}
if (
node.parent.type === "MemberExpression" &&
node.parent.property === node
) {
// Already reported.
return
}
if (
node.parent.type === "Property" &&
!node.parent.shorthand &&
node.parent.key === node
) {
return
}
const sourceCode = getSourceCode(context)
const scopeManager = sourceCode.scopeManager
if (
// Not defined as global variables.
!scopeManager.globalScope.through.some(
({ identifier }) => identifier === node,
)
) {
const variable = findVariable(
sourceCode.getScope(node),
node,
)
if (!variable) {
return
}
// It is defined as global variables.
if (variable.defs.length) {
return
}
}
report(name, node)
},
}
},
}

View file

@ -1,60 +0,0 @@
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
"use strict"
const utils = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow logical assignment operators.",
category: "ES2021",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-logical-assignment-operators.html",
},
fixable: "code",
messages: {
forbidden: "ES2021 logical assignment operators are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = getSourceCode(context)
return {
"AssignmentExpression[operator=/(?:\\|\\||&&|\\?\\?)=/]"(node) {
const operatorToken = sourceCode.getTokenAfter(node.left)
context.report({
node: operatorToken,
messageId: "forbidden",
fix(fixer) {
if (node.left.type !== "Identifier") {
return null
}
const newOperator = node.operator.slice(-1)
const biOperator = node.operator.slice(0, -1)
const varText = sourceCode.getText(node.left)
const results = [
fixer.replaceText(operatorToken, newOperator),
fixer.insertTextAfter(
operatorToken,
` ${varText} ${biOperator}`,
),
]
if (!utils.isParenthesized(node.right, sourceCode)) {
results.push(
fixer.insertTextBefore(node.right, "("),
fixer.insertTextAfter(node.right, ")"),
)
}
return results
},
})
},
}
},
}

View file

@ -1,36 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description:
"disallow template literals with invalid escape sequences.",
category: "ES2018",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-malformed-template-literals.html",
},
fixable: null,
messages: {
forbidden:
"ES2018 template literals with invalid escape sequences are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const reported = new Set()
return {
"TemplateElement[value.cooked=null]"(elementNode) {
const node = elementNode.parent
if (!reported.has(node)) {
reported.add(node)
context.report({ node, messageId: "forbidden" })
}
},
}
},
}

View file

@ -1,44 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Map` class.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-map.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Map: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.acosh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-acosh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
acosh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.asinh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-asinh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
asinh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.atanh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-atanh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
atanh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.cbrt` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-cbrt.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
cbrt: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.clz32` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-clz32.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
clz32: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.cosh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-cosh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
cosh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.expm1` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-expm1.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
expm1: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.fround` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-fround.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
fround: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.hypot` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-hypot.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
hypot: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.imul` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-imul.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
imul: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log10` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-log10.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log10: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log1p` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-log1p.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log1p: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log2` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-log2.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log2: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.sign` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-sign.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
sign: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.sinh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-sinh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
sinh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.tanh` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-tanh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
tanh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

View file

@ -1,46 +0,0 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.trunc` method.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-math-trunc.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
trunc: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}

Some files were not shown because too many files have changed in this diff Show more