diff --git a/.cron/deno.lock b/.cron/deno.lock index 2ef94da..20811ed 100644 --- a/.cron/deno.lock +++ b/.cron/deno.lock @@ -5,6 +5,7 @@ "npm:@antfu/eslint-config@^2.6.2": "npm:@antfu/eslint-config@2.6.2_eslint@8.56.0_@typescript-eslint+parser@6.18.1__eslint@8.56.0_vue-eslint-parser@9.4.0__eslint@8.56.0_@typescript-eslint+eslint-plugin@6.18.1__@typescript-eslint+parser@6.18.1___eslint@8.56.0__eslint@8.56.0", "npm:@stylistic/eslint-plugin-js@^1.5.3": "npm:@stylistic/eslint-plugin-js@1.5.3_eslint@8.56.0", "npm:@tsconfig/deno@^1.0.9": "npm:@tsconfig/deno@1.0.9", + "npm:@types/node": "npm:@types/node@18.16.19", "npm:@types/node@^20.11.2": "npm:@types/node@20.11.2", "npm:blend-promise-utils": "npm:blend-promise-utils@1.29.0", "npm:chalk@5": "npm:chalk@5.3.0", @@ -236,6 +237,10 @@ "@types/unist": "@types/unist@2.0.10" } }, + "@types/node@18.16.19": { + "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==", + "dependencies": {} + }, "@types/node@20.11.2": { "integrity": "sha512-cZShBaVa+UO1LjWWBPmWRR4+/eY/JR/UIEcDlVsw3okjWEu+rB7/mH6X3B/L+qJVHDLjk9QW/y2upp9wp1yDXA==", "dependencies": { diff --git a/.cron/jobs/example1.job.ts b/.cron/jobs/example1.job.ts index 9bbf72d..559aaeb 100755 --- a/.cron/jobs/example1.job.ts +++ b/.cron/jobs/example1.job.ts @@ -1,9 +1,10 @@ #!/usr/bin/env -S deno run -A -import { Code, benchmark, bkt, hr, log, root } from 'util.ts' +import { Code, benchmark, bkt, hr, log, root, wc } from 'util.ts' import { $ } from 'deps.ts' -const b = benchmark(1000) +const b1 = benchmark() +const b2 = benchmark(1000) await $`echo hello world` const param = '+%Y-%m-%d-%H%M%S' @@ -28,4 +29,12 @@ log(Code.OK) log(Code.ERROR) log(Code.WARN) -log(b()) +log(b1()) +log(b2()) + +$.cd(root) +log('Lines:', await wc('.cron/jobs/example1.job.ts')) + +// Disable on purpose to test working no-floating-promises +// eslint-disable-next-line ts/no-floating-promises +wc('.cron/jobs/example1.job.ts') diff --git a/.cron/tsconfig.json b/.cron/tsconfig.json index 6a72ea6..3f171a7 100644 --- a/.cron/tsconfig.json +++ b/.cron/tsconfig.json @@ -7,19 +7,22 @@ "rootDir": ".", "module": "NodeNext", "moduleResolution": "nodenext", - "checkJs": true, - "strict": true, + "checkJs": false, + "strict": false, + "noImplicitAny": false, "outDir": "./dist", "allowSyntheticDefaultImports": true, "esModuleInterop": true }, "files": [ - // "./jobs/example1.ts", - // "./jobs/example2.ts", + // "./.cron/jobs/example1.job.ts", + // "./.cron/jobs/example2.job.ts", + // "./.cron/*.ts", + // "./.cron/**/*.ts" ], "include": [ - "**/*.ts" - // ".*/**/*.ts" + "**/*.ts", + ".cron/**/*.ts" ], "exclude": [ "deno.json" diff --git a/.cron/util.ts b/.cron/util.ts index 0251f69..8e12001 100644 --- a/.cron/util.ts +++ b/.cron/util.ts @@ -64,9 +64,13 @@ export const Code = { /** * Benchmark helper */ -export function benchmark(unit = 1) { +export function benchmark(unitMs = 1) { const start = performance.now() return (now = performance.now()) => { - return ((now - start) / unit).toFixed(2) + return ((now - start) / unitMs).toFixed(2) } } + +export function wc(path: string): Promise { + return $`cat ${path} | wc -l`.text() +} diff --git a/eslint.config.js b/eslint.config.js index 3d977fe..355c4ee 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,5 +1,3 @@ -// eslint.config.js - import antfu from '@antfu/eslint-config' export default antfu({ @@ -9,102 +7,30 @@ export default antfu({ quotes: 'single', }, - // Or customize the stylistic rules - + typescript: { + tsconfigPath: '.cron/tsconfig.json', + parserOptions: { + project: '.cron/tsconfig.json', + }, + }, // Disable jsonc and yaml support jsonc: true, yaml: true, - typescript: true, - - // `.eslintignore` is no longer supported in Flat config, use `ignores` instead -}, - // { - // root: true, - // ignorePatterns: [ - // '!.*' - // ], - // parserOptions: { - // ecmaVersion: 'latest', - // sourceType: 'module', - // project: './cron/tsconfig.json' - // }, - // plugins: [ - // 'unicorn' - // ], - // rules: { - // 'unicorn/template-indent': [ - // 'warn', - // { - // tags: [], - // functions: [], - // selectors: [ - // 'TemplateLiteral' - // ] - // } - // ] - // }, - // globals: {}, - // overrides: [ - // { - // files: [ - // '*', - // '*.ts', - // '*.tsx', - // '*.js', - // '*.mjs' - // ], - // rules: { - // 'template-tag-spacing': [ - // 'error', - // 'always' - // ], - // curly: [ - // 'error', - // 'multi-line' - // ], - // 'no-console': 'error', - // '@typescript-eslint/comma-dangle': 'off', - // '@typescript-eslint/require-await': [ - // 'error' - // ], - // '@typescript-eslint/no-floating-promises': [ - // 'error' - // ], - // '@typescript-eslint/no-misused-promises': [ - // 'error' - // ], - // 'no-multiple-empty-lines': [ - // 'error', - // { - // max: 1, - // maxBOF: 0, - // maxEOF: 0 - // } - // ] - // } - // }, - // { - // files: [ - // 'settings.json', - // 'deno.json*' - // ], - // rules: { - // 'jsonc/sort-keys': [ - // 'error', - // 'asc', - // { - // caseSensitive: true, - // natural: false, - // minKeys: 2 - // } - // ] - // } - // } - // ] - // } - -) - -// export default [{ -// extends: '@antfu', -// ] +}, { + ignores: [ + '*.js', + // '!.*' + ], +}, { + files: ['**/*.ts', '.cron/**/*.ts'], + rules: { + 'ts/no-unsafe-assignment': 'off', + 'ts/no-unsafe-call': 'off', + 'ts/no-unsafe-return': 'off', + 'ts/no-unsafe-member-access': 'off', + 'ts/no-unsafe-argument': 'off', + 'ts/require-await': 'error', + 'ts/no-floating-promises': 'error', + 'ts/no-misused-promises': 'error', + }, +}) diff --git a/package.json b/package.json index 338c146..de9dbcd 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "@tsconfig/deno": "^1.0.9", "@types/node": "^20.11.2", "eslint": "^8.56.0", - "eslint-plugin-unicorn": "^50.0.1" + "eslint-plugin-unicorn": "^50.0.1", + "typescript": "^5.3.3" }, "preinstallBinaries": [ "https://raw.githubusercontent.com/borestad/ci-utils/main/bin/dl",