Skip to content

Commit 10ac6aa

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

File tree

6 files changed

+10
-17
lines changed

6 files changed

+10
-17
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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +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+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
196197
Promise.resolve()
197198
.then(() => {
198199
if (!this.$$cn && this.$$c) {
199200
this.$$c.$destroy();
200201
destroy_effect(this.$$me);
201202
this.$$c = undefined;
202203
}
203-
})
204-
.catch((err) => {
205-
// eslint-disable-next-line no-console
206-
console.error(err);
207204
});
208205
}
209206

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ 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+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
4546
Promise.resolve()
4647
.then(() => {
4748
if (!evt.defaultPrevented) {
@@ -50,10 +51,6 @@ export function add_form_reset_listener() {
5051
e.__on_r?.();
5152
}
5253
}
53-
})
54-
.catch((err) => {
55-
// eslint-disable-next-line no-console
56-
console.error(err);
5754
});
5855
},
5956
// In the capture phase to guarantee we get noticed of it (no possiblity of stopPropagation)

packages/svelte/src/motion/spring.js

Lines changed: 3 additions & 6 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+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
123124
/** @type {import('../internal/client/types').Task} */ (task).promise
124125
.then(() => {
125126
if (token === current_token) fulfil();
126-
})
127-
.catch((err) => {
128-
// eslint-disable-next-line no-console
129-
console.error(err);
130127
});
131128
});
132129
}
133130
/** @type {import('./public.js').Spring<T>} */
134131
const spring = {
135132
set,
136-
update: (fn, opts) => set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts),
133+
update: async (fn, opts) => 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)