Skip to content

Commit e246a56

Browse files
committed
enable strict rules by typescript-eslint
1 parent 770c1e8 commit e246a56

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

playground/eslint.config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import mocha from 'eslint-plugin-mocha';
66

77
export default ts.config(
88
eslint.configs.recommended,
9-
...ts.configs.recommendedTypeChecked,
9+
...ts.configs.strictTypeChecked,
1010
{
1111
files: ['*.ts'],
1212
languageOptions: {
@@ -21,10 +21,11 @@ export default ts.config(
2121
files: ['*.ts', '*.mjs'],
2222
rules: {
2323
eqeqeq: ['error', 'always'],
24-
'no-constant-condition': ['error', { checkLoops: false }],
24+
'@typescript-eslint/no-unnecessary-condition': ['error', { allowConstantLoopConditions: true }],
2525
'@typescript-eslint/no-unsafe-member-access': 'off',
2626
'@typescript-eslint/no-unsafe-argument': 'off',
2727
'@typescript-eslint/no-unsafe-assignment': 'off',
28+
'@typescript-eslint/restrict-template-expressions': 'off',
2829
},
2930
},
3031
mocha.configs.flat.recommended,

playground/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ jobs:
145145
successMessage.style.display = 'none';
146146
invalidInputMessage.style.display = 'none';
147147
editor.clearGutter('error-marker');
148+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
148149
window.runActionlint!(editor.getValue());
149150
}
150151

@@ -153,7 +154,9 @@ jobs:
153154
return;
154155
}
155156

156-
debounceId = window.setTimeout(() => startActionlint(), debounceInterval);
157+
debounceId = window.setTimeout(() => {
158+
startActionlint();
159+
}, debounceInterval);
157160
});
158161

159162
function getSource(): string {
@@ -192,7 +195,7 @@ jobs:
192195
let rest = text;
193196
while (true) {
194197
const m = rest.match(reUrl);
195-
if (m === null || m.index === undefined || m[0] === undefined) {
198+
if (m === null || m.index === undefined) {
196199
if (rest.length > 0) {
197200
ret.push(span(rest));
198201
}
@@ -212,7 +215,9 @@ jobs:
212215
a.rel = 'noopener';
213216
a.textContent = url;
214217
a.className = 'has-text-link-my-light is-underlined';
215-
a.addEventListener('click', e => e.stopPropagation());
218+
a.addEventListener('click', e => {
219+
e.stopPropagation();
220+
});
216221
ret.push(a);
217222

218223
rest = rest.slice(idx + url.length);
@@ -269,12 +274,11 @@ jobs:
269274
window.addEventListener('beforeunload', e => {
270275
if (contentChanged) {
271276
e.preventDefault();
272-
e.returnValue = '';
273277
}
274278
});
275279

276280
checkUrlInput.addEventListener('keyup', e => {
277-
if (e.key === 'Enter' || e.keyCode === 13) {
281+
if (e.key === 'Enter') {
278282
e.preventDefault();
279283
checkUrlButton.click();
280284
}
@@ -310,7 +314,7 @@ jobs:
310314
window.location.hash = b64;
311315
});
312316

313-
preferDark.addListener(event => {
317+
preferDark.addEventListener('change', event => {
314318
editor.setOption('theme', colorTheme(event.matches));
315319
});
316320

@@ -327,7 +331,8 @@ jobs:
327331
}
328332

329333
await go.run(result.instance);
330-
})().catch(err => {
334+
})().catch((err: unknown) => {
331335
console.error('ERROR!:', err);
332-
alert(`${err.name}: ${err.message}\n\n${err.stack}`);
336+
const msg = err instanceof Error ? `${err.name}: ${err.message}\n\n${err.stack}` : `Error: ${err}`;
337+
alert(msg);
333338
});

playground/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
const json = JSON.stringify(errors);
7777
assert.equal(errors.length, 1, json);
7878

79+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7980
const err = errors[0]!;
8081
assert.equal(err.message, '"runs-on" section is missing in job "test"', `message is unexpected: ${json}`);
8182
assert.equal(err.line, 5, `line is unexpected: ${json}`);
@@ -101,6 +102,7 @@ jobs:
101102
const json = JSON.stringify(errors);
102103
assert.equal(errors.length, 1, json);
103104

105+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
104106
const err = errors[0]!;
105107
assert.ok(err.message.includes('unknown Webhook event "foo"'), `message is unexpected: ${json}`);
106108
assert.equal(err.line, 2, `line is unexpected: ${json}`);

0 commit comments

Comments
 (0)