@kitschpatrol/eslint-config
Version:
ESLint configuration for @kitschpatrol/shared-config.
208 lines (134 loc) • 7.76 kB
Markdown
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +-->
<!-- title -->
# @kitschpatrol/eslint-config
<!-- /title -->
<!-- badges -->
[](https://npmjs.com/package/@kitschpatrol/eslint-config)
[](https://opensource.org/licenses/MIT)
<!-- /badges -->
<!-- description -->
**ESLint configuration for @kitschpatrol/shared-config.**
<!-- /description -->
## Overview
It's a shared [ESLint](https://eslint.org) config, plus a command-line tool `ksc-eslint` to perform ESLint-related project initialization, linting, and fixing.
<!-- recommendation -->
> [!IMPORTANT]
>
> **You can use this package on its own, but it's recommended to use [`@kitschpatrol/shared-config`](https://www.npmjs.com/package/@kitschpatrol/shared-config) instead 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`](https://www.npmjs.com/package/@kitschpatrol/shared-config), which also automatically invokes the command line functionality in this package via its `ksc` command
<!-- /recommendation -->
## Setup
To use just this ESLint config in isolation:
1. Install the `.npmrc` in your project root. This is required for correct PNPM behavior:
```sh
pnpm --package=@kitschpatrol/repo-config dlx ksc-repo init
```
2. Install and initialize the required TypeScript `tsconfig.json` configuration in your project root:
```sh
pnpm add -D @kitschpatrol/typescript-config
pnpm --package=@kitschpatrol/typescript-config dlx ksc-typescript init
```
3. Add the package:
```sh
pnpm add -D @kitschpatrol/eslint-config
```
4. Add the starter `eslint.config.ts` config files to your project root, and add any overrides you'd like:
```sh
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:
```json
{
"scripts": {
"lint": "eslint-config lint",
"fix": "eslint-config fix"
}
}
```
### CLI
<!-- cli-help -->
#### Command: `ksc-eslint`
Kitschpatrol's ESLint shared configuration tools.
This section lists top-level commands for `ksc-eslint`.
Usage:
```txt
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`<br>`-h` | Show help | `boolean` |
| `--version`<br>`-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:
```txt
ksc-eslint init
```
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| `--help`<br>`-h` | Show help | `boolean` |
| `--version`<br>`-v` | Show version number | `boolean` |
#### Subcommand: `ksc-eslint lint`
Lint your project with ESLint. Matches files below the current working directory by default.
Usage:
```txt
ksc-eslint lint [files..]
```
| Positional Argument | Description | Type | Default |
| ------------------- | ------------------------------ | ------- | ------- |
| `files` | Files or glob pattern to lint. | `array` | `"."` |
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| `--help`<br>`-h` | Show help | `boolean` |
| `--version`<br>`-v` | Show version number | `boolean` |
#### Subcommand: `ksc-eslint fix`
Fix your project with ESLint. Matches files below the current working directory by default.
Usage:
```txt
ksc-eslint fix [files..]
```
| Positional Argument | Description | Type | Default |
| ------------------- | ----------------------------- | ------- | ------- |
| `files` | Files or glob pattern to fix. | `array` | `"."` |
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| `--help`<br>`-h` | Show help | `boolean` |
| `--version`<br>`-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:
```txt
ksc-eslint print-config [file]
```
| Positional Argument | Description | Type |
| ------------------- | --------------------------- | -------- |
| `file` | File or glob pattern to TK. | `string` |
| Option | Description | Type |
| ------------------- | ------------------- | --------- |
| `--help`<br>`-h` | Show help | `boolean` |
| `--version`<br>`-v` | Show version number | `boolean` |
<!-- /cli-help -->
## Notes
Regrettably the `eslint-config init --location package` option is not supported due to ESLint 9's deprecation of support for putting configuration in `package.json`. See ESLint discussion thread [18131](https://github.com/eslint/eslint/discussions/18131).
### Origins
This config is a heavily modified variation on Anthony Fu's [@antfu/eslint-config](https://github.com/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](https://github.com/sxzz/eslint-config). See the [modification notes](./modification-notes.md) for more details on what's changed from Anthony's approach.
### References
- [@antfu/eslint-config](https://github.com/antfu/eslint-config)
- [@sxzz/eslint-config](https://github.com/sxzz/eslint-config)
- [linting-setup-using-eslint](https://chris.lu/web_development/tutorials/next-js-static-mdx-blog/linting-setup-using-eslint)
- On [prefer-repository-shorthand](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/223)
<!-- license -->
## License
[MIT](license.txt) © Eric Mika
<!-- /license -->