npm package: @kdcloudjs/eslint-plugin-kwc
Description: Official ESLint rules for KWC
Latest version: 1.0.2

# @kdcloudjs/eslint-plugin-kwc

> Official ESLint rules for Kingdee Web Components (KWC).

## Installation

```
$ npm install eslint @babel/core @babel/eslint-parser @kdcloudjs/eslint-plugin-kwc --save-dev
```

## Usage

_Starting with v3.0.0, @kdcloudjs/eslint-plugin-kwc only supports eslint@v9. Use @kdcloudjs/eslint-plugin-kwc@v1.x for older versions of eslint._

Import `@kdcloudjs/eslint-plugin-kwc` and use it in the `plugins` section of your configuration as shown below. Then configure the desired rules in the `rules` sections. Some of the syntax used in Kingdee Web Components is not yet stage 4 (eg. class fields or decorators), and the out-of-the-box parser from ESLint doesn't support this syntax yet. In order to parse the KWC files properly, set the `parser` field to [`@babel/eslint-parser`](https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser) in the `languageOptions` section of the eslint config.

Example of `eslint.config.js`:

```js
const eslintPluginKwc = require('@kdcloudjs/eslint-plugin-kwc');
const babelParser = require('@babel/eslint-parser');

module.exports = [
    {
        languageOptions: {
            parser: babelParser,
            parserOptions: {
                requireConfigFile: false,
                babelOptions: {
                    parserOpts: {
                        plugins: [
                            'classProperties',
                            ['decorators', { decoratorsBeforeExport: false }],
                        ],
                    },
                },
            },
        },
        plugins: {
            '@kwc/kwc': eslintPluginKwc,
        },
        rules: {
            '@kwc/kwc/no-deprecated': 'error',
            '@kwc/kwc/valid-api': 'error',
            '@kwc/kwc/no-document-query': 'error',
            '@kwc/kwc/ssr-no-unsupported-properties': 'error',
        },
    },
];
```

### Usage with TypeScript

To enable working with TypeScript projects, install `@babel/preset-typescript` as a dependency add `"typescript"` to `languageOptions.parserOptions.babelOptions.parserOpts.plugins` in your `eslint.config.js`.

Example:

```js
const eslintPluginKwc = require('@kdcloudjs/eslint-plugin-kwc');
const babelParser = require('@babel/eslint-parser');

module.exports = [
    {
        languageOptions: {
            parser: babelParser,
            parserOptions: {
                requireConfigFile: false,
                babelOptions: {
                    parserOpts: {
                        plugins: [
                            'classProperties',
                            ['decorators', { decoratorsBeforeExport: false }],
                            'typescript',
                        ],
                    },
                },
            },
        },
    },
];
```

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


### Processors

| Processor ID                        | Description                                       |
| ----------------------------------- | ------------------------------------------------- |
| [kwc/ssr](./docs/processors/ssr.md) | Lint only JavaScript files of SSR-able components |

## Rules

### KWC

| Rule ID                                                                                                                                | Description                                                                    | Fixable |
| -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------- |
| [kwc/consistent-component-name](./docs/rules/consistent-component-name.md)                                                             | ensure component class name matches file name                                  | 🔧      |
| [kwc/no-api-reassignments](./docs/rules/no-api-reassignments.md)                                                                       | prevent public property reassignments                                          |         |
| [kwc/no-deprecated](./docs/rules/no-deprecated.md)                                                                                     | disallow usage of deprecated KWC APIs                                          |         |
| [kwc/no-document-query](./docs/rules/no-document-query.md)                                                                             | disallow DOM query at the document level                                       |         |
| [kwc/no-attributes-during-construction](./docs/rules/no-attributes-during-construction.md)                                             | disallow setting attributes during construction                                |         |
| [kwc/no-disallowed-kwc-imports](./docs/rules/no-disallowed-kwc-imports.md)                                                             | disallow importing unsupported APIs from the `@kdcloudjs/kwc` package                     |         |
| [kwc/no-leading-uppercase-api-name](./docs/rules/no-leading-uppercase-api-name.md)                                                     | ensure public property doesn't start with an upper-case character              |         |
| [kwc/no-unexpected-wire-adapter-usages](./docs/rules/no-unexpected-wire-adapter-usages.md)                                             | enforce wire adapters to be used with `wire` decorator                         |         |
| [kwc/no-unknown-wire-adapters](./docs/rules/no-unknown-wire-adapters.md)                                                               | disallow usage of unknown wire adapters                                        |         |
| [kwc/valid-api](./docs/rules/valid-api.md)                                                                                             | validate `api` decorator usage                                                 |         |
| [kwc/valid-track](./docs/rules/valid-track.md)                                                                                         | validate `track` decorator usage                                               |         |
| [kwc/valid-wire](./docs/rules/valid-wire.md)                                                                                           | validate `wire` decorator usage                                                |         |
| [kwc/valid-graphql-wire-adapter-callback-parameters](./docs/rules/valid-graphql-wire-adapter-callback-parameters.md)                   | ensure graphql wire adapters are using 'errors' instead of 'error'             |         |
| [kwc/no-host-mutation-in-connected-callback](./docs/rules/no-host-mutation-in-connected-callback.md)                                   | disallow the host element mutation in 'connectedCallback'                      |         |
| [kwc/consistent-component-name](./docs/rules/consistent-component-name.md)                                                             | ensure component class name matches file name                                  | 🔧      |
| [kwc/no-api-reassignments](./docs/rules/no-api-reassignments.md)                                                                       | prevent public property reassignments                                          |         |
| [kwc/no-deprecated](./docs/rules/no-deprecated.md)                                                                                     | disallow usage of deprecated KWC APIs                                          |         |
| [kwc/no-document-query](./docs/rules/no-document-query.md)                                                                             | disallow DOM query at the document level                                       |         |
| [kwc/no-attributes-during-construction](./docs/rules/no-attributes-during-construction.md)                                             | disallow setting attributes during construction                                |         |
| [kwc/no-disallowed-kwc-imports](./docs/rules/no-disallowed-kwc-imports.md)                                                             | disallow importing unsupported APIs from the `@kdcloudjs/kwc` package                     |         |
| [kwc/no-leading-uppercase-api-name](./docs/rules/no-leading-uppercase-api-name.md)                                                     | ensure public property doesn't start with an upper-case character              |         |
| [kwc/no-unexpected-wire-adapter-usages](./docs/rules/no-unexpected-wire-adapter-usages.md)                                             | enforce wire adapters to be used with `wire` decorator                         |         |
| [kwc/no-unknown-wire-adapters](./docs/rules/no-unknown-wire-adapters.md)                                                               | disallow usage of unknown wire adapters                                        |         |
| [kwc/valid-api](./docs/rules/valid-api.md)                                                                                             | validate `api` decorator usage                                                 |         |
| [kwc/valid-track](./docs/rules/valid-track.md)                                                                                         | validate `track` decorator usage                                               |         |
| [kwc/valid-wire](./docs/rules/valid-wire.md)                                                                                           | validate `wire` decorator usage                                                |         |
| [kwc/ssr-no-restricted-browser-globals](./docs/rules/ssr/ssr-no-restricted-browser-globals.md)                                         | disallow access to global browser APIs during SSR                              |         |
| [kwc/ssr-no-unsupported-properties](./docs/rules/ssr/ssr-no-unsupported-properties.md)                                                 | disallow access of unsupported properties in SSR                               |         |
| [kwc/ssr-no-node-env](./docs/rules/ssr/ssr-no-node-env.md)                                                                             | disallow usage of process.env.NODE_ENV in SSR                                  |         |
| [kwc/ssr-no-disallowed-kwc-imports](./docs/rules/ssr/ssr-no-disallowed-kwc-imports.md)                                                 | restrict specific imports from the kwc package in SSR-able components          |         |
| [kwc/valid-graphql-wire-adapter-callback-parameters](./docs/rules/valid-graphql-wire-adapter-callback-parameters.md)                   | ensure graphql wire adapters are using 'errors' instead of 'error'             |         |
| [kwc/ssr-no-host-mutation-in-connected-callback](./docs/rules/ssr/ssr-no-host-mutation-in-connected-callback.md)                       | disallow the host element mutation in 'connectedCallback'                      |         |
| [kwc/ssr-no-static-imports-of-user-specific-scoped-modules](./docs/rules/ssr/ssr-no-static-imports-of-user-specific-scoped-modules.md) | disallow static imports of user-specific scoped modules in SSR-able components |         |
| [kwc/ssr-no-form-factor](./docs/rules/ssr/ssr-no-form-factor.md)                                                                       | disallow formFactor in SSR-able components                                     |         |

### Best practices

| Rule ID                                                                            | Description                                                | Fixable |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------- |
| [kwc/no-async-operation](./docs/rules/no-async-operation.md)                       | restrict usage of async operations                         |         |
| [kwc/no-dupe-class-members](./docs/rules/no-dupe-class-members.md)                 | disallow duplicate class members                           |         |
| [kwc/no-inner-html](./docs/rules/no-inner-html.md)                                 | disallow usage of `innerHTML`                              |         |
| [kwc/no-template-children](./docs/rules/no-template-children.md)                   | prevent accessing the immediate children of this.template  |         |
| [kwc/no-leaky-event-listeners](./docs/rules/no-leaky-event-listeners.md)           | prevent event listeners from leaking memory                |         |
| [kwc/prefer-custom-event](./docs/rules/prefer-custom-event.md)                     | suggest usage of `CustomEvent` over `Event` constructor    |         |
| [kwc/ssr-no-unsupported-node-api](./docs/rules/ssr/ssr-no-unsupported-node-api.md) | disallow unsupported Node API calls in SSR-able components |         |

### Compat performance

Older browsers like IE11 run KWC in compatibility mode.

| Rule ID                                                    | Description                                 | Fixable |
| ---------------------------------------------------------- | ------------------------------------------- | ------- |
| [kwc/no-async-await](./docs/rules/no-async-await.md)       | disallow usage of the async-await syntax    |         |
| [kwc/no-for-of](./docs/rules/no-for-of.md)                 | disallow usage of the for-of syntax         |         |
| [kwc/no-rest-parameter](./docs/rules/no-rest-parameter.md) | disallow usage of the rest parameter syntax |         |

### Deprecated

| Rule ID                                                            | Replaced by                                                                                    |
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| [kwc/no-dupe-class-members](./docs/rules/no-dupe-class-members.md) | [no-dupe-class-members](https://eslint.org/docs/rules/no-dupe-class-members)(base eslint rule) |