# A SKY ESLint [Shareable Config](https://eslint.org/docs/developer-guide/shareable-configs)

ESLint configuration file containing rules for Typescript, React and Prettier.

## Installation & usage

1. Confirm there is `.npmrc` file at the same level as `package.json` is in you project.

2. To be able to install dependencies you need to first set NPM_TOKEN environment variable to your Github access token, like 
   * `set NPM_TOKEN=<your token>` on Windows
   * `export NPM_TOKEN=<your token>` on Linux


3. To install the package. Type: 
   ```
   npm i -D @sky-distribution/eslint-config-sky
   ```

4. Remove other ESLint and Pretier configurations, that can conflict with this one (e.g. `.eslintrc` or `.prettierrc`).


5. To use this configuration you need to add it in `package.json`

   1. For backend project

   ```
   "eslintConfig": {
     "extends": [
       "@sky-distribution/eslint-config-sky/backend"
     ]
   }
   ```

   2. For react project

   ```
   "eslintConfig": {
     "extends": [
       "@sky-distribution/eslint-config-sky/frontend"
     ]
   }
   ```

 7. To make sure that eslint will always see your .tsconfig (sometimes it's in ./ and sometimes in ./app) add to editor settings:
    ```
    "eslint.workingDirectories": [
      {
        "directory": ".",
        "changeProcessCWD": true
      },
      {
        "directory": "./app",
        "changeProcessCWD": true
      }
    ],
    ```

## Autoformatting

You need to uninstall or disable Prettier extension for .js and .ts files and use [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) one which will use both ESLint and Prettier rules to format code.

To enable autoformatting (specifically autofixing) code add this lines to your VSCode config json:

```
"editor.codeActionsOnSave": [
  "source.organizeImports",
  "source.fixAll"
],
```

- source.organizeImports is optional, but:
- if order of execution of code formatters on-save matters use square brackets as shown above (e.g. in this case it is important to triggger organizeImports before fixAll)
