From 74b701053feb15a02caeaaace17981dde2a8966d Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Tue, 11 Apr 2023 12:12:00 -0400 Subject: [PATCH] style: update eslint stuff --- .eslintrc.yaml | 27 ++++++++++++------ .yarnrc.yml | 6 ++-- src/BaseCommand.ts | 11 ++++---- src/commands/config/show.ts | 4 --- src/commands/fs/copy.ts | 1 + src/commands/humanize/humanize.ts | 8 +++--- src/connections.ts | 4 +-- src/io.ts | 2 +- src/types.d.ts | 2 -- yarn.lock | 47 ------------------------------- 10 files changed, 35 insertions(+), 77 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index a0219e5..9bd7dae 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,6 +1,7 @@ root: true extends: + - 'plugin:@typescript-eslint/recommended' - plugin:node/recommended - plugin:github/recommended - plugin:promise/recommended @@ -16,6 +17,7 @@ extends: - prettier plugins: + - '@typescript-eslint' - node - github - promise @@ -35,10 +37,10 @@ parser: '@typescript-eslint/parser' parserOptions: ecmaVersion: 2020 - project: './tsconfig.eslint.json' + project: './tsconfig*.json' overrides: - - files: '*.{c,m,}ts' + - files: '*.ts' extends: - plugin:github/typescript - plugin:import/typescript @@ -46,7 +48,7 @@ overrides: - prettier parserOptions: ecmaVersion: 2020 - project: './tsconfig.eslint.json' + project: './tsconfig*.json' rules: '@typescript-eslint/naming-convention': [ @@ -78,6 +80,17 @@ overrides: ] '@typescript-eslint/restrict-template-expressions': off '@typescript-eslint/no-shadow': warn + '@typescript-eslint/no-unused-vars': + [ + warn, + { + args: after-used, + ignoreRestSiblings: true, + varsIgnorePattern: '^_', + argsIgnorePattern: '^_', + }, + ] + '@typescript-eslint/consistent-type-definitions': [warn, interface] rules: notice/notice: @@ -92,7 +105,9 @@ rules: */ onNonMatchingHeader: append nonMatchingTolerance: 0.7 - unicorn/prefer-node-protocol: off + unicorn/prevent-abbreviations: + [warn, { replacements: { db: false, req: false, doc: false, docs: false } }] + '@typescript-eslint/no-shadow': [warn, { allow: [_] }] sonarjs/no-duplicate-string: [warn, 5] sonarjs/cognitive-complexity: warn eslint-comments/no-unused-disable: off @@ -113,7 +128,3 @@ rules: no-constructor-bind/no-constructor-bind: error no-constructor-bind/no-constructor-state: error sort-imports: [warn, { allowSeparatedGroups: true }] - ava/no-ignored-test-files: off - ava/no-import-test-files: off - ava/no-skip-test: warn - ava/no-skip-assert: warn diff --git a/.yarnrc.yml b/.yarnrc.yml index b34f7f4..62f7e3c 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -2,10 +2,10 @@ nodeLinker: node-modules plugins: - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs - spec: "@yarnpkg/plugin-interactive-tools" + spec: '@yarnpkg/plugin-interactive-tools' - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs - spec: "@yarnpkg/plugin-typescript" + spec: '@yarnpkg/plugin-typescript' - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs - spec: "@yarnpkg/plugin-workspace-tools" + spec: '@yarnpkg/plugin-workspace-tools' yarnPath: .yarn/releases/yarn-3.5.0.cjs diff --git a/src/BaseCommand.ts b/src/BaseCommand.ts index 69d6f0c..96d404c 100644 --- a/src/BaseCommand.ts +++ b/src/BaseCommand.ts @@ -27,13 +27,13 @@ import { importable } from './io.js'; /** * Global config stuff */ -export type Config = { +export interface Config { domains?: Record; domain?: string; token?: string; tty?: boolean; ws?: boolean; -}; +} /** * Internal Config type, with defaults filled out @@ -46,7 +46,7 @@ export type IConfig = Record & /** * Config per OADA domain */ -type DomainConfig = { +interface DomainConfig { /** * OADA API token */ @@ -59,7 +59,7 @@ type DomainConfig = { * Allow passing in an OADAClient? */ connection?: Promise; -}; +} /** * Defaults for settings @@ -108,9 +108,8 @@ async function loadUserConfig( paths: readonly string[] ): Promise> { const config = {}; - for (const path of paths) { + for await (const path of paths) { try { - // eslint-disable-next-line no-await-in-loop const { default: userConfig } = (await import(path)) as { default: unknown; }; diff --git a/src/commands/config/show.ts b/src/commands/config/show.ts index 48a6f9d..2efa9e2 100644 --- a/src/commands/config/show.ts +++ b/src/commands/config/show.ts @@ -20,10 +20,6 @@ export default class ShowConfig extends Command { static override aliases = ['config']; - static override flags = { - ...Command.flags, - }; - async run() { const config = this.iconfig; console.error(this.configFiles, 'Loading configs'); diff --git a/src/commands/fs/copy.ts b/src/commands/fs/copy.ts index 990aa77..4b7bf01 100644 --- a/src/commands/fs/copy.ts +++ b/src/commands/fs/copy.ts @@ -40,6 +40,7 @@ export default class Copy extends Command { // eslint-disable-next-line require-yield await input(conn, `${file}`, this.iconfig, async function* (source) { for await (const data of source) { + // eslint-disable-next-line security/detect-object-injection await conn[method]({ path, data: data as any }); } }); diff --git a/src/commands/humanize/humanize.ts b/src/commands/humanize/humanize.ts index 0de7565..7a6ec27 100644 --- a/src/commands/humanize/humanize.ts +++ b/src/commands/humanize/humanize.ts @@ -43,14 +43,14 @@ function humanize(value: unknown): unknown { return value; } -type Item = { +interface Item { k: unknown; v: unknown; -}; -type Transform = { +} +interface Transform { match(value: Item): boolean; apply(value: Item): Item; -}; +} const transforms: readonly Transform[] = [ // KSUIDs transform { diff --git a/src/connections.ts b/src/connections.ts index 7489e4a..77273aa 100644 --- a/src/connections.ts +++ b/src/connections.ts @@ -23,7 +23,7 @@ import { import type { IConfig } from './BaseCommand.js'; -type Connections = { +interface Connections { /** * Default OADA connection * @@ -31,7 +31,7 @@ type Connections = { */ connection?: Promise; domains: Map>; -}; +} // Wrap OADAClient with magics const methods = ['get', 'head', 'put', 'post', 'delete'] as const; diff --git a/src/io.ts b/src/io.ts index dc23684..cad2f55 100644 --- a/src/io.ts +++ b/src/io.ts @@ -120,7 +120,7 @@ async function outputType(outString: string, { tty }: IConfig) { * @todo make this more extensible? * @todo support these extensions coming from remote?? */ -export const importable = ['.json6', '.json5', '.hjson', '.ts', '.js'] as const; +export const importable = ['.ts', '.js'] as const; /** * Load a support file as JSON diff --git a/src/types.d.ts b/src/types.d.ts index ba29312..75c95ca 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -7,8 +7,6 @@ */ declare module 'concatjson' { - import { Readable, Stream, type Transform, Writable } from 'node:stream'; - export function parse(): Transform; export function serialize(): Transform; } diff --git a/yarn.lock b/yarn.lock index f4ebe55..acb4afc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -467,8 +467,6 @@ __metadata: "@oclif/plugin-plugins": ^2.4.4 "@tsconfig/node16": ^1.0.3 "@types/glob": ^8.1.0 - "@types/hjson": ^2.4.3 - "@types/json5": ^2.2.0 "@types/minimatch": ^5.1.2 "@types/ndjson": ^2.0.1 "@types/node": ^16.18.23 @@ -505,8 +503,6 @@ __metadata: gaxios: ^5.1.0 glob: ^10.0.0 globby: ^13.1.3 - hjson: ^3.2.2 - json-6: ^1.1.4 ksuid: ^3.0.0 minimatch: ^9.0.0 ndjson: ^2.0.0 @@ -936,13 +932,6 @@ __metadata: languageName: node linkType: hard -"@types/hjson@npm:^2.4.3": - version: 2.4.3 - resolution: "@types/hjson@npm:2.4.3" - checksum: 4f90e9a41becd3a3ba2636ae7b421e419d102222fcfb729434406bc98cede61a1ecd32bc928f89693d71ab443696bfdb77cb1a7561b6bf44c530ab3506048eef - languageName: node - linkType: hard - "@types/http-cache-semantics@npm:*": version: 4.0.1 resolution: "@types/http-cache-semantics@npm:4.0.1" @@ -971,15 +960,6 @@ __metadata: languageName: node linkType: hard -"@types/json5@npm:^2.2.0": - version: 2.2.0 - resolution: "@types/json5@npm:2.2.0" - dependencies: - json5: "*" - checksum: a295f489dd53fd075181b9c24d489efc2655d68a80636e5edcb5aa785b0afefe3ac8bb68d613f318e177b4c7a0394690243497d54b1da9ac129ddaa901e28fdb - languageName: node - linkType: hard - "@types/keyv@npm:*": version: 3.1.4 resolution: "@types/keyv@npm:3.1.4" @@ -4202,15 +4182,6 @@ __metadata: languageName: node linkType: hard -"hjson@npm:^3.2.2": - version: 3.2.2 - resolution: "hjson@npm:3.2.2" - bin: - hjson: bin/hjson - checksum: 556086424f719c82fc8ae880d388e617e88f38213f69a6c380704fa6808790c68f9233ef480cdb22d6f24549b2edfc19aea67ab2c40013b231001f8168d56e33 - languageName: node - linkType: hard - "hosted-git-info@npm:^2.1.4": version: 2.8.9 resolution: "hosted-git-info@npm:2.8.9" @@ -4967,15 +4938,6 @@ __metadata: languageName: node linkType: hard -"json-6@npm:^1.1.4": - version: 1.1.4 - resolution: "json-6@npm:1.1.4" - bin: - json-6: lib/cli.js - checksum: 0cd3df156616646f4f53d7fbf58f08a5f06387744f1bd2c65a2897ff9fc5678b5b5f1f6c2c3c356c1e9136862a8e0275948ddb46afc2d0c105acedfa4811be98 - languageName: node - linkType: hard - "json-buffer@npm:3.0.1, json-buffer@npm:~3.0.1": version: 3.0.1 resolution: "json-buffer@npm:3.0.1" @@ -5032,15 +4994,6 @@ __metadata: languageName: node linkType: hard -"json5@npm:*": - version: 2.2.1 - resolution: "json5@npm:2.2.1" - bin: - json5: lib/cli.js - checksum: 74b8a23b102a6f2bf2d224797ae553a75488b5adbaee9c9b6e5ab8b510a2fc6e38f876d4c77dea672d4014a44b2399e15f2051ac2b37b87f74c0c7602003543b - languageName: node - linkType: hard - "json5@npm:^1.0.1": version: 1.0.1 resolution: "json5@npm:1.0.1"