Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit f9905a3

Browse files
committed
feat: improve typings of configs, add readme, improve exports
1 parent 7828439 commit f9905a3

File tree

12 files changed

+134
-29
lines changed

12 files changed

+134
-29
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,37 @@ eslint configuration files used in @react-hookz projects
1010
[![Build](https://img.shields.io/github/actions/workflow/status/react-hookz/eslint-config/CI.yml?branch=master&style=flat-square)](https://github.com/react-hookz/eslint-config/actions)
1111

1212
</div>
13+
14+
## Installation
15+
16+
This package does not install `eslint`, `prettier`, or `eslint-plugin-prettier`, so you need to
17+
install them manually.
18+
19+
```shell
20+
yarn install -D @react-hookz/eslint-config eslint eslint-plugin-prettier prettier
21+
```
22+
23+
## Usage
24+
25+
This config is expected to be used with ESLint 8.3+, as it utilizes flat config.
26+
27+
Import the package directly and use the sub-configs you are interested in, spreading them into your
28+
config.
29+
30+
Some configs, like `jest` and `vitest`, require extra dependencies to be installed. You can find the
31+
required dependencies in the respective READMEs.
32+
33+
```js
34+
import { config } from '@react-hookz/eslint-config';
35+
36+
export default [
37+
...config.base,
38+
...config.react,
39+
...config.vitest,
40+
{
41+
rules: {
42+
// your own overrides
43+
},
44+
},
45+
];
46+
```

configs/base.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
66
import pluginPromise from 'eslint-plugin-promise';
77
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
88

9+
/** @typedef {import('eslint').Linter} Linter */
10+
11+
/** @type {Linter.Config[]} */
912
const baseConfig = [
1013
js.configs.recommended,
1114

configs/jest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import jest from 'eslint-plugin-jest';
22

3+
/** @type {Linter.Config[]} */
34
const jestConfig = [jest.configs['flat/recommended']];
45
export default jestConfig;

configs/md.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as mdx from 'eslint-plugin-mdx';
22
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
33

4+
/** @type {Linter.Config[]} */
45
const mdConfig = [
56
{
67
...mdx.flat,
@@ -19,6 +20,8 @@ const mdConfig = [
1920
// If you want to override some rules for code blocks
2021
'no-var': 'error',
2122
'prefer-const': 'error',
23+
'import/no-unresolved': 'off',
24+
'import/no-anonymous-default-export': 'off',
2225
},
2326
},
2427
eslintPluginPrettierRecommended,

configs/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import nodePlugin from 'eslint-plugin-n';
22

3+
/** @type {Linter.Config[]} */
34
const nodeConfig = [
45
nodePlugin.configs['flat/recommended-module'],
56
{

configs/react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pluginReact from 'eslint-plugin-react';
22
import pluginReactHooks from 'eslint-plugin-react-hooks';
33

4+
/** @var {Linter.Config[]} config */
45
const reactConfig = [
56
pluginReact.configs.flat.recommended,
67
pluginReactHooks.configs.recommended,

configs/typescript-unsafe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typescriptConfig from './typescript.js';
22

3+
/** @var {Linter.Config[]} config */
34
const typescriptUnsafeConfig = [
45
...typescriptConfig,
56
{

configs/typescript.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import xoTypescript from 'eslint-config-xo-typescript';
22
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
33
import baseConfig from './base.js';
44

5+
/** @var {Linter.Config[]} config */
56
const typescriptConfig = [
67
...baseConfig,
78

configs/vitest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import vitest from '@vitest/eslint-plugin';
22

3-
const vitestConfig = [vitest.configs.flat.recommended];
3+
/** @var {Linter.Config[]} config */
4+
const vitestConfig = [
5+
{
6+
files: ['*.test.{js,jsx,ts,tsx}', '*.suite.{js,jsx,ts,tsx}'],
7+
plugins: { vitest },
8+
rules: vitest.configs.recommended.rules,
9+
},
10+
];
411
export default vitestConfig;

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import baseConfig from './configs/base.js';
22
import mdConfig from './configs/md.js';
33

4+
/** @typedef {import('eslint').Linter} Linter */
5+
/** @type {Linter.Config[]} */
46
const config = [{ ignores: ['CHANGELOG.md', '.idea', 'node_modules'] }, ...baseConfig, ...mdConfig];
57
export default config;

0 commit comments

Comments
 (0)