UNPKG

@dovenv/eslint-config

Version:
501 lines (481 loc) 15.7 kB
import { Linter } from 'eslint'; import css from '@eslint/css'; export { default as globals } from 'globals'; type Config = Linter.Config; type ConfigParamsSuper = { /** * Custom rules. */ rules?: Config['rules']; }; /** * Enhances ESLint configuration performance by modifying file patterns * and rules based on specific conditions. * * @param {Config[]} config - An array of ESLint configuration objects to be processed. * @returns {Config[]} The modified configuration array. */ declare const experimental__eslintEncreasePerformance: (config: Config[]) => Config[]; /** * Constant for file patterns. */ declare const FILES: { readonly JS: "**/*.{js,jsx,cjs,mjs}"; readonly TS: "**/*.{ts,tsx,cts,mts}"; readonly ESM: "**/*.{mjs,mts}"; readonly COMMON: "**/*.{cjs,cts}"; readonly CSS: "**/*.css"; readonly HTML: "**/*.html"; readonly JSON: "**/*.{json,json5,jsonc}"; readonly PACKAGEJSON: "**/package.json"; readonly SVELTE: "**/*.svelte"; readonly SVELTE_FILE: "**/*.svelte.{js,cjs,mjs,ts,cts,mts}"; readonly MARKDOWN: "**/*.md"; readonly TOML: "**/*.{toml,tml}"; readonly YAML: "**/*.{yaml,yml}"; readonly VUE: "**/*.vue"; readonly TEST_UNIT: "**/*.{spec,test}.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"; readonly TEST_E2E: "tests/**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"; }; type CssRuleKey = keyof typeof css.configs.recommended['rules']; type CssConfigParams = ConfigParamsSuper & { /** * Support for Tailwind CSS. * If set to `3` or `4`, Tailwind CSS 3 or 4 syntax will be used. * * @default false */ tailwind?: boolean | 3 | 4; /** * Support for PostCSS. * * @default false */ postcss?: boolean; /** * Custom rules. */ rules?: Record<CssRuleKey, string>; }; /** * Generates a CSS ESLint config based on the given parameters. * * @param {CssConfigParams} [params] - Parameters to generate the config. * @returns {Config[]} - The generated CSS ESLint config. * @example * // Generates a basic CSS ESLint config. * const config = setCssConfig() * * // Generates a CSS ESLint config with tailwind syntax. * const config = setCssConfig({ tailwind: true }) * * // Generates a CSS ESLint config with postcss syntax. * const config = setCssConfig({ postcss: true }) * * // Generates a CSS ESLint config with custom rules. * const config = setCssConfig({ * rules: { * }, * }) */ declare const setCssConfig: (params?: CssConfigParams) => Config[]; /** * CSS Eslint config. * * @see https://github.com/eslint/css */ declare const cssConfig: Config[]; declare const setTsConfigDir: (tsconfigRootDir?: string) => Config; type JsConfigParams = ConfigParamsSuper; /** * Generates a JS ESLint config based on the given parameters. * * @param {JsConfigParams} [params] - Parameters to customize the config. * @returns {Config[]} - The generated JS ESLint config. * @example * // Generates a basic JS ESLint config. * const config = setJsConfig() * * // Generates a JS ESLint config with custom rules. * const config = setJsConfig({ * rules: { * }, * }) */ declare const setJsConfig: (params?: JsConfigParams) => Config[]; /** * JS CONFIG FILE. * * @see https://eslint.org/docs/user-guide/configuring */ declare const jsConfig: Config[]; type TsConfigParams = ConfigParamsSuper; /** * Generates a TypeScript ESLint config based on the given parameters. * * @param {TsConfigParams} [params] - Parameters to customize the config. * @returns {Config[]} - The generated TypeScript ESLint config. * @see https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#recommended * @example * // Generates a basic TypeScript ESLint config. * const config = setTsConfig() * * // Generates a TypeScript ESLint config with custom rules. * const config = setTsConfig({ * rules: { * }, * }) */ declare const setTsConfig: (params?: TsConfigParams) => Config[]; /** * TYPESCRIPT (TS). * * Includes: jsConfig. * * @see https://typescript-eslint.io/getting-started/ */ declare const tsConfig: Config[]; type HtmlConfigParmas = ConfigParamsSuper; /** * Set HTML ESLint config. * * Generates an HTML ESLint config based on the given parameters. * * @param {HtmlConfigParmas} [params] - Custom rules to apply. * @returns {Config[]} - The generated HTML ESLint config. * @see https://html-eslint.org/docs/rules * @example * // Generates a basic HTML ESLint config. * const config = setHtmlConfig() * * // Generates an HTML ESLint config with custom rules. * const config = setHtmlConfig({ * rules: { * '@html-eslint/indent' : [ 'error', 'tab' ], * '@html-eslint/sort-attrs' : [ 'error' ], * // ... other rules * }, * }) */ declare const setHtmlConfig: (params?: HtmlConfigParmas) => Config[]; /** * HTML Eslint config. * * @see https://html-eslint.org/docs/rules */ declare const htmlConfig: Config[]; /** * Include the contents of a .gitignore file in ESLint's ignore configuration. * * @param {string} [gitIgnorePath] - The path to the .gitignore file. If not provided, * the .gitignore file in the current working directory will be used. * @returns {Config} An object that ESLint can use to ignore files. */ declare const includeGitIgnore: (gitIgnorePath?: string) => Config; /** * Set paths to ignore in ESLint. * * @param {string[]} paths - An array of paths to ignore. * @returns {object} - An object with a single property, * `ignores`, that is an array of paths to ignore. * @example * const config = setIgnoreConfig( [ * './static/*', * './public/*', * ]) */ declare const setIgnoreConfig: (paths: string[]) => Config; type JSDocConfigParmas = { /** * Custom rules. * * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules */ rules?: Config['rules']; }; /** * Generates a JSDoc ESLint config based on the given parameters. * * @param {JSDocConfigParmas} [params] - Parameters to generate the config. * @returns {Config[]} - The generated JSDoc ESLint config. * @see https://github.com/gajus/eslint-plugin-jsdoc * @example * // Generates a basic JSDoc ESLint config. * const config = setJSDocConfig() * * // Generates a JSDoc ESLint config with custom rules. * const config = setJSDocConfig({ * rules: { * 'jsdoc/no-types' : [ 'error' ], * }, * }) */ declare const setJSDocConfig: (params?: JSDocConfigParmas) => Config[]; /** * JSDOC Eslint config. * * @see https://github.com/gajus/eslint-plugin-jsdoc#readme */ declare const jsdocConfig: Config[]; type PackageJsonConfigParams = ConfigParamsSuper; type JsonConfigParmas = ConfigParamsSuper; /** * Generates a package.json ESLint config based on the given parameters. * * @param {PackageJsonConfigParams} [params] - Parameters to customize the config. * @returns {Config[]} - The generated package.json ESLint config. * @see https://ota-meshi.github.io/eslint-plugin-package-json * @example * // Generates a basic package.json ESLint config. * const config = setPackageJsonConfig() * * // Generates a package.json ESLint config with custom rules. * const config = setPackageJsonConfig({ * rules: { * 'package-json/require-version' : 'error', * }, * }) */ declare const setPackageJsonConfig: (params?: PackageJsonConfigParams) => Config[]; /** * Generates a JSON ESLint config based on the given parameters. * * @param {JsonConfigParmas} [params] - Parameters to customize the JSON rules. * @returns {Config[]} - The generated JSON ESLint config. * @see https://ota-meshi.github.io/eslint-plugin-jsonc/user-guide/ * @example * // Generates a basic JSON ESLint config. * const config = setJsonConfig() * * // Generates a JSON ESLint config with custom rules. * const config = setJsonConfig({ * rules: { * 'jsonc/no-dupe-keys': ['error'], * }, * }) */ declare const setJsonConfig: (params?: JsonConfigParmas) => Config[]; /** * JSON ESLINT CONFIG. * * @see https://ota-meshi.github.io/eslint-plugin-jsonc/user-guide/ */ declare const jsonConfig: Config[]; /** * PACKAGE JSON ESLINT CONFIG. * * @see https://github.com/JoshuaKGoldberg/eslint-plugin-package-json#readme */ declare const packageJsonConfig: Config[]; type MdConfigParams = ConfigParamsSuper; /** * Defines a configuration object for the dovenv markdown plugin. * * @param {MdConfigParams} [params] - The configuration object. * @returns {Config[]} The defined configuration object. * The default configuration is based on the recommended configuration for the * `eslint-plugin-markdownlint` plugin. You can override any of these rules by * passing them as part of the `rules` object in the `params` object. * @example * * export default setMdConfig( { * rules: { * 'markdownlint/md013' : 'error', // line length * 'markdownlint/md024' : 'error', // Multiple headers with the same content * }, * } ) */ declare const setMdConfig: (params?: MdConfigParams) => Config[]; /** * MARKDOWN eslint config. * * @see https://gitlab.com/pawelbbdrozd/eslint-plugin-markdownlint */ declare const mdConfig: Config[]; /** * Generates a JSON Schema ESLint config based on the given parameters. * * @returns {Config[]} - The generated JSON Schema ESLint config. * @see https://ota-meshi.github.io/eslint-plugin-json-schema-validator * @example * // Generates a basic JSON Schema ESLint config. * const config = setSchemaConfig() */ declare const setSchemaConfig: () => Config[]; /** * SCHEMA ESLINT CONFIG. * * @see https://ota-meshi.github.io/eslint-plugin-json-schema-validator */ declare const schemaConfig: Config[]; type SvelteParams = { /** * Svelte config file params. */ svelteConfig: Record<string, unknown>; /** * Additional rules for .svelte files. */ rules: Config['rules']; /** * Enable typescript support. * * @default false */ ts: NonNullable<Config['languageOptions']>['parserOptions'] | boolean; }; /** * SET SVELTE ESLINT CONFIG. * * Creates a config for svelte. * * @param {Partial<SvelteParams>} params - Parameters. * @returns {Config[]} A list of configurations. * @see https://sveltejs.github.io/eslint-plugin-svelte/ */ declare const setSvelteConfig: (params?: Partial<SvelteParams>) => Promise<Config[]>; type PlaywrightConfigParams = ConfigParamsSuper & { files?: string[]; }; /** * Generates a Playwright ESLint config based on the given parameters. * * @param {PlaywrightConfigParams} [params] - Optional parameters to customize the config. * @returns {Config[]} - The generated Playwright ESLint config. * @see https://www.npmjs.com/package/eslint-plugin-playwright * @example * // Generates a basic Playwright ESLint config. * const config = setPlaywrightConfig() * * // Generates a Playwright ESLint config with custom rules. * const config = setPlaywrightConfig({ * rules: { * 'playwright/no-focused-tests': 'error', * }, * }) */ declare const setPlaywrightConfig: (params?: PlaywrightConfigParams) => Config[]; /** * PLAYWRIGHT ESLINT CONFIG. * * @see https://www.npmjs.com/package/eslint-plugin-playwright */ declare const playwrightConfig: Config[]; type TomlConfigParams = ConfigParamsSuper; /** * Generates a TOML ESLint config based on the given parameters. * * @param {TomlConfigParams} [params] - Parameters to customize the config. * @returns {Config[]} - The generated TOML ESLint config. * @example * // Generates a basic TOML ESLint config. * const config = setTomlConfig() * * // Generates a TOML ESLint config with custom rules. * const config = setTomlConfig({ * rules: { * 'toml/no-empty-tables': ['error'], * 'toml/no-inline-tables': ['warn'], * }, * }) */ declare const setTomlConfig: (params?: TomlConfigParams) => Config[]; /** * TOML ESLINT CONFIG. * * @see https://www.npmjs.com/package/eslint-plugin-toml */ declare const tomlConfig: Config[]; /** * Generates an ESLint configuration for Vue.js files. * * This configuration extends the 'flat/strongly-recommended' rules from `eslint-plugin-vue` * and applies specific rules for Vue files. * * @returns {Config[]} An array of configuration objects for Vue.js linting. * @see https://www.npmjs.com/package/eslint-plugin-vue */ declare const setVueConfig: () => Config[]; /** * VUE ESLINT CONFIG. * * @see https://www.npmjs.com/package/eslint-plugin-vue */ declare const vueConfig: Config[]; type YamlConfigParams = ConfigParamsSuper; /** * Generates a YAML ESLint config based on the given parameters. * * @param {YamlConfigParams} [params] - Parameters to customize the config. * @returns {Config[]} - The generated YAML ESLint config. * @see https://ota-meshi.github.io/eslint-plugin-yml/ * @example * // Generates a basic YAML ESLint config. * const config = setYamlConfig() * * // Generates a YAML ESLint config with custom rules. * const config = setYamlConfig({ * rules: { * 'yml/require-string-key' : [ 'error' ], * }, * }) */ declare const setYamlConfig: (params?: YamlConfigParams) => Config[]; /** * YAML ESLINT CONFIG. * * @see https://ota-meshi.github.io/eslint-plugin-yml/ */ declare const yamlConfig: Config[]; type ConfigParams = { /** @default 'js' */ general: 'ts' | 'js'; jsdoc: boolean; css: boolean | Parameters<typeof setCssConfig>[0]; html: boolean; md: boolean; json: boolean; package: boolean; yaml: boolean; toml: boolean; schema: boolean; vue: boolean; playwright: boolean | Parameters<typeof setPlaywrightConfig>[0]; /** * Ignore files from gitignore. * If a string is provided, it will be used as the path to the .gitignore file. * * @default false */ gitignore: boolean | string; /** * Ignore files from a list. */ ignore: string[]; }; /** * Set all eslint config at once. * * @param {Partial<ConfigParams>} props - List of config to enable. * @param {(config: Config[]) => Config[]} [callback] - If provided, the config will be passed to the callback, * and the returned value will be used instead of the default config. * @returns {Config[]} - The list of config. */ declare const setConfig: (props: Partial<ConfigParams>, callback?: (config: Config[]) => Config[]) => Config[]; /** * Default dovenv eslint config. * * Includes: * - jsConfig * - tsConfig * - jsdocConfig * - htmlConfig * - mdConfig * - yamlConfig * - jsonConfig * - packageJsonConfig * - tomlConfig. */ declare const config: Config[]; export { FILES, config, cssConfig, config as default, experimental__eslintEncreasePerformance, htmlConfig, includeGitIgnore, jsConfig, jsdocConfig, jsonConfig, mdConfig, packageJsonConfig, playwrightConfig, schemaConfig, setConfig, setCssConfig, setHtmlConfig, setIgnoreConfig, setJSDocConfig, setJsConfig, setJsonConfig, setMdConfig, setPackageJsonConfig, setPlaywrightConfig, setSchemaConfig, setSvelteConfig, setTomlConfig, setTsConfig, setTsConfigDir, setVueConfig, setYamlConfig, tomlConfig, tsConfig, vueConfig, yamlConfig }; export type { ConfigParams };