Skip to content

Commit 0611bef

Browse files
committed
ignore rules rather than adding catch blocks. add async to functions returning promises
1 parent 73eff42 commit 0611bef

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default [
1717
'@typescript-eslint/await-thenable': 'error',
1818
'@typescript-eslint/no-floating-promises': 'error',
1919
'@typescript-eslint/no-misused-promises': 'error',
20+
'@typescript-eslint/prefer-promise-reject-errors': 'error',
21+
'@typescript-eslint/promise-function-async': 'error',
2022
'@typescript-eslint/require-await': 'error',
2123
'no-console': 'error',
2224
'lube/svelte-naming-convention': ['error', { fixSameNames: true }],

packages/svelte/src/compiler/preprocess/replace_in_code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function slice_source(code_slice, offset, { file_basename, filename, get_
2020
* @param {(...match: any[]) => Promise<MappedCode>} get_replacement
2121
* @param {string} source
2222
*/
23-
function calculate_replacements(re, get_replacement, source) {
23+
async function calculate_replacements(re, get_replacement, source) {
2424
/**
2525
* @type {Array<Promise<import('./private.js').Replacement>>}
2626
*/

packages/svelte/src/internal/client/dom/elements/custom-element.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,14 @@ if (typeof HTMLElement === 'function') {
193193
disconnectedCallback() {
194194
this.$$cn = false;
195195
// In a microtask, because this could be a move within the DOM
196-
Promise.resolve()
197-
.then(() => {
198-
if (!this.$$cn && this.$$c) {
199-
this.$$c.$destroy();
200-
destroy_effect(this.$$me);
201-
this.$$c = undefined;
202-
}
203-
})
204-
.catch((err) => {
205-
// eslint-disable-next-line no-console
206-
console.error(err);
207-
});
196+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
197+
Promise.resolve().then(() => {
198+
if (!this.$$cn && this.$$c) {
199+
this.$$c.$destroy();
200+
destroy_effect(this.$$me);
201+
this.$$c = undefined;
202+
}
203+
});
208204
}
209205

210206
/**

packages/svelte/src/internal/client/dom/elements/misc.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ export function add_form_reset_listener() {
4242
(evt) => {
4343
// Needs to happen one tick later or else the dom properties of the form
4444
// elements have not updated to their reset values yet
45-
Promise.resolve()
46-
.then(() => {
47-
if (!evt.defaultPrevented) {
48-
for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) {
49-
// @ts-expect-error
50-
e.__on_r?.();
51-
}
45+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
46+
Promise.resolve().then(() => {
47+
if (!evt.defaultPrevented) {
48+
for (const e of /**@type {HTMLFormElement} */ (evt.target).elements) {
49+
// @ts-expect-error
50+
e.__on_r?.();
5251
}
53-
})
54-
.catch((err) => {
55-
// eslint-disable-next-line no-console
56-
console.error(err);
57-
});
52+
}
53+
});
5854
},
5955
// In the capture phase to guarantee we get noticed of it (no possiblity of stopPropagation)
6056
{ capture: true }

packages/svelte/src/motion/spring.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function spring(value, opts = {}) {
7777
* @param {import('./private').SpringUpdateOpts} opts
7878
* @returns {Promise<void>}
7979
*/
80-
function set(new_value, opts = {}) {
80+
async function set(new_value, opts = {}) {
8181
target_value = new_value;
8282
const token = (current_token = {});
8383
if (value == null || opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) {
@@ -120,20 +120,17 @@ export function spring(value, opts = {}) {
120120
});
121121
}
122122
return new Promise((fulfil) => {
123-
/** @type {import('../internal/client/types').Task} */ (task).promise
124-
.then(() => {
125-
if (token === current_token) fulfil();
126-
})
127-
.catch((err) => {
128-
// eslint-disable-next-line no-console
129-
console.error(err);
130-
});
123+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
124+
/** @type {import('../internal/client/types').Task} */ (task).promise.then(() => {
125+
if (token === current_token) fulfil();
126+
});
131127
});
132128
}
133129
/** @type {import('./public.js').Spring<T>} */
134130
const spring = {
135131
set,
136-
update: (fn, opts) => set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts),
132+
update: async (fn, opts) =>
133+
set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts),
137134
subscribe: store.subscribe,
138135
stiffness,
139136
damping,

packages/svelte/src/motion/tweened.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function tweened(value, defaults = {}) {
8888
* @param {T} new_value
8989
* @param {import('./private').TweenedOptions<T>} [opts]
9090
*/
91-
function set(new_value, opts) {
91+
async function set(new_value, opts) {
9292
target_value = new_value;
9393

9494
if (value == null) {
@@ -145,7 +145,7 @@ export function tweened(value, defaults = {}) {
145145
}
146146
return {
147147
set,
148-
update: (fn, opts) =>
148+
update: async (fn, opts) =>
149149
set(fn(/** @type {any} */ (target_value), /** @type {any} */ (value)), opts),
150150
subscribe: store.subscribe
151151
};

0 commit comments

Comments
 (0)