Skip to content

Commit

Permalink
✨ add rules for ES5 static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Dec 26, 2019
1 parent 3177c5f commit b5928ab
Show file tree
Hide file tree
Showing 43 changed files with 1,110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/rules/no-array-isarray.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Array.isArray` method (es/no-array-isarray)

This rule reports ES5 `Array.isArray` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-array-isarray: error */
var array = Array.isArray(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-array-isarray.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-array-isarray.js)
16 changes: 16 additions & 0 deletions docs/rules/no-date-now.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Date.now` method (es/no-date-now)

This rule reports ES5 `Date.now` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-date-now: error */
var now = Date.now()
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-date-now.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-date-now.js)
17 changes: 17 additions & 0 deletions docs/rules/no-json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# disallow the `JSON` class (es/no-json)

This rule reports ES5 `JSON` class as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-json: error */
var obj = JSON.parse(text)
var str = JSON.stringify(data)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-json.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-json.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-defineproperties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.defineProperties` method (es/no-object-defineproperties)

This rule reports ES5 `Object.defineProperties` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-defineproperties: error */
Object.defineProperties(obj, {})
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-defineproperties.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-defineproperties.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-defineproperty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.defineProperty` method (es/no-object-defineproperty)

This rule reports ES5 `Object.defineProperty` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-defineproperty: error */
Object.defineProperty(obj, "prop", {})
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-defineproperty.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-defineproperty.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-freeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.freeze` method (es/no-object-freeze)

This rule reports ES5 `Object.freeze` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-freeze: error */
Object.freeze(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-freeze.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-freeze.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-getownpropertydescriptor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.getOwnPropertyDescriptor` method (es/no-object-getownpropertydescriptor)

This rule reports ES5 `Object.getOwnPropertyDescriptor` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-getownpropertydescriptor: error */
var descriptors = Object.getOwnPropertyDescriptor(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-getownpropertydescriptor.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-getownpropertydescriptor.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-getownpropertynames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.getOwnPropertyNames` method (es/no-object-getownpropertynames)

This rule reports ES5 `Object.getOwnPropertyNames` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-getownpropertynames: error */
Object.getOwnPropertyNames(obj, "prop", {})
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-getownpropertynames.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-getownpropertynames.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-getprototypeof.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.getPrototypeOf` method (es/no-object-getprototypeof)

This rule reports ES5 `Object.getPrototypeOf` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-getprototypeof: error */
var proto = Object.getPrototypeOf(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-getprototypeof.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-getprototypeof.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-isextensible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.isExtensible` method (es/no-object-isextensible)

This rule reports ES5 `Object.isExtensible` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-isextensible: error */
var extensible = Object.isExtensible(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-isextensible.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-isextensible.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-isfrozen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.isFrozen` method (es/no-object-isfrozen)

This rule reports ES5 `Object.isFrozen` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-isfrozen: error */
var frozen = Object.isFrozen(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-isfrozen.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-isfrozen.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-issealed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.isSealed` method (es/no-object-issealed)

This rule reports ES5 `Object.isSealed` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-issealed: error */
var sealed = Object.isSealed(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-issealed.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-issealed.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-preventextensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.preventExtensions` method (es/no-object-preventextensions)

This rule reports ES5 `Object.preventExtensions` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-preventextensions: error */
Object.preventExtensions(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-preventextensions.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-preventextensions.js)
16 changes: 16 additions & 0 deletions docs/rules/no-object-seal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# disallow the `Object.seal` method (es/no-object-seal)

This rule reports ES5 `Object.seal` method as errors.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-object-seal: error */
Object.seal(obj)
" />

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/lib/rules/no-object-seal.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v2.0.0/tests/lib/rules/no-object-seal.js)
14 changes: 14 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = {
rules: {
"no-accessor-properties": require("./rules/no-accessor-properties"),
"no-array-from": require("./rules/no-array-from"),
"no-array-isarray": require("./rules/no-array-isarray"),
"no-array-of": require("./rules/no-array-of"),
"no-arrow-functions": require("./rules/no-arrow-functions"),
"no-async-functions": require("./rules/no-async-functions"),
Expand All @@ -131,6 +132,7 @@ module.exports = {
"no-block-scoped-variables": require("./rules/no-block-scoped-variables"),
"no-classes": require("./rules/no-classes"),
"no-computed-properties": require("./rules/no-computed-properties"),
"no-date-now": require("./rules/no-date-now"),
"no-default-parameters": require("./rules/no-default-parameters"),
"no-destructuring": require("./rules/no-destructuring"),
"no-dynamic-import": require("./rules/no-dynamic-import"),
Expand All @@ -139,6 +141,7 @@ module.exports = {
"no-generators": require("./rules/no-generators"),
"no-global-this": require("./rules/no-global-this"),
"no-json-superset": require("./rules/no-json-superset"),
"no-json": require("./rules/no-json"),
"no-keyword-properties": require("./rules/no-keyword-properties"),
"no-malformed-template-literals": require("./rules/no-malformed-template-literals"),
"no-map": require("./rules/no-map"),
Expand Down Expand Up @@ -171,11 +174,22 @@ module.exports = {
"no-number-parsefloat": require("./rules/no-number-parsefloat"),
"no-number-parseint": require("./rules/no-number-parseint"),
"no-object-assign": require("./rules/no-object-assign"),
"no-object-defineproperties": require("./rules/no-object-defineproperties"),
"no-object-defineproperty": require("./rules/no-object-defineproperty"),
"no-object-entries": require("./rules/no-object-entries"),
"no-object-freeze": require("./rules/no-object-freeze"),
"no-object-getownpropertydescriptor": require("./rules/no-object-getownpropertydescriptor"),
"no-object-getownpropertydescriptors": require("./rules/no-object-getownpropertydescriptors"),
"no-object-getownpropertynames": require("./rules/no-object-getownpropertynames"),
"no-object-getownpropertysymbols": require("./rules/no-object-getownpropertysymbols"),
"no-object-getprototypeof": require("./rules/no-object-getprototypeof"),
"no-object-is": require("./rules/no-object-is"),
"no-object-isextensible": require("./rules/no-object-isextensible"),
"no-object-isfrozen": require("./rules/no-object-isfrozen"),
"no-object-issealed": require("./rules/no-object-issealed"),
"no-object-keys": require("./rules/no-object-keys"),
"no-object-preventextensions": require("./rules/no-object-preventextensions"),
"no-object-seal": require("./rules/no-object-seal"),
"no-object-setprototypeof": require("./rules/no-object-setprototypeof"),
"no-object-super-properties": require("./rules/no-object-super-properties"),
"no-object-values": require("./rules/no-object-values"),
Expand Down
43 changes: 43 additions & 0 deletions lib/rules/no-array-isarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"

const { READ, ReferenceTracker } = require("eslint-utils")

module.exports = {
meta: {
docs: {
description: "disallow the `Array.isArray` method.",
category: undefined, // TODO(mysticatea): set ES5 category
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-array-isarray.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Array: {
isArray: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
43 changes: 43 additions & 0 deletions lib/rules/no-date-now.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"

const { READ, ReferenceTracker } = require("eslint-utils")

module.exports = {
meta: {
docs: {
description: "disallow the `Date.now` method.",
category: undefined, // TODO(mysticatea): set ES5 category
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-date-now.html",
},
fixable: null,
messages: {
forbidden: "ES5 '{{name}}' method is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
for (const { node, path } of tracker.iterateGlobalReferences({
Date: {
now: { [READ]: true },
},
})) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
},
}
},
}
Loading

0 comments on commit b5928ab

Please sign in to comment.