# Developer Guide

- Node: >= 16
- Helpful: https://astexplorer.net/, https://github.com/estree/estree
- To make development easier, use https://yeoman.io/ (as in the https://eslint.org/docs/latest/developer-guide/working-with-plugins#create-a-plugin recommended)
    - Install yo:
      ```sh
      npm install
      ```

## Create a rule

Execute the generator to create a rule.

```sh
yo eslint:rule
```

- Enter your name
- >Where will this rule be published?
    - Select `ESLint Plugin`
- >What is the rule ID?
    - The rule ID is the rule name. Enter a plausible name for the rule
- Enter a short description for the rule (can be changed later)
- Enter a short example of the code that will fail (can be changed later).

Add to `new RuleTester()` as parameter:
```js
const ruleTester = new RuleTester({
  parserOptions: {
    parser: '@babel/eslint-parser',
    ecmaVersion: 2020,
  },
});

// For Vue.js
const ruleTester = new RuleTester({
  parser: require.resolve('vue-eslint-parser'),
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 2020,
  },
});
```

This generator creates a test file (./tests/lib/rules), a rule file (./lib/rules) and a docs file (./docs/rules).
A Rule has to have a working test and a descriptive doc file.
Link the custom rule doc in the [Readme](./README.md) under the 'Custom Rules' section.

**Important**: Please use `messageId:` in the invalid code examples in the test and add the messages in the rule. (As it is in the existing rules)

### Config file

Please use the config files, for example, for AST types or function names.

### Activate a custom rule

New rules aren't enabled automatically.

To activate a rule, add the rule to one of the config files, or create a new one (section below), in the ./config directory with the prefix `rules_`

#### How to add a rule?

Use the prefix of the plugin, `@clubdrei/clubdrei/` then the name of the rule. Then add the "type" ('error', 'warning', 'off') after the ':'

### New Ruleset

* Use the prefix `rules_` and a name.
* Export a module with `rules` in it (like the other ones).
* Import it in the `index.js` (./lib/index.js)
* Add it to the rules section to the needed configs.

## Testing

### In other projects

#### Both projects are local
If you want to test changes in a rule in another project, you can install the local version of `@clubdrei/eslint-plugin-clubdrei` with the following command:

```bash
npm install -D file:/PATH_TO_ESLINT_PROJECT --install-links
```

or use `npm link` to create a symbolic link

1. Go into the eslint-config and run `npm link` 
2. Go into the project you want to test and run `npm link @clubdrei/eslint-plugin-clubdrei --install-links`

It's necessary to use `--install-links`, otherwise some dependencies of `@clubdrei/eslint-plugin-clubdrei` will be missing (e.g. `eslint-plugin-filenames-simple`)

#### Install from Git branch
1. Open Projects
2. Execute npm install git+ssh://git@your_vcs.com:your_project.git#your_branch_name
3. Run npm run lint

## Use the rule in the plugin itself

We installed the [eslint-plugin-self](https://www.npmjs.com/package/eslint-plugin-self) to use new rules in this plugin.
To use a new rule, add it in the `.eslintrc.js` with the prefix `self/` and the name. If the rules aren't working in the plugin itself, reinstall the `eslint-plugin-self`.

## Publish Packages

1. Create a branch `release/VERSION`
2. Change the version in the `package.json`
3. Run `npm i --package-lock-only` to sync the version to `package-lock.json`
4. Create an MR in GitLab 
5. Merge the MR
6. Start the deployment job from the GitLab UI
   * `deploy:npmjs:stable` for a normal/stable version
   * `deploy:npmjs:prerelease` for a release candidate/beta/alpha version

## Other

If there are changes made that aren't described in this file, please adapt this file.
