-
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-hasown
rule
- Loading branch information
1 parent
f425126
commit 9b40bb3
Showing
9 changed files
with
84 additions
and
7 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-hasown` 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-hasown | ||
> disallow the `Object.hasOwn` method. | ||
- ✅ The following configurations enable this rule: `plugin:es-roikoren/no-new-in-esnext` | ||
|
||
This rule reports ES2022 `Object.hasOwn` method as errors. | ||
|
||
## Examples | ||
|
||
⛔ Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint es-roikoren/no-object-hasown: error */ | ||
const hasFoo = Object.hasOwn(obj, 'foo'); | ||
``` | ||
|
||
## 📚 References | ||
|
||
- [Rule source](https://github.com/roikoren755/eslint-plugin-es/blob/v0.0.3/src/rules/no-object-hasown.ts) | ||
- [Test source](https://github.com/roikoren755/eslint-plugin-es/blob/v0.0.3/tests/src/rules/no-object-hasown.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 = 'ES2022'; | ||
export default createRule<[], 'forbidden'>({ | ||
name: 'no-object-hasown', | ||
meta: { | ||
type: 'problem', | ||
docs: { description: 'disallow the `Object.hasOwn` method.', recommended: false }, | ||
schema: [], | ||
messages: { forbidden: "ES2022 '{{name}}' method is forbidden." }, | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return referenceTracker(context, { Object: { hasOwn: { [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
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,21 @@ | ||
import { AST_NODE_TYPES } from '@typescript-eslint/types'; | ||
|
||
import { RuleTester } from '../../tester'; | ||
import rule from '../../../src/rules/no-object-hasown'; | ||
|
||
const error = { | ||
messageId: 'forbidden' as const, | ||
line: 1, | ||
column: 1, | ||
type: AST_NODE_TYPES.MemberExpression, | ||
data: { name: 'Object.hasOwn' }, | ||
}; | ||
|
||
if (!RuleTester.isSupported(2022)) { | ||
console.log('Skip the tests of no-object-hasown.'); | ||
} else { | ||
new RuleTester().run('no-object-hasown', rule, { | ||
valid: ['Object', 'Object.assign', 'let Object = 0; Object.is'], | ||
invalid: [{ code: 'Object.hasOwn', errors: [error] }], | ||
}); | ||
} |