👾
Node.js
  • 🧑‍💻Full-Stack Web Developer
  • 📚Теорія
    • 1️⃣Основи Node.js
      • Вступ
      • Модулі Node.js
      • Запуск скриптів модулів в Node.js
      • Структура проєкту, експорт-імпорт, index.js як хаб
      • Модулі CommonJS
      • Модулі MJS
      • Модулі ECMAScript
      • Модулі NPM + базові модулі
      • Глобальні змінні
      • Робота з файлами
    • 2️⃣Консольні додатки
      • Створення консольних додатків
    • 3️⃣Фреймворк Express
      • Про Express
      • Nodemon і запуски скриптів
      • Postman
      • Проміжне ПЗ middleware
      • Передача даних на сервер
      • Роутінг
      • CRUD
      • Налаштування лінтера
    • 4️⃣REST API
      • Змінні оточення
      • Логування
      • REST
      • Методи HTTP
      • CORS
      • Формування URL для REST API
      • Контроллери відсутнього роуту і непередбачуваної помилки
      • Валідація даних Joi
      • Рефакторинг додатку за MVC архітектурою
      • Express автогенератор додатку
    • 5️⃣База даних Mongo.DB
      • Основи MongoDB
      • Налаштування Mongo Atlas
      • Встановлення локальної MongoDB і основні команди
    • 6️⃣ODM Mongoose
      • Mongoose
      • Порядок планування бекенд додатку
      • чорнетка
    • 7️⃣Автентифякація WJT
      • чорнетка
      • чорнетка 2
    • 8️⃣Файли
      • чернетка
    • 9️⃣тестування
      • чернетка
    • 🔟Page 14
      • імейли
    • чорнетка докер
    • чорнетка сокети
    • додаткові матеріали
    • 👷Практика
      • 1️⃣Page 4
      • 2️⃣Page 5
      • 3️⃣Page 6
      • 4️⃣Page 7
      • 5️⃣Page 8
      • 6️⃣Page 9
  • Про мене
    • Про мене
Powered by GitBook
On this page
  1. Теорія
  2. Фреймворк Express

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

PreviousCRUDNextREST API

Last updated 1 year ago

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

Для почаку встановлюємо розширення .

Тепер в корені нашого проєкту створимо файл .eslintrc.js.

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

Код налаштувань .eslintrc.js
.eslintrc.js
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,
      },
    },
  ],
};

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

package.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"
  }

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

termnal
npm i

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

📚
3️⃣
ESLint