[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Expose out ESLint and CLI to require.
|
---|
| 3 | * @author Ian Christian Myers
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | //-----------------------------------------------------------------------------
|
---|
| 9 | // Requirements
|
---|
| 10 | //-----------------------------------------------------------------------------
|
---|
| 11 |
|
---|
| 12 | const { ESLint, FlatESLint } = require("./eslint");
|
---|
| 13 | const { shouldUseFlatConfig } = require("./eslint/flat-eslint");
|
---|
| 14 | const { Linter } = require("./linter");
|
---|
| 15 | const { RuleTester } = require("./rule-tester");
|
---|
| 16 | const { SourceCode } = require("./source-code");
|
---|
| 17 |
|
---|
| 18 | //-----------------------------------------------------------------------------
|
---|
| 19 | // Functions
|
---|
| 20 | //-----------------------------------------------------------------------------
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * Loads the correct ESLint constructor given the options.
|
---|
| 24 | * @param {Object} [options] The options object
|
---|
| 25 | * @param {boolean} [options.useFlatConfig] Whether or not to use a flat config
|
---|
| 26 | * @param {string} [options.cwd] The current working directory
|
---|
| 27 | * @returns {Promise<ESLint|LegacyESLint>} The ESLint constructor
|
---|
| 28 | */
|
---|
| 29 | async function loadESLint({ useFlatConfig, cwd = process.cwd() } = {}) {
|
---|
| 30 |
|
---|
| 31 | /*
|
---|
| 32 | * Note: The v9.x version of this function doesn't have a cwd option
|
---|
| 33 | * because it's not used. It's only used in the v8.x version of this
|
---|
| 34 | * function.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | const shouldESLintUseFlatConfig = typeof useFlatConfig === "boolean"
|
---|
| 38 | ? useFlatConfig
|
---|
| 39 | : await shouldUseFlatConfig({ cwd });
|
---|
| 40 |
|
---|
| 41 | return shouldESLintUseFlatConfig ? FlatESLint : ESLint;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | //-----------------------------------------------------------------------------
|
---|
| 45 | // Exports
|
---|
| 46 | //-----------------------------------------------------------------------------
|
---|
| 47 |
|
---|
| 48 | module.exports = {
|
---|
| 49 | Linter,
|
---|
| 50 | loadESLint,
|
---|
| 51 | ESLint,
|
---|
| 52 | RuleTester,
|
---|
| 53 | SourceCode
|
---|
| 54 | };
|
---|