Skip to content

Commit f4d5113

Browse files
authored
chore: match svelte and kit eslint config (#720)
1 parent 462ba22 commit f4d5113

File tree

43 files changed

+252
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+252
-187
lines changed

.eslintrc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
Atomics: 'readonly',
1212
SharedArrayBuffer: 'readonly'
1313
},
14-
plugins: ['@typescript-eslint', 'html', 'markdown'],
14+
plugins: ['@typescript-eslint', 'html', 'markdown', 'unicorn'],
1515
parser: '@typescript-eslint/parser',
1616
parserOptions: {
1717
sourceType: 'module',
@@ -56,7 +56,9 @@ module.exports = {
5656
],
5757
'n/no-unpublished-import': 'off',
5858
'n/no-unpublished-require': 'off',
59-
'no-process-exit': 'off'
59+
'no-process-exit': 'off',
60+
quotes: ['error', 'single', { avoidEscape: true }],
61+
'unicorn/prefer-node-protocol': 'error'
6062
},
6163
overrides: [
6264
{

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"eslint-plugin-n": "^16.0.1",
3535
"eslint-plugin-prettier": "^5.0.0",
3636
"eslint-plugin-svelte": "^2.32.4",
37+
"eslint-plugin-unicorn": "^48.0.1",
3738
"execa": "^7.2.0",
3839
"fs-extra": "^11.1.1",
3940
"husky": "^8.0.3",

packages/e2e-tests/_test_dependencies/vite-plugins/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const path = require('path');
2-
const fs = require('fs');
1+
const path = require('node:path');
2+
const fs = require('node:fs');
33
/**
44
* Ensure transform flow is not interrupted
55
* @returns {import('vite').Plugin[]}
@@ -68,7 +68,7 @@ function writeResolvedConfig() {
6868
fs.mkdirSync(dir);
6969
}
7070
const filename = path.join(dir, `vite.config.${cmd}${config.build.ssr ? '.ssr' : ''}.json`);
71-
fs.writeFileSync(filename, JSON.stringify(serializableConfig, replacer, `\t`), 'utf-8');
71+
fs.writeFileSync(filename, JSON.stringify(serializableConfig, replacer, '\t'), 'utf-8');
7272
}
7373
};
7474
}

packages/e2e-tests/autoprefixer-browerslist/svelte.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sveltePreprocess from 'svelte-preprocess';
2-
import path from 'path';
3-
import { fileURLToPath } from 'url';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
44

55
export default {
66
preprocess: sveltePreprocess({

packages/e2e-tests/configfile-custom/__tests__/configfile-custom.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (!isBuild) {
1313
// TODO split into different tests
1414
it('should load custom cjs config and work', async () => {
1515
await editViteConfig((c) =>
16-
c.replace(/svelte\([^)]*\)/, `svelte({configFile:'svelte.config.custom.cjs'})`)
16+
c.replace(/svelte\([^)]*\)/, "svelte({configFile:'svelte.config.custom.cjs'})")
1717
);
1818
expect(e2eServer.logs.server.out).toContain('custom svelte config loaded cjs');
1919
expect(await page.textContent('h1')).toMatch('Hello world!');
@@ -23,7 +23,7 @@ if (!isBuild) {
2323

2424
it('should not read default config when explicitly disabled', async () => {
2525
const currentLogPos = e2eServer.logs.server.out.length;
26-
await editViteConfig((c) => c.replace(/svelte\([^)]*\)/, `svelte({configFile: false})`));
26+
await editViteConfig((c) => c.replace(/svelte\([^)]*\)/, 'svelte({configFile: false})'));
2727
const logsAfterChange = e2eServer.logs.server.out.slice(currentLogPos);
2828
expect(logsAfterChange).not.toContain('default svelte config loaded');
2929
expect(await page.textContent('h1')).toMatch('Hello world!');

packages/e2e-tests/configfile-esm/__tests__/configfile-esm.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ it('should load default config and work', async () => {
99

1010
it('should load custom cjs config and work', async () => {
1111
await editViteConfig((c) =>
12-
c.replace('svelte()', `svelte({configFile:'svelte.config.custom.cjs'})`)
12+
c.replace('svelte()', "svelte({configFile:'svelte.config.custom.cjs'})")
1313
);
1414
expect(await page.textContent('h1')).toMatch('Hello world!');
1515
expect(await page.textContent('#test-child')).toBe('test-child');

packages/e2e-tests/css-dev-sourcemap/__tests__/css-dev-sourcemap.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('should apply css compiled from scss', async () => {
1717
if (!isBuild) {
1818
test('should generate sourcemap', async () => {
1919
const style = await getText('style[data-vite-dev-id*="App.svelte"]');
20-
const lines = style.split(`\n`).map((l) => l.trim());
20+
const lines = style.split('\n').map((l) => l.trim());
2121
const css = lines[0];
2222
const mapComment = lines[1];
2323
expect(css).toBe(

packages/e2e-tests/e2e-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// script to start package.json dev/build/preview scripts with execa for e2e tests
22
import { execa } from 'execa';
33
import treeKill from 'tree-kill';
4-
import fs from 'fs';
5-
import path from 'path';
4+
import fs from 'node:fs';
5+
import path from 'node:path';
66
const isWin = process.platform === 'win32';
77

88
async function startedOnPort(serverProcess, port, timeout) {

packages/e2e-tests/hmr/__tests__/hmr.spec.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -62,53 +62,53 @@ if (!isBuild) {
6262

6363
test('should have expected initial state', async () => {
6464
// initial state, both counters 0, both labels red
65-
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
66-
expect(await getText(`#hmr-test-2 .counter`)).toBe('0');
67-
expect(await getText(`#hmr-test-1 .label`)).toBe('hmr-test');
68-
expect(await getText(`#hmr-test-2 .label`)).toBe('hmr-test');
69-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
70-
expect(await getColor(`#hmr-test-2 .label`)).toBe('red');
65+
expect(await getText('#hmr-test-1 .counter')).toBe('0');
66+
expect(await getText('#hmr-test-2 .counter')).toBe('0');
67+
expect(await getText('#hmr-test-1 .label')).toBe('hmr-test');
68+
expect(await getText('#hmr-test-2 .label')).toBe('hmr-test');
69+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
70+
expect(await getColor('#hmr-test-2 .label')).toBe('red');
7171
});
7272

7373
test('should have working increment button', async () => {
7474
// increment counter of one instance to have local state to verify after hmr updates
75-
await (await getEl(`#hmr-test-1 .increment`)).click();
75+
await (await getEl('#hmr-test-1 .increment')).click();
7676
await sleep(50);
7777

7878
// counter1 = 1, counter2 = 0
79-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
80-
expect(await getText(`#hmr-test-2 .counter`)).toBe('0');
79+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
80+
expect(await getText('#hmr-test-2 .counter')).toBe('0');
8181
});
8282

8383
test('should apply css changes in HmrTest.svelte', async () => {
8484
// update style, change label color from red to green
8585
await updateHmrTest((content) => content.replace('color: red', 'color: green'));
8686

8787
// counter state should remain
88-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
89-
expect(await getText(`#hmr-test-2 .counter`)).toBe('0');
88+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
89+
expect(await getText('#hmr-test-2 .counter')).toBe('0');
9090

9191
// color should have changed
92-
expect(await getColor(`#hmr-test-1 .label`)).toBe('green');
93-
expect(await getColor(`#hmr-test-2 .label`)).toBe('green');
92+
expect(await getColor('#hmr-test-1 .label')).toBe('green');
93+
expect(await getColor('#hmr-test-2 .label')).toBe('green');
9494
});
9595

9696
test('should apply js change in HmrTest.svelte ', async () => {
9797
// update script, change label value
9898
await updateHmrTest((content) =>
9999
content.replace("const label = 'hmr-test'", "const label = 'hmr-test-updated'")
100100
);
101-
expect(await getText(`#hmr-test-1 .label`)).toBe('hmr-test-updated');
102-
expect(await getText(`#hmr-test-2 .label`)).toBe('hmr-test-updated');
101+
expect(await getText('#hmr-test-1 .label')).toBe('hmr-test-updated');
102+
expect(await getText('#hmr-test-2 .label')).toBe('hmr-test-updated');
103103
});
104104

105105
test('should keep state of external store intact on change of HmrTest.svelte', async () => {
106106
// counter state should remain
107107
await updateHmrTest((content) =>
108108
content.replace('<!-- HMR-TEMPLATE-INJECT -->', '<span/>\n<!-- HMR-TEMPLATE-INJECT -->')
109109
);
110-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
111-
expect(await getText(`#hmr-test-2 .counter`)).toBe('0');
110+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
111+
expect(await getText('#hmr-test-2 .counter')).toBe('0');
112112
});
113113

114114
test('should preserve state of external store used by HmrTest.svelte when editing App.svelte', async () => {
@@ -120,53 +120,53 @@ if (!isBuild) {
120120
)
121121
);
122122
// counter state is preserved
123-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
124-
expect(await getText(`#hmr-test-2 .counter`)).toBe('0');
123+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
124+
expect(await getText('#hmr-test-2 .counter')).toBe('0');
125125
// a third instance has been added
126-
expect(await getText(`#hmr-test-3 .counter`)).toBe('0');
126+
expect(await getText('#hmr-test-3 .counter')).toBe('0');
127127
});
128128

129129
test('should preserve state of store when editing hmr-stores.js', async () => {
130130
// change state
131-
await (await getEl(`#hmr-test-2 .increment`)).click();
131+
await (await getEl('#hmr-test-2 .increment')).click();
132132
await sleep(50);
133133
// update store
134134
await updateStore((content) => `${content}\n/*trigger change*/\n`);
135135
// counter state is preserved
136-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
137-
expect(await getText(`#hmr-test-2 .counter`)).toBe('1');
136+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
137+
expect(await getText('#hmr-test-2 .counter')).toBe('1');
138138
// a third instance has been added
139-
expect(await getText(`#hmr-test-3 .counter`)).toBe('0');
139+
expect(await getText('#hmr-test-3 .counter')).toBe('0');
140140
});
141141

142142
test('should work when editing script context="module"', async () => {
143-
expect(await getText(`#hmr-with-context`)).toContain('x=0 y=1 slot=1');
144-
expect(await getText(`#hmr-without-context`)).toContain('x=0 y=1 slot=');
143+
expect(await getText('#hmr-with-context')).toContain('x=0 y=1 slot=1');
144+
expect(await getText('#hmr-without-context')).toContain('x=0 y=1 slot=');
145145
expect(hmrCount('UsingNamed.svelte'), 'updates for UsingNamed.svelte').toBe(0);
146146
expect(hmrCount('UsingDefault.svelte'), 'updates for UsingDefault.svelte').toBe(0);
147147
await updateModuleContext((content) => content.replace('y = 1', 'y = 2'));
148-
expect(await getText(`#hmr-with-context`)).toContain('x=0 y=2 slot=2');
149-
expect(await getText(`#hmr-without-context`)).toContain('x=0 y=2 slot=');
148+
expect(await getText('#hmr-with-context')).toContain('x=0 y=2 slot=2');
149+
expect(await getText('#hmr-without-context')).toContain('x=0 y=2 slot=');
150150
expect(hmrCount('UsingNamed.svelte'), 'updates for UsingNamed.svelte').toBe(1);
151151
expect(hmrCount('UsingDefault.svelte'), 'updates for UsingDefault.svelte').toBe(0);
152152
});
153153

154154
test('should work with emitCss: false in vite config', async () => {
155155
await editViteConfig((c) => c.replace('svelte()', 'svelte({emitCss:false})'));
156-
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
157-
expect(await getColor(`#hmr-test-1 .label`)).toBe('green');
158-
await (await getEl(`#hmr-test-1 .increment`)).click();
156+
expect(await getText('#hmr-test-1 .counter')).toBe('0');
157+
expect(await getColor('#hmr-test-1 .label')).toBe('green');
158+
await (await getEl('#hmr-test-1 .increment')).click();
159159
await sleep(50);
160-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
160+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
161161
await updateHmrTest((content) => content.replace('color: green', 'color: red'));
162-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
163-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
162+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
163+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
164164
});
165165

166166
test('should work with emitCss: false in svelte config', async () => {
167-
addFile('svelte.config.cjs', `module.exports={vitePlugin:{emitCss:false}}`);
167+
addFile('svelte.config.cjs', 'module.exports={vitePlugin:{emitCss:false}}');
168168
await waitForServerRestartAndPageReload();
169-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
169+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
170170
removeFile('svelte.config.cjs');
171171
});
172172

@@ -188,14 +188,14 @@ if (!isBuild) {
188188
);
189189
await waitForServerRestartAndPageReload();
190190
expect(await getText('#preprocess-inject')).toBe('Injected');
191-
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
192-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
193-
await (await getEl(`#hmr-test-1 .increment`)).click();
191+
expect(await getText('#hmr-test-1 .counter')).toBe('0');
192+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
193+
await (await getEl('#hmr-test-1 .increment')).click();
194194
await sleep(50);
195-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
195+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
196196
await updateHmrTest((content) => content.replace('color: red', 'color: green'));
197-
expect(await getColor(`#hmr-test-1 .label`)).toBe('green');
198-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
197+
expect(await getColor('#hmr-test-1 .label')).toBe('green');
198+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
199199
await editFile('svelte.config.cjs', (content) =>
200200
content
201201
.replace('preprocess-inject', 'preprocess-inject-2')
@@ -204,20 +204,20 @@ if (!isBuild) {
204204
await waitForServerRestartAndPageReload();
205205
expect(await getText('#preprocess-inject-2')).toBe('Injected 2');
206206
expect(await getEl('#preprocess-inject')).toBe(null);
207-
expect(await getColor(`#hmr-test-1 .label`)).toBe('green');
208-
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
209-
await (await getEl(`#hmr-test-1 .increment`)).click();
207+
expect(await getColor('#hmr-test-1 .label')).toBe('green');
208+
expect(await getText('#hmr-test-1 .counter')).toBe('0');
209+
await (await getEl('#hmr-test-1 .increment')).click();
210210
await sleep(50);
211-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
211+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
212212
await updateHmrTest((content) => content.replace('color: green', 'color: red'));
213-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
214-
expect(await getText(`#hmr-test-1 .counter`)).toBe('1');
213+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
214+
expect(await getText('#hmr-test-1 .counter')).toBe('1');
215215
await removeFile('svelte.config.cjs');
216216
await waitForServerRestartAndPageReload();
217217
expect(await getEl('#preprocess-inject-2')).toBe(null);
218218
expect(await getEl('#preprocess-inject')).toBe(null);
219-
expect(await getColor(`#hmr-test-1 .label`)).toBe('red');
220-
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
219+
expect(await getColor('#hmr-test-1 .label')).toBe('red');
220+
expect(await getText('#hmr-test-1 .counter')).toBe('0');
221221
});
222222
});
223223
}

packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('raw', () => {
3939
expect(result).toMatchFileSnapshot(snapshotFilename('preprocessed'));
4040
});
4141

42-
test(`Dummy.svelte?raw&svelte&type=script`, async () => {
42+
test('Dummy.svelte?raw&svelte&type=script', async () => {
4343
const result = await getText('#script');
4444
expect(normalizeSnapshot(result)).toMatchFileSnapshot(snapshotFilename('script'));
4545
});

0 commit comments

Comments
 (0)