-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
es-roikoren/no-object-create
rule
- Loading branch information
1 parent
fd26659
commit 2238048
Showing
8 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'eslint-plugin-es-roikoren': patch | ||
--- | ||
|
||
feat: add `es-roikoren/no-object-create` rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# es-roikoren/no-object-create | ||
> disallow the `Object.create` method | ||
- ✅ The following configurations enable this rule: `plugin:es-roikoren/no-new-in-es5` and `plugin:es-roikoren/restrict-to-es3` | ||
|
||
This rule reports ES5 `Object.create` methods as errors. | ||
|
||
## Examples | ||
|
||
⛔ Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint es-roikoren/no-object-create: error */ | ||
const obj = Object.assign({}); | ||
``` | ||
|
||
## 📚 References | ||
|
||
- [Rule source](https://github.com/roikoren755/eslint-plugin-es/blob/v0.0.3/src/rules/no-object-create.ts) | ||
- [Test source](https://github.com/roikoren755/eslint-plugin-es/blob/v0.0.3/tests/src/rules/no-object-create.ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ASTUtils } from '@typescript-eslint/experimental-utils'; | ||
|
||
import { createRule } from '../util/create-rule'; | ||
import { referenceTracker } from '../util/reference-tracker'; | ||
|
||
export const category = 'ES5'; | ||
export default createRule<[], 'forbidden'>({ | ||
name: 'no-object-create', | ||
meta: { | ||
type: 'problem', | ||
docs: { description: 'disallow the `Object.create` method', recommended: false }, | ||
schema: [], | ||
messages: { forbidden: "ES5 '{{name}}' method is forbidden." }, | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return referenceTracker(context, { Object: { create: { [ASTUtils.ReferenceTracker.READ]: true } } }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AST_NODE_TYPES } from '@typescript-eslint/types'; | ||
|
||
import { RuleTester } from '../../tester'; | ||
import rule from '../../../src/rules/no-object-create'; | ||
|
||
const error = { | ||
messageId: 'forbidden' as const, | ||
line: 1, | ||
column: 1, | ||
type: AST_NODE_TYPES.MemberExpression, | ||
data: { name: 'Object.create' }, | ||
}; | ||
|
||
new RuleTester().run('no-object-create', rule, { | ||
valid: ['Object', 'Object.foo', 'let Object = 0; Object.create'], | ||
invalid: [{ code: 'Object.create', errors: [error] }], | ||
}); |