npm package: @kdcloudjs/eslint-config-kwc
Description: Opinionated ESLint configurations for KWC projects
Latest version: 1.0.2

# @kdcloudjs/eslint-config-kwc

> Opinionated ESLint configurations for Kingdee Web Components (KWC) projects.

## Installation

```sh
npm install --save-dev @kdcloudjs/eslint-config-kwc @kdcloudjs/eslint-plugin-kwc eslint-plugin-import eslint-plugin-jest
```

Note that `@kdcloudjs/eslint-plugin-kwc`, `eslint-plugin-import`, and `eslint-plugin-jest` are peer dependencies of `@kdcloudjs/eslint-config-kwc`.

## Usage

> [!IMPORTANT]
> Starting with v4.0.0, @kdcloudjs/eslint-config-kwc only supports `eslint@v9`. Use `@kdcloudjs/eslint-config-kwc@v3.x` for older versions of eslint.

This repo exports the configurations as an array of config objects. [Apply](https://eslint.org/docs/latest/use/configure/combine-configs#apply-a-config-array) the appropriate [configuration](#Configurations) into your configuration using the spread operator.

Example of `eslint.config.js`:

```js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.recommended];
```

For more details about configuration, please refer to the dedicated section in the ESLint documentation: https://eslint.org/docs/user-guide/configuring#using-a-shareable-configuration-package

### [Experimental] Usage with TypeScript

To enable working with TypeScript projects, install `@babel/preset-typescript` as a dependency, and apply any of the TypeScript-enabled [configurations](#configurations) (any config ending in `Ts`).

Note that these configs use [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser), and compatibility with [@typescript-eslint/parser](https://npmjs.com/package/@typescript-eslint/parser) is not guaranteed.

> [!IMPORTANT]
> While these configs are capable of parsing TypeScript files, not all rules support all TypeScript language features. For example, using type assertions (`variable as Type`) will break many rules.

Example `eslint.config.js`:

```js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.recommendedTs];
```

## Configurations

This package exposes multiple configurations for your usage. Each configuration listed below is available for both JavaScript projects and TypeScript projects (when using `Ts` suffix).

### Base

**Usage:**

```js
// eslint.config.js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.base];
```

**TypeScript:** Use `configs.baseTs` to use this config in TypeScript projects.

### Recommended`@kdcloudjs/eslint-config-kwc/recommended`

**Goal:**
Prevent common Javascript pitfalls and enforce all best practices.

**Usage:**

```js
// eslint.config.js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.recommended];
```

**TypeScript:** Use `configs.recommendedTs` to use this config in TypeScript projects.

### Extended

**Goal:**
Restrict usage of some Javascript language features known to be slow after the _COMPAT_ transformation. KWC runs in _COMPAT_ mode on older browsers (eg. IE11). To support new Javascript syntax and language features on older browser the KWC compiler transforms KWC modules. This linting configuration targets patterns known to be slow in _COMPAT_ mode.

**Usage:**

```js
// eslint.config.js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.extended];
```

**TypeScript:** Use `configs.extendedTs` to use this config in TypeScript projects.

### i18n `@kdcloudjs/eslint-config-kwc/i18n`

**Usage:**

Add the `i18n` configuration to the `extends` field in your `eslint.config.js` configuration file, for example:

```js
// eslint.config.js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.recommended, ...kwcConfig.configs.i18n];
```

**TypeScript:** Use `configs.i18nTs` to use this config in TypeScript projects.

### Ssr

**Goal:**
Promote writing server-side-rendering friendly components. We only recommend using this configuration if your components are running in experiences supporting KWC server-side-rendering.

**Usage:**

```js
// eslint.config.js
const kwcConfig = require('@kdcloudjs/eslint-config-kwc');

module.exports = [...kwcConfig.configs.ssr];
```

**TypeScript:** Use `configs.ssrTs` to use this config in TypeScript projects.