chore(users/Profpatsch/lyric): add typescript linting rules

Change-Id: I9ab0336450519648f7a8edeec94bd64b78e2f05b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12554
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2024-10-01 03:54:36 +02:00
parent 102c9b30a7
commit ad711b15a0
6 changed files with 140 additions and 89 deletions

View file

@ -1,6 +1,6 @@
import tseslint from "typescript-eslint";
import tsplugin from "@typescript-eslint/eslint-plugin";
import parser from "@typescript-eslint/parser";
import tseslint from 'typescript-eslint';
import tsplugin from '@typescript-eslint/eslint-plugin';
import parser from '@typescript-eslint/parser';
export default tseslint.config(tseslint.configs.eslintRecommended, {
languageOptions: {
@ -9,34 +9,63 @@ export default tseslint.config(tseslint.configs.eslintRecommended, {
projectService: true,
},
},
ignores: ["node_modules/", "eslint.config.mjs"],
plugins: { "@typescript-eslint": tsplugin },
ignores: ['node_modules/', 'eslint.config.mjs'],
plugins: { '@typescript-eslint': tsplugin },
rules: {
"prettier/prettier": "off",
"prefer-const": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-duplicate-enum-values": "warn",
"@typescript-eslint/no-empty-object-type": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extra-non-null-assertion": "warn",
"@typescript-eslint/no-misused-new": "warn",
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-require-imports": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-unsafe-function-type": "warn",
"@typescript-eslint/strict-boolean-expressions": ["warn"],
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-wrapper-object-types": "warn",
"@typescript-eslint/prefer-as-const": "warn",
"@typescript-eslint/prefer-namespace-keyword": "warn",
"@typescript-eslint/triple-slash-reference": "warn",
'prettier/prettier': 'off',
'prefer-const': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extra-non-null-assertion': 'warn',
'@typescript-eslint/no-misused-new': 'warn',
'@typescript-eslint/no-namespace': 'warn',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
'@typescript-eslint/no-require-imports': 'warn',
'@typescript-eslint/no-this-alias': 'warn',
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/strict-boolean-expressions': ['warn'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'warn',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-wrapper-object-types': 'warn',
'@typescript-eslint/prefer-as-const': 'warn',
'@typescript-eslint/prefer-namespace-keyword': 'warn',
'@typescript-eslint/triple-slash-reference': 'warn',
'@typescript-eslint/await-thenable': 'warn',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-delete': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-for-in-array': 'warn',
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-enum-comparison': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-unary-minus': 'warn',
'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'warn',
'prefer-promise-reject-errors': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'warn',
'require-await': 'off',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/unbound-method': 'warn',
},
});

View file

@ -1,6 +1,6 @@
import tseslint from "typescript-eslint";
import tsplugin from "@typescript-eslint/eslint-plugin";
import parser from "@typescript-eslint/parser";
import tseslint from 'typescript-eslint';
import tsplugin from '@typescript-eslint/eslint-plugin';
import parser from '@typescript-eslint/parser';
export default tseslint.config(tseslint.configs.eslintRecommended, {
languageOptions: {
@ -9,34 +9,63 @@ export default tseslint.config(tseslint.configs.eslintRecommended, {
projectService: true,
},
},
ignores: ["node_modules/", "eslint.config.mjs"],
plugins: { "@typescript-eslint": tsplugin },
ignores: ['node_modules/', 'eslint.config.mjs'],
plugins: { '@typescript-eslint': tsplugin },
rules: {
"prettier/prettier": "off",
"prefer-const": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-duplicate-enum-values": "warn",
"@typescript-eslint/no-empty-object-type": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extra-non-null-assertion": "warn",
"@typescript-eslint/no-misused-new": "warn",
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-require-imports": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-unsafe-function-type": "warn",
"@typescript-eslint/strict-boolean-expressions": ["warn"],
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-wrapper-object-types": "warn",
"@typescript-eslint/prefer-as-const": "warn",
"@typescript-eslint/prefer-namespace-keyword": "warn",
"@typescript-eslint/triple-slash-reference": "warn",
'prettier/prettier': 'off',
'prefer-const': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extra-non-null-assertion': 'warn',
'@typescript-eslint/no-misused-new': 'warn',
'@typescript-eslint/no-namespace': 'warn',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
'@typescript-eslint/no-require-imports': 'warn',
'@typescript-eslint/no-this-alias': 'warn',
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/strict-boolean-expressions': ['warn'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'warn',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-wrapper-object-types': 'warn',
'@typescript-eslint/prefer-as-const': 'warn',
'@typescript-eslint/prefer-namespace-keyword': 'warn',
'@typescript-eslint/triple-slash-reference': 'warn',
'@typescript-eslint/await-thenable': 'warn',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-delete': 'warn',
'@typescript-eslint/no-base-to-string': 'warn',
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-for-in-array': 'warn',
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-enum-comparison': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-unary-minus': 'warn',
'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'warn',
'prefer-promise-reject-errors': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'warn',
'require-await': 'off',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/unbound-method': 'warn',
},
});

View file

@ -416,7 +416,7 @@ class Ext {
if (!match) {
return;
}
const [, timestamp, text] = match!;
const [, timestamp, text] = match;
const milliseconds = parseTimestamp(timestamp);
const seconds = milliseconds / 1000;
return { milliseconds, seconds, text };

View file

@ -1,16 +1,16 @@
import { tapBpm } from "./tap-bpm.js";
import { tapBpm } from './tap-bpm.js';
async function main() {
function main() {
// subcommand for tap-bpm
if (process.argv[2] === "tap-bpm") {
await tapBpm();
if (process.argv[2] === 'tap-bpm') {
tapBpm();
}
}
await main();
main();
// sleep in a loop to block nodejs
console.log("Blocking event loop...");
console.log('Blocking event loop...');
while (true) {
await new Promise((resolve) => setTimeout(resolve, 1000));
await new Promise(resolve => setTimeout(resolve, 1000));
}

View file

@ -1,7 +1,7 @@
// create a node command line listener that allows the user to press any key , and averages the distances between the key presses to determine the BPM (with a window of 4 key presses). If the user presses q, the program should exit and print the final BPM.
// Import the necessary modules
import * as readline from "readline";
import * as readline from 'readline';
export function tapBpm() {
// Set up readline interface to listen for keypresses
@ -19,35 +19,28 @@ export function tapBpm() {
return 0;
}
const averageTimeDiff =
timeDifferences.reduce((acc, curr) => acc + curr, 0) /
timeDifferences.length;
timeDifferences.reduce((acc, curr) => acc + curr, 0) / timeDifferences.length;
return (60 * 1000) / averageTimeDiff;
}
// Handle the SIGINT (Ctrl+C) event manually
process.on("SIGINT", () => {
console.log(
"\nExiting via SIGINT (Ctrl+C)... Final BPM:",
calculateBPM().toFixed(2)
);
process.on('SIGINT', () => {
console.log('\nExiting via SIGINT (Ctrl+C)... Final BPM:', calculateBPM().toFixed(2));
process.exit();
});
// Listen for keypress events
process.stdin.on("keypress", (str, key) => {
process.stdin.on('keypress', (str, key: { name: string; sequence: string }) => {
// Exit if 'q' is pressed
if (key.name === "q") {
console.log("Exiting... Final BPM:", calculateBPM().toFixed(2));
if (key.name === 'q') {
console.log('Exiting... Final BPM:', calculateBPM().toFixed(2));
process.exit();
}
// Handle Ctrl+C (SIGINT)
if (key.sequence === "\u0003") {
if (key.sequence === '\u0003') {
// '\u0003' is the raw code for Ctrl+C
console.log(
"\nExiting via Ctrl+C... Final BPM:",
calculateBPM().toFixed(2)
);
console.log('\nExiting via Ctrl+C... Final BPM:', calculateBPM().toFixed(2));
process.exit();
}
@ -66,9 +59,9 @@ export function tapBpm() {
// Calculate and display the BPM
const bpm = calculateBPM();
console.log("Current BPM:", bpm.toFixed(2));
console.log('Current BPM:', bpm.toFixed(2));
} else {
console.log("Waiting for more key presses to calculate BPM...");
console.log('Waiting for more key presses to calculate BPM...');
}
// Update the lastPressTime to the current time

View file

@ -9,7 +9,7 @@
"esModuleInterop": true
},
"include": [
"src/**/*.ts"
"src/**/*.ts",
],
"exclude": [
"node_modules"