File tree Expand file tree Collapse file tree 7 files changed +100
-0
lines changed Expand file tree Collapse file tree 7 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
13
13
| [ es-x/no-dynamic-import-options] ( ./no-dynamic-import-options.md ) | disallow second parameter to ` import() ` . | |
14
14
| [ es-x/no-import-attributes] ( ./no-import-attributes.md ) | disallow Import Attributes. | |
15
15
| [ es-x/no-json-modules] ( ./no-json-modules.md ) | disallow JSON Modules. | |
16
+ | [ es-x/no-promise-try] ( ./no-promise-try.md ) | disallow ` Promise.try ` function. | |
16
17
| [ es-x/no-regexp-duplicate-named-capturing-groups] ( ./no-regexp-duplicate-named-capturing-groups.md ) | disallow RegExp duplicate named capturing groups. | |
17
18
| [ es-x/no-regexp-modifiers] ( ./no-regexp-modifiers.md ) | disallow RegExp Modifiers. | |
18
19
| [ es-x/no-set-prototype-difference] ( ./no-set-prototype-difference.md ) | disallow the ` Set.prototype.difference ` method. | |
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " es-x/no-promise-try"
3
+ description : " disallow `Promise.try` function"
4
+ ---
5
+
6
+ # es-x/no-promise-try
7
+ > disallow ` Promise.try ` function
8
+
9
+ - ❗ <badge text =" This rule has not been released yet. " vertical =" middle " type =" error " > *** This rule has not been released yet.*** </badge >
10
+ - ✅ The following configurations enable this rule: [ no-new-in-esnext]
11
+
12
+ This rule reports ES2025 [ ` Promise.try ` ] ( https://github.com/tc39/proposal-promise-try ) as errors.
13
+
14
+ ## 💡 Examples
15
+
16
+ ⛔ Examples of ** incorrect** code for this rule:
17
+
18
+ <eslint-playground type =" bad " >
19
+
20
+ ``` js
21
+ /* eslint es-x/no-promise-try: error */
22
+ const p = Promise .try (f)
23
+ ```
24
+
25
+ </eslint-playground >
26
+
27
+ ## 📚 References
28
+
29
+ - [ Rule source] ( https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-promise-try.js )
30
+ - [ Test source] ( https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-promise-try.js )
31
+
32
+ [ no-new-in-esnext ] : ../configs/index.md#no-new-in-esnext
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ module.exports = {
14
14
"es-x/no-dynamic-import-options" : "error" ,
15
15
"es-x/no-import-attributes" : "error" ,
16
16
"es-x/no-json-modules" : "error" ,
17
+ "es-x/no-promise-try" : "error" ,
17
18
"es-x/no-regexp-duplicate-named-capturing-groups" : "error" ,
18
19
"es-x/no-regexp-modifiers" : "error" ,
19
20
"es-x/no-set-prototype-difference" : "error" ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module.exports = {
10
10
"es-x/no-dynamic-import-options" : "error" ,
11
11
"es-x/no-import-attributes" : "error" ,
12
12
"es-x/no-json-modules" : "error" ,
13
+ "es-x/no-promise-try" : "error" ,
13
14
"es-x/no-regexp-duplicate-named-capturing-groups" : "error" ,
14
15
"es-x/no-regexp-modifiers" : "error" ,
15
16
"es-x/no-set-prototype-difference" : "error" ,
Original file line number Diff line number Diff line change @@ -295,6 +295,7 @@ module.exports = {
295
295
"no-promise-all-settled" : require ( "./rules/no-promise-all-settled" ) ,
296
296
"no-promise-any" : require ( "./rules/no-promise-any" ) ,
297
297
"no-promise-prototype-finally" : require ( "./rules/no-promise-prototype-finally" ) ,
298
+ "no-promise-try" : require ( "./rules/no-promise-try" ) ,
298
299
"no-promise-withresolvers" : require ( "./rules/no-promise-withresolvers" ) ,
299
300
"no-property-shorthands" : require ( "./rules/no-property-shorthands" ) ,
300
301
"no-proxy" : require ( "./rules/no-proxy" ) ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ "use strict"
6
+
7
+ const { READ , ReferenceTracker } = require ( "@eslint-community/eslint-utils" )
8
+ const { getSourceCode } = require ( "eslint-compat-utils" )
9
+
10
+ module . exports = {
11
+ meta : {
12
+ docs : {
13
+ description : "disallow `Promise.try` function" ,
14
+ category : "ES2025" ,
15
+ recommended : false ,
16
+ url : "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-promise-try.html" ,
17
+ } ,
18
+ fixable : null ,
19
+ messages : {
20
+ forbidden : "ES2025 '{{name}}' is forbidden." ,
21
+ } ,
22
+ schema : [ ] ,
23
+ type : "problem" ,
24
+ } ,
25
+ create ( context ) {
26
+ return {
27
+ "Program:exit" ( program ) {
28
+ const sourceCode = getSourceCode ( context )
29
+ const tracker = new ReferenceTracker (
30
+ sourceCode . getScope ( program ) ,
31
+ )
32
+ for ( const { node, path } of tracker . iterateGlobalReferences ( {
33
+ Promise : {
34
+ try : { [ READ ] : true } ,
35
+ } ,
36
+ } ) ) {
37
+ context . report ( {
38
+ node,
39
+ messageId : "forbidden" ,
40
+ data : { name : path . join ( "." ) } ,
41
+ } )
42
+ }
43
+ } ,
44
+ }
45
+ } ,
46
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ "use strict"
6
+
7
+ const RuleTester = require ( "../../tester" )
8
+ const rule = require ( "../../../lib/rules/no-promise-try.js" )
9
+
10
+ new RuleTester ( ) . run ( "no-promise-try" , rule , {
11
+ valid : [ "Promise.all" ] ,
12
+ invalid : [
13
+ {
14
+ code : "Promise.try" ,
15
+ errors : [ "ES2025 'Promise.try' is forbidden." ] ,
16
+ } ,
17
+ ] ,
18
+ } )
You can’t perform that action at this time.
0 commit comments