Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rellafella committed Feb 17, 2025
1 parent ecfead4 commit e272b6f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 72 deletions.
10 changes: 8 additions & 2 deletions cspell.config.js
Original file line number Diff line number Diff line change
@@ -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: [],
});
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
122 changes: 61 additions & 61 deletions packages/prettier-config/src/command.ts
Original file line number Diff line number Diff line change
@@ -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,
};
16 changes: 8 additions & 8 deletions src/command-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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'
Expand All @@ -90,15 +90,15 @@ 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;
printConfig?: PrintConfigCommand;
}

// Exported for aggregation later
export interface CommandDefinition {
export type CommandDefinition = {
commands: Commands;
description: string;
logColor: ChalkColor;
Expand Down Expand Up @@ -255,7 +255,7 @@ export async function executeCommands(
verbose?: boolean,
showSummary?: boolean,
): Promise<number> {
const exitCodes: { exitCode: number; name: string }[] = [];
const exitCodes: Array<{ exitCode: number; name: string }> = [];

for (const command of commands) {
const exitCode = await (isCommandFunction(command)
Expand Down Expand Up @@ -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`);
Expand All @@ -637,7 +637,7 @@ export function getCosmiconfigCommand(configName: string): CommandFunction {
};
}

type NullToUndefined<T> = T extends null ? undefined : T;
type NullToUndefined<T> = T extends undefined ? undefined : T;

/**
* Convenience wrapper to safely fetch a cosmiconfig result.
Expand Down
1 change: 1 addition & 0 deletions src/json-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function stringify(object: any): string {
}),
{
colors: {
// eslint-disable-next-line ts/naming-convention
BRACKET: 'gray',
},
},
Expand Down
1 change: 1 addition & 0 deletions src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function suppressNodeWarnings(): void {
);
}

// @ts-expect-error - Missing types
return originalEmit.call(this, ...args);
} as typeof process.emit;
}
Expand Down
1 change: 1 addition & 0 deletions src/stream-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down

0 comments on commit e272b6f

Please sign in to comment.