# Налаштування лінтера

Опціональні налаштування системи для розробника. Можна зробити так, щоб VSCode сам контролював правильність написання коду і в разі помилок - позначав місце помилки та не дозволяв зробити коміт на GitHub поки вони не будудуть виправлені.&#x20;

Для почаку встановлюємо розширення [ESLint](https://eslint.org/).&#x20;

<figure><img src="/files/4fc0YY3QmQUMsz7ePqmQ" alt=""><figcaption></figcaption></figure>

Тепер в корені нашого проєкту створимо файл <mark style="background-color:red;">.eslintrc.js</mark>.&#x20;

<figure><img src="/files/1taPA21HyM9uBxphhzxA" alt="" width="375"><figcaption></figcaption></figure>

Внесемо цей файл наступні налаштування.

<details>

<summary>Код налаштувань .eslintrc.js</summary>

{% code title=".eslintrc.js" %}

```json
module.exports = {
  env: {
    es6: true,
    node: true,
  },
  globals: {},
  parserOptions: {
    ecmaVersion: 2020,
  },
  extends: ['airbnb-base', 'eslint:recommended'],
  plugins: [],
  rules: {
    'class-methods-use-this': 'off',
    'array-bracket-newline': 'off',
    'array-element-newline': 'off',
    'arrow-body-style': 'error',
    'block-scoped-var': 'error',
    complexity: 'error',
    'constructor-super': 'error',
    camelcase: 'off',
    curly: 'error',
    'default-case': 'off',
    'no-case-declarations': 'off',
    'dot-notation': 'error',
    'eol-last': 'error',
    eqeqeq: 'error',
    'func-names': 'warn',
    'guard-for-in': 'off',
    'global-require': 'off',
    'implicit-arrow-linebreak': 'off',
    'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
    indent: ['warn', 2, { SwitchCase: 1 }],
    'linebreak-style': 'off',
    'max-classes-per-file': 'off',
    'newline-per-chained-call': 'error',
    'new-parens': 'error',
    'no-alert': 'error',
    'no-duplicate-imports': 'error',
    'no-nested-ternary': 'error',
    'no-mixed-spaces-and-tabs': 'error',
    'no-underscore-dangle': 'off',
    'no-bitwise': 'error',
    'no-caller': 'error',
    'no-cond-assign': 'error',
    'no-console': 'warn',
    'no-else-return': 'error',
    'no-empty': 'off',
    'no-plusplus': 'off',
    'no-empty-functions': 'off',
    'consistent-return': 'off',
    'no-dynamic-require': 'off',
    'no-eval': 'error',
    'no-extend-native': 'error',
    'no-extra-bind': 'error',
    'no-fallthrough': 'error',
    'no-floating-decimal': 'error',
    'no-implicit-globals': 'error',
    'no-implied-eval': 'error',
    'no-invalid-this': 'off',
    'no-iterator': 'error',
    'no-labels': 'error',
    'no-lone-blocks': 'error',
    'no-loop-func': 'error',
    'max-len': [
      'error',
      {
        ignoreRegExpLiterals: true,
        ignoreUrls: true,
        comments: 130,
        code: 130,
      },
    ],
    'no-magic-numbers': ['off', { ignoreArrayIndexes: true }],
    'no-multi-spaces': 'error',
    'no-multi-str': 'error',
    'no-multiple-empty-lines': 'error',
    'no-new': 'error',
    'comma-dangle': 'off',
    'no-new-func': 'error',
    'no-new-wrappers': 'error',
    'no-octal-escape': 'error',
    'no-param-reassign': 'warn',
    'no-proto': 'error',
    'no-return-assign': 'error',
    'no-return-await': 'error',
    'no-restricted-syntax': 'off',
    'no-script-url': 'error',
    'no-self-compare': 'error',
    'no-sequences': 'error',
    'no-throw-literal': 'error',
    'no-undef-init': 'error',
    'no-unsafe-finally': 'error',
    'no-unused-expressions': 'error',
    'no-unused-vars': 'warn',
    'no-use-before-define': ['error', { functions: false }],
    'no-useless-call': 'error',
    'no-useless-concat': 'error',
    'no-useless-return': 'error',
    'no-var': 'error',
    'no-void': 'error',
    'object-shorthand': 'error',
    'object-curly-newline': 'warn',
    'one-var': ['error', 'never'],
    'padding-line-between-statements': 'error',
    'prefer-const': 'error',
    'prefer-object-spread': 'warn',
    'quote-props': ['error', 'as-needed'],
    radix: 'error',
    'require-await': 'error',
    'sort-imports': [
      'error',
      {
        ignoreCase: true,
        ignoreDeclarationSort: true,
        ignoreMemberSort: false,
      },
    ],
    'space-before-function-paren': [
      'error',
      {
        anonymous: 'never',
        asyncArrow: 'always',
        named: 'never',
      },
    ],
    'use-isnan': 'error',
    'wrap-iife': 'error',
    yoda: 'error',
  },
  overrides: [
    {
      files: ['**/*.test.js'],
      env: {
        jest: true,
      },
    },
  ],
};
```

{% endcode %}

</details>

Крім того, в package.json в devDependencies вписуємо такі пакети.&#x20;

{% code title="package.json" %}

```json
 "devDependencies": {
    "eslint": "^8.34.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^6.1.1",
    "husky": "^4.3.8",
    "lint-staged": "^13.1.2",
    "nodemon": "^2.0.22"
  },
  "lint-staged": {
    "*.js": [
      "eslint"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.18.2",
    "uuid": "^9.0.0"
  }
```

{% endcode %}

Нові залежності потрібно встановити:

{% code title="termnal" %}

```
npm i
```

{% endcode %}

Тепер лінтер буде перевіряти наш код, підсвічувати помилки і не пропустить коміт поки їх не виправлять. Далі можна конфігурувати налаштування під себе.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oleksandr-khomiak.gitbook.io/node/teoriya/freimvork-express/nalashtuvannya-lintera.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
