diff --git a/cspell.config.js b/cspell.config.js index 07309ee..5ecd000 100644 --- a/cspell.config.js +++ b/cspell.config.js @@ -1,6 +1,12 @@ import { cspellConfig } from '@envsa/cspell-config'; export default cspellConfig({ - ignorePaths: ['/packages/*/init/*.json', '/packages/*/bin', './test/fixtures/input', './test/fixtures/output-fixed-auto', './packages/eslint-config/src/typegen.d.ts'], - words: [] + ignorePaths: [ + '/packages/*/init/*.json', + '/packages/*/bin', + './test/fixtures/input', + './test/fixtures/output-fixed-auto', + './packages/eslint-config/src/typegen.d.ts', + ], + words: [], }); diff --git a/eslint.config.ts b/eslint.config.ts index ee01841..53fc01a 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -7,7 +7,7 @@ export default eslintConfig( 'bin/', 'packages/eslint-config/src/typegen.d.ts', 'test/fixtures/input/*', - 'test/fixtures/output-fixed-auto/*' + 'test/fixtures/output-fixed-auto/*', ], ts: { overrides: { diff --git a/packages/prettier-config/src/command.ts b/packages/prettier-config/src/command.ts index cb52a1e..b51aacd 100644 --- a/packages/prettier-config/src/command.ts +++ b/packages/prettier-config/src/command.ts @@ -1,67 +1,67 @@ import { - type CommandDefinition, - DESCRIPTION, - getCosmiconfigCommand, -} from '../../../src/command-builder.js' -import { getFilePathAtProjectRoot } from '../../../src/path-utils.js' + type CommandDefinition, + DESCRIPTION, + getCosmiconfigCommand, +} from '../../../src/command-builder.js'; +import { getFilePathAtProjectRoot } from '../../../src/path-utils.js'; // TODO bad idea? const sharedOptions = [ - '--log-level=warn', - '--plugin=@prettier/plugin-php', - '--plugin=@prettier/plugin-xml', - '--plugin=prettier-plugin-packagejson', - '--plugin=prettier-plugin-sh', - '--plugin=prettier-plugin-svelte', - '--plugin=prettier-plugin-tailwindcss', - // Have to resolve to the project root for ignore to work when calling prettier in subdirectories - `--ignore-path=${getFilePathAtProjectRoot('.gitignore') ?? '.gitignore'}`, - `--ignore-path=${getFilePathAtProjectRoot('.prettierignore') ?? '.prettierignore'}`, -] + '--log-level=warn', + '--plugin=@prettier/plugin-php', + '--plugin=@prettier/plugin-xml', + '--plugin=prettier-plugin-packagejson', + '--plugin=prettier-plugin-sh', + '--plugin=prettier-plugin-svelte', + '--plugin=prettier-plugin-tailwindcss', + // Have to resolve to the project root for ignore to work when calling prettier in subdirectories + `--ignore-path=${getFilePathAtProjectRoot('.gitignore') ?? '.gitignore'}`, + `--ignore-path=${getFilePathAtProjectRoot('.prettierignore') ?? '.prettierignore'}`, +]; export const commandDefinition: CommandDefinition = { - commands: { - fix: { - commands: [ - { - name: 'prettier', - optionFlags: [...sharedOptions, '--write'], - receivePositionalArguments: true, - }, - ], - description: `Format files according to your Prettier configuration. ${DESCRIPTION.fileRun}`, - positionalArgumentDefault: '.', - positionalArgumentMode: 'optional', - }, - init: { - configFile: 'prettier.config.js', - configPackageJson: { - prettier: '@envsa/prettier-config', - }, - locationOptionFlag: true, - }, - lint: { - commands: [ - { - name: 'prettier', - optionFlags: [...sharedOptions, '--check'], - receivePositionalArguments: true, - }, - ], - description: `Check that files are formatted according to your Prettier configuration. ${DESCRIPTION.fileRun}`, - positionalArgumentDefault: '.', - positionalArgumentMode: 'optional', - }, - printConfig: { - // See also --find-config-path and --file-info options for fancier per-file approaches... - commands: [getCosmiconfigCommand('prettier')], - description: `Print the effective Prettier configuration. ${DESCRIPTION.packageSearch}. ${DESCRIPTION.monorepoSearch}.`, - positionalArgumentMode: 'none', - }, - }, - description: "Envsa's Prettier shared configuration tools.", - logColor: 'blue', - logPrefix: '[Prettier]', - name: 'envsa-prettier', - order: 9, -} + commands: { + fix: { + commands: [ + { + name: 'prettier', + optionFlags: [...sharedOptions, '--write'], + receivePositionalArguments: true, + }, + ], + description: `Format files according to your Prettier configuration. ${DESCRIPTION.fileRun}`, + positionalArgumentDefault: '.', + positionalArgumentMode: 'optional', + }, + init: { + configFile: 'prettier.config.js', + configPackageJson: { + prettier: '@envsa/prettier-config', + }, + locationOptionFlag: true, + }, + lint: { + commands: [ + { + name: 'prettier', + optionFlags: [...sharedOptions, '--check'], + receivePositionalArguments: true, + }, + ], + description: `Check that files are formatted according to your Prettier configuration. ${DESCRIPTION.fileRun}`, + positionalArgumentDefault: '.', + positionalArgumentMode: 'optional', + }, + printConfig: { + // See also --find-config-path and --file-info options for fancier per-file approaches... + commands: [getCosmiconfigCommand('prettier')], + description: `Print the effective Prettier configuration. ${DESCRIPTION.packageSearch}. ${DESCRIPTION.monorepoSearch}.`, + positionalArgumentMode: 'none', + }, + }, + description: "Envsa's Prettier shared configuration tools.", + logColor: 'blue', + logPrefix: '[Prettier]', + name: 'envsa-prettier', + order: 9, +}; diff --git a/src/command-builder.ts b/src/command-builder.ts index 961811a..c3e50fe 100644 --- a/src/command-builder.ts +++ b/src/command-builder.ts @@ -24,7 +24,7 @@ import { pluralize } from './string-utils.js'; type ChalkColor = (typeof foregroundColorNames)[number]; -interface CommandCommon { +type CommandCommon = { /** Customizes color of log prefix string. Default color used if undefined. */ logColor?: ChalkColor; /** Enables a string prefix in the log output. False if undefined */ @@ -62,7 +62,7 @@ export type Command = CommandCli | CommandFunction; // Init // Optionally takes --location option flag -interface InitCommand { +type InitCommand = { /** Optional additional commands to run */ commands?: Command[]; /** Specific config file */ @@ -75,7 +75,7 @@ interface InitCommand { // Lint // Optionally takes files (plural) positional arguments (array of strings, possibly expanded from glob?) -interface LintCommand { +type LintCommand = { commands: Command[]; description: string; positionalArgumentDefault?: string; // Only applies if arguments mode is not 'none' @@ -90,7 +90,7 @@ type FixCommand = LintCommand; // Same as lint for now, Optionally takes file (singular) positional argument type PrintConfigCommand = LintCommand; -export interface Commands { +export type Commands = { fix?: FixCommand; init?: InitCommand; lint?: LintCommand; @@ -98,7 +98,7 @@ export interface Commands { } // Exported for aggregation later -export interface CommandDefinition { +export type CommandDefinition = { commands: Commands; description: string; logColor: ChalkColor; @@ -255,7 +255,7 @@ export async function executeCommands( verbose?: boolean, showSummary?: boolean, ): Promise { - const exitCodes: { exitCode: number; name: string }[] = []; + const exitCodes: Array<{ exitCode: number; name: string }> = []; for (const command of commands) { const exitCode = await (isCommandFunction(command) @@ -617,7 +617,7 @@ export function getCosmiconfigCommand(configName: string): CommandFunction { return 1; } - // eslint-disable-next-line ts/no-unsafe-assignment + const { config, filepath: configFilePath, isEmpty } = result; logStream.write(`Found ${configName} configuration at "${configFilePath}"\n`); @@ -637,7 +637,7 @@ export function getCosmiconfigCommand(configName: string): CommandFunction { }; } -type NullToUndefined = T extends null ? undefined : T; +type NullToUndefined = T extends undefined ? undefined : T; /** * Convenience wrapper to safely fetch a cosmiconfig result. diff --git a/src/json-utils.ts b/src/json-utils.ts index 1610ea2..4a8e786 100644 --- a/src/json-utils.ts +++ b/src/json-utils.ts @@ -25,6 +25,7 @@ export function stringify(object: any): string { }), { colors: { + // eslint-disable-next-line ts/naming-convention BRACKET: 'gray', }, }, diff --git a/src/node-utils.ts b/src/node-utils.ts index b4ba728..2eaedfe 100644 --- a/src/node-utils.ts +++ b/src/node-utils.ts @@ -20,6 +20,7 @@ export function suppressNodeWarnings(): void { ); } + // @ts-expect-error - Missing types return originalEmit.call(this, ...args); } as typeof process.emit; } diff --git a/src/stream-utils.ts b/src/stream-utils.ts index 30e6c1c..b709853 100644 --- a/src/stream-utils.ts +++ b/src/stream-utils.ts @@ -38,6 +38,7 @@ export function createStreamTransform( const transformed = lines .map( (line) => + // eslint-disable-next-line ts/no-unnecessary-condition `${logPrefix ? (logColor === undefined ? logPrefix : chalk[logColor](logPrefix)) : ''} ${line}\n`, ) .join('');