# eslint-config-iplayer

> The main [eslint](http://eslint.org/) config for BBC iPlayer

## Installation

```
npm install --save-dev eslint-config-iplayer
```

## Usage

Since this package now uses ESLint 9, consuming repos will need to update to ESLint 9 too. You will need an `eslint.config.js` file, and the rules defined in this package can then be imported.

Each config automatically targets its own file extension(s), so you only need to spread the configs you want. The following example covers a typical TypeScript + React project:

```javascript
// eslint.config.js
import tsxConfig from 'eslint-config-iplayer/tsx';

const ignores = {
  ignores: ['node_modules/**', 'dist/**', 'public/**']
};

export default [ignores, ...tsxConfig];
```

| Import                         | Files linted                                  |
| ------------------------------ | --------------------------------------------- |
| `eslint-config-iplayer/js`     | `**/*.js`, `**/*.mjs`, `**/*.cjs`             |
| `eslint-config-iplayer/jsx`    | `**/*.js`, `**/*.mjs`, `**/*.cjs`, `**/*.jsx` |
| `eslint-config-iplayer/ts`     | `**/*.ts`, `**/*.tsx`                         |
| `eslint-config-iplayer/tsx`    | `**/*.ts`, `**/*.tsx`                         |
| `eslint-config-iplayer/legacy` | `**/*.js` (ES5 / RequireJS / Jasmine)         |

Only import the configs relevant to your project. For a TypeScript + React project, `tsx` alone is enough — it covers all `.ts` and `.tsx` files. For a JavaScript + React project, `jsx` alone covers all `.js` and `.jsx` files.

**Note:** `base.js` is only an internal fragment and is not intended to be consumed directly as a flat config. For most use cases, you should use one of the main entry points (`tsx`, `ts`, `jsx`, or `legacy`).

## Legacy Usage - prior to v10

Adding the following to your `eslintConfig` in `package.json` will import the iPlayer ES6 config rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer"
  }
}
```

`jsx` rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer/jsx"
  }
}
```

`ts` rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer/ts"
  }
}
```

`tsx` rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer/tsx"
  }
}
```

`base` rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer/base"
  }
}
```

`legacy` rules:

```json
{
  "eslintConfig": {
    "extends": "iplayer/legacy"
  }
}
```

This package currently sets the default ECMAScript Version to be 9 for the base rules, with the `legacy` rules set to use ECMAScript Version 5. If you require a different version you can change it like so:

```json
{
  "eslintConfig": {
    "extends": "iplayer"
  },
  "parserOptions": {
    "ecmaVersion": 6
  }
}
```
