Skip to content

Commit a0c417c

Browse files
authored
Add rules for Float16Array (#239)
1 parent a749c7e commit a0c417c

28 files changed

+530
-7
lines changed

docs/.vitepress/theme/components/eslint-playground.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import EslintEditor from "./eslint-editor.vue"
33
import { markRaw, ref, reactive, computed, onMounted, useSlots } from "vue"
44
import * as plugin from "../../../.."
5+
import { builtin } from "globals"
56
const { rules } = plugin.default || plugin
67
78
const props = defineProps({
@@ -56,6 +57,10 @@ const config = computed(() => ({
5657
jsx: true,
5758
},
5859
},
60+
globals: {
61+
Float16Array: "readonly",
62+
...builtin,
63+
},
5964
},
6065
rules: {},
6166
settings: {

docs/configs/index.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,34 @@ export default [
10291029
}
10301030
```
10311031

1032+
## no-float16array
1033+
1034+
disallow proposal ES2025 [Float16Array](https://github.com/tc39/proposal-float16array)\
1035+
⚠️ This config will be changed in the minor versions of this plugin.
1036+
1037+
This configs includes rules for [es-x/no-dataview-prototype-getfloat16-setfloat16](../rules/no-dataview-prototype-getfloat16-setfloat16.md), [es-x/no-float16array](../rules/no-float16array.md), and [es-x/no-math-f16round](../rules/no-math-f16round.md).
1038+
1039+
### [Config (Flat Config)]
1040+
1041+
eslint.config.js:
1042+
1043+
```js
1044+
import pluginESx from "eslint-plugin-es-x"
1045+
export default [
1046+
pluginESx.configs['flat/no-float16array']
1047+
]
1048+
```
1049+
1050+
### [Legacy Config]
1051+
1052+
.eslintrc.*:
1053+
1054+
```json
1055+
{
1056+
"extends": ["plugin:es-x/no-float16array"],
1057+
}
1058+
```
1059+
10321060
## no-import-attributes
10331061

10341062
disallow proposal ES2025 [Import Attributes](https://github.com/tc39/proposal-import-attributes)\

docs/rules/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1010

1111
| Rule ID | Description | |
1212
|:--------|:------------|:--:|
13+
| [es-x/no-dataview-prototype-getfloat16-setfloat16](./no-dataview-prototype-getfloat16-setfloat16.md) | disallow the `DataView.prototype.{getFloat16,setFloat16}` methods. | |
1314
| [es-x/no-dynamic-import-options](./no-dynamic-import-options.md) | disallow the second parameter to `import()`. | |
15+
| [es-x/no-float16array](./no-float16array.md) | disallow the `Float16Array` class. | |
1416
| [es-x/no-import-attributes](./no-import-attributes.md) | disallow Import Attributes. | |
1517
| [es-x/no-iterator-prototype-drop](./no-iterator-prototype-drop.md) | disallow the `Iterator.prototype.drop` method. | |
1618
| [es-x/no-iterator-prototype-every](./no-iterator-prototype-every.md) | disallow the `Iterator.prototype.every` method. | |
@@ -25,6 +27,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
2527
| [es-x/no-iterator-prototype-toarray](./no-iterator-prototype-toarray.md) | disallow the `Iterator.prototype.toArray` method. | |
2628
| [es-x/no-iterator](./no-iterator.md) | disallow the `Iterator` class. | |
2729
| [es-x/no-json-modules](./no-json-modules.md) | disallow JSON Modules. | |
30+
| [es-x/no-math-f16round](./no-math-f16round.md) | disallow the `Math.f16round` method. | |
2831
| [es-x/no-promise-try](./no-promise-try.md) | disallow `Promise.try` function. | |
2932
| [es-x/no-regexp-duplicate-named-capturing-groups](./no-regexp-duplicate-named-capturing-groups.md) | disallow RegExp duplicate named capturing groups. | |
3033
| [es-x/no-regexp-escape](./no-regexp-escape.md) | disallow `RegExp.escape` function. | |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "es-x/no-dataview-prototype-getfloat16-setfloat16"
3+
description: "disallow the `DataView.prototype.{getFloat16,setFloat16}` methods"
4+
---
5+
6+
# es-x/no-dataview-prototype-getfloat16-setfloat16
7+
> disallow the `DataView.prototype.{getFloat16,setFloat16}` methods
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-float16array] and [no-new-in-esnext]
11+
12+
This rule reports ES2025 [`DataView.prototype.{getFloat16,setFloat16}` methods](https://github.com/tc39/proposal-float16array) as errors.
13+
14+
This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.
15+
16+
## 💡 Examples
17+
18+
⛔ Examples of **incorrect** code for this rule:
19+
20+
<eslint-playground type="bad">
21+
22+
```js
23+
/*eslint es-x/no-dataview-prototype-getfloat16-setfloat16: error */
24+
const buffer = new ArrayBuffer(16);
25+
26+
const view = new DataView(buffer);
27+
view.setFloat16(1, Math.PI);
28+
29+
console.log(view.getFloat16(1));
30+
```
31+
32+
</eslint-playground>
33+
34+
## 📚 References
35+
36+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-dataview-prototype-getfloat16-setfloat16.js)
37+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-dataview-prototype-getfloat16-setfloat16.js)
38+
39+
[no-float16array]: ../configs/index.md#no-float16array
40+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-float16array.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "es-x/no-float16array"
3+
description: "disallow the `Float16Array` class"
4+
---
5+
6+
# es-x/no-float16array
7+
> disallow the `Float16Array` class
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-float16array] and [no-new-in-esnext]
11+
12+
This rule reports ES2025 [`Float16Array` class](https://github.com/tc39/proposal-float16array) 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-float16array: error */
22+
const float16 = new Float16Array(2);
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-float16array.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-float16array.js)
31+
32+
[no-float16array]: ../configs/index.md#no-float16array
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

docs/rules/no-math-f16round.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "es-x/no-math-f16round"
3+
description: "disallow the `Math.f16round` method"
4+
---
5+
6+
# es-x/no-math-f16round
7+
> disallow the `Math.f16round` 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-float16array] and [no-new-in-esnext]
11+
12+
This rule reports ES2025 [`Math.f16round` method](https://github.com/tc39/proposal-float16array) 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-math-f16round: error */
22+
const n = Math.f16round(value)
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-math-f16round.js)
30+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-math-f16round.js)
31+
32+
[no-float16array]: ../configs/index.md#no-float16array
33+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

lib/configs/flat/no-float16array.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* DON'T EDIT THIS FILE.
3+
* This file was generated by "scripts/update-lib-flat-configs.js" script.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
plugins: {
9+
get "es-x"() {
10+
return require("../../index.js")
11+
},
12+
},
13+
rules: {
14+
"es-x/no-dataview-prototype-getfloat16-setfloat16": "error",
15+
"es-x/no-float16array": "error",
16+
"es-x/no-math-f16round": "error",
17+
},
18+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ module.exports = {
1111
},
1212
},
1313
rules: {
14+
"es-x/no-dataview-prototype-getfloat16-setfloat16": "error",
1415
"es-x/no-dynamic-import-options": "error",
16+
"es-x/no-float16array": "error",
1517
"es-x/no-import-attributes": "error",
1618
"es-x/no-iterator-prototype-drop": "error",
1719
"es-x/no-iterator-prototype-every": "error",
@@ -26,6 +28,7 @@ module.exports = {
2628
"es-x/no-iterator-prototype-toarray": "error",
2729
"es-x/no-iterator": "error",
2830
"es-x/no-json-modules": "error",
31+
"es-x/no-math-f16round": "error",
2932
"es-x/no-promise-try": "error",
3033
"es-x/no-regexp-duplicate-named-capturing-groups": "error",
3134
"es-x/no-regexp-escape": "error",

lib/configs/no-float16array.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* DON'T EDIT THIS FILE.
3+
* This file was generated by "scripts/update-lib-configs.js" script.
4+
*/
5+
"use strict"
6+
7+
module.exports = {
8+
plugins: ["es-x"],
9+
rules: {
10+
"es-x/no-dataview-prototype-getfloat16-setfloat16": "error",
11+
"es-x/no-float16array": "error",
12+
"es-x/no-math-f16round": "error",
13+
},
14+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
module.exports = {
88
plugins: ["es-x"],
99
rules: {
10+
"es-x/no-dataview-prototype-getfloat16-setfloat16": "error",
1011
"es-x/no-dynamic-import-options": "error",
12+
"es-x/no-float16array": "error",
1113
"es-x/no-import-attributes": "error",
1214
"es-x/no-iterator-prototype-drop": "error",
1315
"es-x/no-iterator-prototype-every": "error",
@@ -22,6 +24,7 @@ module.exports = {
2224
"es-x/no-iterator-prototype-toarray": "error",
2325
"es-x/no-iterator": "error",
2426
"es-x/no-json-modules": "error",
27+
"es-x/no-math-f16round": "error",
2528
"es-x/no-promise-try": "error",
2629
"es-x/no-regexp-duplicate-named-capturing-groups": "error",
2730
"es-x/no-regexp-escape": "error",

0 commit comments

Comments
 (0)