📄 ESLintShared¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 8 |
| 🧱 Classes | 1 |
| 📦 Imports | 2 |
| 📐 Interfaces | 13 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/utils/src/ts-eslint/eslint/ESLintShared.ts
📦 Imports¶
| Name | Source |
|---|---|
Linter |
../Linter |
RuleMetaData |
../Rule |
Functions¶
ESLintBase.calculateConfigForFile(filePath: string): Promise<Config>¶
This method calculates the configuration for a given file, which can be useful for debugging purposes. - It resolves and merges extends and overrides settings into the top level configuration. - It resolves the parser setting to absolute paths. - It normalizes the plugins setting to align short names. (e.g., eslint-plugin-foo → foo) - It adds the processor setting if a legacy file extension processor is matched. - It doesn't interpret the env setting to the globals and parserOptions settings, so the result object contains the env setting as is.
Parameters:
filePathany: The path to the file whose configuration you would like to calculate. Directory paths are forbidden because ESLint cannot handle the overrides setting.
Returns: undefined
The promise that will be fulfilled with a configuration object.
Raw JSDoc
/**
* This method calculates the configuration for a given file, which can be useful for debugging purposes.
* - It resolves and merges extends and overrides settings into the top level configuration.
* - It resolves the parser setting to absolute paths.
* - It normalizes the plugins setting to align short names. (e.g., eslint-plugin-foo → foo)
* - It adds the processor setting if a legacy file extension processor is matched.
* - It doesn't interpret the env setting to the globals and parserOptions settings, so the result object contains
* the env setting as is.
* @param filePath The path to the file whose configuration you would like to calculate. Directory paths are forbidden
* because ESLint cannot handle the overrides setting.
* @returns The promise that will be fulfilled with a configuration object.
*/
ESLintBase.getRulesMetaForResults(results: LintResult[]): Record<string, RuleMetaData<string, Record<string, unknown>…¶
Parameters:
resultsLintResult[]
Returns: Record<string, RuleMetaData<string, Record<string, unknown>>>
Code
ESLintBase.isPathIgnored(filePath: string): Promise<boolean>¶
This method checks if a given file is ignored by your configuration.
Parameters:
filePathany: The path to the file you want to check.
Returns: undefined
The promise that will be fulfilled with whether the file is ignored or not. If the file is ignored, then
it will return true.
Raw JSDoc
ESLintBase.lintFiles(patterns: string | string[]): Promise<LintResult[]>¶
This method lints the files that match the glob patterns and then returns the results.
Parameters:
patternsany: The lint target files. This can contain any of file paths, directory paths, and glob patterns.
Returns: undefined
The promise that will be fulfilled with an array of LintResult objects.
Raw JSDoc
ESLintBase.lintText(code: string, options: LintTextOptions): Promise<LintResult[]>¶
This method lints the given source code text and then returns the results.
By default, this method uses the configuration that applies to files in the current working directory (the cwd constructor option). If you want to use a different configuration, pass options.filePath, and ESLint will load the same configuration that eslint.lintFiles() would use for a file at options.filePath.
If the options.filePath value is configured to be ignored, this method returns an empty array. If the options.warnIgnored option is set along with the options.filePath option, this method returns a LintResult object. In that case, the result may contain a warning that indicates the file was ignored.
Parameters:
codeany: The source code text to check.
Returns: undefined
The promise that will be fulfilled with an array of LintResult objects. This is an array (despite there
being only one lint result) in order to keep the interfaces between this and the eslint.lintFiles()
method similar.
Raw JSDoc
/**
* This method lints the given source code text and then returns the results.
*
* By default, this method uses the configuration that applies to files in the current working directory (the cwd
* constructor option). If you want to use a different configuration, pass options.filePath, and ESLint will load the
* same configuration that eslint.lintFiles() would use for a file at options.filePath.
*
* If the options.filePath value is configured to be ignored, this method returns an empty array. If the
* options.warnIgnored option is set along with the options.filePath option, this method returns a LintResult object.
* In that case, the result may contain a warning that indicates the file was ignored.
* @param code The source code text to check.
* @returns The promise that will be fulfilled with an array of LintResult objects. This is an array (despite there
* being only one lint result) in order to keep the interfaces between this and the eslint.lintFiles()
* method similar.
*/
ESLintBase.loadFormatter(name: string): Promise<Formatter>¶
This method loads a formatter. Formatters convert lint results to a human- or machine-readable string.
Parameters:
nameany: TThe path to the file you want to check. The following values are allowed:- undefined. In this case, loads the "stylish" built-in formatter.
- A name of built-in formatters.
- A name of third-party formatters. For examples:
--
foowill load eslint-formatter-foo. --@foowill load@foo/eslint-formatter. --@foo/barwill load@foo/eslint-formatter-bar. - A path to the file that defines a formatter. The path must contain one or more path separators (/) in order to distinguish if it's a path or not. For example, start with ./.
Returns: undefined
The promise that will be fulfilled with a Formatter object.
Raw JSDoc
/**
* This method loads a formatter. Formatters convert lint results to a human- or machine-readable string.
* @param name TThe path to the file you want to check.
* The following values are allowed:
* - undefined. In this case, loads the "stylish" built-in formatter.
* - A name of built-in formatters.
* - A name of third-party formatters. For examples:
* -- `foo` will load eslint-formatter-foo.
* -- `@foo` will load `@foo/eslint-formatter`.
* -- `@foo/bar` will load `@foo/eslint-formatter-bar`.
* - A path to the file that defines a formatter. The path must contain one or more path separators (/) in order to distinguish if it's a path or not. For example, start with ./.
* @returns The promise that will be fulfilled with a Formatter object.
*/
ESLintBase.getErrorResults(results: LintResult): LintResult¶
This method copies the given results and removes warnings. The returned value contains only errors.
Parameters:
resultsany: The LintResult objects to filter.
Returns: undefined
The filtered LintResult objects.
Raw JSDoc
ESLintBase.outputFixes(results: LintResult[]): Promise<void>¶
This method writes code modified by ESLint's autofix feature into its respective file. If any of the modified files don't exist, this method does nothing.
Parameters:
resultsany: The LintResult objects to write.
Returns: undefined
The promise that will be fulfilled after all files are written.
Raw JSDoc
Classes¶
ESLintBase¶
Methods (8) — full entries under Functions
| Method | Signature |
|---|---|
calculateConfigForFile |
(filePath: string): Promise<Config> |
getRulesMetaForResults |
(results: LintResult[]): Record<string, RuleMetaData<string, Record<string, unknown>>> |
isPathIgnored |
(filePath: string): Promise<boolean> |
lintFiles |
(patterns: string \| string[]): Promise<LintResult[]> |
lintText |
(code: string, options: LintTextOptions): Promise<LintResult[]> |
loadFormatter |
(name: string): Promise<Formatter> |
getErrorResults |
(results: LintResult): LintResult |
outputFixes |
(results: LintResult[]): Promise<void> |
Interfaces¶
ESLintOptions<Config extends Linter.ConfigType>¶
Interface Code
export interface ESLintOptions<Config extends Linter.ConfigType> {
/**
* If false is present, ESLint suppresses comment directives in source code.
* If this option is false, it overrides the noInlineConfig setting in your configurations.
* @default true
*/
allowInlineConfig?: boolean;
/**
* Configuration object, extended by all configurations used with this instance.
* You can use this option to define the default settings that will be used if your configuration files don't
* configure it.
* @default null
*/
baseConfig?: Config | null;
/**
* If `true` is present, the `eslint.lintFiles()` method caches lint results and uses it if each target file is not
* changed. Please mind that ESLint doesn't clear the cache when you upgrade ESLint plugins. In that case, you have
* to remove the cache file manually. The `eslint.lintText()` method doesn't use caches even if you pass the
* options.filePath to the method.
* @default false
*/
cache?: boolean;
/**
* The eslint.lintFiles() method writes caches into this file.
* @default '.eslintcache'
*/
cacheLocation?: string;
/**
* Strategy for the cache to use for detecting changed files.
* @default 'metadata'
*/
cacheStrategy?: 'content' | 'metadata';
/**
* The working directory. This must be an absolute path.
* @default process.cwd()
*/
cwd?: string;
/**
* Unless set to false, the `eslint.lintFiles()` method will throw an error when no target files are found.
* @default true
*/
errorOnUnmatchedPattern?: boolean;
/**
* If `true` is present, the `eslint.lintFiles()` and `eslint.lintText()` methods work in autofix mode.
* If a predicate function is present, the methods pass each lint message to the function, then use only the
* lint messages for which the function returned true.
* @default false
*/
fix?: boolean | ((message: LintMessage) => boolean);
/**
* The types of the rules that the `eslint.lintFiles()` and `eslint.lintText()` methods use for autofix.
* @default null
*/
fixTypes?: ('directive' | 'problem' | 'suggestion')[] | null;
/**
* If false is present, the `eslint.lintFiles()` method doesn't interpret glob patterns.
* @default true
*/
globInputPaths?: boolean;
/**
* Configuration object, overrides all configurations used with this instance.
* You can use this option to define the settings that will be used even if your configuration files configure it.
* @default null
*/
overrideConfig?: Config | null;
/**
* When set to true, missing patterns cause the linting operation to short circuit and not report any failures.
* @default false
*/
passOnNoPatterns?: boolean;
/**
* The plugin implementations that ESLint uses for the plugins setting of your configuration.
* This is a map-like object. Those keys are plugin IDs and each value is implementation.
* @default null
*/
plugins?: Record<string, Linter.Plugin> | null;
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
allowInlineConfig |
boolean |
✓ | not shown |
baseConfig |
Config \| null |
✓ | not shown |
cache |
boolean |
✓ | not shown |
cacheLocation |
string |
✓ | not shown |
cacheStrategy |
'content' \| 'metadata' |
✓ | not shown |
cwd |
string |
✓ | not shown |
errorOnUnmatchedPattern |
boolean |
✓ | not shown |
fix |
boolean \| ((message: LintMessage) => boolean) |
✓ | not shown |
fixTypes |
('directive' \| 'problem' \| 'suggestion')[] \| null |
✓ | not shown |
globInputPaths |
boolean |
✓ | not shown |
overrideConfig |
Config \| null |
✓ | not shown |
passOnNoPatterns |
boolean |
✓ | not shown |
plugins |
Record<string, Linter.Plugin> \| null |
✓ | not shown |
DeprecatedRuleInfo¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
replacedBy |
string[] |
✗ | not shown |
ruleId |
string |
✗ | not shown |
LintResult¶
Interface Code
export interface LintResult {
/**
* The number of errors. This includes fixable errors.
*/
errorCount: number;
/**
* The number of fatal errors.
*/
fatalErrorCount: number;
/**
* The absolute path to the file of this result. This is the string "<text>" if the file path is unknown (when you
* didn't pass the options.filePath option to the eslint.lintText() method).
*/
filePath: string;
/**
* The number of errors that can be fixed automatically by the fix constructor option.
*/
fixableErrorCount: number;
/**
* The number of warnings that can be fixed automatically by the fix constructor option.
*/
fixableWarningCount: number;
/**
* The array of LintMessage objects.
*/
messages: LintMessage[];
/**
* The source code of the file that was linted, with as many fixes applied as possible.
*/
output?: string;
/**
* The original source code text. This property is undefined if any messages didn't exist or the output
* property exists.
*/
source?: string;
/**
* Timing information of the lint run.
* This exists if and only if the `--stats` CLI flag was added or the `stats: true`
* option was passed to the ESLint class
* @since 9.0.0
*/
stats?: LintStats;
/**
* The array of SuppressedLintMessage objects.
*/
suppressedMessages: SuppressedLintMessage[];
/**
* The information about the deprecated rules that were used to check this file.
*/
usedDeprecatedRules: DeprecatedRuleInfo[];
/**
* The number of warnings. This includes fixable warnings.
*/
warningCount: number;
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
errorCount |
number |
✗ | not shown |
fatalErrorCount |
number |
✗ | not shown |
filePath |
string |
✗ | not shown |
fixableErrorCount |
number |
✗ | not shown |
fixableWarningCount |
number |
✗ | not shown |
messages |
LintMessage[] |
✗ | not shown |
output |
string |
✓ | not shown |
source |
string |
✓ | not shown |
stats |
LintStats |
✓ | not shown |
suppressedMessages |
SuppressedLintMessage[] |
✗ | not shown |
usedDeprecatedRules |
DeprecatedRuleInfo[] |
✗ | not shown |
warningCount |
number |
✗ | not shown |
LintStats¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
fixPasses |
number |
✗ | not shown |
times |
{ passes: LintStatsTimePass[]; } |
✗ | not shown |
LintStatsTimePass¶
Interface Code
export interface LintStatsTimePass {
/**
* The total time that is spent on applying fixes to the code.
*/
fix: LintStatsFixTime;
/**
* The total time that is spent when parsing a file.
*/
parse: LintStatsParseTime;
/**
* The total time that is spent on a rule.
*/
rules?: Record<string, LintStatsRuleTime>;
/**
* The cumulative total
*/
total: number;
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
fix |
LintStatsFixTime |
✗ | not shown |
parse |
LintStatsParseTime |
✗ | not shown |
rules |
Record<string, LintStatsRuleTime> |
✓ | not shown |
total |
number |
✗ | not shown |
LintStatsParseTime¶
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
total |
number |
✗ | not shown |
LintStatsRuleTime¶
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
total |
number |
✗ | not shown |
LintStatsFixTime¶
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
total |
number |
✗ | not shown |
LintTextOptions¶
Interface Code
export interface LintTextOptions {
/**
* The path to the file of the source code text. If omitted, the result.filePath becomes the string "<text>".
*/
filePath?: string;
/**
* If true is present and the options.filePath is a file ESLint should ignore, this method returns a lint result
* contains a warning message.
*/
warnIgnored?: boolean;
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
filePath |
string |
✓ | not shown |
warnIgnored |
boolean |
✓ | not shown |
LintMessage¶
Interface Code
export interface LintMessage {
/**
* The 1-based column number of the begin point of this message.
*/
column: number | undefined;
/**
* The 1-based column number of the end point of this message. This property is undefined if this message
* is not a range.
*/
endColumn: number | undefined;
/**
* The 1-based line number of the end point of this message. This property is undefined if this
* message is not a range.
*/
endLine: number | undefined;
/**
* `true` if this is a fatal error unrelated to a rule, like a parsing error.
*/
fatal?: boolean | undefined;
/**
* The EditInfo object of autofix. This property is undefined if this message is not fixable.
*/
fix: EditInfo | undefined;
/**
* The 1-based line number of the begin point of this message.
*/
line: number | undefined;
/**
* The error message
*/
message: string;
/**
* The rule name that generates this lint message. If this message is generated by the ESLint core rather than
* rules, this is null.
*/
ruleId: string | null;
/**
* The severity of this message. 1 means warning and 2 means error.
*/
severity: 1 | 2;
/**
* The list of suggestions. Each suggestion is the pair of a description and an EditInfo object to fix code. API
* users such as editor integrations can choose one of them to fix the problem of this message. This property is
* undefined if this message doesn't have any suggestions.
*/
suggestions:
| {
desc: string;
fix: EditInfo;
}[]
| undefined;
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
column |
number \| undefined |
✗ | not shown |
endColumn |
number \| undefined |
✗ | not shown |
endLine |
number \| undefined |
✗ | not shown |
fatal |
boolean \| undefined |
✓ | not shown |
fix |
EditInfo \| undefined |
✗ | not shown |
line |
number \| undefined |
✗ | not shown |
message |
string |
✗ | not shown |
ruleId |
string \| null |
✗ | not shown |
severity |
1 \| 2 |
✗ | not shown |
suggestions |
\| { desc: string; fix: EditInfo; }[] \| undefined |
✗ | not shown |
SuppressedLintMessage¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
suppressions |
{ /** * The free text description added after the--in the comment */ just... |
✓ | not shown |
EditInfo¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
range |
[number, number] |
✗ | not shown |
text |
string |
✗ | not shown |
Formatter¶
Interface Code
Generated by Syntax Scribe