npm package: @rainstormy/preset-eslint-base
Description: A predefined, opinionated ESLint configuration suitable for any TypeScript project.
Author: Steffen Diswal
Latest version: 1.0.0-alpha.3
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# General Preset for ESLint

This package provides a predefined, opinionated [ESLint](https://eslint.org) configuration suitable for any [TypeScript](https://www.typescriptlang.org) project.

## Installation
Install the `@rainstormy/preset-eslint-base` package and its peer dependencies:

```shell
npm install --save-dev @rainstormy/preset-eslint-base eslint typescript
```

```shell
pnpm install --save-dev @rainstormy/preset-eslint-base eslint typescript
```

```shell
yarn add --dev @rainstormy/preset-eslint-base eslint typescript
```

In addition to the [built-in rules of ESLint](https://eslint.org/docs/latest/rules), this preset configures a subset of rules from the following plugins, which are installed along with the preset package:

* [eslint-plugin-eslint-comments](https://mysticatea.github.io/eslint-plugin-eslint-comments/rules) (with rule names prefixed by `eslint-comments/`)
* [eslint-plugin-functional](https://github.com/eslint-functional/eslint-plugin-functional#rules) (with rule names prefixed by `functional/`)
* [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import#rules) (with rule names prefixed by `import/`)
* [@limegrass/eslint-plugin-import-alias](https://github.com/Limegrass/eslint-plugin-import-alias#configuration) (with rule names prefixed by `import-alias/`)
* [eslint-plugin-no-barrel-files](https://github.com/art0rz/eslint-plugin-no-barrel-files#rules) (with rule names prefixed by `no-barrel-files/`)
* [eslint-plugin-redundant-undefined](https://github.com/a-tarasyuk/eslint-plugin-redundant-undefined#usage) (with rule names prefixed by `redundant-undefined/`)
* [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/rules) (with rule names prefixed by `typescript/`)
* [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn#rules) (with rule names prefixed by `unicorn/`)

## Usage
Create or extend a [flat ESLint configuration file](https://eslint.org/docs/latest/use/configure/configuration-files-new) (`eslint.config.js`) to target TypeScript files (and optionally also JavaScript files, e.g. configuration files).
For example:

```javascript
import {
	eslintAmbientTypeScriptModules,
	eslintBase
} from "@rainstormy/preset-eslint-base"

export default [
	eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),

	// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
	eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
```

<dl><dt><strong>💡 TIP: Override Rules</strong></dt><dd>

To override a subset of the rules configured by this preset, add an extra configuration at the end of the array to take precedence over the preset.
For example:

```javascript
import {
	eslintAmbientTypeScriptModules,
	eslintBase
} from "@rainstormy/preset-eslint-base"

export default [
	eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),

	// `eslintAmbientTypeScriptModules` and custom configurations must follow `eslintBase` to take effect.
	eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
	{
		files: ["**/*.+(js|ts|tsx)"],
		rules: {
			"max-lines": "off",
			"prefer-destructuring": "error",
			"typescript/no-magic-numbers": "off",
			"unicorn/prefer-at": "error",
		},
	},
]
```
</dd></dl>

<dl><dt><strong>💡 TIP: Custom `tsconfig.json` Location</strong></dt><dd>

By default, this preset assumes that the TypeScript configuration file is `./tsconfig.json`.
Use the `tsconfig` option to specify a different file or set of files.
For example:

```javascript
import {
	eslintAmbientTypeScriptModules,
	eslintBase
} from "@rainstormy/preset-eslint-base"

export default [
	eslintBase({
		files: ["**/*.+(js|ts|tsx)"],
		tsconfig: ["./configs/tsconfig.eslint.json"],
	}),

	// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
	eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
```
</dd></dl>

<dl><dt><strong>💡 TIP: Ignore Patterns</strong></dt><dd>

To exclude certain files and directories from linting, add an extra configuration at the beginning of the array.
For example:

```javascript
import {
	eslintAmbientTypeScriptModules,
	eslintBase
} from "@rainstormy/preset-eslint-base"

export default [
	{
		ignores: ["coverage/**", "dist/**"],
	},
	eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),

	// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
	eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
```

Alternatively, you can avoid the need for ignore patterns altogether by explicitly listing the directories you want to include when you run ESLint from the terminal.
For example:

```shell
eslint "./src/**/*.{ts,tsx}" "./*.config.{js,ts}" "./*.d.ts"
```
</dd></dl>

## Complementary Presets
* [@rainstormy/preset-prettier-base](https://github.com/rainstormy/presets-web/tree/main/packages/preset-prettier-base)
* [@rainstormy/preset-typescript](https://github.com/rainstormy/presets-web/tree/main/packages/preset-typescript)