@pandell/eslint-config
Version:
Pandell ESLint shared config
243 lines (242 loc) • 10.4 kB
TypeScript
import type { TSESLint } from "@typescript-eslint/utils";
import type { Linter } from "eslint";
/**
* Files and directories that ESLint ignores in Pandell projects by default.
*/
export declare const defaultGlobalIgnores: string[];
/**
* Files to which ESLint TypeScript rules apply in Pandell projects by default.
*/
export declare const defaultTypeScriptFiles: string[];
/**
* Files to which ESLint testing rules apply in Pandell projects by default.
*/
export declare const defaultTestFiles: string[];
/**
* Settings that control behavior of {@link createPandellEsLintConfig}.
*/
export interface PandellEsLintConfigSettings {
/**
* List of extra configuration layers to append to the end of ESLint configuration
* sequence returned by {@link createPandellEsLintConfig}.
*/
readonly extraConfigs?: ReadonlyArray<Linter.Config>;
/**
* Enforce the consistent use of either function declarations (default)
* or expressions assigned to variables ("arrow functions").
*
* Rule "func-style", @see https://eslint.org/docs/latest/rules/func-style
*
* @default ["error","declaration"]
*/
readonly funcStyle?: Linter.RuleEntry;
/**
* List of ESLint global ignores.
*
* From ESLint documentation, @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores:
* "Patterns specified in files and ignores use minimatch syntax and are evaluated
* relative to the location of the eslint.config.js file."
*
* @default defaultGlobalIgnores
*/
readonly ignores?: Linter.Config["ignores"];
/**
* Settings for React ESLint configuration layers (opt in, not enabled by default).
*/
readonly react?: {
/**
* Enable React ESLint configuration layers. When false (default), final ESLint
* configuration will not include React layers at all.
*
* @default false
*/
readonly enabled?: boolean;
/**
* Extra rule configurations that will be appended to Pandell React configuration layer.
*/
readonly extraRules?: Linter.Config["rules"];
/**
* List of files to apply TypeScript configuration layers to.
*
* "do not set" indicates "files" property will not be set, i.e. the configuration
* layers will apply to all files matched by ESLint.
*
* From ESLint documentation, @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores:
* "Patterns specified in files and ignores use minimatch syntax and are evaluated
* relative to the location of the eslint.config.js file."
*
* @default defaultTypeScriptFiles
*/
readonly files?: "do not set" | Linter.Config["files"];
/**
* Should the React configuration include TanStack Query rules?
* (https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query)
* When false (default), final ESLint configuration will not include
* TanStack Query layer at all.
*
* @default false
*/
readonly includeReactQuery?: boolean;
/**
* Should the React configuration include type-checked rules?
* This setting requires TypeScript configuration to be enabled and also
* include type-checked rules.
*
* @default true
*/
readonly typeChecked?: boolean;
};
/**
* Settings for testing configuration layers (opt in, not enabled by default).
*/
readonly testing?: {
/**
* Enable testing-library ESLint configuration layers. When false (default), final ESLint
* configuration will not include testing-library layers at all.
*
* @default false
*/
enabledTestingLibrary?: boolean;
/**
* Enable Vitest ESLint configuration layers. When false (default), final ESLint
* configuration will not include Vitest layers at all.
*
* @default false
*/
enabledVitest?: boolean;
/**
* Extra rule configurations that will be appended to Pandell testing configuration layer.
*/
readonly extraRules?: Linter.Config["rules"];
/**
* List of files to apply testing configuration layers to.
*
* "do not set" indicates "files" property will not be set, i.e. the configuration
* layers will apply to all files matched by ESLint.
*
* From ESLint documentation, @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores:
* "Patterns specified in files and ignores use minimatch syntax and are evaluated
* relative to the location of the eslint.config.js file."
*
* @default defaultTestFiles
*/
readonly files?: "do not set" | Linter.Config["files"];
};
/**
* Settings for TypeScript ESLint configuration layers.
*/
readonly typeScript?: {
/**
* Enable TypeScript ESLint configuration layers. When false, final ESLint
* configuration will not include TypeScript layers at all.
*
* @default true
*/
readonly enabled?: boolean;
/**
* Extra rule configurations that will be appended to Pandell TypeScript configuration layer.
*/
readonly extraRules?: Linter.Config["rules"];
/**
* List of files to apply TypeScript configuration layers to.
*
* "do not set" indicates "files" property will not be set, i.e. the configuration
* layers will apply to all files matched by ESLint.
*
* From ESLint documentation, @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores:
* "Patterns specified in files and ignores use minimatch syntax and are evaluated
* relative to the location of the eslint.config.js file."
*
* @default defaultTypeScriptFiles
*/
readonly files?: "do not set" | Linter.Config["files"];
/**
* Are explicit "any" type annotations allowed in TypeScript? ("give up on type-checking")
*
* Rule "@typescript-eslint/no-explicit-any", @see https://typescript-eslint.io/rules/no-explicit-any/
*
* @default "error"
*/
readonly noExplicitAny?: Linter.RuleEntry;
/**
* Custom entry for "@typescript-eslint/prefer-nullish-coalescing" rule.
*
* Rule "@typescript-eslint/prefer-nullish-coalescing", @see https://typescript-eslint.io/rules/prefer-nullish-coalescing/
*
* @default "off"
*/
readonly preferNullishCoalescing?: Linter.RuleEntry;
/**
* Custom value for "parserOptions" of "typescript-eslint", @see https://typescript-eslint.io/packages/parser/#configuration.
*
* Anthony Fu configuration https://github.com/antfu/eslint-config/blob/v2.20.0/src/configs/typescript.ts#L70
* uses "process.cwd()" for "parserOptions.tsconfigRootDir", but this makes configuration
* behavior dependent on current directory which can change dynamically.
* Note that using "process" requires "import process from 'node:process';"
* and addition of "@types/node" to "package.json".
*
* "typescript-eslint" documentation https://typescript-eslint.io/getting-started/typed-linting/
* recommends using "import.meta.dirname" for "parserOptions.tsconfigRootDir",
* but this doesn't work in a shared library, as it would set the root directory
* to somewhere in "node_modules/...".
* Note that using "import.meta.dirname" might require additional type definition as documented in
* https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#support-for-importmeta,
* for example "interface ImportMeta { dirname: string; }".
*
* @default {projectService:true}
*/
readonly parserOptions?: TSESLint.ParserOptions;
/**
* Should the TypeScript configuration include strict rules?
* Strict rules contain all recommended rules, but add opinionated extra
* rules that can catch some bugs.
*
* @default true
*/
readonly strict?: boolean;
/**
* When a truthy string, will set "languageOptions.parserOptions.tsconfigRootDir".
*
* For more information see https://typescript-eslint.io/blog/typed-linting/#enabling-typed-linting.
* Note that documentation page https://typescript-eslint.io/troubleshooting/typed-linting/performance/#project-service-issues
* does not include "tsconfigRootDir" property.
*/
readonly tsconfigRootDir?: string | null;
/**
* Should the TypeScript configuration include type-checked rules?
* This setting requires project to be using "tsconfig.json" and might reduce
* speed of linting the project, but is strongly recommended for all Pandell projects.
*
* @default true
*/
readonly typeChecked?: boolean;
};
/**
* Settings for ViteJS ESLint configuration layer.
*/
readonly vite?: {
/**
* Enable ViteJS ESLint configuration layer. When false (default), final ESLint
* configuration will not include ViteJS layer at all.
*
* @default false
*/
readonly enabled?: boolean;
/**
* Sets the TSConfig file to set as "project" for ESLint TypeScript parser.
*
* @default "tsconfig.node.json"
*/
readonly tsConfigPath?: string;
/**
* Sets the files that will be analyzed with Vite's "tsConfigPath".
*
* @default "vite.*.ts"
*/
readonly files?: string[];
};
}
/**
* Creates Pandell ESLint configuration, applying specified customizations ("settings").
*/
export declare function createPandellEsLintConfig(settings?: PandellEsLintConfigSettings): Promise<ReadonlyArray<Linter.Config>>;