You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/extend/custom-parsers.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ ESLint custom parsers let you extend ESLint to support linting new non-standard
12
12
13
13
## Creating a Custom Parser
14
14
15
+
### Methods in Custom Parsers
16
+
15
17
A custom parser is a JavaScript object with either a `parse` or `parseForESLint` method. The `parse` method only returns the AST, whereas `parseForESLint` also returns additional values that let the parser customize the behavior of ESLint even more.
16
18
17
19
Both methods should take in the source code as the first argument, and an optional configuration object as the second argument, which is provided as [`parserOptions`](../use/configure/language-options#specifying-parser-options) in a configuration file.
@@ -33,11 +35,11 @@ function parse(code, options) {
33
35
module.exports= { parse };
34
36
```
35
37
36
-
## `parse` Return Object
38
+
###`parse` Return Object
37
39
38
40
The `parse` method should simply return the [AST](#ast-specification) object.
39
41
40
-
## `parseForESLint` Return Object
42
+
###`parseForESLint` Return Object
41
43
42
44
The `parseForESLint` method should return an object that contains the required property `ast` and optional properties `services`, `scopeManager`, and `visitorKeys`.
43
45
@@ -48,6 +50,22 @@ The `parseForESLint` method should return an object that contains the required p
48
50
*`visitorKeys` can be an object to customize AST traversal. The keys of the object are the type of AST nodes. Each value is an array of the property names which should be traversed. The default is [KEYS of `eslint-visitor-keys`](https://github.com/eslint/eslint-visitor-keys#evkkeys).
49
51
* Support for `visitorKeys` was added in ESLint v4.14.0. ESLint versions that support `visitorKeys` will provide an `eslintVisitorKeys: true` property in `parserOptions`, which can be used for feature detection.
50
52
53
+
### Meta Data in Custom Parsers
54
+
55
+
For easier debugging and more effective caching of custom parsers, it's recommended to provide a name and version in a `meta` object at the root of your custom parsers, like this:
56
+
57
+
```js
58
+
// preferred location of name and version
59
+
module.exports= {
60
+
meta: {
61
+
name:"eslint-parser-custom",
62
+
version:"1.2.3"
63
+
}
64
+
};
65
+
```
66
+
67
+
The `meta.name` property should match the npm package name for your custom parser and the `meta.version` property should match the npm package version for your custom parser. The easiest way to accomplish this is by reading this information from your `package.json`.
68
+
51
69
## AST Specification
52
70
53
71
The AST that custom parsers should create is based on [ESTree](https://github.com/estree/estree). The AST requires some additional properties about detail information of the source code.
Copy file name to clipboardExpand all lines: docs/src/extend/plugins.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,34 +18,6 @@ Each plugin is an npm module with a name in the format of `eslint-plugin-<plugin
18
18
19
19
The easiest way to start creating a plugin is to use the [Yeoman generator](https://www.npmjs.com/package/generator-eslint). The generator will guide you through setting up the skeleton of a plugin.
20
20
21
-
### Metadata in Plugins
22
-
23
-
For easier debugging and more effective caching of plugins, it's recommended to provide a name and version in a `meta` object at the root of your plugin, like this:
24
-
25
-
```js
26
-
// preferred location of name and version
27
-
module.exports= {
28
-
meta: {
29
-
name:"eslint-plugin-custom",
30
-
version:"1.2.3"
31
-
}
32
-
};
33
-
```
34
-
35
-
The `meta.name` property should match the npm package name for your plugin and the `meta.version` property should match the npm package version for your plugin. The easiest way to accomplish this is by reading this information from your `package.json`.
36
-
37
-
As an alternative, you can also expose `name` and `version` properties at the root of your plugin, such as:
38
-
39
-
```js
40
-
// alternate location of name and version
41
-
module.exports= {
42
-
name:"eslint-plugin-custom",
43
-
version:"1.2.3"
44
-
};
45
-
```
46
-
47
-
While the `meta` object is the preferred way to provide the plugin name and version, this format is also acceptable and is provided for backward compatibility.
48
-
49
21
### Rules in Plugins
50
22
51
23
Plugins can expose custom rules for use in ESLint. To do so, the plugin must export a `rules` object containing a key-value mapping of rule ID to rule. The rule ID does not have to follow any naming convention (so it can just be `dollar-sign`, for instance). To learn more about creating custom rules in plugins, refer to [Custom Rules](custom-rules).
@@ -163,6 +135,34 @@ If the example plugin above were called `eslint-plugin-myPlugin`, the `myConfig`
163
135
164
136
```
165
137
138
+
### Meta Data in Plugins
139
+
140
+
For easier debugging and more effective caching of plugins, it's recommended to provide a name and version in a `meta` object at the root of your plugin, like this:
141
+
142
+
```js
143
+
// preferred location of name and version
144
+
module.exports= {
145
+
meta: {
146
+
name:"eslint-plugin-custom",
147
+
version:"1.2.3"
148
+
}
149
+
};
150
+
```
151
+
152
+
The `meta.name` property should match the npm package name for your plugin and the `meta.version` property should match the npm package version for your plugin. The easiest way to accomplish this is by reading this information from your `package.json`.
153
+
154
+
As an alternative, you can also expose `name` and `version` properties at the root of your plugin, such as:
155
+
156
+
```js
157
+
// alternate location of name and version
158
+
module.exports= {
159
+
name:"eslint-plugin-custom",
160
+
version:"1.2.3"
161
+
};
162
+
```
163
+
164
+
While the `meta` object is the preferred way to provide the plugin name and version, this format is also acceptable and is provided for backward compatibility.
165
+
166
166
### Peer Dependency
167
167
168
168
To make clear that the plugin requires ESLint to work correctly, you must declare ESLint as a peer dependency by mentioning it in the `peerDependencies` field of your plugin's `package.json`.
0 commit comments