# eslint-config

This package includes shareable ESLint configurations.

## How to use

Modify your package.json to contain the following parts:

```json
{
    ...

    "scripts":{
        ...

        "lint:js": "eslint --cache --cache-location .cache/.eslintcache src",
    },
    "devDependencies": {
        ...

        "@theorchard/eslint-config": "^1.0.0"
        "eslint": "^9.19.0",
    }
}
```

Then create either an `eslint.config.js` file, or `eslint.config.mts` with the appropriate configs:

##### eslint.config.js

```js
const configs = require('@theorchard/eslint-config');

module.exports = [...configs.frontend, ...configs.jest];
```

##### eslint.config.mts

**Note** that using typescript requires adding `jiti` as a dev dependency.

```typescript
import { frontend, jest } from '@theorchard/eslint-config';

export default [...frontend, ...jest];
```

## Configs

The package contains different eslint configs that can be composed to match your repo setup. It also exports presets that contain commonly used configurations.

### Presets

-   `frontend`: Includes `typescript`, `react`, `reactTestingLibrary`, and `prettier`.
-   `backend`: Includes `typescript`, `node`, and `prettier`.

**Note** that the presets do not include configs for testing frameworks, and you will have to include either `jest` or `vitest` separately.

### Configurations

-   `typescript`: Based on `@eslint/js`, `typescript-eslint`, and `eslint-plugin-import-x`. Can be used by any javascript or typescript project.
-   `react`: Based on `eslint-plugin-react`, and `eslint-plugin-react-hooks`.
-   `jsxRuntime`: Based on `eslint-plugin-react`. Should be included by any react project which uses the new JSX transforms.
-   `node`: Based on `eslint-plugin-n`.
-   `prettier`: Based on `eslint-config-prettier`. Disables rules which would interfere with prettier formatting.
-   `jest`: Based on `eslint-plugin-jest`.
-   `vitest`: Based on `eslint-plugin-vitest`.

## Customising configs

The configs can be customised by appending new config objects.

The following will disable the `@typescript-eslint/ban-ts-comment` for all files.

```json
{
    ...typescript,
    {
        rules: {
            "@typescript-eslint/ban-ts-comment": "off"
        }
    }
}
```

Configs can also be targeted by adding a `files` glob pattern. The following will only disable the rule for files in `__tests__` folders.

```json
{
    ...typescript,
    {
        files: ['**/__tests__/*'],
        rules: {
            "@typescript-eslint/ban-ts-comment": "off"
        }
    }
}
```

### Ignoring files and folders

Files and folders can be ignored entirely by adding an empty config with only an `ignores` key:

```json
{
    ...typescript,
    {
        ignores: ["foo.js"]
    }
}
```
