Skip to content

Commit 804c08e

Browse files
committed
Docs: Add parserOptions to RuleTester section of working-with-rules
1 parent 8ca6bed commit 804c08e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/developer-guide/working-with-rules.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,45 @@ invalid: [
439439
]
440440
```
441441

442+
### Specifying Parser Options
443+
444+
Some tests require that a certain parser configuration must be used. This can be specified in test specifications via the `parserOptions` setting.
445+
446+
For example, to set `ecmaVersion` to 6 (in order to use constructs like `for ... of`):
447+
448+
```js
449+
valid: [
450+
{
451+
code: "for (x of a) doSomething();",
452+
parserOptions: { ecmaVersion: 6 }
453+
}
454+
]
455+
```
456+
457+
If you are working with ES6 modules:
458+
459+
```js
460+
valid: [
461+
{
462+
code: "export default function () {};",
463+
parserOptions: { ecmaVersion: 6, sourceType: "module" }
464+
}
465+
]
466+
```
467+
468+
For non-version specific features such as JSX:
469+
470+
```js
471+
valid: [
472+
{
473+
code: "var foo = <div>{bar}</div>",
474+
parserOptions: { ecmaFeatures: { jsx: true } }
475+
}
476+
]
477+
```
478+
479+
The options available and the expected syntax for `parserOptions` is the same as those used in [configuration](../user-guide/configuring#specifying-parser-options).
480+
442481
### Write Several Tests
443482

444483
Provide as many unit tests as possible. Your pull request will never be turned down for having too many tests submitted with it!

0 commit comments

Comments
 (0)