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
+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://travis-ci.org/mysticatea/eslint-plugin-es.svg?branch=master)](https://travis-ci.org/mysticatea/eslint-plugin-es)
[![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://mysticatea.github.io/eslint-plugin-es/)
## 🚥 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.
+200
View File
@@ -0,0 +1,200 @@
/**
* DON'T EDIT THIS FILE.
* This file was generated automatically by 'scripts/update-index.js'.
*/
"use strict"
module.exports = {
configs: {
"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-keyword-properties": "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-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-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-default-parameters": require("./rules/no-default-parameters"),
"no-destructuring": require("./rules/no-destructuring"),
"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-json-superset": require("./rules/no-json-superset"),
"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-entries": require("./rules/no-object-entries"),
"no-object-getownpropertydescriptors": require("./rules/no-object-getownpropertydescriptors"),
"no-object-getownpropertysymbols": require("./rules/no-object-getownpropertysymbols"),
"no-object-is": require("./rules/no-object-is"),
"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": 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": 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"),
},
}
+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(".") },
})
}
},
}
},
}
+56
View File
@@ -0,0 +1,56 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
CALL,
CONSTRUCT,
PatternMatcher,
ReferenceTracker,
getStringIfConstant,
} = require("eslint-utils")
module.exports = {
/**
* Define generator to search pattern.
* The iterator generated by the generator returns the start and end index of the match.
* @param {RegExp} pattern Base pattern
* @returns {function(string):IterableIterator<RegExpExecArray>} generator
*/
definePatternSearchGenerator(pattern) {
const matcher = new PatternMatcher(pattern)
return matcher.execAll.bind(matcher)
},
/**
* Check whether a given token is a comma token or not.
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is a comma token.
*/
isCommaToken(token) {
return (
token != null && token.type === "Punctuator" && token.value === ","
)
},
/**
* Iterate the calls of the `RegExp` global variable.
* @param {Scope} globalScope The global scope object.
* @returns {IterableIterator<{node:Node,pattern:(string|null),flags:(string|null)}>} The iterator of `CallExpression` or `NewExpression` for `RegExp`.
*/
*getRegExpCalls(globalScope) {
const tracker = new ReferenceTracker(globalScope)
for (const { node } of tracker.iterateGlobalReferences({
RegExp: { [CALL]: true, [CONSTRUCT]: true },
})) {
const [patternNode, flagsNode] = node.arguments
yield {
node,
pattern: getStringIfConstant(patternNode, globalScope),
flags: getStringIfConstant(flagsNode, globalScope),
}
}
},
}
+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.
+178
View File
@@ -0,0 +1,178 @@
# regexpp
[![npm version](https://img.shields.io/npm/v/regexpp.svg)](https://www.npmjs.com/package/regexpp)
[![Downloads/month](https://img.shields.io/npm/dm/regexpp.svg)](http://www.npmtrends.com/regexpp)
[![Build Status](https://travis-ci.org/mysticatea/regexpp.svg?branch=master)](https://travis-ci.org/mysticatea/regexpp)
[![Coverage Status](https://coveralls.io/repos/github/mysticatea/regexpp/badge.svg)](https://coveralls.io/github/mysticatea/regexpp)
[![Dependency Status](https://david-dm.org/mysticatea/regexpp.svg)](https://david-dm.org/mysticatea/regexpp)
The regular expression parser for ECMAScript.
## 💿 Installation
```bash
$ npm install regexpp
```
- require Node.js 6.5.0 or newer.
## 📖 Usage
```ts
import {
AST,
RegExpParser,
RegExpValidator,
RegExpVisitor,
parseRegExpLiteral,
validateRegExpLiteral,
visitRegExpAST
} from "regexpp"
```
### parseRegExpLiteral(source, options?)
Parse a given regular expression literal then make AST object.
This is equivalent to `new RegExpParser(options).parseLiteral(source)`.
- **Parameters:**
- `source` (`string | RegExp`) The source code to parse.
- `options?` ([`RegExpParser.Options`]) The options to parse.
- **Return:**
- The AST of the regular expression.
### validateRegExpLiteral(source, options?)
Validate a given regular expression literal.
This is equivalent to `new RegExpValidator(options).validateLiteral(source)`.
- **Parameters:**
- `source` (`string`) The source code to validate.
- `options?` ([`RegExpValidator.Options`]) The options to validate.
### visitRegExpAST(ast, handlers)
Visit each node of a given AST.
This is equivalent to `new RegExpVisitor(handlers).visit(ast)`.
- **Parameters:**
- `ast` ([`AST.Node`]) The AST to visit.
- `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
### RegExpParser
#### new RegExpParser(options?)
- **Parameters:**
- `options?` ([`RegExpParser.Options`]) The options to parse.
#### parser.parseLiteral(source, start?, end?)
Parse a regular expression literal.
- **Parameters:**
- `source` (`string`) The source code to parse. E.g. `"/abc/g"`.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
- **Return:**
- The AST of the regular expression.
#### parser.parsePattern(source, start?, end?, uFlag?)
Parse a regular expression pattern.
- **Parameters:**
- `source` (`string`) The source code to parse. E.g. `"abc"`.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
- `uFlag?` (`boolean`) The flag to enable Unicode mode.
- **Return:**
- The AST of the regular expression pattern.
#### parser.parseFlags(source, start?, end?)
Parse a regular expression flags.
- **Parameters:**
- `source` (`string`) The source code to parse. E.g. `"gim"`.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
- **Return:**
- The AST of the regular expression flags.
### RegExpValidator
#### new RegExpValidator(options)
- **Parameters:**
- `options` ([`RegExpValidator.Options`]) The options to validate.
#### validator.validateLiteral(source, start, end)
Validate a regular expression literal.
- **Parameters:**
- `source` (`string`) The source code to validate.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
#### validator.validatePattern(source, start, end, uFlag)
Validate a regular expression pattern.
- **Parameters:**
- `source` (`string`) The source code to validate.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
- `uFlag?` (`boolean`) The flag to enable Unicode mode.
#### validator.validateFlags(source, start, end)
Validate a regular expression flags.
- **Parameters:**
- `source` (`string`) The source code to validate.
- `start?` (`number`) The start index in the source code. Default is `0`.
- `end?` (`number`) The end index in the source code. Default is `source.length`.
### RegExpVisitor
#### new RegExpVisitor(handlers)
- **Parameters:**
- `handlers` ([`RegExpVisitor.Handlers`]) The callbacks.
#### visitor.visit(ast)
Validate a regular expression literal.
- **Parameters:**
- `ast` ([`AST.Node`]) The AST to visit.
## 📰 Changelog
- [GitHub Releases](https://github.com/mysticatea/regexpp/releases)
## 🍻 Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
### Development Tools
- `npm test` runs tests and measures coverage.
- `npm run build` compiles TypeScript source code to `index.js`, `index.js.map`, and `index.d.ts`.
- `npm run clean` removes the temporary files which are created by `npm test` and `npm run build`.
- `npm run lint` runs ESLint.
- `npm run update:test` updates test fixtures.
- `npm run update:ids` updates `src/unicode/ids.ts`.
- `npm run watch` runs tests with `--watch` option.
[`AST.Node`]: src/ast.ts#L4
[`RegExpParser.Options`]: src/parser.ts#L539
[`RegExpValidator.Options`]: src/validator.ts#L127
[`RegExpVisitor.Handlers`]: src/visitor.ts#L204
+241
View File
@@ -0,0 +1,241 @@
// Generated by dts-bundle v0.7.3
declare module 'regexpp' {
import * as AST from "regexpp/ast";
import { RegExpParser } from "regexpp/parser";
import { RegExpValidator } from "regexpp/validator";
import { RegExpVisitor } from "regexpp/visitor";
export { AST, RegExpParser, RegExpValidator };
export function parseRegExpLiteral(source: string | RegExp, options?: RegExpParser.Options): AST.RegExpLiteral;
export function validateRegExpLiteral(source: string, options?: RegExpValidator.Options): void;
export function visitRegExpAST(node: AST.Node, handlers: RegExpVisitor.Handlers): void;
}
declare module 'regexpp/ast' {
export type Node = BranchNode | LeafNode;
export type BranchNode = RegExpLiteral | Pattern | Alternative | Group | CapturingGroup | Quantifier | CharacterClass | LookaroundAssertion | CharacterClassRange;
export type LeafNode = BoundaryAssertion | CharacterSet | Character | Backreference | Flags;
export type Element = Assertion | Quantifier | QuantifiableElement;
export type QuantifiableElement = Group | CapturingGroup | CharacterClass | CharacterSet | Character | Backreference | LookaheadAssertion;
export type CharacterClassElement = EscapeCharacterSet | UnicodePropertyCharacterSet | Character | CharacterClassRange;
export interface NodeBase {
type: Node["type"];
parent: Node["parent"];
start: number;
end: number;
raw: string;
}
export interface RegExpLiteral extends NodeBase {
type: "RegExpLiteral";
parent: null;
pattern: Pattern;
flags: Flags;
}
export interface Pattern extends NodeBase {
type: "Pattern";
parent: RegExpLiteral | null;
alternatives: Alternative[];
}
export interface Alternative extends NodeBase {
type: "Alternative";
parent: Pattern | Group | CapturingGroup | LookaroundAssertion;
elements: Element[];
}
export interface Group extends NodeBase {
type: "Group";
parent: Alternative | Quantifier;
alternatives: Alternative[];
}
export interface CapturingGroup extends NodeBase {
type: "CapturingGroup";
parent: Alternative | Quantifier;
name: string | null;
alternatives: Alternative[];
references: Backreference[];
}
export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion;
export interface LookaheadAssertion extends NodeBase {
type: "Assertion";
parent: Alternative | Quantifier;
kind: "lookahead";
negate: boolean;
alternatives: Alternative[];
}
export interface LookbehindAssertion extends NodeBase {
type: "Assertion";
parent: Alternative;
kind: "lookbehind";
negate: boolean;
alternatives: Alternative[];
}
export interface Quantifier extends NodeBase {
type: "Quantifier";
parent: Alternative;
min: number;
max: number;
greedy: boolean;
element: QuantifiableElement;
}
export interface CharacterClass extends NodeBase {
type: "CharacterClass";
parent: Alternative | Quantifier;
negate: boolean;
elements: CharacterClassElement[];
}
export interface CharacterClassRange extends NodeBase {
type: "CharacterClassRange";
parent: CharacterClass;
min: Character;
max: Character;
}
export type Assertion = BoundaryAssertion | LookaroundAssertion;
export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion;
export interface EdgeAssertion extends NodeBase {
type: "Assertion";
parent: Alternative | Quantifier;
kind: "start" | "end";
}
export interface WordBoundaryAssertion extends NodeBase {
type: "Assertion";
parent: Alternative | Quantifier;
kind: "word";
negate: boolean;
}
export type CharacterSet = AnyCharacterSet | EscapeCharacterSet | UnicodePropertyCharacterSet;
export interface AnyCharacterSet extends NodeBase {
type: "CharacterSet";
parent: Alternative | Quantifier;
kind: "any";
}
export interface EscapeCharacterSet extends NodeBase {
type: "CharacterSet";
parent: Alternative | Quantifier | CharacterClass;
kind: "digit" | "space" | "word";
negate: boolean;
}
export interface UnicodePropertyCharacterSet extends NodeBase {
type: "CharacterSet";
parent: Alternative | Quantifier | CharacterClass;
kind: "property";
key: string;
value: string | null;
negate: boolean;
}
export interface Character extends NodeBase {
type: "Character";
parent: Alternative | Quantifier | CharacterClass | CharacterClassRange;
value: number;
}
export interface Backreference extends NodeBase {
type: "Backreference";
parent: Alternative | Quantifier;
ref: number | string;
resolved: CapturingGroup;
}
export interface Flags extends NodeBase {
type: "Flags";
parent: RegExpLiteral | null;
dotAll: boolean;
global: boolean;
ignoreCase: boolean;
multiline: boolean;
sticky: boolean;
unicode: boolean;
}
}
declare module 'regexpp/parser' {
import { Flags, RegExpLiteral, Pattern } from "regexpp/ast";
export namespace RegExpParser {
interface Options {
strict?: boolean;
ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018;
}
}
export class RegExpParser {
constructor(options?: RegExpParser.Options);
parseLiteral(source: string, start?: number, end?: number): RegExpLiteral;
parseFlags(source: string, start?: number, end?: number): Flags;
parsePattern(source: string, start?: number, end?: number, uFlag?: boolean): Pattern;
}
}
declare module 'regexpp/validator' {
export namespace RegExpValidator {
interface Options {
strict?: boolean;
ecmaVersion?: 5 | 2015 | 2016 | 2017 | 2018;
onLiteralEnter?(start: number): void;
onLiteralLeave?(start: number, end: number): void;
onFlags?(start: number, end: number, global: boolean, ignoreCase: boolean, multiline: boolean, unicode: boolean, sticky: boolean, dotAll: boolean): void;
onPatternEnter?(start: number): void;
onPatternLeave?(start: number, end: number): void;
onDisjunctionEnter?(start: number): void;
onDisjunctionLeave?(start: number, end: number): void;
onAlternativeEnter?(start: number, index: number): void;
onAlternativeLeave?(start: number, end: number, index: number): void;
onGroupEnter?(start: number): void;
onGroupLeave?(start: number, end: number): void;
onCapturingGroupEnter?(start: number, name: string | null): void;
onCapturingGroupLeave?(start: number, end: number, name: string | null): void;
onQuantifier?(start: number, end: number, min: number, max: number, greedy: boolean): void;
onLookaroundAssertionEnter?(start: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
onLookaroundAssertionLeave?(start: number, end: number, kind: "lookahead" | "lookbehind", negate: boolean): void;
onEdgeAssertion?(start: number, end: number, kind: "start" | "end"): void;
onWordBoundaryAssertion?(start: number, end: number, kind: "word", negate: boolean): void;
onAnyCharacterSet?(start: number, end: number, kind: "any"): void;
onEscapeCharacterSet?(start: number, end: number, kind: "digit" | "space" | "word", negate: boolean): void;
onUnicodePropertyCharacterSet?(start: number, end: number, kind: "property", key: string, value: string | null, negate: boolean): void;
onCharacter?(start: number, end: number, value: number): void;
onBackreference?(start: number, end: number, ref: number | string): void;
onCharacterClassEnter?(start: number, negate: boolean): void;
onCharacterClassLeave?(start: number, end: number, negate: boolean): void;
onCharacterClassRange?(start: number, end: number, min: number, max: number): void;
}
}
export class RegExpValidator {
constructor(options?: RegExpValidator.Options);
validateLiteral(source: string, start?: number, end?: number): void;
validateFlags(source: string, start?: number, end?: number): void;
validatePattern(source: string, start?: number, end?: number, uFlag?: boolean): void;
}
}
declare module 'regexpp/visitor' {
import { Alternative, Assertion, Backreference, CapturingGroup, Character, CharacterClass, CharacterClassRange, CharacterSet, Flags, Group, Node, Pattern, Quantifier, RegExpLiteral } from "regexpp/ast";
export class RegExpVisitor {
constructor(handlers: RegExpVisitor.Handlers);
visit(node: Node): void;
}
export namespace RegExpVisitor {
interface Handlers {
onAlternativeEnter?(node: Alternative): void;
onAlternativeLeave?(node: Alternative): void;
onAssertionEnter?(node: Assertion): void;
onAssertionLeave?(node: Assertion): void;
onBackreferenceEnter?(node: Backreference): void;
onBackreferenceLeave?(node: Backreference): void;
onCapturingGroupEnter?(node: CapturingGroup): void;
onCapturingGroupLeave?(node: CapturingGroup): void;
onCharacterEnter?(node: Character): void;
onCharacterLeave?(node: Character): void;
onCharacterClassEnter?(node: CharacterClass): void;
onCharacterClassLeave?(node: CharacterClass): void;
onCharacterClassRangeEnter?(node: CharacterClassRange): void;
onCharacterClassRangeLeave?(node: CharacterClassRange): void;
onCharacterSetEnter?(node: CharacterSet): void;
onCharacterSetLeave?(node: CharacterSet): void;
onFlagsEnter?(node: Flags): void;
onFlagsLeave?(node: Flags): void;
onGroupEnter?(node: Group): void;
onGroupLeave?(node: Group): void;
onPatternEnter?(node: Pattern): void;
onPatternLeave?(node: Pattern): void;
onQuantifierEnter?(node: Quantifier): void;
onQuantifierLeave?(node: Quantifier): void;
onRegExpLiteralEnter?(node: RegExpLiteral): void;
onRegExpLiteralLeave?(node: RegExpLiteral): void;
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+107
View File
@@ -0,0 +1,107 @@
{
"_from": "regexpp@^2.0.1",
"_id": "regexpp@2.0.1",
"_inBundle": false,
"_integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==",
"_location": "/eslint-plugin-es/regexpp",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "regexpp@^2.0.1",
"name": "regexpp",
"escapedName": "regexpp",
"rawSpec": "^2.0.1",
"saveSpec": null,
"fetchSpec": "^2.0.1"
},
"_requiredBy": [
"/eslint-plugin-es"
],
"_resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
"_shasum": "8d19d31cf632482b589049f8281f93dbcba4d07f",
"_spec": "regexpp@^2.0.1",
"_where": "D:\\Atom\\Git\\Laravel_CSSd\\node_modules\\eslint-plugin-es",
"author": {
"name": "Toru Nagashima",
"url": "https://github.com/mysticatea"
},
"bugs": {
"url": "https://github.com/mysticatea/regexpp/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Regular expression parser for ECMAScript 2018.",
"devDependencies": {
"@types/eslint": "^4.16.2",
"@types/mocha": "^5.2.2",
"@types/node": "^10.3.3",
"coveralls": "^3.0.1",
"dts-bundle": "^0.7.3",
"eslint": "^4.19.1",
"eslint-plugin-mysticatea": "^5.0.0-beta.15",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3",
"nyc": "^12.0.2",
"rimraf": "^2.6.2",
"rollup": "^0.60.7",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-watch": "^4.3.1",
"ts-node": "^6.1.1",
"typescript": "^2.9.2",
"typescript-eslint-parser": "^16.0.0"
},
"engines": {
"node": ">=6.5.0"
},
"files": [
"index.*"
],
"homepage": "https://github.com/mysticatea/regexpp#readme",
"keywords": [
"regexp",
"regular",
"expression",
"parser",
"validator",
"ast",
"abstract",
"syntax",
"tree",
"ecmascript",
"es2015",
"es2016",
"es2017",
"es2018",
"annexB"
],
"license": "MIT",
"main": "index",
"name": "regexpp",
"repository": {
"type": "git",
"url": "git+https://github.com/mysticatea/regexpp.git"
},
"scripts": {
"build": "run-s build:*",
"build:dts": "dts-bundle --name regexpp --main .temp/index.d.ts --out ../index.d.ts",
"build:rollup": "rollup -c",
"build:tsc": "tsc --module es2015",
"clean": "rimraf .temp index.*",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint scripts src test --ext .ts",
"postversion": "git push && git push --tags",
"prebuild": "npm run -s clean",
"pretest": "run-s build lint",
"preversion": "npm test",
"prewatch": "npm run -s clean",
"test": "nyc _mocha \"test/*.ts\" --reporter dot --timeout 10000",
"update:ids": "ts-node scripts/update-unicode-ids.ts",
"update:test": "ts-node scripts/update-fixtures.ts",
"version": "npm run -s build",
"watch": "_mocha \"test/*.ts\" --require ts-node/register --reporter dot --timeout 10000 --watch-extensions .ts --watch --growl"
},
"version": "2.0.1"
}
+97
View File
@@ -0,0 +1,97 @@
{
"_from": "eslint-plugin-es@^1.3.1",
"_id": "eslint-plugin-es@1.4.0",
"_inBundle": false,
"_integrity": "sha512-XfFmgFdIUDgvaRAlaXUkxrRg5JSADoRC8IkKLc/cISeR3yHVMefFHQZpcyXXEUUPHfy5DwviBcrfqlyqEwlQVw==",
"_location": "/eslint-plugin-es",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "eslint-plugin-es@^1.3.1",
"name": "eslint-plugin-es",
"escapedName": "eslint-plugin-es",
"rawSpec": "^1.3.1",
"saveSpec": null,
"fetchSpec": "^1.3.1"
},
"_requiredBy": [
"/eslint-plugin-node"
],
"_resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-1.4.0.tgz",
"_shasum": "475f65bb20c993fc10e8c8fe77d1d60068072da6",
"_spec": "eslint-plugin-es@^1.3.1",
"_where": "D:\\Atom\\Git\\Laravel_CSSd\\node_modules\\eslint-plugin-node",
"author": {
"name": "Toru Nagashima",
"url": "https://github.com/mysticatea"
},
"bugs": {
"url": "https://github.com/mysticatea/eslint-plugin-es/issues"
},
"bundleDependencies": false,
"dependencies": {
"eslint-utils": "^1.3.0",
"regexpp": "^2.0.1"
},
"deprecated": false,
"description": "ESLint plugin about ECMAScript syntactic features.",
"devDependencies": {
"@mysticatea/eslint-plugin": "^7.0.0",
"babel-eslint": "^10.0.1",
"codecov": "^3.1.0",
"eslint": "^5.8.0",
"eslint4b": "^5.8.0",
"espree": "^4.1.0",
"globals": "^11.8.0",
"mocha": "^5.0.5",
"npm-run-all": "^4.1.2",
"nyc": "^13.1.0",
"opener": "^1.5.1",
"rimraf": "^2.6.2",
"vue-eslint-editor": "^0.1.2",
"vuepress": "^0.14.4"
},
"engines": {
"node": ">=6.5.0"
},
"files": [
"lib"
],
"homepage": "https://github.com/mysticatea/eslint-plugin-es#readme",
"keywords": [
"eslint",
"plugin",
"eslintplugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "eslint-plugin-es",
"peerDependencies": {
"eslint": ">=4.19.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mysticatea/eslint-plugin-es.git"
},
"scripts": {
"clean": "rimraf .nyc_output coverage",
"codecov": "nyc report -r lcovonly && codecov",
"coverage": "nyc report -r lcov && opener ./coverage/lcov-report/index.html",
"docs:build": "vuepress build docs",
"docs:watch": "vuepress dev docs",
"lint": "eslint lib tests scripts",
"new": "node scripts/new-rule",
"postversion": "git push && git push --tags",
"pretest": "npm run -s lint",
"preversion": "npm test",
"test": "nyc mocha tests/**/*.js --reporter dot",
"update": "run-s update:*",
"update:index": "node scripts/update-index",
"update:ruledocs": "node scripts/update-docs-rules",
"update:url": "npm run -s lint -- --fix",
"version": "run-s update:* && git add .",
"watch": "mocha tests/**/*.js --reporter progress --watch --growl"
},
"version": "1.4.0"
}