You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We will reformat the configuration file from its current form to the following:
258
+
Let's reformat the configuration file_eslint.config.mjs_ from its current form to the following:
268
259
269
260
```js
270
261
importglobalsfrom'globals'
@@ -337,6 +328,10 @@ export default [
337
328
338
329
The [plugins](https://eslint.org/docs/latest/use/configure/plugins) property provides a way to extend ESLint's functionality by adding custom rules, configurations, and other capabilities that are not available in the core ESLint library. We've installed and enabled the _@stylistic/eslint-plugin-js_, which adds JavaScript stylistic rules for ESLint. In addition, rules for indentation, line breaks, quotes, and semicolons have been added. These four rules are all defined in the [Eslint styles plugin](https://eslint.style/packages/js).
339
330
331
+
**Note for Windows users:** The linebreak style is set to _unix_ in the style rules. It is recommended to use Unix-style linebreaks (_\n_) regardless of your operating system, as they are compatible with most modern operating systems and facilitate collaboration when multiple people are working on the same files. If you are using Windows-style linebreaks, ESLint will produce the following errors: <i>Expected linebreaks to be 'LF' but found 'CRLF'</i>. In this case, configure Visual Studio Code to use Unix-style linebreaks by following [this guide](https://stackoverflow.com/questions/48692741/how-can-i-make-all-line-endings-eols-in-all-files-in-visual-studio-code-unix).
332
+
333
+
### Running the Linter
334
+
340
335
Inspecting and validating a file like _index.js_ can be done with the following command:
341
336
342
337
```bash
@@ -384,8 +379,6 @@ Lint has quite a lot to say about our code:
384
379
385
380

386
381
387
-
Let's not fix these issues just yet.
388
-
389
382
A better alternative to executing the linter from the command line is to configure an _eslint-plugin_ to the editor, that runs the linter continuously. By using the plugin you will see errors in your code immediately. You can find more information about the Visual Studio ESLint plugin [here](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
390
383
391
384
The VS Code ESlint plugin will underline style violations with a red line:
@@ -394,6 +387,8 @@ The VS Code ESlint plugin will underline style violations with a red line:
394
387
395
388
This makes errors easy to spot and fix right away.
396
389
390
+
### Adding More Style Rules
391
+
397
392
ESlint has a vast array of [rules](https://eslint.org/docs/rules/) that are easy to take into use by editing the _eslint.config.mjs_ file.
398
393
399
394
Let's add the [eqeqeq](https://eslint.org/docs/rules/eqeqeq) rule that warns us if equality is checked with anything but the triple equals operator. The rule is added under the rules field in the configuration file.
Copy file name to clipboardExpand all lines: src/content/3/fi/osa3d.md
+10-16Lines changed: 10 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -239,20 +239,11 @@ Vastaillaan kysymyksiin:
239
239
240
240

Muutetaan tiedoston _eslint.config.mjs_sisältö seuraavaan muotoon:
256
247
257
248
```js
258
249
importglobalsfrom'globals'
@@ -322,10 +313,13 @@ export default [
322
313
]
323
314
```
324
315
325
-
[Pluginit](https://eslint.org/docs/latest/use/configure/plugins) tarjoavat tavan laajentaa ESLintin toiminnallisuutta lisäämällä määrittelyjä jotka eivät ole mukana ESLint-ydinkirjastossa. Otimme nyt käyttöön pluginin [@stylistic/eslint-plugin-js](https://eslint.style/packages/js), joka tuo käyttöömme joukon JavaScriptin tyylisääntöjä joista otimme käyttöön sisennystä, rivinvaihtoa, lainausmerkkejä ja puolipisteitä koskevat säännöt.
316
+
[Pluginit](https://eslint.org/docs/latest/use/configure/plugins) tarjoavat tavan laajentaa ESLintin toiminnallisuutta lisäämällä määrittelyjä jotka eivät ole mukana ESLint-ydinkirjastossa. Otimme nyt käyttöön pluginin [@stylistic/eslint-plugin-js](https://eslint.style/packages/js), joka tuo käyttöömme joukon JavaScriptin tyylisääntöjä, joista otimme käyttöön sisennystä, rivinvaihtoa, lainausmerkkejä ja puolipisteitä koskevat säännöt.
317
+
318
+
**Huomautus Windows-käyttäjille:** Rivinvaihtojen tyypiksi on tyylisäännössä määritelty _unix_. On suositeltavaa käyttää Unix-tyyppisiä rivinvaihtoja (_\n_) riippumatta käyttämästäsi käyttöjärjestelmästä, sillä ne ovat yhteensopivia useimpien modernien käyttöjärjestelmien kanssa ja helpottavat työskentelyä, jos useat eri henkilöt työstävät samoja tiedostoja. Jos käytössäsi on Windows-tyyppiset rivinvaihdot, ESLint antaa seuraavia virheitä: <i>Expected linebreaks to be 'LF' but found 'CRLF'</i>. Konfiguroi tällöin Visual Studio Code käyttämään Unix-tyyppisiä rivinvaihtoja esimerkiksi [tämän ohjeen](https://stackoverflow.com/questions/48692741/how-can-i-make-all-line-endings-eols-in-all-files-in-visual-studio-code-unix) mukaan.
326
319
320
+
### Lintterin ajaminen
327
321
328
-
Esim tiedoston_index.js_ tarkastus tapahtuu komennolla:
322
+
Tiedoston_index.js_ tarkastus tapahtuu komennolla:
329
323
330
324
```bash
331
325
npx eslint index.js
@@ -372,8 +366,6 @@ Kun nyt suoritamme linttauksen, löytyy koodistamme jonkin verran huomautettavaa
372
366
373
367

374
368
375
-
Ei kuitenkaan korjata ongelmia vielä.
376
-
377
369
Parempi vaihtoehto linttauksen suorittamiselle komentoriviltä on konfiguroida editorille <i>eslint-plugin</i>, joka suorittaa linttausta koko ajan. Näin pääset korjaamaan pienet virheet välittömästi. Tietoja esim. Visual Studion ESLint-pluginista on [täällä](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
378
370
379
371
VS Coden ESLint-plugin alleviivaa tyylisääntöjä rikkovat kohdat punaisella:
@@ -384,6 +376,8 @@ Näin ongelmat on helppo korjata koodiin heti.
384
376
385
377
Komento _npm run lint -- --fix_ voi olla avuksi, jos koodissa on esim. useampia syntaksivirheitä.
386
378
379
+
### Lisää tyylisääntöjä
380
+
387
381
ESLintille on määritelty suuri määrä [sääntöjä](https://eslint.org/docs/rules/), joita on helppo ottaa käyttöön muokkaamalla tiedostoa _eslint.config.mjs_.
388
382
389
383
Otetaan käyttöön sääntö [eqeqeq](https://eslint.org/docs/rules/eqeqeq) joka varoittaa, jos koodissa yhtäsuuruutta verrataan muuten kuin käyttämällä kolmea = ‑merkkiä. Sääntö lisätään konfiguraatiotiedostoon kentän <i>rules</i> alle.
0 commit comments