This commit is contained in:
2022-07-21 03:28:35 +00:00
parent d7c883d6df
commit 51b34b0e1d
30103 changed files with 4152204 additions and 23 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Toru Nagashima
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+44
View File
@@ -0,0 +1,44 @@
# eslint-plugin-es
[![npm version](https://img.shields.io/npm/v/eslint-plugin-es.svg)](https://www.npmjs.com/package/eslint-plugin-es)
[![Downloads/month](https://img.shields.io/npm/dm/eslint-plugin-es.svg)](http://www.npmtrends.com/eslint-plugin-es)
[![Build Status](https://github.com/mysticatea/eslint-plugin-es/workflows/CI/badge.svg)](https://github.com/mysticatea/eslint-plugin-es/actions)
[![Coverage Status](https://codecov.io/gh/mysticatea/eslint-plugin-es/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/eslint-plugin-es)
[![Dependency Status](https://david-dm.org/mysticatea/eslint-plugin-es.svg)](https://david-dm.org/mysticatea/eslint-plugin-es)
ESLint plugin which disallows each ECMAScript syntax.
## 🏁 Goal
[Espree](https://github.com/eslint/espree#readme), the default parser of [ESLint](https://eslint.org/), has supported `ecmaVersion` option.
However, it doesn't support to enable each syntactic feature individually.
This plugin lets us disable each syntactic feature individually.
So we can enable arbitrary syntactic features with the combination of `ecmaVersion` and this plugin.
## 📖 Usage
See [documentation](https://eslint-plugin-es.mysticatea.dev/)
## 🚥 Semantic Versioning Policy
This plugin follows [semantic versioning](http://semver.org/) and [ESLint's semantic versioning policy](https://github.com/eslint/eslint#semantic-versioning-policy).
## 📰 Changelog
See [releases](https://github.com/mysticatea/eslint-plugin-es/releases).
## ❤️ Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
### Development Tools
- `npm test` runs tests and measures coverage.
- `npm run clean` removes the coverage result of `npm test` command.
- `npm run coverage` shows the coverage result of the last `npm test` command.
- `npm run docs:build` builds documentation.
- `npm run docs:watch` builds documentation on each file change.
- `npm run watch` runs tests on each file change.
+242
View File
@@ -0,0 +1,242 @@
/**
* DON'T EDIT THIS FILE.
* This file was generated automatically by 'scripts/update-index.js'.
*/
"use strict"
module.exports = {
configs: {
"no-2019": {
rules: {
"es/no-json-superset": "error",
"es/no-optional-catch-binding": "error",
"es/no-regexp-unicode-property-escapes-2019": "error",
},
},
"no-2018": {
rules: {
"es/no-async-iteration": "error",
"es/no-malformed-template-literals": "error",
"es/no-regexp-lookbehind-assertions": "error",
"es/no-regexp-named-capture-groups": "error",
"es/no-regexp-s-flag": "error",
"es/no-regexp-unicode-property-escapes": "error",
"es/no-rest-spread-properties": "error",
},
},
"no-2017": {
rules: {
"es/no-async-functions": "error",
"es/no-atomics": "error",
"es/no-object-entries": "error",
"es/no-object-getownpropertydescriptors": "error",
"es/no-object-values": "error",
"es/no-shared-array-buffer": "error",
"es/no-trailing-function-commas": "error",
},
},
"no-2016": {
rules: {
"es/no-exponential-operators": "error",
},
},
"no-2015": {
rules: {
"es/no-array-from": "error",
"es/no-array-of": "error",
"es/no-arrow-functions": "error",
"es/no-binary-numeric-literals": "error",
"es/no-block-scoped-functions": "error",
"es/no-block-scoped-variables": "error",
"es/no-classes": "error",
"es/no-computed-properties": "error",
"es/no-default-parameters": "error",
"es/no-destructuring": "error",
"es/no-for-of-loops": "error",
"es/no-generators": "error",
"es/no-map": "error",
"es/no-math-acosh": "error",
"es/no-math-asinh": "error",
"es/no-math-atanh": "error",
"es/no-math-cbrt": "error",
"es/no-math-clz32": "error",
"es/no-math-cosh": "error",
"es/no-math-expm1": "error",
"es/no-math-fround": "error",
"es/no-math-hypot": "error",
"es/no-math-imul": "error",
"es/no-math-log10": "error",
"es/no-math-log1p": "error",
"es/no-math-log2": "error",
"es/no-math-sign": "error",
"es/no-math-sinh": "error",
"es/no-math-tanh": "error",
"es/no-math-trunc": "error",
"es/no-modules": "error",
"es/no-new-target": "error",
"es/no-number-epsilon": "error",
"es/no-number-isfinite": "error",
"es/no-number-isinteger": "error",
"es/no-number-isnan": "error",
"es/no-number-issafeinteger": "error",
"es/no-number-maxsafeinteger": "error",
"es/no-number-minsafeinteger": "error",
"es/no-number-parsefloat": "error",
"es/no-number-parseint": "error",
"es/no-object-assign": "error",
"es/no-object-getownpropertysymbols": "error",
"es/no-object-is": "error",
"es/no-object-setprototypeof": "error",
"es/no-object-super-properties": "error",
"es/no-octal-numeric-literals": "error",
"es/no-promise": "error",
"es/no-property-shorthands": "error",
"es/no-proxy": "error",
"es/no-reflect": "error",
"es/no-regexp-u-flag": "error",
"es/no-regexp-y-flag": "error",
"es/no-rest-parameters": "error",
"es/no-set": "error",
"es/no-spread-elements": "error",
"es/no-string-fromcodepoint": "error",
"es/no-string-raw": "error",
"es/no-subclassing-builtins": "error",
"es/no-symbol": "error",
"es/no-template-literals": "error",
"es/no-typed-arrays": "error",
"es/no-unicode-codepoint-escapes": "error",
"es/no-weak-map": "error",
"es/no-weak-set": "error",
},
},
"no-5": {
rules: {
"es/no-accessor-properties": "error",
"es/no-array-isarray": "error",
"es/no-date-now": "error",
"es/no-json": "error",
"es/no-keyword-properties": "error",
"es/no-object-defineproperties": "error",
"es/no-object-defineproperty": "error",
"es/no-object-freeze": "error",
"es/no-object-getownpropertydescriptor": "error",
"es/no-object-getownpropertynames": "error",
"es/no-object-getprototypeof": "error",
"es/no-object-isextensible": "error",
"es/no-object-isfrozen": "error",
"es/no-object-issealed": "error",
"es/no-object-keys": "error",
"es/no-object-preventextensions": "error",
"es/no-object-seal": "error",
"es/no-trailing-commas": "error",
},
},
},
rules: {
"no-accessor-properties": require("./rules/no-accessor-properties"),
"no-array-from": require("./rules/no-array-from"),
"no-array-isarray": require("./rules/no-array-isarray"),
"no-array-of": require("./rules/no-array-of"),
"no-arrow-functions": require("./rules/no-arrow-functions"),
"no-async-functions": require("./rules/no-async-functions"),
"no-async-iteration": require("./rules/no-async-iteration"),
"no-atomics": require("./rules/no-atomics"),
"no-bigint": require("./rules/no-bigint"),
"no-binary-numeric-literals": require("./rules/no-binary-numeric-literals"),
"no-block-scoped-functions": require("./rules/no-block-scoped-functions"),
"no-block-scoped-variables": require("./rules/no-block-scoped-variables"),
"no-classes": require("./rules/no-classes"),
"no-computed-properties": require("./rules/no-computed-properties"),
"no-date-now": require("./rules/no-date-now"),
"no-default-parameters": require("./rules/no-default-parameters"),
"no-destructuring": require("./rules/no-destructuring"),
"no-dynamic-import": require("./rules/no-dynamic-import"),
"no-exponential-operators": require("./rules/no-exponential-operators"),
"no-for-of-loops": require("./rules/no-for-of-loops"),
"no-generators": require("./rules/no-generators"),
"no-global-this": require("./rules/no-global-this"),
"no-json-superset": require("./rules/no-json-superset"),
"no-json": require("./rules/no-json"),
"no-keyword-properties": require("./rules/no-keyword-properties"),
"no-malformed-template-literals": require("./rules/no-malformed-template-literals"),
"no-map": require("./rules/no-map"),
"no-math-acosh": require("./rules/no-math-acosh"),
"no-math-asinh": require("./rules/no-math-asinh"),
"no-math-atanh": require("./rules/no-math-atanh"),
"no-math-cbrt": require("./rules/no-math-cbrt"),
"no-math-clz32": require("./rules/no-math-clz32"),
"no-math-cosh": require("./rules/no-math-cosh"),
"no-math-expm1": require("./rules/no-math-expm1"),
"no-math-fround": require("./rules/no-math-fround"),
"no-math-hypot": require("./rules/no-math-hypot"),
"no-math-imul": require("./rules/no-math-imul"),
"no-math-log10": require("./rules/no-math-log10"),
"no-math-log1p": require("./rules/no-math-log1p"),
"no-math-log2": require("./rules/no-math-log2"),
"no-math-sign": require("./rules/no-math-sign"),
"no-math-sinh": require("./rules/no-math-sinh"),
"no-math-tanh": require("./rules/no-math-tanh"),
"no-math-trunc": require("./rules/no-math-trunc"),
"no-modules": require("./rules/no-modules"),
"no-new-target": require("./rules/no-new-target"),
"no-number-epsilon": require("./rules/no-number-epsilon"),
"no-number-isfinite": require("./rules/no-number-isfinite"),
"no-number-isinteger": require("./rules/no-number-isinteger"),
"no-number-isnan": require("./rules/no-number-isnan"),
"no-number-issafeinteger": require("./rules/no-number-issafeinteger"),
"no-number-maxsafeinteger": require("./rules/no-number-maxsafeinteger"),
"no-number-minsafeinteger": require("./rules/no-number-minsafeinteger"),
"no-number-parsefloat": require("./rules/no-number-parsefloat"),
"no-number-parseint": require("./rules/no-number-parseint"),
"no-object-assign": require("./rules/no-object-assign"),
"no-object-defineproperties": require("./rules/no-object-defineproperties"),
"no-object-defineproperty": require("./rules/no-object-defineproperty"),
"no-object-entries": require("./rules/no-object-entries"),
"no-object-freeze": require("./rules/no-object-freeze"),
"no-object-getownpropertydescriptor": require("./rules/no-object-getownpropertydescriptor"),
"no-object-getownpropertydescriptors": require("./rules/no-object-getownpropertydescriptors"),
"no-object-getownpropertynames": require("./rules/no-object-getownpropertynames"),
"no-object-getownpropertysymbols": require("./rules/no-object-getownpropertysymbols"),
"no-object-getprototypeof": require("./rules/no-object-getprototypeof"),
"no-object-is": require("./rules/no-object-is"),
"no-object-isextensible": require("./rules/no-object-isextensible"),
"no-object-isfrozen": require("./rules/no-object-isfrozen"),
"no-object-issealed": require("./rules/no-object-issealed"),
"no-object-keys": require("./rules/no-object-keys"),
"no-object-preventextensions": require("./rules/no-object-preventextensions"),
"no-object-seal": require("./rules/no-object-seal"),
"no-object-setprototypeof": require("./rules/no-object-setprototypeof"),
"no-object-super-properties": require("./rules/no-object-super-properties"),
"no-object-values": require("./rules/no-object-values"),
"no-octal-numeric-literals": require("./rules/no-octal-numeric-literals"),
"no-optional-catch-binding": require("./rules/no-optional-catch-binding"),
"no-promise-all-settled": require("./rules/no-promise-all-settled"),
"no-promise": require("./rules/no-promise"),
"no-property-shorthands": require("./rules/no-property-shorthands"),
"no-proxy": require("./rules/no-proxy"),
"no-reflect": require("./rules/no-reflect"),
"no-regexp-lookbehind-assertions": require("./rules/no-regexp-lookbehind-assertions"),
"no-regexp-named-capture-groups": require("./rules/no-regexp-named-capture-groups"),
"no-regexp-s-flag": require("./rules/no-regexp-s-flag"),
"no-regexp-u-flag": require("./rules/no-regexp-u-flag"),
"no-regexp-unicode-property-escapes-2019": require("./rules/no-regexp-unicode-property-escapes-2019"),
"no-regexp-unicode-property-escapes": require("./rules/no-regexp-unicode-property-escapes"),
"no-regexp-y-flag": require("./rules/no-regexp-y-flag"),
"no-rest-parameters": require("./rules/no-rest-parameters"),
"no-rest-spread-properties": require("./rules/no-rest-spread-properties"),
"no-set": require("./rules/no-set"),
"no-shared-array-buffer": require("./rules/no-shared-array-buffer"),
"no-spread-elements": require("./rules/no-spread-elements"),
"no-string-fromcodepoint": require("./rules/no-string-fromcodepoint"),
"no-string-raw": require("./rules/no-string-raw"),
"no-subclassing-builtins": require("./rules/no-subclassing-builtins"),
"no-symbol": require("./rules/no-symbol"),
"no-template-literals": require("./rules/no-template-literals"),
"no-trailing-commas": require("./rules/no-trailing-commas"),
"no-trailing-function-commas": require("./rules/no-trailing-function-commas"),
"no-typed-arrays": require("./rules/no-typed-arrays"),
"no-unicode-codepoint-escapes": require("./rules/no-unicode-codepoint-escapes"),
"no-weak-map": require("./rules/no-weak-map"),
"no-weak-set": require("./rules/no-weak-set"),
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.from` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-array-from.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
from: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.isArray` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-array-isarray.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
isArray: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Array.of` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-array-of.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
of: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+129
View File
@@ -0,0 +1,129 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { isArrowToken, isParenthesized } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow arrow function expressions.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-arrow-functions.html",
},
fixable: "code",
messages: {
forbidden: "ES2015 arrow function expressions are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = context.getSourceCode()
/**
* 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 @mysticatea/prettier */
node.body.type === "BlockStatement" ? (
`function(${paramText}) ${bodyText}`
) : preText.includes("\n") ? (
`function(${paramText}) { return (${bodyText}) }`
) : (
`function(${paramText}) { return ${bodyText} }`
)
/*eslint-enable @mysticatea/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
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+33
View File
@@ -0,0 +1,33 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Atomics` class.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-atomics.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Atomics: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+47
View File
@@ -0,0 +1,47 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow `bigint` syntax and built-ins",
category: "ES2020",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/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"() {
const tracker = new ReferenceTracker(context.getScope())
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 })
}
},
}
},
}
+34
View File
@@ -0,0 +1,34 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
}
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Date.now` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-date-now.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Date: {
now: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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 })
},
}
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `globalThis` variable",
category: "ES2020",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-global-this.html",
},
fixable: null,
messages: {
forbidden: "ES2020 '{{name}}' variable is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
globalThis: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+55
View File
@@ -0,0 +1,55 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
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://mysticatea.github.io/eslint-plugin-es/rules/no-json-superset.html",
},
fixable: "code",
messages: {
forbidden: "ES2019 '\\u{{code}}' in string literals is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = context.getSourceCode()
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}`
)
},
})
}
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `JSON` class.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-json.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
JSON: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+108
View File
@@ -0,0 +1,108 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
}
},
}
},
}
@@ -0,0 +1,37 @@
/**
* @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://mysticatea.github.io/eslint-plugin-es/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" })
}
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Map` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-map.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Map: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.acosh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-acosh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
acosh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.asinh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-asinh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
asinh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.atanh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-atanh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
atanh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.cbrt` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-cbrt.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
cbrt: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.clz32` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-clz32.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
clz32: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.cosh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-cosh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
cosh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.expm1` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-expm1.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
expm1: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.fround` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-fround.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
fround: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.hypot` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-hypot.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
hypot: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.imul` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-imul.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
imul: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log10` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-log10.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log10: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log1p` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-log1p.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log1p: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.log2` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-log2.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
log2: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.sign` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-sign.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
sign: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.sinh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-sinh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
sinh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.tanh` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-tanh.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
tanh: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Math.trunc` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-math-trunc.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Math: {
trunc: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow modules.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-modules.html",
},
fixable: null,
messages: {
forbidden: "ES2015 modules are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow `new.target` meta property.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-new-target.html",
},
fixable: null,
messages: {
forbidden: "ES2015 'new.target' meta property is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"MetaProperty[meta.name='new'][property.name='target']"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.EPSILON` property.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-epsilon.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
EPSILON: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.isFinite` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-isfinite.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
isFinite: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.isInteger` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-isinteger.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
isInteger: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.isNaN` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-isnan.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
isNaN: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.isSafeInteger` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-issafeinteger.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
isSafeInteger: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.MAX_SAFE_INTEGER` property.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-maxsafeinteger.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
MAX_SAFE_INTEGER: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.MIN_SAFE_INTEGER` property.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-minsafeinteger.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
MIN_SAFE_INTEGER: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.parseFloat` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-parsefloat.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
parseFloat: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Number.parseInt` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-number-parseint.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Number: {
parseInt: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.assign` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-assign.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
assign: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.defineProperties` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-defineproperties.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
defineProperties: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.defineProperty` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-defineproperty.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
defineProperty: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.entries` method.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-entries.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
entries: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.freeze` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-freeze.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
freeze: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,44 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description:
"disallow the `Object.getOwnPropertyDescriptor` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertydescriptor.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
getOwnPropertyDescriptor: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,44 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description:
"disallow the `Object.getOwnPropertyDescriptors` method.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertydescriptors.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
getOwnPropertyDescriptors: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.getOwnPropertyNames` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertynames.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
getOwnPropertyNames: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.getOwnPropertySymbols` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertysymbols.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
getOwnPropertySymbols: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.getPrototypeOf` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getprototypeof.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
getPrototypeOf: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.is` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-is.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
is: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.isExtensible` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-isextensible.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
isExtensible: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.isFrozen` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-isfrozen.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
isFrozen: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.isSealed` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-issealed.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
isSealed: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.keys` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-keys.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
keys: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.preventExtensions` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-preventextensions.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
preventExtensions: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.seal` method.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-seal.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
seal: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.setPrototypeOf` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-setprototypeof.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
setPrototypeOf: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+47
View File
@@ -0,0 +1,47 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description:
"disallow `super` property accesses in object literals.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-super-properties.html",
},
fixable: null,
messages: {
forbidden:
"ES2015 'super' property accesses in object literals are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
let stack = null
return {
Super(node) {
if (stack && stack.inObjectMethod) {
context.report({ node, messageId: "forbidden" })
}
},
":matches(FunctionExpression, FunctionDeclaration)"(node) {
const { type, method } = node.parent
stack = {
inObjectMethod: type === "Property" && method === true,
upper: stack,
}
},
":matches(FunctionExpression, FunctionDeclaration):exit"() {
stack = stack.upper
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Object.values` method.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-values.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Object: {
values: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+34
View File
@@ -0,0 +1,34 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const Pattern = /^0[oO]/u
module.exports = {
meta: {
docs: {
description: "disallow octal numeric literals.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-octal-numeric-literals.html",
},
fixable: null,
messages: {
forbidden: "ES2015 octal 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" })
}
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow optional `catch` binding.",
category: "ES2019",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-optional-catch-binding.html",
},
fixable: null,
messages: {
forbidden: "ES2019 optional 'catch' binding is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"CatchClause[param=null]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+37
View File
@@ -0,0 +1,37 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow `Promise.allSettled` function",
category: "ES2020",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-promise-all-settled.html",
},
fixable: null,
messages: {
forbidden: "ES2020 'Promise.allSettled' function is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node } of tracker.iterateGlobalReferences({
Promise: { allSettled: { [READ]: true } },
})) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Promise` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-promise.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Promise: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+78
View File
@@ -0,0 +1,78 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { isOpeningBracketToken, isClosingBracketToken } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow property shorthands.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-property-shorthands.html",
},
fixable: "code",
messages: {
forbidden: "ES2015 property shorthands are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
const sourceCode = context.getSourceCode()
/**
* Fixes a FunctionExpression node by making it into a longform property.
* @param {SourceCodeFixer} fixer The fixer object
* @param {ASTNode} node A `Property` node that has a `FunctionExpression` as its value
* @returns {object} A fix for this node
*/
function makeFunctionLongform(fixer, node) {
const firstKeyToken = node.computed
? sourceCode.getTokenBefore(node.key, isOpeningBracketToken)
: sourceCode.getFirstToken(node.key)
const lastKeyToken = node.computed
? sourceCode.getTokenAfter(node.key, isClosingBracketToken)
: sourceCode.getLastToken(node.key)
const keyText = sourceCode.text.slice(
firstKeyToken.range[0],
lastKeyToken.range[1]
)
let functionHeader = "function"
if (node.value.async) {
functionHeader = `async ${functionHeader}`
}
if (node.value.generator) {
functionHeader = `${functionHeader}*`
}
return fixer.replaceTextRange(
[node.range[0], lastKeyToken.range[1]],
`${keyText}: ${functionHeader}`
)
}
return {
"ObjectExpression > :matches(Property[method=true], Property[shorthand=true])"(
node
) {
context.report({
node,
messageId: "forbidden",
fix: node.method
? fixer => makeFunctionLongform(fixer, node)
: fixer =>
fixer.insertTextAfter(
node.key,
`: ${node.key.name}`
),
})
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Proxy` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-proxy.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Proxy: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Reflect` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-reflect.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Reflect: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,74 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { RegExpValidator } = require("regexpp")
const { getRegExpCalls } = require("../utils")
/**
* Verify a given regular expression.
* @param {RuleContext} context The rule context to report.
* @param {Node} node The AST node to report.
* @param {string} pattern The pattern part of a RegExp.
* @param {string} flags The flags part of a RegExp.
* @returns {void}
*/
function verify(context, node, pattern, flags) {
try {
let found = false
new RegExpValidator({
onLookaroundAssertionEnter(_start, kind) {
if (kind === "lookbehind") {
found = true
}
},
}).validatePattern(pattern, 0, pattern.length, flags.includes("u"))
if (found) {
context.report({ node, messageId: "forbidden" })
}
} catch (error) {
//istanbul ignore else
if (error.message.startsWith("Invalid regular expression:")) {
return
}
//istanbul ignore next
throw error
}
}
module.exports = {
meta: {
docs: {
description: "disallow RegExp lookbehind assertions.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-lookbehind-assertions.html",
},
fixable: null,
messages: {
forbidden: "ES2018 RegExp lookbehind assertions are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
const { pattern, flags } = node.regex
verify(context, node, pattern || "", flags || "")
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, pattern, flags } of getRegExpCalls(scope)) {
verify(context, node, pattern || "", flags || "")
}
},
}
},
}
@@ -0,0 +1,79 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { RegExpValidator } = require("regexpp")
const { getRegExpCalls } = require("../utils")
/**
* Verify a given regular expression.
* @param {RuleContext} context The rule context to report.
* @param {Node} node The AST node to report.
* @param {string} pattern The pattern part of a RegExp.
* @param {string} flags The flags part of a RegExp.
* @returns {void}
*/
function verify(context, node, pattern, flags) {
try {
let found = false
new RegExpValidator({
onCapturingGroupEnter(_start, name) {
if (name) {
found = true
}
},
onBackreference(_start, _end, ref) {
if (typeof ref === "string") {
found = true
}
},
}).validatePattern(pattern, 0, pattern.length, flags.includes("u"))
if (found) {
context.report({ node, messageId: "forbidden" })
}
} catch (error) {
//istanbul ignore else
if (error.message.startsWith("Invalid regular expression:")) {
return
}
//istanbul ignore next
throw error
}
}
module.exports = {
meta: {
docs: {
description: "disallow RegExp named capture groups.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-named-capture-groups.html",
},
fixable: null,
messages: {
forbidden: "ES2018 RegExp named capture groups are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
const { pattern, flags } = node.regex
verify(context, node, pattern || "", flags || "")
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, pattern, flags } of getRegExpCalls(scope)) {
verify(context, node, pattern || "", flags || "")
}
},
}
},
}
+44
View File
@@ -0,0 +1,44 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { getRegExpCalls } = require("../utils")
module.exports = {
meta: {
docs: {
description: "disallow RegExp `s` flag.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-s-flag.html",
},
fixable: null,
messages: {
forbidden: "ES2018 RegExp 's' flag is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
if (node.regex.flags.includes("s")) {
context.report({ node, messageId: "forbidden" })
}
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, flags } of getRegExpCalls(scope)) {
if (flags && flags.includes("s")) {
context.report({ node, messageId: "forbidden" })
}
}
},
}
},
}
+44
View File
@@ -0,0 +1,44 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { getRegExpCalls } = require("../utils")
module.exports = {
meta: {
docs: {
description: "disallow RegExp `u` flag.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-u-flag.html",
},
fixable: null,
messages: {
forbidden: "ES2015 RegExp 'u' flag is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
if (node.regex.flags.includes("u")) {
context.report({ node, messageId: "forbidden" })
}
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, flags } of getRegExpCalls(scope)) {
if (flags && flags.includes("u")) {
context.report({ node, messageId: "forbidden" })
}
}
},
}
},
}
@@ -0,0 +1,97 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { RegExpValidator } = require("regexpp")
const { getRegExpCalls } = require("../utils")
const scNamePattern = /^(?:Script(?:_Extensions)?|scx?)$/u
const scValuePattern = /^(?:Dogr|Dogra|Gong|Gunjala_Gondi|Hanifi_Rohingya|Maka|Makasar|Medefaidrin|Medf|Old_Sogdian|Rohg|Sogd|Sogdian|Sogo)$/u
function isNewUnicodePropertyKeyValuePair(key, value) {
return scNamePattern.test(key) && scValuePattern.test(value)
}
function isNewBinaryUnicodeProperty(key) {
return key === "Extended_Pictographic"
}
/**
* Verify a given regular expression.
* @param {RuleContext} context The rule context to report.
* @param {Node} node The AST node to report.
* @param {string} pattern The pattern part of a RegExp.
* @param {string} flags The flags part of a RegExp.
* @returns {void}
*/
function verify(context, node, pattern, flags) {
try {
let foundValue = ""
new RegExpValidator({
onUnicodePropertyCharacterSet(start, end, _kind, key, value) {
if (foundValue) {
return
}
if (
value
? isNewUnicodePropertyKeyValuePair(key, value)
: isNewBinaryUnicodeProperty(key)
) {
foundValue = pattern.slice(start, end)
}
},
}).validatePattern(pattern, 0, pattern.length, flags.includes("u"))
if (foundValue) {
context.report({
node,
messageId: "forbidden",
data: { value: foundValue },
})
}
} catch (error) {
//istanbul ignore else
if (error.message.startsWith("Invalid regular expression:")) {
return
}
//istanbul ignore next
throw error
}
}
module.exports = {
meta: {
docs: {
description:
"disallow the new values of RegExp Unicode property escape sequences in ES2019",
category: "ES2019",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-unicode-property-escapes-2019.html",
},
fixable: null,
messages: {
forbidden: "ES2019 '{{value}}' is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
const { pattern, flags } = node.regex
verify(context, node, pattern || "", flags || "")
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, pattern, flags } of getRegExpCalls(scope)) {
verify(context, node, pattern || "", flags || "")
}
},
}
},
}
@@ -0,0 +1,73 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { RegExpValidator } = require("regexpp")
const { getRegExpCalls } = require("../utils")
/**
* Verify a given regular expression.
* @param {RuleContext} context The rule context to report.
* @param {Node} node The AST node to report.
* @param {string} pattern The pattern part of a RegExp.
* @param {string} flags The flags part of a RegExp.
* @returns {void}
*/
function verify(context, node, pattern, flags) {
try {
let found = false
new RegExpValidator({
onUnicodePropertyCharacterSet() {
found = true
},
}).validatePattern(pattern, 0, pattern.length, flags.includes("u"))
if (found) {
context.report({ node, messageId: "forbidden" })
}
} catch (error) {
//istanbul ignore else
if (error.message.startsWith("Invalid regular expression:")) {
return
}
//istanbul ignore next
throw error
}
}
module.exports = {
meta: {
docs: {
description: "disallow RegExp Unicode property escape sequences.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-unicode-property-escapes.html",
},
fixable: null,
messages: {
forbidden:
"ES2018 RegExp Unicode property escape sequences are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
const { pattern, flags } = node.regex
verify(context, node, pattern || "", flags || "")
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, pattern, flags } of getRegExpCalls(scope)) {
verify(context, node, pattern || "", flags || "")
}
},
}
},
}
+44
View File
@@ -0,0 +1,44 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { getRegExpCalls } = require("../utils")
module.exports = {
meta: {
docs: {
description: "disallow RegExp `y` flag.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-regexp-y-flag.html",
},
fixable: null,
messages: {
forbidden: "ES2015 RegExp 'y' flag is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Literal[regex]"(node) {
if (node.regex.flags.includes("y")) {
context.report({ node, messageId: "forbidden" })
}
},
"Program:exit"() {
const scope = context.getScope()
for (const { node, flags } of getRegExpCalls(scope)) {
if (flags && flags.includes("y")) {
context.report({ node, messageId: "forbidden" })
}
}
},
}
},
}
+30
View File
@@ -0,0 +1,30 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow rest parameters.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-rest-parameters.html",
},
fixable: null,
messages: {
forbidden: "ES2015 rest parameters are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":function > RestElement"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+33
View File
@@ -0,0 +1,33 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow rest/spread properties.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-rest-spread-properties.html",
},
fixable: null,
messages: {
forbidden: "ES2018 rest/spread properties are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"ObjectPattern > RestElement"(node) {
context.report({ node, messageId: "forbidden" })
},
"ObjectExpression > SpreadElement"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `Set` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-set.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Set: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+41
View File
@@ -0,0 +1,41 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `SharedArrayBuffer` class.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-shared-array-buffer.html",
},
fixable: null,
messages: {
forbidden: "ES2017 '{{name}}' class is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
SharedArrayBuffer: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
module.exports = {
meta: {
docs: {
description: "disallow spread elements.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-spread-elements.html",
},
fixable: null,
messages: {
forbidden: "ES2015 spread elements are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
":matches(ArrayExpression, CallExpression, NewExpression) > SpreadElement"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `String.fromCodePoint` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-string-fromcodepoint.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
String: {
fromCodePoint: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+43
View File
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the `String.raw` method.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-string-raw.html",
},
fixable: null,
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
String: {
raw: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+55
View File
@@ -0,0 +1,55 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("eslint-utils")
module.exports = {
meta: {
docs: {
description: "disallow the subclassing of the built-in classes.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-subclassing-builtins.html",
},
fixable: null,
messages: {
forbidden: "ES2015 subclassing of '{{name}}' is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Array: { [READ]: true },
Boolean: { [READ]: true },
Error: { [READ]: true },
RegExp: { [READ]: true },
Function: { [READ]: true },
Map: { [READ]: true },
Number: { [READ]: true },
Promise: { [READ]: true },
Set: { [READ]: true },
String: { [READ]: true },
})) {
if (
node.parent.type.startsWith("Class") &&
node.parent.superClass === node
) {
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