Skip to content

Commit 1e0161d

Browse files
committed
Add no-atomics-pause rule
1 parent 821498f commit 1e0161d

File tree

9 files changed

+110
-1
lines changed

9 files changed

+110
-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
@@ -193,6 +193,7 @@ module.exports = {
193193
"no-async-iteration": require("./rules/no-async-iteration"),
194194
"no-asyncdisposablestack": require("./rules/no-asyncdisposablestack"),
195195
"no-atomics": require("./rules/no-atomics"),
196+
"no-atomics-pause": require("./rules/no-atomics-pause"),
196197
"no-atomics-waitasync": require("./rules/no-atomics-waitasync"),
197198
"no-bigint": require("./rules/no-bigint"),
198199
"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/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+
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const RuleTester = require("../../tester")
44
const rule = require("../../../lib/rules/no-atomics-waitasync.js")
55

66
new RuleTester().run("no-atomics-waitasync", rule, {
7-
valid: ["Atomics", "Atomics.wait", "let Atomics = 0; Atomics.watiAsync"],
7+
valid: ["Atomics", "Atomics.wait", "let Atomics = 0; Atomics.waitAsync"],
88
invalid: [
99
{
1010
code: "Atomics.waitAsync",

0 commit comments

Comments
 (0)