UNPKG

eslint-config-sheriff

Version:

A comprehensive and opinionated TypeScript-first ESLint configuration.

148 lines (147 loc) 6.47 kB
import { Config } from "eslint/config"; import tseslint from "typescript-eslint"; import { TSESLint } from "@typescript-eslint/utils"; //#region ../sheriff-types/dist/index.d.ts interface NoRestrictedSyntaxSlice { selector: string; message: string; } interface Entry { ruleName: string; parentPluginName: string; severity: NumericSeverity; ruleOptions: RuleOptionsConfig; affectedFiles: string; docs: { description: string; url: string; }; } type NumericSeverity = 0 | 1 | 2; type StringSeverity = 'error' | 'warn' | 'off'; type Severity = NumericSeverity | StringSeverity; type RuleOptions = [Severity, ...(Record<string, unknown> | string)[]] | Severity | undefined; type RuleOptionsConfig = (Record<string, any> | string)[]; interface SheriffConfigurablePlugins { /** * React support. */ react: boolean; /** * Lodash support. */ lodash: boolean; /** * Remeda support. */ remeda: boolean; /** * Nextjs support. */ next: boolean; /** * Astro support. */ astro: boolean; /** * Playwright support. */ playwright: boolean; /** * Storybook support. */ storybook: boolean; /** * Jest support. Select this or vitest, not both. */ jest: boolean; /** * Vitest support. Select this or jest, not both. */ vitest: boolean; } type TsProjectType = 'projectService' | 'project' | false | null; interface TsProjectTypeResolution { project?: boolean; projectService?: boolean; } interface SheriffSettings extends Partial<SheriffConfigurablePlugins> { /** * This parameter allows you to override the paths for some Sheriff settings. */ pathsOverrides?: { /** * With this setting, if you have multiple tsconfig.json files in your project (like tsconfig.json, tsconfig.eslint.json, tsconfig.node.json, etc...) you can specify which config Sheriff will pickup. You can also specify a list of paths, see: https://typescript-eslint.io/linting/typed-linting/monorepos/#one-tsconfigjson-per-package-and-an-optional-one-in-the-root. * * @deprecated This setting is now unsupported. `projectService` is now enabled by default. If you need to specify a custom `tsconfig.json` file, set `tsProjectType` to false or null and define a new configuration object with the `project`: /path/to/tsconfig.json property. */ tsconfigLocation?: string | string[]; /** * This setting overrides the default Sheriff filepaths for Vitest and Jest linting. It accepts an array of filepaths, dictaced by minimatch syntax. Sheriff will apply Jest or Vitest rules only on these files. */ tests?: string[]; /** * This setting overrides the default Sheriff filepaths for Playwright linting. It accepts an array of filepaths, dictaced by minimatch syntax. Sheriff will apply Playwright rules only on these files. */ playwrightTests?: string[]; }; /** * This setting apply some ignore patterns to the whole config. */ ignores?: { /** * Some commonly ignored folders. */ recommended?: boolean; /** * With this setting, Sheriff will ignore all the files that are currently ignored by git. Chances are that if you are ignoring a file in git, you don't want to lint it, which usually is the case with temporary and autogenerated files. */ inheritedFromGitignore?: boolean; }; /** * This setting accepts an array of filepaths, described by minimatch syntax. Only the matching files found in this array will be linted. All other files will be ignored. This is useful if you want to lint only a subset of your project. * * @default undefined */ files?: string[]; /** * This setting allows you to specify the typescript-eslint parserOption "project type" that Sheriff will use. * In line with typescript-eslint specifications, `projectService` is enabled by default, but you can fallback to `project` or disable the setting entirely, if you want. This can be especially useful if you want to use a custom `tsconfig.json` file for any reason. * * See: https://typescript-eslint.io/packages/parser/#projectservice * * **WARNING**: setting this option to false or null will disable every type-aware linting rule and will possibly break Sheriff in multiple ways. Only disable this if you want to manually re-configure the typescript-eslint parserOptions. * * @default 'projectService' */ tsProjectType?: TsProjectType; /** * This setting allows you to override the root directory that typescript-eslint' parser uses to resolve tsconfig.json files. * It's usually better to set this explicitly to `import.meta.dirname` (the directory of the current file). * * See: https://typescript-eslint.io/packages/parser/#tsconfigrootdir * * @default undefined */ tsconfigRootDir?: string; } interface ServerResponse { compiledConfig: Entry[]; pluginsNames: string[]; totalAvailableRulesAmount?: number; } //#endregion //#region src/getExportableConfig.d.ts declare const getExportableConfig: (userConfigChoices?: SheriffSettings, /** @internal */ areAllRulesForced?: boolean) => Config[]; //#endregion //#region src/index.d.ts declare const exportableAllJsExtensions = "js,mjs,cjs,ts,mts,cts"; declare const exportableAllJsxExtensions = "jsx,mjsx,tsx,mtsx"; declare const exportableIgnores: readonly ["**/node_modules/**", "**/dist/**", "**/build/**", "**/artifacts/**", "**/coverage/**", "eslint.config.{js,mjs,cjs}"]; declare const exportableSheriffStartingOptions: SheriffConfigurablePlugins; declare const exportableSupportedFileTypes = "**/*{js,mjs,cjs,ts,mts,cts,jsx,mjsx,tsx,mtsx,astro}"; declare const exportableTestsFilePatterns: readonly ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}", "**/tests/**/*.{js,mjs,cjs,ts,mts,cts}", "**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts}"]; //#endregion export { Entry, NoRestrictedSyntaxSlice, NumericSeverity, RuleOptions, RuleOptionsConfig, ServerResponse, Severity, SheriffConfigurablePlugins, SheriffSettings, StringSeverity, type TSESLint, TsProjectType, TsProjectTypeResolution, exportableAllJsExtensions as allJsExtensions, exportableAllJsxExtensions as allJsxExtensions, getExportableConfig as default, getExportableConfig as sheriff, exportableIgnores as ignores, exportableSheriffStartingOptions as sheriffStartingOptions, exportableSupportedFileTypes as supportedFileTypes, exportableTestsFilePatterns as testsFilePatterns, tseslint }; //# sourceMappingURL=index.d.ts.map