Skip to content

Commit

Permalink
enable strict rules by typescript-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Sep 15, 2024
1 parent 770c1e8 commit e246a56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions playground/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mocha from 'eslint-plugin-mocha';

export default ts.config(
eslint.configs.recommended,
...ts.configs.recommendedTypeChecked,
...ts.configs.strictTypeChecked,
{
files: ['*.ts'],
languageOptions: {
Expand All @@ -21,10 +21,11 @@ export default ts.config(
files: ['*.ts', '*.mjs'],
rules: {
eqeqeq: ['error', 'always'],
'no-constant-condition': ['error', { checkLoops: false }],
'@typescript-eslint/no-unnecessary-condition': ['error', { allowConstantLoopConditions: true }],
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
mocha.configs.flat.recommended,
Expand Down
21 changes: 13 additions & 8 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
successMessage.style.display = 'none';
invalidInputMessage.style.display = 'none';
editor.clearGutter('error-marker');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
window.runActionlint!(editor.getValue());
}

Expand All @@ -153,7 +154,9 @@ jobs:
return;
}

debounceId = window.setTimeout(() => startActionlint(), debounceInterval);
debounceId = window.setTimeout(() => {
startActionlint();
}, debounceInterval);
});

function getSource(): string {
Expand Down Expand Up @@ -192,7 +195,7 @@ jobs:
let rest = text;
while (true) {
const m = rest.match(reUrl);
if (m === null || m.index === undefined || m[0] === undefined) {
if (m === null || m.index === undefined) {
if (rest.length > 0) {
ret.push(span(rest));
}
Expand All @@ -212,7 +215,9 @@ jobs:
a.rel = 'noopener';
a.textContent = url;
a.className = 'has-text-link-my-light is-underlined';
a.addEventListener('click', e => e.stopPropagation());
a.addEventListener('click', e => {
e.stopPropagation();
});
ret.push(a);

rest = rest.slice(idx + url.length);
Expand Down Expand Up @@ -269,12 +274,11 @@ jobs:
window.addEventListener('beforeunload', e => {
if (contentChanged) {
e.preventDefault();
e.returnValue = '';
}
});

checkUrlInput.addEventListener('keyup', e => {
if (e.key === 'Enter' || e.keyCode === 13) {
if (e.key === 'Enter') {
e.preventDefault();
checkUrlButton.click();
}
Expand Down Expand Up @@ -310,7 +314,7 @@ jobs:
window.location.hash = b64;
});

preferDark.addListener(event => {
preferDark.addEventListener('change', event => {
editor.setOption('theme', colorTheme(event.matches));
});

Expand All @@ -327,7 +331,8 @@ jobs:
}

await go.run(result.instance);
})().catch(err => {
})().catch((err: unknown) => {
console.error('ERROR!:', err);
alert(`${err.name}: ${err.message}\n\n${err.stack}`);
const msg = err instanceof Error ? `${err.name}: ${err.message}\n\n${err.stack}` : `Error: ${err}`;
alert(msg);
});
2 changes: 2 additions & 0 deletions playground/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
const json = JSON.stringify(errors);
assert.equal(errors.length, 1, json);

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

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

0 comments on commit e246a56

Please sign in to comment.