Skip to content

Commit 4233d7d

Browse files
committed
Add headers and info about Windows-style linebreaks
1 parent a847a94 commit 4233d7d

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

src/content/3/en/part3d.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,11 @@ We will answer all of the questions:
251251

252252
![terminal output from ESlint init](../../images/3/lint1.png)
253253

254-
The configuration will be saved in the generated _eslint.config.mjs_ file:
254+
The configuration will be saved in the generated _eslint.config.mjs_ file.
255255

256-
```js
257-
import globals from "globals";
258-
259-
260-
/** @type {import('eslint').Linter.Config[]} */
261-
export default [
262-
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
263-
{languageOptions: { globals: globals.browser }},
264-
];
265-
```
256+
### Formatting the Configuration File
266257

267-
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:
268259

269260
```js
270261
import globals from 'globals'
@@ -337,6 +328,10 @@ export default [
337328

338329
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).
339330

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+
340335
Inspecting and validating a file like _index.js_ can be done with the following command:
341336

342337
```bash
@@ -384,8 +379,6 @@ Lint has quite a lot to say about our code:
384379

385380
![terminal output of ESlint errors](../../images/3/53ea.png)
386381

387-
Let's not fix these issues just yet.
388-
389382
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).
390383

391384
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:
394387

395388
This makes errors easy to spot and fix right away.
396389

390+
### Adding More Style Rules
391+
397392
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.
398393

399394
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.

src/content/3/fi/osa3d.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,11 @@ Vastaillaan kysymyksiin:
239239

240240
![Vastataan kysymyksiin koodin luonteen mukaan, erityisesti että kyse ei ole TypeSriptistä, käytetään ' merkkijonoissa, ei käytetä ; rivien lopussa](../../images/3/lint1.png)
241241

242-
Konfiguraatiot tallentuvat tiedostoon _eslint.config.mjs_:
242+
Konfiguraatiot tallentuvat tiedostoon _eslint.config.mjs_.
243243

244-
```js
245-
import globals from "globals";
246-
247-
248-
/** @type {import('eslint').Linter.Config[]} */
249-
export default [
250-
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
251-
{languageOptions: { globals: globals.browser }},
252-
];
253-
```
244+
### Konfiguraatiotiedoston muotoilu
254245

255-
Muutetaan tiedoston sisältö seuraavaan muotoon:
246+
Muutetaan tiedoston _eslint.config.mjs_ sisältö seuraavaan muotoon:
256247

257248
```js
258249
import globals from 'globals'
@@ -322,10 +313,13 @@ export default [
322313
]
323314
```
324315

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.
326319

320+
### Lintterin ajaminen
327321

328-
Esim tiedoston _index.js_ tarkastus tapahtuu komennolla:
322+
Tiedoston _index.js_ tarkastus tapahtuu komennolla:
329323

330324
```bash
331325
npx eslint index.js
@@ -372,8 +366,6 @@ Kun nyt suoritamme linttauksen, löytyy koodistamme jonkin verran huomautettavaa
372366

373367
![Lint kertoo kolmesta virheestä, kaikki muuttujia joille ei ole käyttöä](../../images/3/53ea.png)
374368

375-
Ei kuitenkaan korjata ongelmia vielä.
376-
377369
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).
378370

379371
VS Coden ESLint-plugin alleviivaa tyylisääntöjä rikkovat kohdat punaisella:
@@ -384,6 +376,8 @@ Näin ongelmat on helppo korjata koodiin heti.
384376

385377
Komento _npm run lint -- --fix_ voi olla avuksi, jos koodissa on esim. useampia syntaksivirheitä.
386378

379+
### Lisää tyylisääntöjä
380+
387381
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_.
388382

389383
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

Comments
 (0)