Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9988c15

Browse files
committed
Merge branch 'next'
2 parentsd9ed4eb +eef513c commit9988c15

File tree

64 files changed

+12097
-1083
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+12097
-1083
lines changed

‎.eslintrc.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
"env": {
55
"node":true,
66
"jest":true
7-
}
7+
},
8+
"parserOptions": {
9+
"ecmaVersion":2021
10+
},
11+
"plugins": ["node"]
812
}

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
-master
6+
-next
67

78
permissions:
89
contents:read# for checkout

‎.nvmrc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.17.0
1+
20.9.0

‎README.md‎

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ Then configure the rules you want to use under the rules section.
4343
"xstate/invoke-usage":"error",
4444
"xstate/entry-exit-action":"error",
4545
"xstate/prefer-always":"error",
46+
"xstate/prefer-predictable-action-arguments":"error",
4647
"xstate/no-misplaced-on-transition":"error",
4748
"xstate/no-invalid-transition-props":"error",
4849
"xstate/no-invalid-state-props":"error",
50+
"xstate/no-invalid-conditional-action":"error",
4951
"xstate/no-async-guard":"error",
5052
"xstate/event-names": ["warn","macroCase"],
5153
"xstate/state-names": ["warn","camelCase"],
5254
"xstate/no-inline-implementation":"warn",
53-
"xstate/no-auto-forward":"warn"
55+
"xstate/no-auto-forward":"warn",
56+
"xstate/system-id":"warn"
5457
}
5558
}
5659
```
@@ -73,13 +76,41 @@ There is also an `all` configuration which includes every available rule. It enf
7376
}
7477
```
7578

79+
###XState Version
80+
81+
The default shareable configurations are for XState v5. If you use XState version 4, append`_v4` to the name of the configuration you want to use.
82+
83+
```json
84+
{
85+
"extends": ["plugin:xstate/recommended_v4"]
86+
}
87+
```
88+
89+
```json
90+
{
91+
"extends": ["plugin:xstate/all_v4"]
92+
}
93+
```
94+
95+
If you do not use shareable configs, you need to manually specify the XState version in the ESLint config (defaults to 5):
96+
97+
```json
98+
{
99+
"settings": {
100+
"xstate": {
101+
"version":4
102+
}
103+
}
104+
}
105+
```
106+
76107
##Supported Rules
77108

78109
###Possible Errors
79110

80111
| Rule| Description| Recommended|
81112
| ----------------------------------------------------------------------------------| ------------------------------------------------------------------| ------------------|
82-
|[spawn-usage](docs/rules/spawn-usage.md)| Enforce correct usage of`spawn`|:heavy_check_mark:|
113+
|[spawn-usage](docs/rules/spawn-usage.md)| Enforce correct usage of`spawn`.**Only for XState v4!**|:heavy_check_mark:|
83114
|[no-infinite-loop](docs/rules/no-infinite-loop.md)| Detect infinite loops with eventless transitions|:heavy_check_mark:|
84115
|[no-imperative-action](docs/rules/no-imperative-action.md)| Forbid using action creators imperatively|:heavy_check_mark:|
85116
|[no-ondone-outside-compound-state](docs/rules/no-ondone-outside-compound-state.md)| Forbid onDone transitions on`atomic`,`history` and`final` nodes|:heavy_check_mark:|
@@ -89,18 +120,35 @@ There is also an `all` configuration which includes every available rule. It enf
89120
|[no-invalid-transition-props](docs/rules/no-invalid-transition-props.md)| Forbid invalid properties in transition declarations|:heavy_check_mark:|
90121
|[no-invalid-state-props](docs/rules/no-invalid-state-props.md)| Forbid invalid properties in state node declarations|:heavy_check_mark:|
91122
|[no-async-guard](docs/rules/no-async-guard.md)| Forbid asynchronous guard functions|:heavy_check_mark:|
123+
|[no-invalid-conditional-action](docs/rules/no-invalid-conditional-action.md)| Forbid invalid declarations inside the`choose` action creator|:heavy_check_mark:|
92124

93125
###Best Practices
94126

95-
| Rule| Description| Recommended|
96-
| ------------------------------------------------------------------| -----------------------------------------------------------------------| ------------------|
97-
|[no-inline-implementation](docs/rules/no-inline-implementation.md)| Suggest refactoring guards, actions and services into machine options||
98-
|[prefer-always](docs/rules/prefer-always.md)| Suggest using the`always` syntax for transient (eventless) transitions|:heavy_check_mark:|
99-
|[no-auto-forward](docs/rules/no-auto-forward.md)| Forbid auto-forwarding events to invoked services or spawned actors||
127+
| Rule| Description| Recommended|
128+
| ----------------------------------------------------------------------------------------| -----------------------------------------------------------------------| ------------------|
129+
|[no-inline-implementation](docs/rules/no-inline-implementation.md)| Suggest refactoring guards, actions and services into machine options||
130+
|[prefer-always](docs/rules/prefer-always.md)| Suggest using the`always` syntax for transient (eventless) transitions|:heavy_check_mark:|
131+
|[prefer-predictable-action-arguments](docs/rules/prefer-predictable-action-arguments.md)| Suggest turning on the`predictableActionArguments` option|:heavy_check_mark:|
132+
|[no-auto-forward](docs/rules/no-auto-forward.md)| Forbid auto-forwarding events to invoked services or spawned actors||
133+
|[system-id](docs/rules/system-id.md)| Suggest using systemId for invoked or spawned actors||
100134

101135
###Stylistic Issues
102136

103137
| Rule| Description| Recommended|
104138
| ----------------------------------------| ------------------------------------------------------------------------| -----------|
105139
|[event-names](docs/rules/event-names.md)| Suggest consistent formatting of event names||
106140
|[state-names](docs/rules/state-names.md)| Suggest consistent formatting of state names and prevent confusing names||
141+
142+
##Comment Directives
143+
144+
By default, the plugin lints only code within the`createMachine` or`Machine` calls. However, if your machine configuration is imported from another file, you will need to enable this plugin's rules by adding a comment directive to the top of the file:
145+
146+
```js
147+
/* eslint-plugin-xstate-include*/
148+
// 💡 This machine config will now be linted too.
149+
exportconstmachine= {
150+
initial:'active',
151+
context: {},
152+
// etc
153+
}
154+
```

‎docs/rules/event-names.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ While the XState library neither enforces nor recommends any particular format f
1111
- camelCase
1212
- regular expression
1313

14-
The default MACRO*CASE for event names is an\_unofficial* convention, typically used within the XState community.
14+
The default MACRO*CASE for event names is an*unofficial\* convention, typically used within the XState community.
1515

1616
Examples of**incorrect** code for this rule:
1717

‎docs/rules/no-async-guard.md‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
##Rule Details
66

7-
Async functions return a promise which is a truthy value. Therefore, async guard functions always pass. Transitions guarded by such functions will always be taken as if no`cond` was specified.
7+
Async functions return a promise which is a truthy value. Therefore, async guard functions always pass. Transitions guarded by such functions will always be taken as if no`cond`(XState v4) or`guard` (XState v5)was specified.
88

99
Examples of**incorrect** code for this rule:
1010

1111
```javascript
12-
// ❌ async guard in an event transition
12+
// ❌ async guard in an event transition (XState v4)
1313
createMachine({
1414
on: {
1515
EVENT: {
@@ -19,37 +19,47 @@ createMachine({
1919
},
2020
})
2121

22-
// ❌ async guard in an onDone transition
22+
// ❌ async guard in an event transition (XState v5)
23+
createMachine({
24+
on: {
25+
EVENT: {
26+
guard:async ()=> {},
27+
target:'active',
28+
},
29+
},
30+
})
31+
32+
// ❌ async guard in an onDone transition (XState v5)
2333
createMachine({
2434
states: {
2535
active: {
2636
invoke: {
2737
src:'myService',
2838
onDone: {
29-
cond:asyncfunction () {},
39+
guard:asyncfunction () {},
3040
target:'finished',
3141
},
3242
},
3343
},
3444
},
3545
})
3646

37-
// ❌ async guard in the choose action creator
47+
// ❌ async guard in the choose action creator (XState v5)
3848
createMachine({
3949
entry:choose([
4050
{
41-
cond:async ()=> {},
51+
guard:async ()=> {},
4252
actions:'myAction',
4353
},
4454
]),
4555
})
4656

47-
// ❌ async guards in machine options
57+
// ❌ async guards in machine options (XState v5)
4858
createMachine(
4959
{
5060
on: {
5161
EVENT: {
52-
cond:'myGuard',
62+
guard:'myGuard',
5363
target:'active',
5464
},
5565
},
@@ -67,7 +77,7 @@ createMachine(
6777
Examples of**correct** code for this rule:
6878

6979
```javascript
70-
// ✅ guard is synchronous
80+
// ✅ guard is synchronous (XState v4)
7181
createMachine({
7282
on: {
7383
EVENT: {
@@ -77,27 +87,37 @@ createMachine({
7787
},
7888
})
7989

80-
// ✅ guard is synchronous
90+
// ✅ guard is synchronous (XState v5)
91+
createMachine({
92+
on: {
93+
EVENT: {
94+
guard: ()=> {},
95+
target:'active',
96+
},
97+
},
98+
})
99+
100+
// ✅ guard is synchronous (XState v5)
81101
createMachine({
82102
states: {
83103
active: {
84104
invoke: {
85105
src:'myService',
86106
onDone: {
87-
cond:function () {},
107+
guard:function () {},
88108
target:'finished',
89109
},
90110
},
91111
},
92112
},
93113
})
94114

95-
// ✅ all guards in machine options are synchronous
115+
// ✅ all guards in machine options are synchronous (XState v5)
96116
createMachine(
97117
{
98118
on: {
99119
EVENT: {
100-
cond:'myGuard',
120+
guard:'myGuard',
101121
target:'active',
102122
},
103123
},

‎docs/rules/no-auto-forward.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Prefer sending events explicitly to child actors/services.
66

77
Avoid blindly forwarding all events to invoked services or spawned actors - it may lead to unexpected behavior or infinite loops. The official documentation[suggests sending events explicitly](https://xstate.js.org/docs/guides/communication.html#the-invoke-property) with the[`forwardTo`](https://xstate.js.org/docs/guides/actions.html#forward-to-action) or`send` action creators.
88

9+
**XState v5 removed the`autoForward` option. This rule will report errors if`autoForward` is used with XState v5.**
10+
911
Examples of**incorrect** code for this rule:
1012

1113
```javascript
@@ -33,7 +35,7 @@ createMachine({
3335
})
3436
```
3537

36-
Examples of**correct** code for this rule:
38+
Examples of**correct** code for this rule (XState v4 only):
3739

3840
```javascript
3941
// ✅ no auto-forward

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp