eslintFactory

Gitlab
A utility function for creating eslint configurations for Nuxt applications.
Added since: v0.1.0
Last changed:

Type Definitions

/**
 * Available configuration names for the ESLint flat config system.
 * These correspond to the different rule sets that can be enabled or disabled.
 */
export type ConfigNames = "base" | "typescript" | "vue" | "import" | "stylistic";

/**
 * Represents a preset configuration that combines Antfu ESLint settings with custom rules.
 * 
 * @property antfu - The Antfu ESLint configuration options (excluding files property)
 * @property custom - Array of custom ESLint configuration items to apply
 */
export type Preset = {
    antfu: OptionsConfig & Omit<TypedFlatConfigItem, "files">;
    custom: TypedFlatConfigItem[];
};

/**
 * Options for configuring the ESLint factory function.
 * 
 * @property preset - Optional preset to use for the configuration ("nuxt-app", "nuxt-module", "ts-lib")
 * @property antfu - Optional Antfu ESLint configuration overrides
 */
export type FactoryOptions = {
    preset?: "nuxt-app" | "nuxt-module" | "ts-lib";
    antfu?: OptionsConfig & Omit<TypedFlatConfigItem, "files">;
};


/**
 * Factory function to create ESLint configurations with optional presets and custom configurations.
 * 
 * This function provides a flexible way to generate ESLint configurations by combining:
 * - Antfu ESLint config base
 * - Optional preset configurations (nuxt-app, nuxt-module, ts-lib)
 * - Custom user configurations
 * 
 * @param options - Configuration options for the factory
 * @param options.preset - Optional preset to use ("nuxt-app", "nuxt-module", "ts-lib")
 * @param options.antfu - Optional Antfu ESLint configuration overrides
 * @param userConfigs - Additional user-defined ESLint configurations to merge
 * @returns A FlatConfigComposer instance with the combined ESLint configuration
 */
export function eslintFactory(
    options: FactoryOptions = {},
    ...userConfigs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | FlatConfigComposer<any, any> | Linter.Config[]>[]
): FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;

Examples

import { eslintFactory } from "@nobears-front-end/eslint";

export default eslintFactory();

Changelog