-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
100 additions
and
0 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
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,32 @@ | ||
--- | ||
title: "es-x/no-promise-try" | ||
description: "disallow `Promise.try` function" | ||
--- | ||
|
||
# es-x/no-promise-try | ||
> disallow `Promise.try` function | ||
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- ✅ The following configurations enable this rule: [no-new-in-esnext] | ||
|
||
This rule reports ES2025 [`Promise.try`](https://github.com/tc39/proposal-promise-try) as errors. | ||
|
||
## 💡 Examples | ||
|
||
⛔ Examples of **incorrect** code for this rule: | ||
|
||
<eslint-playground type="bad"> | ||
|
||
```js | ||
/*eslint es-x/no-promise-try: error */ | ||
const p = Promise.try(f) | ||
``` | ||
|
||
</eslint-playground> | ||
|
||
## 📚 References | ||
|
||
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-promise-try.js) | ||
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-promise-try.js) | ||
|
||
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext |
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,46 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict" | ||
|
||
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils") | ||
const { getSourceCode } = require("eslint-compat-utils") | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "disallow `Promise.try` function", | ||
category: "ES2025", | ||
recommended: false, | ||
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-promise-try.html", | ||
}, | ||
fixable: null, | ||
messages: { | ||
forbidden: "ES2025 '{{name}}' is forbidden.", | ||
}, | ||
schema: [], | ||
type: "problem", | ||
}, | ||
create(context) { | ||
return { | ||
"Program:exit"(program) { | ||
const sourceCode = getSourceCode(context) | ||
const tracker = new ReferenceTracker( | ||
sourceCode.getScope(program), | ||
) | ||
for (const { node, path } of tracker.iterateGlobalReferences({ | ||
Promise: { | ||
try: { [READ]: true }, | ||
}, | ||
})) { | ||
context.report({ | ||
node, | ||
messageId: "forbidden", | ||
data: { name: path.join(".") }, | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
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,18 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict" | ||
|
||
const RuleTester = require("../../tester") | ||
const rule = require("../../../lib/rules/no-promise-try.js") | ||
|
||
new RuleTester().run("no-promise-try", rule, { | ||
valid: ["Promise.all"], | ||
invalid: [ | ||
{ | ||
code: "Promise.try", | ||
errors: ["ES2025 'Promise.try' is forbidden."], | ||
}, | ||
], | ||
}) |