Skip to content

Commit 12fc0f3

Browse files
committed
Add no-atomics-pause rule
1 parent f7a9733 commit 12fc0f3

File tree

11 files changed

+142
-1
lines changed

11 files changed

+142
-1
lines changed

docs/rules/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1212
|:--------|:------------|:--:|
1313
| [es-x/no-array-fromasync](./no-array-fromasync.md) | disallow the `Array.fromAsync` method. | |
1414
| [es-x/no-asyncdisposablestack](./no-asyncdisposablestack.md) | disallow the `AsyncDisposableStack` class. | |
15+
| [es-x/no-atomics-pause](./no-atomics-pause.md) | disallow the `Atomics.pause` method. | |
1516
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
1617
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
1718
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |

docs/rules/no-atomics-pause.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "es-x/no-atomics-pause"
3+
description: "disallow the `Atomics.pause` method"
4+
---
5+
6+
# es-x/no-atomics-pause
7+
> disallow the `Atomics.pause` method
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 ES2026 [`Atomics.pause` method](https://github.com/tc39/proposal-atomics-microwait) 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-atomics-pause: [error] */
22+
Atomics.pause()
23+
```
24+
25+
</eslint-playground>
26+
27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-atomics-pause": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-atomics-pause.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-atomics-pause.js)
53+
54+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

lib/configs/flat/no-new-in-esnext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
rules: {
1414
"es-x/no-array-fromasync": "error",
1515
"es-x/no-asyncdisposablestack": "error",
16+
"es-x/no-atomics-pause": "error",
1617
"es-x/no-disposablestack": "error",
1718
"es-x/no-error-iserror": "error",
1819
"es-x/no-suppressederror": "error",

lib/configs/no-new-in-esnext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
rules: {
1010
"es-x/no-array-fromasync": "error",
1111
"es-x/no-asyncdisposablestack": "error",
12+
"es-x/no-atomics-pause": "error",
1213
"es-x/no-disposablestack": "error",
1314
"es-x/no-error-iserror": "error",
1415
"es-x/no-suppressederror": "error",

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ module.exports = {
183183
"no-async-iteration": require("./rules/no-async-iteration"),
184184
"no-asyncdisposablestack": require("./rules/no-asyncdisposablestack"),
185185
"no-atomics": require("./rules/no-atomics"),
186+
"no-atomics-pause": require("./rules/no-atomics-pause"),
186187
"no-atomics-waitasync": require("./rules/no-atomics-waitasync"),
187188
"no-bigint": require("./rules/no-bigint"),
188189
"no-binary-numeric-literals": require("./rules/no-binary-numeric-literals"),

lib/rules/no-atomics-pause.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict"
2+
3+
const {
4+
defineStaticPropertiesHandler,
5+
} = require("../util/define-static-properties-handler")
6+
7+
module.exports = {
8+
meta: {
9+
docs: {
10+
description: "disallow the `Atomics.pause` method.",
11+
category: "ES2026",
12+
recommended: false,
13+
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-atomics-pause.html",
14+
},
15+
fixable: null,
16+
messages: {
17+
forbidden: "ES2024 '{{name}}' method is forbidden.",
18+
},
19+
schema: [
20+
{
21+
type: "object",
22+
properties: {
23+
allowTestedProperty: { type: "boolean" },
24+
},
25+
additionalProperties: false,
26+
},
27+
],
28+
type: "problem",
29+
},
30+
create(context) {
31+
return defineStaticPropertiesHandler(context, {
32+
Atomics: { pause: "function" },
33+
})
34+
},
35+
}

lib/util/type-checker/es-types.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,35 @@ const WELLKNOWN_GLOBALS = {
459459
stackTraceLimit: { type: "Number" },
460460
},
461461
},
462+
Atomics: {
463+
type: "Object",
464+
/** @type {Record<import('./types').AtomicsProperty,TypeInfo|undefined>} */
465+
properties: {
466+
add: RETURN_NUMBER,
467+
and: RETURN_NUMBER,
468+
compareExchange: RETURN_NUMBER,
469+
exchange: RETURN_NUMBER,
470+
isLockFree: RETURN_BOOLEAN,
471+
load: RETURN_NUMBER,
472+
notify: RETURN_NUMBER,
473+
or: RETURN_NUMBER,
474+
store: RETURN_NUMBER,
475+
sub: RETURN_NUMBER,
476+
wait: RETURN_STRING,
477+
waitAsync: {
478+
type: "Function",
479+
return: {
480+
type: "Object",
481+
properties: {
482+
async: { type: "Boolean" },
483+
// value: { type: "Promise" or "String" },
484+
},
485+
},
486+
},
487+
xor: RETURN_NUMBER,
488+
pause: { type: "Function" },
489+
},
490+
},
462491
}
463492

464493
/** @type {Record<import('./types').ObjectPrototypeProperty, TypeInfo>} */

lib/util/type-checker/types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,6 @@ export type MathProperty = Exclude<keyof typeof Math, ExcludeProperty>;
234234
export type ErrorProperty =
235235
| Exclude<keyof typeof Error, ExcludeProperty | "prepareStackTrace">
236236
| "isError";
237+
export type AtomicsProperty =
238+
| Exclude<keyof typeof Atomics, ExcludeProperty>
239+
| "pause";

lib/util/well-known-properties.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ const atomicsProperties = new Set([
801801
"notify",
802802
"xor",
803803
// [ %Symbol.toStringTag% ]
804+
805+
"pause",
804806
])
805807

806808
const jsonProperties = new Set([

tests/lib/rules/no-atomics-pause.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict"
2+
3+
const RuleTester = require("../../tester")
4+
const rule = require("../../../lib/rules/no-atomics-pause.js")
5+
6+
new RuleTester().run("no-atomics-pause", rule, {
7+
valid: ["Atomics", "Atomics.wait", "let Atomics = 0; Atomics.pause"],
8+
invalid: [
9+
{
10+
code: "Atomics.pause",
11+
errors: ["ES2026 'Atomics.pause' method is forbidden."],
12+
},
13+
],
14+
})

0 commit comments

Comments
 (0)