Skip to content

⬅️ Back to Table of Contents

📄 Linter

📊 Analysis Summary

Metric Count
🔧 Functions 7
🧱 Classes 2
📦 Imports 12
📐 Interfaces 8
📑 Type Aliases 22

📚 Table of Contents

🛠️ File Location:

📂 packages/utils/src/ts-eslint/Linter.ts

📦 Imports

Name Source
ESLintLinter eslint
ClassicConfig ./Config
FlatConfig ./Config
SharedConfig ./Config
Parser ./Parser
ProcessorType ./Processor
AnyRuleCreateFunction ./Rule
AnyRuleModule ./Rule
RuleCreateFunction ./Rule
RuleFix ./Rule
RuleModule ./Rule
SourceCode ./SourceCode

Functions

LinterBase.defineParser(parserId: string, parserModule: Parser.LooseParserModule): void

Define a new parser module

Parameters:

  • parserId any: Name of the parser
  • parserModule any: The parser object
Raw JSDoc
/**
   * Define a new parser module
   * @param parserId Name of the parser
   * @param parserModule The parser object
   */
Code
defineParser(parserId: string, parserModule: Parser.LooseParserModule): void;

LinterBase.defineRule(ruleId: string, ruleModule: MinimalRuleModule<MessageIds, Options> …): void

Defines a new linting rule.

Parameters:

  • ruleId any: A unique rule identifier
  • ruleModule any: Function from context to object mapping AST node types to event handlers
Raw JSDoc
/**
   * Defines a new linting rule.
   * @param ruleId A unique rule identifier
   * @param ruleModule Function from context to object mapping AST node types to event handlers
   */
Code
defineRule<MessageIds extends string, Options extends readonly unknown[]>(
    ruleId: string,
    ruleModule: MinimalRuleModule<MessageIds, Options> | RuleCreateFunction,
  ): void;

LinterBase.defineRules(rulesToDefine: Record< string, | MinimalRuleModule<Mes…): void

Defines many new linting rules.

Parameters:

  • rulesToDefine any: map from unique rule identifier to rule
Raw JSDoc
/**
   * Defines many new linting rules.
   * @param rulesToDefine map from unique rule identifier to rule
   */
Code
defineRules<MessageIds extends string, Options extends readonly unknown[]>(
    rulesToDefine: Record<
      string,
      | MinimalRuleModule<MessageIds, Options>
      | RuleCreateFunction<MessageIds, Options>
    >,
  ): void;

LinterBase.getRules(): Map<string, MinimalRuleModule<string, unknown[]>>

Gets an object with all loaded rules.

Returns: undefined All loaded rules

Raw JSDoc
/**
   * Gets an object with all loaded rules.
   * @returns All loaded rules
   */
Code
getRules(): Map<string, MinimalRuleModule<string, unknown[]>>;

LinterBase.getSourceCode(): SourceCode

Gets the SourceCode object representing the parsed source.

Returns: undefined The SourceCode object.

Raw JSDoc
/**
   * Gets the `SourceCode` object representing the parsed source.
   * @returns The `SourceCode` object.
   */
Code
getSourceCode(): SourceCode;

LinterBase.verify(textOrSourceCode: string | SourceCode, config: Linter.ConfigType, filenameOrOptions: string | Linter.VerifyOptions): Linter.LintMessage[]

Verifies the text against the rules specified by the second argument.

Parameters:

  • textOrSourceCode any: The text to parse or a SourceCode object.
  • config any: An ESLintConfig instance to configure everything.
  • filenameOrOptions any: The optional filename of the file being checked. If this is not set, the filename will default to '' in the rule context. If this is an object, then it has "filename", "allowInlineConfig", and some properties.

Returns: undefined The results as an array of messages or an empty array if no messages.

Raw JSDoc
/**
   * Verifies the text against the rules specified by the second argument.
   * @param textOrSourceCode The text to parse or a SourceCode object.
   * @param config An ESLintConfig instance to configure everything.
   * @param filenameOrOptions The optional filename of the file being checked.
   *        If this is not set, the filename will default to '<input>' in the rule context.
   *        If this is an object, then it has "filename", "allowInlineConfig", and some properties.
   * @returns The results as an array of messages or an empty array if no messages.
   */
Code
verify(
    textOrSourceCode: string | SourceCode,
    config: Linter.ConfigType,
    filenameOrOptions?: string | Linter.VerifyOptions,
  ): Linter.LintMessage[];

LinterBase.verifyAndFix(code: string, config: Linter.ConfigType, options: Linter.FixOptions): Linter.FixReport

Performs multiple autofix passes over the text until as many fixes as possible have been applied.

Parameters:

  • code any: The source text to apply fixes to.
  • config any: The ESLint config object to use.
  • options any: The ESLint options object to use.

Returns: undefined The result of the fix operation as returned from the SourceCodeFixer.

Raw JSDoc
/**
   * Performs multiple autofix passes over the text until as many fixes as possible have been applied.
   * @param code The source text to apply fixes to.
   * @param config The ESLint config object to use.
   * @param options The ESLint options object to use.
   * @returns The result of the fix operation as returned from the SourceCodeFixer.
   */
Code
verifyAndFix(
    code: string,
    config: Linter.ConfigType,
    options: Linter.FixOptions,
  ): Linter.FixReport;

Classes

LinterBase

Class Code
declare class LinterBase {
  /**
   * The version from package.json.
   */
  readonly version: string;

  /**
   * Initialize the Linter.
   * @param config the config object
   */
  constructor(config?: Linter.LinterOptions);

  /**
   * Define a new parser module
   * @param parserId Name of the parser
   * @param parserModule The parser object
   */
  defineParser(parserId: string, parserModule: Parser.LooseParserModule): void;

  /**
   * Defines a new linting rule.
   * @param ruleId A unique rule identifier
   * @param ruleModule Function from context to object mapping AST node types to event handlers
   */
  defineRule<MessageIds extends string, Options extends readonly unknown[]>(
    ruleId: string,
    ruleModule: MinimalRuleModule<MessageIds, Options> | RuleCreateFunction,
  ): void;

  /**
   * Defines many new linting rules.
   * @param rulesToDefine map from unique rule identifier to rule
   */
  defineRules<MessageIds extends string, Options extends readonly unknown[]>(
    rulesToDefine: Record<
      string,
      | MinimalRuleModule<MessageIds, Options>
      | RuleCreateFunction<MessageIds, Options>
    >,
  ): void;

  /**
   * Gets an object with all loaded rules.
   * @returns All loaded rules
   */
  getRules(): Map<string, MinimalRuleModule<string, unknown[]>>;

  /**
   * Gets the `SourceCode` object representing the parsed source.
   * @returns The `SourceCode` object.
   */
  getSourceCode(): SourceCode;

  /**
   * Verifies the text against the rules specified by the second argument.
   * @param textOrSourceCode The text to parse or a SourceCode object.
   * @param config An ESLintConfig instance to configure everything.
   * @param filenameOrOptions The optional filename of the file being checked.
   *        If this is not set, the filename will default to '<input>' in the rule context.
   *        If this is an object, then it has "filename", "allowInlineConfig", and some properties.
   * @returns The results as an array of messages or an empty array if no messages.
   */
  verify(
    textOrSourceCode: string | SourceCode,
    config: Linter.ConfigType,
    filenameOrOptions?: string | Linter.VerifyOptions,
  ): Linter.LintMessage[];

  ////////////////////
  // static members //
  ////////////////////

  /**
   * The version from package.json.
   */
  static readonly version: string;

  /**
   * Performs multiple autofix passes over the text until as many fixes as possible have been applied.
   * @param code The source text to apply fixes to.
   * @param config The ESLint config object to use.
   * @param options The ESLint options object to use.
   * @returns The result of the fix operation as returned from the SourceCodeFixer.
   */
  verifyAndFix(
    code: string,
    config: Linter.ConfigType,
    options: Linter.FixOptions,
  ): Linter.FixReport;
}

Methods (7) — full entries under Functions

Method Signature
defineParser (parserId: string, parserModule: Parser.LooseParserModule): void
defineRule (ruleId: string, ruleModule: MinimalRuleModule<MessageIds, Options> \| RuleCreateFunction): void
defineRules (rulesToDefine: Record< string, \| MinimalRuleModule<MessageIds, Options> \| RuleCreateFunction<M...
getRules (): Map<string, MinimalRuleModule<string, unknown[]>>
getSourceCode (): SourceCode
verify (textOrSourceCode: string \| SourceCode, config: Linter.ConfigType, filenameOrOptions: string \| ...
verifyAndFix (code: string, config: Linter.ConfigType, options: Linter.FixOptions): Linter.FixReport

Linter

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.

Extends: (ESLintLinter as typeof LinterBase)

Class Code
class Linter extends (ESLintLinter as typeof LinterBase) {}

Interfaces

LinterOptions

Interface Code
export interface LinterOptions {
    /**
     * Which config format to use.
     * @default 'flat'
     */
    configType?: ConfigTypeSpecifier;

    /**
     * path to a directory that should be considered as the current working directory.
     */
    cwd?: string;
  }

Properties

Name Type Optional Description
configType ConfigTypeSpecifier not shown
cwd string not shown

VerifyOptions

Interface Code
export interface VerifyOptions {
    /**
     * Allow/disallow inline comments' ability to change config once it is set. Defaults to true if not supplied.
     * Useful if you want to validate JS without comments overriding rules.
     */
    allowInlineConfig?: boolean;
    /**
     * if `true` then the linter doesn't make `fix` properties into the lint result.
     */
    disableFixes?: boolean;
    /**
     * the filename of the source code.
     */
    filename?: string;
    /**
     * the predicate function that selects adopt code blocks.
     */
    filterCodeBlock?: (filename: string, text: string) => boolean;
    /**
     * postprocessor for report messages.
     * If provided, this should accept an array of the message lists
     * for each code block returned from the preprocessor, apply a mapping to
     * the messages as appropriate, and return a one-dimensional array of
     * messages.
     */
    postprocess?: ProcessorType.PostProcess;
    /**
     * preprocessor for source text.
     * If provided, this should accept a string of source text, and return an array of code blocks to lint.
     */
    preprocess?: ProcessorType.PreProcess;
    /**
     * Adds reported errors for unused `eslint-disable` directives.
     */
    reportUnusedDisableDirectives?: boolean | SeverityString;
  }

Properties

Name Type Optional Description
allowInlineConfig boolean not shown
disableFixes boolean not shown
filename string not shown
filterCodeBlock (filename: string, text: string) => boolean not shown
postprocess ProcessorType.PostProcess not shown
preprocess ProcessorType.PreProcess not shown
reportUnusedDisableDirectives boolean \| SeverityString not shown

FixOptions

Interface Code
export interface FixOptions extends VerifyOptions {
    /**
     * Determines whether fixes should be applied.
     */
    fix?: boolean;
  }

Properties

Name Type Optional Description
fix boolean not shown

LintSuggestion

Interface Code
export interface LintSuggestion {
    desc: string;
    fix: RuleFix;
    messageId?: string;
  }

Properties

Name Type Optional Description
desc string not shown
fix RuleFix not shown
messageId string not shown

LintMessage

Interface Code
export interface LintMessage {
    /**
     * The 1-based column number.
     */
    column: number;
    /**
     * The 1-based column number of the end location.
     */
    endColumn?: number;
    /**
     * The 1-based line number of the end location.
     */
    endLine?: number;
    /**
     * If `true` then this is a fatal error.
     */
    fatal?: true;
    /**
     * Information for autofix.
     */
    fix?: RuleFix;
    /**
     * The 1-based line number.
     */
    line: number;
    /**
     * The error message.
     */
    message: string;
    messageId?: string;
    /**
     * @deprecated `nodeType` is deprecated and will be removed in the next major version.
     */
    nodeType?: string;
    /**
     * The ID of the rule which makes this message.
     */
    ruleId: string | null;
    /**
     * The severity of this message.
     */
    severity: Severity;
    source: string | null;
    /**
     * Information for suggestions
     */
    suggestions?: LintSuggestion[];
  }

Properties

Name Type Optional Description
column number not shown
endColumn number not shown
endLine number not shown
fatal true not shown
fix RuleFix not shown
line number not shown
message string not shown
messageId string not shown
nodeType string not shown
ruleId string \| null not shown
severity Severity not shown
source string \| null not shown
suggestions LintSuggestion[] not shown

FixReport

Interface Code
export interface FixReport {
    /**
     * True, if the code was fixed
     */
    fixed: boolean;
    /**
     * Collection of all messages for the given code
     */
    messages: LintMessage[];
    /**
     * Fixed code text (might be the same as input if no fixes were applied).
     */
    output: string;
  }

Properties

Name Type Optional Description
fixed boolean not shown
messages LintMessage[] not shown
output string not shown

Environment

Interface Code
export interface Environment {
    /**
     * The definition of global variables.
     */
    globals?: GlobalsConfig;
    /**
     * The parser options that will be enabled under this environment.
     */
    parserOptions?: ParserOptions;
  }

Properties

Name Type Optional Description
globals GlobalsConfig not shown
parserOptions ParserOptions not shown

Plugin

Interface Code
export interface Plugin {
    /**
     * The definition of plugin configs.
     */
    configs?: Record<string, ClassicConfig.Config>;
    /**
     * The definition of plugin environments.
     */
    environments?: Record<string, Environment>;
    /**
     * Metadata about your plugin for easier debugging and more effective caching of plugins.
     */
    meta?: PluginMeta;
    /**
     * The definition of plugin processors.
     */
    processors?: Record<string, ProcessorType.ProcessorModule>;
    /**
     * The definition of plugin rules.
     */
    rules?: LegacyPluginRules;
  }

Properties

Name Type Optional Description
configs Record<string, ClassicConfig.Config> not shown
environments Record<string, Environment> not shown
meta PluginMeta not shown
processors Record<string, ProcessorType.ProcessorModule> not shown
rules LegacyPluginRules not shown

Type Aliases

MinimalRuleModule<MessageIds extends string = string, Options extends readonly unknown[] = []>

type MinimalRuleModule<MessageIds extends string = string, Options extends readonly unknown[] = []> = Partial<Omit<RuleModule<MessageIds, Options>, 'create'>> &
  Pick<RuleModule<MessageIds, Options>, 'create'>;

ConfigTypeSpecifier

type ConfigTypeSpecifier = 'eslintrc' | 'flat';

EnvironmentConfig

type EnvironmentConfig = SharedConfig.EnvironmentConfig;

GlobalsConfig

type GlobalsConfig = SharedConfig.GlobalsConfig;

GlobalVariableOption

type GlobalVariableOption = SharedConfig.GlobalVariableOption;

GlobalVariableOptionBase

type GlobalVariableOptionBase = SharedConfig.GlobalVariableOptionBase;

ParserOptions

type ParserOptions = SharedConfig.ParserOptions;

PluginMeta

type PluginMeta = SharedConfig.PluginMeta;

RuleEntry

type RuleEntry = SharedConfig.RuleEntry;

RuleLevel

type RuleLevel = SharedConfig.RuleLevel;

RuleLevelAndOptions

type RuleLevelAndOptions = SharedConfig.RuleLevelAndOptions;

RulesRecord

type RulesRecord = SharedConfig.RulesRecord;

Severity

type Severity = SharedConfig.Severity;

SeverityString

type SeverityString = SharedConfig.SeverityString;

Config

/* @deprecated use {@link Linter.ConfigType} instead /

type Config = ClassicConfig.Config;

ConfigType

type ConfigType = ClassicConfig.Config | FlatConfig.Config | FlatConfig.ConfigArray;

ConfigOverride

/* @deprecated use {@link ClassicConfig.ConfigOverride} instead /

type ConfigOverride = ClassicConfig.ConfigOverride;

ParserModule

/* @deprecated use {@link Parser.ParserModule} /

type ParserModule = Parser.LooseParserModule;

ESLintParseResult

/* @deprecated use {@link Parser.ParseResult} /

type ESLintParseResult = Parser.ParseResult;

Processor

/* @deprecated use {@link ProcessorType.ProcessorModule} /

type Processor = ProcessorType.ProcessorModule;

LegacyPluginRules

type LegacyPluginRules = Record<
    string,
    AnyRuleCreateFunction | AnyRuleModule
  >;

PluginRules

type PluginRules = Record<string, AnyRuleModule>;

Generated by Syntax Scribe