Skip to content

Commit 1c1ddd5

Browse files
authored
chore: use @sveltejs/eslint-config (#9977)
1 parent ac8123e commit 1c1ddd5

File tree

64 files changed

+556
-302
lines changed

Some content is hidden

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

64 files changed

+556
-302
lines changed

.eslintrc.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
{
2+
"root": true,
3+
"extends": "@sveltejs",
24
"env": {
35
"es2022": true
46
},
5-
"parserOptions": {
6-
"ecmaVersion": "latest",
7-
"sourceType": "module"
8-
},
9-
"plugins": ["unicorn"],
10-
"root": true,
117
"ignorePatterns": ["packages/create-svelte/shared/"],
128
"rules": {
13-
"unicorn/prefer-node-protocol": "error"
9+
"no-undef": "off"
1410
}
1511
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
"@rollup/plugin-commonjs": "^25.0.0",
3232
"@rollup/plugin-json": "^6.0.0",
3333
"@rollup/plugin-node-resolve": "^15.0.1",
34+
"@sveltejs/eslint-config": "^6.0.2",
3435
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
3536
"@typescript-eslint/eslint-plugin": "^5.53.0",
36-
"eslint": "^8.33.0",
37+
"eslint": "^8.40.0",
38+
"eslint-config-prettier": "^8.8.0",
39+
"eslint-plugin-import": "^2.27.5",
40+
"eslint-plugin-svelte": "^2.28.0",
3741
"eslint-plugin-unicorn": "^47.0.0",
3842
"playwright": "1.30.0",
3943
"prettier": "^2.8.0",

packages/adapter-cloudflare/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ export default function (options = {}) {
7171
*/
7272
function get_routes_json(builder, assets, { include = ['/*'], exclude = ['<all>'] }) {
7373
if (!Array.isArray(include) || !Array.isArray(exclude)) {
74-
throw new Error(`routes.include and routes.exclude must be arrays`);
74+
throw new Error('routes.include and routes.exclude must be arrays');
7575
}
7676

7777
if (include.length === 0) {
78-
throw new Error(`routes.include must contain at least one route`);
78+
throw new Error('routes.include must contain at least one route');
7979
}
8080

8181
if (include.length > 100) {
82-
throw new Error(`routes.include must contain 100 or fewer routes`);
82+
throw new Error('routes.include must contain 100 or fewer routes');
8383
}
8484

8585
exclude = exclude

packages/adapter-node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default function (opts = {}) {
7171
dir: `${out}/server`,
7272
format: 'esm',
7373
sourcemap: true,
74-
chunkFileNames: `chunks/[name]-[hash].js`
74+
chunkFileNames: 'chunks/[name]-[hash].js'
7575
});
7676

7777
builder.copy(files, out, {

packages/adapter-vercel/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const plugin = function (defaults = {}) {
224224

225225
if (ignored_isr.size) {
226226
builder.log.warn(
227-
`\nWarning: The following routes have an ISR config which is ignored because the route is prerendered:`
227+
'\nWarning: The following routes have an ISR config which is ignored because the route is prerendered:'
228228
);
229229

230230
for (const ignored of ignored_isr) {
@@ -586,7 +586,7 @@ function validate_vercel_json(builder, vercel_config) {
586586

587587
if (unmatched_paths.length) {
588588
builder.log.warn(
589-
`\nWarning: vercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your \`handle\` hook):`
589+
'\nWarning: vercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your `handle` hook):'
590590
);
591591

592592
for (const path of unmatched_paths) {

packages/create-svelte/bin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ await create(cwd, {
114114
vitest: options.features.includes('vitest')
115115
});
116116

117-
p.outro(`Your project is ready!`);
117+
p.outro('Your project is ready!');
118118

119119
if (options.types === 'typescript') {
120120
console.log(bold('✔ Typescript'));

packages/create-svelte/scripts/build-templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function strip_jsdoc(content) {
3939
return '';
4040
}
4141

42-
return `/**${description.replace(/\*\ $/, '')}*/${whitespace}`;
42+
return `/**${description.replace(/\* $/, '')}*/${whitespace}`;
4343
}
4444
);
4545
}

packages/create-svelte/test/check.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ for (const pkg_path of glob(resolve_path('../../../packages/*/package.json'))) {
3232

3333
try {
3434
const kit_dir = resolve_path('../../../packages/kit');
35-
const ls_vite_result = execSync(`pnpm ls --json vite`, { cwd: kit_dir });
35+
const ls_vite_result = execSync('pnpm ls --json vite', { cwd: kit_dir });
3636
const vite_version = JSON.parse(ls_vite_result.toString())[0].devDependencies.vite.version;
3737
overrides.vite = vite_version;
3838
} catch (e) {
@@ -61,7 +61,7 @@ fs.writeFileSync(path.join(test_workspace_dir, 'pnpm-workspace.yaml'), 'packages
6161
const exec_async = promisify(exec);
6262

6363
beforeAll(async () => {
64-
await exec_async(`pnpm install --no-frozen-lockfile`, {
64+
await exec_async('pnpm install --no-frozen-lockfile', {
6565
cwd: test_workspace_dir
6666
});
6767
}, 60000);

packages/kit/src/core/config/options.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const options = object(
210210
(/** @type {any} */ { message }) => {
211211
throw new Error(
212212
message +
213-
`\nTo suppress or handle this error, implement \`handleHttpError\` in https://kit.svelte.dev/docs/configuration#prerender`
213+
'\nTo suppress or handle this error, implement `handleHttpError` in https://kit.svelte.dev/docs/configuration#prerender'
214214
);
215215
},
216216
(input, keypath) => {
@@ -224,7 +224,7 @@ const options = object(
224224
(/** @type {any} */ { message }) => {
225225
throw new Error(
226226
message +
227-
`\nTo suppress or handle this error, implement \`handleMissingId\` in https://kit.svelte.dev/docs/configuration#prerender`
227+
'\nTo suppress or handle this error, implement `handleMissingId` in https://kit.svelte.dev/docs/configuration#prerender'
228228
);
229229
},
230230
(input, keypath) => {
@@ -238,7 +238,7 @@ const options = object(
238238
(/** @type {any} */ { message }) => {
239239
throw new Error(
240240
message +
241-
`\nTo suppress or handle this error, implement \`handleEntryGeneratorMismatch\` in https://kit.svelte.dev/docs/configuration#prerender`
241+
'\nTo suppress or handle this error, implement `handleEntryGeneratorMismatch` in https://kit.svelte.dev/docs/configuration#prerender'
242242
);
243243
},
244244
(input, keypath) => {

packages/kit/src/core/env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function create_dynamic_types(id, env, prefix) {
7575

7676
if (id === 'private') {
7777
properties.push(`${prefixed}: undefined;`);
78-
properties.push(`[key: string]: string | undefined;`);
78+
properties.push('[key: string]: string | undefined;');
7979
} else {
8080
properties.push(`${prefixed}: string | undefined;`);
8181
}

packages/kit/src/core/generate_manifest/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function generate_manifest({ build_data, relative_path, routes }) {
5555

5656
/** @param {Array<number | undefined>} indexes */
5757
function get_nodes(indexes) {
58-
let string = indexes.map((n) => reindexed.get(n) ?? '').join(',');
58+
const string = indexes.map((n) => reindexed.get(n) ?? '').join(',');
5959

6060
// since JavaScript ignores trailing commas, we need to insert a dummy
6161
// comma so that the array has the correct length if the last item

packages/kit/src/core/sync/create_manifest_data/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function analyze(project_relative, file, component_extensions, module_extensions
456456
);
457457
}
458458

459-
const kind = !!(match[1] || match[4] || match[7]) ? 'server' : 'universal';
459+
const kind = match[1] || match[4] || match[7] ? 'server' : 'universal';
460460

461461
return {
462462
kind,
@@ -513,7 +513,7 @@ function prevent_conflicts(routes) {
513513
const normalized = normalize_route_id(route.id);
514514

515515
// find all permutations created by optional parameters
516-
const split = normalized.split(/<\?(.+?)\>/g);
516+
const split = normalized.split(/<\?(.+?)>/g);
517517

518518
let permutations = [/** @type {string} */ (split[0])];
519519

packages/kit/src/core/sync/write_client_manifest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
2121
if (node.universal) {
2222
declarations.push(
2323
`import * as universal from ${s(relative_path(`${output}/nodes`, node.universal))};`,
24-
`export { universal };`
24+
'export { universal };'
2525
);
2626
}
2727

packages/kit/src/core/sync/write_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export { set_assets, set_building, set_private_env, set_public_env };
7575
* @param {string} output
7676
*/
7777
export function write_server(config, output) {
78-
// TODO the casting shouldn't be necessary — investigate
78+
// TODO the casting shouldn't be necessary — investigate
7979
const hooks_file = /** @type {string} */ (resolve_entry(config.kit.files.hooks.server));
8080

8181
/** @param {string} file */

packages/kit/src/core/sync/write_types/index.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function write_all_types(config, manifest_data) {
5252
// it could be invoked by another process in the meantime.
5353
const meta_data_file = `${types_dir}/route_meta_data.json`;
5454
const has_meta_data = fs.existsSync(meta_data_file);
55-
let meta_data = has_meta_data
55+
const meta_data = has_meta_data
5656
? /** @type {Record<string, string[]>} */ (JSON.parse(fs.readFileSync(meta_data_file, 'utf-8')))
5757
: {};
5858
const routes_map = create_routes_map(manifest_data);
@@ -177,7 +177,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
177177
const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
178178

179179
// now generate new types
180-
const imports = [`import type * as Kit from '@sveltejs/kit';`];
180+
const imports = ["import type * as Kit from '@sveltejs/kit';"];
181181

182182
/** @type {string[]} */
183183
const declarations = [];
@@ -196,7 +196,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
196196

197197
if (route.params.length > 0) {
198198
exports.push(
199-
`export type EntryGenerator = () => Promise<Array<RouteParams>> | Array<RouteParams>;`
199+
'export type EntryGenerator = () => Promise<Array<RouteParams>> | Array<RouteParams>;'
200200
);
201201
}
202202

@@ -206,24 +206,24 @@ function update_types(config, routes, route, to_delete = new Set()) {
206206
if (route.layout || route.leaf) {
207207
declarations.push(
208208
// If T extends the empty object, void is also allowed as a return type
209-
`type MaybeWithVoid<T> = {} extends T ? T | void : T;`,
209+
'type MaybeWithVoid<T> = {} extends T ? T | void : T;',
210210

211211
// Returns the key of the object whose values are required.
212-
`export type RequiredKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T];`,
212+
'export type RequiredKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T];',
213213

214214
// Helper type to get the correct output type for load functions. It should be passed the parent type to check what types from App.PageData are still required.
215215
// If none, void is also allowed as a return type.
216-
`type OutputDataShape<T> = MaybeWithVoid<Omit<App.PageData, RequiredKeys<T>> & Partial<Pick<App.PageData, keyof T & keyof App.PageData>> & Record<string, any>>`,
216+
'type OutputDataShape<T> = MaybeWithVoid<Omit<App.PageData, RequiredKeys<T>> & Partial<Pick<App.PageData, keyof T & keyof App.PageData>> & Record<string, any>>',
217217

218218
// null & {} == null, we need to prevent that in some situations
219-
`type EnsureDefined<T> = T extends null | undefined ? {} : T;`,
219+
'type EnsureDefined<T> = T extends null | undefined ? {} : T;',
220220

221221
// Takes a union type and returns a union type where each type also has all properties
222222
// of all possible types (typed as undefined), making accessing them more ergonomic
223-
`type OptionalUnion<U extends Record<string, any>, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;`,
223+
'type OptionalUnion<U extends Record<string, any>, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;',
224224

225225
// Re-export `Snapshot` from @sveltejs/kit — in future we could use this to infer <T> from the return type of `snapshot.capture`
226-
`export type Snapshot<T = any> = Kit.Snapshot<T>;`
226+
'export type Snapshot<T = any> = Kit.Snapshot<T>;'
227227
);
228228
}
229229

@@ -255,10 +255,10 @@ function update_types(config, routes, route, to_delete = new Set()) {
255255

256256
if (route.leaf.server) {
257257
exports.push(
258-
`export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>`
258+
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>'
259259
);
260260
exports.push(
261-
`export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>`
261+
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>'
262262
);
263263
}
264264
}
@@ -326,11 +326,11 @@ function update_types(config, routes, route, to_delete = new Set()) {
326326
}
327327

328328
if (route.endpoint) {
329-
exports.push(`export type RequestHandler = Kit.RequestHandler<RouteParams, RouteId>;`);
329+
exports.push('export type RequestHandler = Kit.RequestHandler<RouteParams, RouteId>;');
330330
}
331331

332332
if (route.leaf?.server || route.layout?.server || route.endpoint) {
333-
exports.push(`export type RequestEvent = Kit.RequestEvent<RouteParams, RouteId>;`);
333+
exports.push('export type RequestEvent = Kit.RequestEvent<RouteParams, RouteId>;');
334334
}
335335

336336
const output = [imports.join('\n'), declarations.join('\n'), exports.join('\n')]
@@ -386,7 +386,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
386386
// +page.js load present -> server can return all-optional data
387387
const output_data_shape =
388388
node.universal || (!is_page && all_pages_have_load)
389-
? `Partial<App.PageData> & Record<string, any> | void`
389+
? 'Partial<App.PageData> & Record<string, any> | void'
390390
: `OutputDataShape<${parent_type}>`;
391391
exports.push(
392392
`export type ${prefix}ServerLoad<OutputData extends ${output_data_shape} = ${output_data_shape}> = Kit.ServerLoad<${params}, ${parent_type}, OutputData, ${route_id}>;`
@@ -404,15 +404,15 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
404404
: path_to_original(outdir, node.server);
405405

406406
exports.push(
407-
`type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;`,
408-
`type ActionsSuccess<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: ExcludeActionFailure<Awaited<ReturnType<T[Key]>>>; }[keyof T];`,
409-
`type ExtractActionFailure<T> = T extends Kit.ActionFailure<infer X> ? X extends void ? never : X : never;`,
410-
`type ActionsFailure<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: Exclude<ExtractActionFailure<Awaited<ReturnType<T[Key]>>>, void>; }[keyof T];`,
407+
'type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;',
408+
'type ActionsSuccess<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: ExcludeActionFailure<Awaited<ReturnType<T[Key]>>>; }[keyof T];',
409+
'type ExtractActionFailure<T> = T extends Kit.ActionFailure<infer X> ? X extends void ? never : X : never;',
410+
'type ActionsFailure<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: Exclude<ExtractActionFailure<Awaited<ReturnType<T[Key]>>>, void>; }[keyof T];',
411411
`type ActionsExport = typeof import('${from}').actions`,
412-
`export type SubmitFunction = Kit.SubmitFunction<Expand<ActionsSuccess<ActionsExport>>, Expand<ActionsFailure<ActionsExport>>>`
412+
'export type SubmitFunction = Kit.SubmitFunction<Expand<ActionsSuccess<ActionsExport>>, Expand<ActionsFailure<ActionsExport>>>'
413413
);
414414

415-
type = `Expand<Kit.AwaitedActions<ActionsExport>> | null`;
415+
type = 'Expand<Kit.AwaitedActions<ActionsExport>> | null';
416416
}
417417
exports.push(`export type ActionData = ${type};`);
418418
}
@@ -440,7 +440,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
440440

441441
const output_data_shape =
442442
!is_page && all_pages_have_load
443-
? `Partial<App.PageData> & Record<string, any> | void`
443+
? 'Partial<App.PageData> & Record<string, any> | void'
444444
: `OutputDataShape<${parent_type}>`;
445445
exports.push(
446446
`export type ${prefix}Load<OutputData extends ${output_data_shape} = ${output_data_shape}> = Kit.Load<${params}, ${prefix}ServerData, ${parent_type}, OutputData, ${route_id}>;`
@@ -688,7 +688,7 @@ export function tweak_types(content, is_server) {
688688
// remove type from `export const load: Load ...`
689689
if (declaration.type) {
690690
let a = declaration.type.pos;
691-
let b = declaration.type.end;
691+
const b = declaration.type.end;
692692
while (/\s/.test(content[a])) a += 1;
693693

694694
const type = content.slice(a, b);
@@ -760,7 +760,7 @@ export function tweak_types(content, is_server) {
760760
// remove type from `export const actions: Actions ...`
761761
if (declaration.type) {
762762
let a = declaration.type.pos;
763-
let b = declaration.type.end;
763+
const b = declaration.type.end;
764764
while (/\s/.test(content[a])) a += 1;
765765

766766
const type = content.slice(a, b);
@@ -788,7 +788,7 @@ export function tweak_types(content, is_server) {
788788
if (arg && !arg.type) {
789789
code.appendLeft(
790790
arg.name.end,
791-
`: import('./$types').RequestEvent` + (add_parens ? ')' : '')
791+
": import('./$types').RequestEvent" + (add_parens ? ')' : '')
792792
);
793793
}
794794
}

0 commit comments

Comments
 (0)