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/developer-guide/nodejs-api.md
+26-6Lines changed: 26 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,15 +49,16 @@ var codeLines = SourceCode.splitLines(code);
49
49
*/
50
50
```
51
51
52
-
## linter
52
+
## Linter
53
53
54
-
The `linter` object does the actual evaluation of the JavaScript code. It doesn't do any filesystem operations, it simply parses and reports on the code. In particular, the `linter` object does not process configuration objects or files. You can retrieve `linter` like this:
54
+
The `Linter` object does the actual evaluation of the JavaScript code. It doesn't do any filesystem operations, it simply parses and reports on the code. In particular, the `Linter` object does not process configuration objects or files. You can retrieve instances of `Linter` like this:
55
55
56
56
```js
57
-
var linter =require("eslint").linter;
57
+
var Linter =require("eslint").Linter;
58
+
var linter =newLinter();
58
59
```
59
60
60
-
The most important method on `linter` is `verify()`, which initiates linting of the given text. This method accepts four arguments:
61
+
The most important method on `Linter` is `verify()`, which initiates linting of the given text. This method accepts four arguments:
61
62
62
63
*`code` - the source code to lint (a string or instance of `SourceCode`).
63
64
*`config` - a configuration object that has been processed and normalized by CLIEngine using eslintrc files and/or other configuration arguments.
@@ -71,7 +72,8 @@ The most important method on `linter` is `verify()`, which initiates linting of
71
72
You can call `verify()` like this:
72
73
73
74
```js
74
-
var linter =require("eslint").linter;
75
+
var Linter =require("eslint").Linter;
76
+
var linter =newLinter();
75
77
76
78
var messages =linter.verify("var foo;", {
77
79
rules: {
@@ -129,7 +131,8 @@ The information available for each linting message is:
129
131
You can also get an instance of the `SourceCode` object used inside of `linter` by using the `getSourceCode()` method:
In this way, you can retrieve the text and AST used for the last run of `linter.verify()`.
146
149
150
+
## linter
151
+
152
+
The `eslint.linter` object (deprecated) is an instance of the `Linter` class as defined [above](#Linter). `eslint.linter` exists for backwards compatibility, but we do not recommend using it because any mutations to it are shared among every module that uses `eslint`. Instead, please create your own instance of `eslint.Linter`.
153
+
154
+
```js
155
+
var linter =require("eslint").linter;
156
+
157
+
var messages =linter.verify("var foo;", {
158
+
rules: {
159
+
semi:2
160
+
}
161
+
}, { filename:"foo.js" });
162
+
```
163
+
164
+
Note: This API is deprecated as of 4.0.0.
165
+
147
166
## CLIEngine
148
167
149
168
The primary Node.js API is `CLIEngine`, which is the underlying utility that runs the ESLint command line interface. This object will read the filesystem for configuration and file information but will not output any results. Instead, it allows you direct access to the important information so you can deal with the output yourself.
*`cli` - the `cli` object has been deprecated in favor of `CLIEngine`. As of v1.0.0, `cli` is no longer exported and should not be used by external tools.
588
+
*`linter` - the `linter` object has has been deprecated in favor of `Linter`, as of v4.0.0
0 commit comments