@kitschpatrol/eslint-config
v8.6.0
Published
ESLint configuration for @kitschpatrol/shared-config.
Maintainers
Readme
@kitschpatrol/eslint-config
ESLint configuration for @kitschpatrol/shared-config.
Overview
It's a shared ESLint config, plus a command-line tool ksc-eslint to perform ESLint-related project initialization, linting, and fixing.
[!IMPORTANT]
You can use this package on its own, but it's recommended to use
@kitschpatrol/shared-configinstead for a single-dependency and single-package approach to linting and fixing your project.This package is included as a dependency in
@kitschpatrol/shared-config, which also automatically invokes the command line functionality in this package via itsksccommand
Setup
To use just this ESLint config in isolation:
Install the basic repository configuration files in your project root. This is required for correct PNPM behavior:
pnpm --package=@kitschpatrol/repo-config dlx ksc-repo initInstall and initialize the required TypeScript
tsconfig.jsonconfiguration in your project root:pnpm add -D @kitschpatrol/typescript-config pnpm --package=@kitschpatrol/typescript-config dlx ksc-typescript initAdd the package:
pnpm add -D @kitschpatrol/eslint-configAdd the starter
eslint.config.tsconfig files to your project root, and add any overrides you'd like:pnpm exec eslint-ksc init
Usage
The ESLint binary should be picked up automatically by VS Code plugins.
You can call it directly, or use the script bundled with the config.
Integrate with your package.json scripts as you see fit, for example:
{
"scripts": {
"lint": "eslint-config lint",
"fix": "eslint-config fix"
}
}CLI
Command: ksc-eslint
Kitschpatrol's ESLint shared configuration tools.
This section lists top-level commands for ksc-eslint.
Usage:
ksc-eslint <command>| Command | Argument | Description |
| -------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| init | | Initialize by copying starter config files to your project root. |
| lint | [files..] | Lint your project with ESLint. Matches files below the current working directory by default. |
| fix | [files..] | Fix your project with ESLint. Matches files below the current working directory by default. |
| print-config | [file] | Print the effective ESLint configuration. Package-scoped by default, file-scoped if a file argument is provided. Use @eslint/config-inspector for a more detailed view. |
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| --help-h | Show help | boolean |
| --version-v | Show version number | boolean |
See the sections below for more information on each subcommand.
Subcommand: ksc-eslint init
Initialize by copying starter config files to your project root.
Usage:
ksc-eslint init| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| --help-h | Show help | boolean |
| --version-v | Show version number | boolean |
Subcommand: ksc-eslint lint
Lint your project with ESLint. Matches files below the current working directory by default.
Usage:
ksc-eslint lint [files..]| Positional Argument | Description | Type | Default |
| ------------------- | ------------------------------ | ------- | ------- |
| files | Files or glob pattern to lint. | array | "." |
| Option | Description | Type | Default |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ---------- |
| --format | Output format: "native" streams each tool's own output, "machine" prints one parseable line per issue for editor problem matchers, "json" prints an aggregate report. | "json" "machine" "native" | "native" |
| --cache | Use tool-native caches stored below node_modules/.cache/ksc at the workspace root. Disable with --no-cache. | boolean | true |
| --help-h | Show help | boolean | |
| --version-v | Show version number | boolean | |
Subcommand: ksc-eslint fix
Fix your project with ESLint. Matches files below the current working directory by default.
Usage:
ksc-eslint fix [files..]| Positional Argument | Description | Type | Default |
| ------------------- | ----------------------------- | ------- | ------- |
| files | Files or glob pattern to fix. | array | "." |
| Option | Description | Type | Default |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ---------- |
| --format | Output format: "native" streams each tool's own output, "machine" prints one parseable line per issue for editor problem matchers, "json" prints an aggregate report. | "json" "machine" "native" | "native" |
| --cache | Use tool-native caches stored below node_modules/.cache/ksc at the workspace root. Disable with --no-cache. | boolean | true |
| --help-h | Show help | boolean | |
| --version-v | Show version number | boolean | |
Subcommand: ksc-eslint print-config
Print the effective ESLint configuration. Package-scoped by default, file-scoped if a file argument is provided. Use @eslint/config-inspector for a more detailed view.
Usage:
ksc-eslint print-config [file]| Positional Argument | Description | Type |
| ------------------- | ------------------------------------------------ | -------- |
| file | File or glob pattern to print configuration for. | string |
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| --help-h | Show help | boolean |
| --version-v | Show version number | boolean |
VS Code tasks
ksc-eslint init adds a .vscode/tasks.json with two tasks:
ksc-eslint lintrunsksc-eslint lint --format machineacross the whole projectksc-eslint fixrunsksc-eslint fix --format machine, applying auto-fixes and reporting whatever couldn't be fixed
If you're using the complete @kitschpatrol/shared-config package, you'd more likely want to run:
ksc lintrunsksc lint --format machine, which runs allksc linttools across the whole projectksc fixrunsksc fix --format machine, which applies allksc fixauto-fixes and reports anything unfixable
Run them via the Tasks: Run Task command (or the Terminal → Run Task… menu item).
Each task's problem matcher parses the machine-format output and populates VS Code's Problems panel with every reported issue, pointing to the offending file, line, and column.
The tasks share a problem matcher owner with the other @kitschpatrol/shared-config tasks, so the panel reflects the most recent run rather than stacking duplicates.
If your project already has a .vscode/tasks.json, init merges by task label: your own tasks are left alone, and same-label tasks are replaced with the latest definitions.
API
The package also exports fix, fixFile functions for linting and fixing code programmatically, pre-configured with the shared ESLint configuration.
import { clearCache, fix, fixFile } from '@kitschpatrol/eslint-config'
// Fix a string (defaults to TypeScript parser)
const fixed = await fix('let x = 1\nconsole.log(x)\n')
// Fix with a bare file extension for parser inference
const withExtension = await fix(code, 'tsx')
// Fix with ESLint options
const withOptions = await fix(code, { react: true })
// Both file type and options
const withBoth = await fix(code, 'tsx', { react: true })
// Fix a file in place with options
await fixFile('./src/index.ts', { type: 'lib' })
// Clear cached ESLint module and instances
clearCache()Config is resolved using the shared eslintConfig() factory with isInEditor: false. Per-call options accept the same OptionsConfig shape as the factory.
The ESLint module and instances are cached internally for performance across multiple calls. Use clearCache() to force re-initialization.
Notes
Config location
Regrettably the eslint-config init --location package option is not supported due to ESLint's removal of support for putting configuration in package.json. See ESLint discussion thread 18131.
Preset generation
The update-rules script is used to manually regenerate preset rule sets when plugin dependencies are updated.
The script requires two calls to ksc-prettier fix to accommodate a lack of idempotence in Prettier's handling of the resulting typegen.d.ts file. This surfaced a few Prettier versions ago, and the necessity of this work-around should be reevaluated periodically against future versions of Prettier.
Origins
This config is a heavily modified variation on Anthony Fu's @antfu/eslint-config. This package is a somewhat leaner approach intended to work with other tools wrapped behind a monolithic CLI instead of handling everything on its own. It mainly leverages the factory / type generation implementation from the original repo, which itself builds on Kevin Deng's @sxzz/eslint-config. See the modification notes for more details on what's changed from Anthony's approach.
