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/integrate/nodejs-api.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -457,6 +457,49 @@ The `LoadedFormatter` value is the object to convert the [LintResult] objects to
457
457
458
458
---
459
459
460
+
## loadESLint()
461
+
462
+
The `loadESLint()` function is used for integrations that wish to support both the current configuration system (flat config) and the old configuration system (eslintrc). This function returns the correct `ESLint` class implementation based on the arguments provided:
463
+
464
+
```js
465
+
const { loadESLint } =require("eslint");
466
+
467
+
// loads the default ESLint that the CLI would use based on process.cwd()
468
+
constDefaultESLint=awaitloadESLint();
469
+
470
+
// loads the default ESLint that the CLI would use based on the provided cwd
You can then use the returned constructor to instantiate a new `ESLint` instance, like this:
481
+
482
+
```js
483
+
// loads the default ESLint that the CLI would use based on process.cwd()
484
+
constDefaultESLint=awaitloadESLint();
485
+
consteslint=newDefaultESLint();
486
+
```
487
+
488
+
If you're ever unsure which config system the returned constructor uses, check the `configType` property, which is either `"flat"` or `"eslintrc"`:
489
+
490
+
```js
491
+
// loads the default ESLint that the CLI would use based on process.cwd()
492
+
constDefaultESLint=awaitloadESLint();
493
+
494
+
if (DefaultESLint.configType==="flat") {
495
+
// do something specific to flat config
496
+
}
497
+
```
498
+
499
+
If you don't need to support both the old and new configuration systems, then it's recommended to just use the `ESLint` constructor directly.
500
+
501
+
---
502
+
460
503
## SourceCode
461
504
462
505
The `SourceCode` type represents the parsed source code that ESLint executes on. It's used internally in ESLint and is also available so that already-parsed code can be used. You can create a new instance of `SourceCode` by passing in the text string representing the code and an abstract syntax tree (AST) in [ESTree](https://github.com/estree/estree) format (including location information, range information, comments, and tokens):
0 commit comments