node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES5 accessor properties are forbidden.",
},
},
create(context) {
return {
"Property[kind='get'], Property[kind='set'], MethodDefinition[kind='get'], MethodDefinition[kind='set']"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+111
View File
@@ -0,0 +1,111 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { isArrowToken } = 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",
schema: [],
messages: {
forbidden: "ES2015 arrow function expressions are forbidden.",
},
},
create(context) {
const sourceCode = context.getSourceCode()
/**
* ArrowFunctionExpression to FunctionExpression
* @param {Node} node ArrowFunctionExpression Node
* @returns {string} function expression text
*/
function toFunctionExpression(node) {
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]
)
if (node.body.type === "BlockStatement") {
return `function(${paramText})${bodyText}`
}
if (preText.includes("\n")) {
return `function(${paramText}){return(${bodyText})}`
}
return `function(${paramText}){return ${bodyText}}`
}
/**
* 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
}
const functionText = toFunctionExpression(node)
return fixer.replaceText(
node,
hasThis ? `${functionText}.bind(this)` : functionText
)
},
})
}
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
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2017 async function declarations are forbidden.",
},
},
create(context) {
return {
":function[async=true]"(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 async iteration.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-async-iteration.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2018 async iteration is forbidden.",
},
},
create(context) {
return {
":function[async=true][generator=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
"ForOfStatement[await=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2017 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+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"
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,
schema: [],
messages: {
forbidden: "ES2015 binary numeric literals are forbidden.",
},
},
create(context) {
return {
Literal(node) {
if (typeof node.value === "number" && Pattern.test(node.raw)) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 block-scoped functions are forbidden.",
},
},
create(context) {
return {
":not(:function) > BlockStatement > FunctionDeclaration"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 block-scoped variables are forbidden.",
},
},
create(context) {
return {
"VariableDeclaration[kind='const'], VariableDeclaration[kind='let']"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 class declarations are forbidden.",
},
},
create(context) {
return {
"ClassDeclaration, ClassExpression"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 computed properties are forbidden.",
},
},
create(context) {
return {
":matches(Property, MethodDefinition)[computed=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 default parameters are forbidden.",
},
},
create(context) {
return {
":function > AssignmentPattern"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 destructuring is forbidden.",
},
},
create(context) {
return {
":matches(:function, AssignmentExpression, VariableDeclarator, :function > :matches(AssignmentPattern, RestElement), ForInStatement, ForOfStatement) > :matches(ArrayPattern, ObjectPattern)"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2016 exponential operators are forbidden.",
},
},
create(context) {
return {
"AssignmentExpression[operator='**='], BinaryExpression[operator='**']"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 'for-of' statements are forbidden.",
},
},
create(context) {
return {
ForOfStatement(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 generator function declarations are forbidden.",
},
},
create(context) {
return {
":function[generator=true]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+54
View File
@@ -0,0 +1,54 @@
/**
* @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",
schema: [],
messages: {
forbidden: "ES2019 '\\u{{code}}' in string literals is forbidden.",
},
},
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}`
)
},
})
}
},
}
},
}
+107
View File
@@ -0,0 +1,107 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES5 reserved words as property names are forbidden.",
},
},
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,36 @@
/**
* @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,
schema: [],
messages: {
forbidden:
"ES2018 template literals with invalid escape sequences are forbidden.",
},
},
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" })
}
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 modules are forbidden.",
},
},
create(context) {
return {
"ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 'new.target' meta property is forbidden.",
},
},
create(context) {
return {
"MetaProperty[meta.name='new'][property.name='target']"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' property is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
@@ -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.getOwnPropertyDescriptors` method.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-object-getownpropertydescriptors.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
},
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,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+46
View File
@@ -0,0 +1,46 @@
/**
* @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,
schema: [],
messages: {
forbidden:
"ES2015 'super' property accesses in object literals are forbidden.",
},
},
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
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2017 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+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"
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,
schema: [],
messages: {
forbidden: "ES2015 octal numeric literals are forbidden.",
},
},
create(context) {
return {
Literal(node) {
if (typeof node.value === "number" && Pattern.test(node.raw)) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2019 optional 'catch' binding is forbidden.",
},
},
create(context) {
return {
"CatchClause[param=null]"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+77
View File
@@ -0,0 +1,77 @@
/**
* @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",
schema: [],
messages: {
forbidden: "ES2015 property shorthands are forbidden.",
},
},
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}`
),
})
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
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,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({
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,
schema: [],
messages: {
forbidden: "ES2018 RegExp lookbehind assertions are forbidden.",
},
},
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,78 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2018 RegExp named capture groups are forbidden.",
},
},
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 || "")
}
},
}
},
}
+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 { 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,
schema: [],
messages: {
forbidden: "ES2018 RegExp 's' flag is forbidden.",
},
},
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" })
}
}
},
}
},
}
+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 { 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,
schema: [],
messages: {
forbidden: "ES2015 RegExp 'u' flag is forbidden.",
},
},
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,72 @@
/**
* @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,
schema: [],
messages: {
forbidden:
"ES2018 RegExp Unicode property escape sequences are forbidden.",
},
},
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 || "")
}
},
}
},
}
+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 { 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,
schema: [],
messages: {
forbidden: "ES2015 RegExp 'y' flag is forbidden.",
},
},
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" })
}
}
},
}
},
}
+29
View File
@@ -0,0 +1,29 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 rest parameters are forbidden.",
},
},
create(context) {
return {
":function > RestElement"(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 rest/spread properties.",
category: "ES2018",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-rest-spread-properties.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2018 rest/spread properties are forbidden.",
},
},
create(context) {
return {
"ObjectPattern > RestElement"(node) {
context.report({ node, messageId: "forbidden" })
},
"ObjectExpression > SpreadElement"(node) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2017 '{{name}}' class is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+31
View File
@@ -0,0 +1,31 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 spread elements are forbidden.",
},
},
create(context) {
return {
":matches(ArrayExpression, CallExpression, NewExpression) > SpreadElement"(
node
) {
context.report({ node, messageId: "forbidden" })
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+42
View File
@@ -0,0 +1,42 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' method is forbidden.",
},
},
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(".") },
})
}
},
}
},
}
+54
View File
@@ -0,0 +1,54 @@
/**
* @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,
schema: [],
messages: {
forbidden: "ES2015 subclassing of '{{name}}' is forbidden.",
},
},
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(".") },
})
}
}
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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 `Symbol` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-symbol.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Symbol: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+84
View File
@@ -0,0 +1,84 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
/**
* Checks whether it is string literal
* @param {string} s string source code
* @returns {boolean} true: is string literal source code
*/
function isStringLiteralCode(s) {
return (
(s.startsWith("'") && s.endsWith("'")) ||
(s.startsWith('"') && s.endsWith('"'))
)
}
/**
* Transform template literal to string concatenation.
* @param {ASTNode} node TemplateLiteral node.(not within TaggedTemplateExpression)
* @param {SourceCode} sourceCode SourceCode
* @returns {string} After transformation
*/
function templateLiteralToStringConcat(node, sourceCode) {
const ss = []
node.quasis.forEach((q, i) => {
const value = q.value.cooked
if (value) {
ss.push(JSON.stringify(value))
}
if (i < node.expressions.length) {
const e = node.expressions[i]
const text = sourceCode.getText(e)
ss.push(text)
}
})
if (!ss.length || !isStringLiteralCode(ss[0])) {
ss.unshift(`""`)
}
return ss.join("+")
}
module.exports = {
meta: {
docs: {
description: "disallow template literals.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-template-literals.html",
},
fixable: "code",
schema: [],
messages: {
forbidden: "ES2015 template literals are forbidden.",
},
},
create(context) {
const sourceCode = context.getSourceCode()
return {
"TaggedTemplateExpression, :not(TaggedTemplateExpression) > TemplateLiteral"(
node
) {
context.report({
node,
messageId: "forbidden",
fix:
node.type === "TemplateLiteral"
? fixer =>
fixer.replaceText(
node,
templateLiteralToStringConcat(
node,
sourceCode
)
)
: undefined,
})
},
}
},
}
+38
View File
@@ -0,0 +1,38 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { isCommaToken } = require("../utils")
module.exports = {
meta: {
docs: {
description: "disallow trailing commas in array/object literals.",
category: "ES5",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-trailing-commas.html",
},
fixable: null,
schema: [],
messages: {
forbidden:
"ES5 trailing commas in array/object literals are forbidden.",
},
},
create(context) {
const sourceCode = context.getSourceCode()
return {
"ArrayExpression, ArrayPattern, ObjectExpression, ObjectPattern"(
node
) {
const token = sourceCode.getLastToken(node, 1)
if (isCommaToken(token)) {
context.report({ node, messageId: "forbidden" })
}
},
}
},
}
+61
View File
@@ -0,0 +1,61 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { isCommaToken } = require("../utils")
module.exports = {
meta: {
docs: {
description:
"disallow trailing commas in parameter/argument lists.",
category: "ES2017",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-trailing-function-commas.html",
},
fixable: "code",
schema: [],
messages: {
forbidden:
"ES2017 trailing commas in parameter/argument lists are forbidden.",
},
},
create(context) {
const sourceCode = context.getSourceCode()
return {
":function"(node) {
const length = node.params.length
if (length === 0) {
return
}
const lastParam = node.params[length - 1]
const token = sourceCode.getTokenAfter(lastParam)
if (isCommaToken(token)) {
context.report({
loc: token.loc,
messageId: "forbidden",
fix(fixer) {
return fixer.remove(token)
},
})
}
},
"CallExpression, NewExpression"(node) {
const token = sourceCode.getLastToken(node, 1)
if (node.arguments.length >= 1 && isCommaToken(token)) {
context.report({
loc: token.loc,
messageId: "forbidden",
fix(fixer) {
return fixer.remove(token)
},
})
}
},
}
},
}
+49
View File
@@ -0,0 +1,49 @@
/**
* @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 ES2015 typed arrays.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-typed-arrays.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' is forbidden.",
},
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Int8Array: { [READ]: true },
Uint8Array: { [READ]: true },
Uint8ClampedArray: { [READ]: true },
Int16Array: { [READ]: true },
Uint16Array: { [READ]: true },
Int32Array: { [READ]: true },
Uint32Array: { [READ]: true },
Float32Array: { [READ]: true },
Float64Array: { [READ]: true },
DataView: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
@@ -0,0 +1,99 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { definePatternSearchGenerator } = require("../utils")
const codePointEscapeSearchGenerator = definePatternSearchGenerator(
/\\u\{[0-9a-fA-F]+\}/gu
)
/**
* Number to Hex
* @param {number} num number
* @returns {string} hex string
*/
function toHex(num) {
return `0000${num.toString(16).toUpperCase()}`.substr(-4)
}
module.exports = {
meta: {
docs: {
description: "disallow Unicode code point escape sequences.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-unicode-codepoint-escapes.html",
},
fixable: "code",
schema: [],
messages: {
forbidden:
"ES2015 Unicode code point escape sequences are forbidden.",
},
},
create(context) {
const sourceCode = context.getSourceCode()
/**
* find code point escape, and report
* @param {string} text text
* @param {Node} node node
* @returns {void}
*/
function findAndReport(text, node) {
for (const match of codePointEscapeSearchGenerator(text)) {
const start = match.index
const end = start + match[0].length
const range = [start + node.start, end + node.start]
context.report({
node,
loc: {
start: sourceCode.getLocFromIndex(range[0]),
end: sourceCode.getLocFromIndex(range[1]),
},
messageId: "forbidden",
fix(fixer) {
const codePointStr = text.slice(start + 3, end - 1)
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
let codePoint = Number(`0x${codePointStr}`)
let replacement = null
if (codePoint <= 0xffff) {
// BMP code point
replacement = toHex(codePoint)
} else {
// Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000
const highSurrogate = (codePoint >> 10) + 0xd800
const lowSurrogate = (codePoint % 0x400) + 0xdc00
replacement = `${toHex(highSurrogate)}\\u${toHex(
lowSurrogate
)}`
}
return fixer.replaceTextRange(
[range[0] + 2, range[1]],
replacement
)
},
})
}
}
return {
Identifier(node) {
findAndReport(sourceCode.getText(node), node)
},
Literal(node) {
if (typeof node.value === "string") {
findAndReport(node.raw, node)
}
},
TemplateElement(elementNode) {
findAndReport(elementNode.value.raw, elementNode)
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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 `WeakMap` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-weak-map.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
WeakMap: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
+40
View File
@@ -0,0 +1,40 @@
/**
* @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 `WeakSet` class.",
category: "ES2015",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-weak-set.html",
},
fixable: null,
schema: [],
messages: {
forbidden: "ES2015 '{{name}}' class is forbidden.",
},
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
WeakSet: { [READ]: true },
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}