Created
June 20, 2023 20:29
-
-
Save Zamay/7974280a9940190cdb80d0f7bb890066 to your computer and use it in GitHub Desktop.
Welcome file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Що робити з попередженнями в eslint ? | |
**1.** В файлі **fightersService.js** в методі async **getFighterDetails(id) {...}** відбувається помилка | |
``` | |
class FighterService { | |
#endpoint = 'fighters.json'; | |
async getFighters() { | |
try { | |
return await callApi(this.#endpoint); | |
} catch (error) { | |
throw error; | |
} | |
} | |
async getFighterDetails(id) { | |
try { | |
const endpoint = `details/fighter/${id}.json`; | |
return await callApi(endpoint); | |
} catch (error) { | |
throw error; | |
} | |
} | |
} | |
``` | |
> ESLint: Expected 'this' to be used by class async method 'getFighterDetails'.(class-methods-use-this) | |
### Є варіант вирішення проблеми: | |
#### 1) ігнорувати ( не дуже варіант, але є) | |
```sh | |
// eslint-disable-next-line class-methods-use-this | |
``` | |
#### 2) в .eslintrc додати ( я за цей ) | |
``` | |
{ "rules": { "class-methods-use-this": "off" } } | |
``` | |
# | |
**2.** В файлі **fight.js** в **switch**відбувається помилка на слові **const** : | |
``` | |
switch (event.code) { | |
case controls.PlayerOneBlock: | |
firstFighterBlock = true; | |
break; | |
case controls.PlayerTwoBlock: | |
secondFighterBlock = true; | |
break; | |
case controls.PlayerOneAttack: | |
if (!isPlayerOneAttacking || firstFighterBlock) return; | |
const damageFirstFighter = secondFighterBlock ? 0 : getDamage(firstFighter, secondFighter); | |
secondFighterHP -= damageFirstFighter; | |
reduceHealthIndicator('right', secondFighterHP, secondFighter.health); | |
printResultToConsole(secondFighter, secondFighterHP, damageFirstFighter); | |
if (secondFighterHP <= 0) { | |
resolve(firstFighter); | |
} | |
isPlayerOneAttacking = false; | |
break; | |
... | |
} | |
``` | |
>ESLint: Unexpected lexical declaration in case block.(no-case-declarations) | |
>Ви не можете оголошувати змінні з ключовим словом `const`, `let` або `var` прямо в блоку `case`. Це обмеження на випадок блоку `case` було введене для підтримки старих версій JavaScript, де оголошення змінних відбувається на рівні функцій або глобального області видимості. | |
### Є варіант вирішення проблеми: | |
#### 1) ігнорувати ( не дуже варіант, але є) | |
```sh | |
// eslint-disable-next-line no-case-declarations | |
``` | |
#### 2) Винести оголошення змінної за межі блоку `case`: | |
``` | |
let damageSecondFighter; | |
switch (someVariable) { | |
case 'someCase': | |
damageSecondFighter = firstFighterBlock ? 0 : getDamage(secondFighter, firstFighter); | |
break; | |
// інші випадки | |
} | |
``` | |
#### 3) або: | |
``` | |
{ | |
"rules": { | |
"no-case-declarations": [ | |
"error", | |
{ | |
"ignoreInSwitchCase": true | |
} | |
] | |
} | |
} | |
``` | |
# | |
**3.** В файлі **fight.js** в **for** відбувається помилка | |
``` | |
for (const code of controls.PlayerOneCriticalHitCombination) { | |
if (!pressed.has(code)) { | |
allKeysPressedFirstFighter = false; | |
break; | |
} | |
} | |
``` | |
>ESLint: iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.(no-restricted-syntax) | |
### Є варіант вирішення проблеми: | |
#### 1) ігнорувати ( не дуже варіант, але є) | |
```sh | |
// eslint-disable-next-line no-restricted-syntax | |
``` | |
#### 2) Встановити пакет `regenerator-runtime` і далі викоистати такий код ( але такий варіат я не перевіряв ): | |
```sh | |
const allKeysPressedSecondFighter = controls.PlayerTwoCriticalHitCombination.every(code => pressed.has(code)); | |
``` | |
#### 3) або: | |
``` | |
{ | |
"rules": { | |
"no-restricted-syntax": [ | |
"error", | |
{ | |
"selector": "ForOfStatement", | |
"message": "Iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.", | |
"allowForLoopAfterthoughts": true | |
} | |
] | |
} | |
} | |
``` | |
# | |
### Перевірив варіанти з налаштуванням .eslintrc і воно працює, але я поки вибрав всюди перший варіант, щоб запушити код і спитати у вас що робити. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment