@soleil-se/eslint-config 6.0.0 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ Alla förändringar i detta repository antecknas här.
7
7
  Formatet baseras på [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
8
  och projektet använder [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
+ ## [6.0.2] - 2025-02-07
11
+
12
+ * Uppdatera definitioner i package.json.
13
+
14
+ ## [6.0.1] - 2025-02-05
15
+
16
+ * Läs in Svelte konfiguration dynamiskt.
17
+ * Uppdatera referenser för publicering på npm.
18
+
10
19
  ## [6.0.0] - 2025-02-04
11
20
 
12
21
  * Uppdatera till ESLint 9 och format på konfigurationsfiler till flat config.
package/README.md CHANGED
@@ -1,261 +1,5 @@
1
+ # @soleil-se/eslint-config
1
2
 
2
- ESLint konfiguration för Sitevision projekt som bygger på Airbnbs JavaScript styleguide.
3
+ ESLint configuration for Sitevision apps and projects.
3
4
 
4
- **ES2015+**
5
- <https://github.com/airbnb/javascript>
6
-
7
- Om man stöter på ett fel man inte förstår kan man kolla i styleguiden eller söka på ESLints hemsida.
8
- <https://eslint.org/docs/rules/>
9
-
10
- ## Installera
11
-
12
- Installera dependencies och sätt upp konfigurationsfiler:
13
-
14
- ```sh
15
- npx @soleil-se/eslint-config-sitevision@latest --setup
16
- ```
17
-
18
- För att installera manuellt installera följande dependencies och skapa upp konfigurationsfiler enligt [nedan](#config).
19
-
20
- ```sh
21
- npm i @soleil-se/eslint-config-sitevision eslint --save-dev
22
- ```
23
-
24
- ## Uppgradera
25
-
26
- Enklast är att köra setup skriptet för att uppdatera till senaste versionen.
27
- ```sh
28
- npx @soleil-se/eslint-config-sitevision@latest --setup
29
- ```
30
-
31
- :::::details[Manuellt]
32
- ::::steps
33
- :::step[Avinstallera plugins]
34
- Avinstallera alla gamla plugins med:
35
-
36
- ```sh
37
- npm remove eslint-config-airbnb-base eslint-plugin-import eslint-plugin-svelte
38
- ```
39
-
40
- :::
41
- :::step[Uppdatera dependencies]
42
- Uppdatera `@soleil-se/eslint-config-sitevision` till version 6 och `eslint` till version 9:
43
-
44
- ```sh
45
- npm i @soleil-se/eslint-config-sitevision@6 eslint@9 --save-dev
46
- ```
47
-
48
- :::
49
- :::step[Ta bort gammal konfiguration]
50
-
51
- Ta bort gamla konfigurationsfiler.
52
-
53
- - `.eslintrc.cjs`
54
- - `.eslintignore`
55
- - `.prettierrc.cjs`
56
-
57
- :::
58
- :::step[Skapa upp ny konfiguration]
59
- Skapa upp nya konfigurationsfiler enligt [nedan](#config).
60
- :::
61
-
62
- ::::
63
-
64
- :::::
65
-
66
- ## Config
67
-
68
- ESLint läser främst från `eslint.config.js` filer i projektet.
69
- <https://eslint.org/docs/user-guide/configuring#using-configuration-files-1>
70
-
71
- ### Importera config
72
-
73
- ```js
74
- // eslint.config.js
75
- import sitevision from '@soleil-se/eslint-config-sitevision';
76
-
77
- export default [
78
- ...sitevision,
79
- ];
80
-
81
- ```
82
-
83
- Config för skriptmoduler och Rhino.
84
-
85
- ```js
86
- // eslint.config.js
87
- import script from '@soleil-se/eslint-config-sitevision/script-module';
88
-
89
- export default [
90
- ...script,
91
- ];
92
-
93
- ```
94
-
95
- ## Editors
96
-
97
- Enklaste sättet att komma igång med ESLint är att installera det som extension i din editor.
98
-
99
- ### Visual Studio Code
100
-
101
- Installera [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) till Visual Studio Code.
102
-
103
- #### End of line
104
-
105
- Airbnb använder sig av LF för EOL. Ställs in under [settings](https://code.visualstudio.com/docs/getstarted/settings) i Visual Studio Code.
106
- Ändra `\r\n` till `\n`.
107
- Sen vill man även ha att en ny rad inkluderas i filerna.
108
-
109
- ```json
110
- "files.eol": "\n",
111
- "files.insertFinalNewline": true
112
- ```
113
-
114
- #### Indentation
115
-
116
- Airbnb indenterar med två spaces.
117
-
118
- ```json
119
- "editor.tabSize": 2,
120
- "editor.insertSpaces": true
121
- ```
122
-
123
- #### Autofix
124
-
125
- Man kan ställa in så enklare fel åtgärdas automatiskt under [settings](https://code.visualstudio.com/docs/getstarted/settings) i Visual Studio Code.
126
-
127
- ```json
128
- "editor.codeActionsOnSave": {
129
- "source.fixAll.eslint": true
130
- }
131
- ```
132
-
133
- #### Max length
134
-
135
- Airbnb förespråkar en maxlängd på 100 tecken på en rad.
136
- Man kan ställa in så man visar en linje i Visual Studio Code för att visualisera detta. Görs i [settings](https://code.visualstudio.com/docs/getstarted/settings).
137
-
138
- ```json
139
- "editor.rulers": [
140
- 100
141
- ]
142
- ```
143
-
144
- #### Svelte
145
-
146
- För att få stöd för Svelte behöver man lägga in följande i [settings](https://code.visualstudio.com/docs/getstarted/settings).
147
-
148
- ```json
149
- "eslint.validate": [
150
- "javascript",
151
- "javascriptreact",
152
- "svelte"
153
- ]
154
- ```
155
-
156
- #### Konfig i underkatalog
157
-
158
- Om man vill köra ESLint i en underkatalog som har en egen installation och konfiguration av `eslint`
159
- behöver man antingen lägga till katalogens sökväg i inställningen `eslint.workingDirectories` eller ändra till `{ "mode": "auto" }`.
160
- Läs mer här: <https://github.com/microsoft/vscode-eslint#settings-options>
161
-
162
- Exempelvis om en standalone WebApp har en egen konfiguration och plugins som läses in.
163
-
164
- ```json
165
- "eslint.workingDirectories": ["./standalone_apps/MyApp"]
166
- ```
167
-
168
- Slår man på `{ "mode": "auto" }` försöker den automatiskt hitta rätt konfiguration.
169
-
170
- ```json
171
- "eslint.workingDirectories": [{ "mode": "auto" }]
172
- ```
173
-
174
- #### Komplett config
175
-
176
- `Ctrl` + `Shift` + `P` och skriv settings och öppna `settings.json`.
177
-
178
- ```json
179
- // settings.json
180
-
181
- "files.eol": "\n",
182
- "files.insertFinalNewline": true,
183
- "editor.codeActionsOnSave": {
184
- "source.fixAll.eslint": "explicit"
185
- },
186
- "editor.rulers": [
187
- 100
188
- ],
189
- "editor.formatOnSave": false,
190
- "editor.tabSize": 2,
191
- "editor.insertSpaces": true,
192
- "eslint.validate": [
193
- "javascript",
194
- "javascriptreact",
195
- "svelte",
196
- ],
197
- "[svelte]": {
198
- "editor.formatOnSave": true
199
- },
200
- "eslint.workingDirectories": [{ "mode": "auto" }],
201
-
202
- ```
203
-
204
- ## CLI
205
-
206
- Om man vill köra ESLint i sin terminal.
207
- <https://eslint.org/docs/user-guide/command-line-interface>
208
-
209
- ## Svelte
210
-
211
- Installera [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) tillägget till Visual Studio Code.
212
-
213
- ### Kodformatering
214
-
215
- Formatering av kod i Svelte använder Prettier så man behöver lägga till insällningar för det så HTML kan formateras,
216
- dessvärre påverkar detta även JavaScript så några regler som man är van vid har fått stängas av så
217
- det inte krockar med Prettier.
218
- Skapa en fil som heter `prettier.config.js` i roten av appen eller projektet.
219
-
220
- ```js
221
- // prettier.config.js
222
- export { default } from '@soleil-se/eslint-config-sitevision/prettier';
223
-
224
- ```
225
-
226
- För att formatera automatiskt behöver man lägga till följande i `settings.json` i Visual Studio Code.
227
-
228
- ```json
229
- // settings.json
230
- {
231
- "[svelte]": {
232
- "editor.formatOnSave": true,
233
- "editor.defaultFormatter": "svelte.svelte-vscode"
234
- },
235
- }
236
- ```
237
-
238
- Man kan även stänga av formateringen av skript genom att lägga till kommentaren `<!-- prettier-ignore -->` före skripttaggen om det blir krockar och problem.
239
-
240
- ```svelte
241
- // App.svelte
242
- <!-- prettier-ignore -->
243
- <script>
244
- const foo = 'bar';
245
- </script>
246
-
247
- <p>{foo}</p>
248
- ```
249
-
250
- ## Git
251
-
252
- Om man har problem med linebreaks i git kan man behöva göra följande:
253
-
254
- 1. Pusha upp / stasha alla förändringar.
255
- 2. Skapa en fil i roten av projektet med namnet `.gitattributes`.
256
- 3. Ange innehåll i filen: `* text=auto eol=lf`.
257
- 4. Kör: `git rm --cached -r .`
258
- 5. Kör: `git reset --hard`.
259
- 6. Pusha upp filen.
260
-
261
- <https://stackoverflow.com/questions/9976986/force-lf-eol-in-git-repo-and-working-copy/34810209#34810209>
5
+ [Documentation](https://docs.soleil.se/packages/eslint-config)
package/index.js CHANGED
@@ -1,11 +1,46 @@
1
1
  import globals from 'globals';
2
2
  import importPlugin from 'eslint-plugin-import';
3
- import eslintPluginSvelte from 'eslint-plugin-svelte';
4
- import eslintConfigPrettier from 'eslint-config-prettier';
5
3
 
6
4
  import jsRules from './rules/js/index.js';
7
5
  import svelteRules from './rules/svelte/index.js';
8
6
 
7
+ function loadSvelteConfig() {
8
+ // eslint-disable-next-line import/no-extraneous-dependencies
9
+ return import('svelte').then(async () => {
10
+ const { default: eslintPluginSvelte } = await import('eslint-plugin-svelte');
11
+ const { default: eslintConfigPrettier } = await import('eslint-config-prettier');
12
+ return [
13
+ ...eslintPluginSvelte.configs['flat/recommended'],
14
+ ...eslintPluginSvelte.configs['flat/prettier'],
15
+ {
16
+ name: 'soleil/svelte',
17
+ files: ['**/*.svelte'],
18
+ rules: {
19
+ ...svelteRules,
20
+ ...eslintConfigPrettier.rules,
21
+ },
22
+ }, {
23
+ name: 'soleil/svelte.js',
24
+ files: ['**/*.svelte.js', '**/*.svelte.ts'],
25
+ languageOptions: {
26
+ ecmaVersion: 'latest',
27
+ sourceType: 'module',
28
+ globals: {
29
+ $state: 'readonly',
30
+ $derived: 'readonly',
31
+ $effect: 'readonly',
32
+ $inspect: 'readonly',
33
+ },
34
+ },
35
+ rules: {
36
+ // Do not enforce const because of reactivity for runes in Svelte 5.
37
+ 'prefer-const': 0,
38
+ },
39
+ },
40
+ ];
41
+ }).catch(() => []);
42
+ }
43
+
9
44
  export default [
10
45
  {
11
46
  name: 'soleil/base',
@@ -19,7 +54,7 @@ export default [
19
54
  ...globals.browser,
20
55
  },
21
56
  },
22
- ignores: ['dist', 'node_modules'],
57
+ ignores: ['dist', 'node_modules', 'prettier.config.js'],
23
58
  plugins: { import: importPlugin },
24
59
  rules: jsRules,
25
60
  settings: {
@@ -31,31 +66,5 @@ export default [
31
66
  },
32
67
  },
33
68
  },
34
- ...eslintPluginSvelte.configs['flat/recommended'],
35
- ...eslintPluginSvelte.configs['flat/prettier'],
36
- {
37
- name: 'soleil/svelte',
38
- files: ['**/*.svelte'],
39
- rules: {
40
- ...svelteRules,
41
- ...eslintConfigPrettier.rules,
42
- },
43
- }, {
44
- name: 'soleil/svelte.js',
45
- files: ['**/*.svelte.js', '**/*.svelte.ts'],
46
- languageOptions: {
47
- ecmaVersion: 'latest',
48
- sourceType: 'module',
49
- globals: {
50
- $state: 'readonly',
51
- $derived: 'readonly',
52
- $effect: 'readonly',
53
- $inspect: 'readonly',
54
- },
55
- },
56
- rules: {
57
- // Do not enforce const because of reactivity for runes in Svelte 5.
58
- 'prefer-const': 0,
59
- },
60
- },
69
+ ...await loadSvelteConfig(),
61
70
  ];
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@soleil-se/eslint-config",
3
- "version": "6.0.0",
4
- "description": "ESLint konfiguration för Sitevision utveckling",
3
+ "version": "6.0.2",
4
+ "description": "ESLint configuration for Sitevision apps and projects.",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslint-config",
8
+ "sitevision"
9
+ ],
5
10
  "author": "Soleil AB",
6
11
  "license": "UNLICENSED",
7
12
  "private": false,
8
- "homepage": "https://docs.soleil.se/packages/@soleil-se/eslint-config/",
13
+ "homepage": "https://docs.soleil.se/packages/eslint-config",
9
14
  "type": "module",
10
15
  "bin": "./bin/index.js",
11
16
  "main": "./index.js",
12
17
  "exports": {
13
18
  ".": "./index.js",
14
- "./prettier": "./prettier-config.js",
15
- "./script-module": "./script-module-config.js",
16
- "./node": "./node-config.js"
19
+ "./prettier": "./prettier.js",
20
+ "./script-module": "./script-module.js",
21
+ "./node": "./node-config.js",
22
+ "./rules":"./rules/**/*.js"
17
23
  },
18
24
  "dependencies": {
19
25
  "eslint-config-prettier": "^10.0.1",
@@ -28,4 +34,4 @@
28
34
  "peerDependencies": {
29
35
  "eslint": ">= 9"
30
36
  }
31
- }
37
+ }
package/setup.js CHANGED
@@ -11,10 +11,10 @@ const dependencies = {
11
11
  eslint: '^9.18.0',
12
12
  };
13
13
 
14
- const eslintConfigFileContent = `import sitevision from '${name}';
14
+ const eslintConfigFileContent = `import config from '${name}';
15
15
 
16
16
  export default [
17
- ...sitevision,
17
+ ...config,
18
18
  ];
19
19
  `;
20
20
 
File without changes
File without changes