Skip to content

Commit

Permalink
Add ability to specify a custom message for reignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Heiner committed Apr 27, 2022
1 parent 8f7828d commit 806b8c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/ts-migrate-plugins/src/plugins/ts-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { createValidate, Properties } from '../utils/validateOptions';
type Options = {
useTsIgnore?: boolean;
messageLimit?: number;
messagePrefix?: string;
};

const optionProperties: Properties = {
useTsIgnore: { type: 'boolean' },
messageLimit: { type: 'number' },
messagePrefix: { type: 'string' },
};

const tsIgnorePlugin: Plugin<Options> = {
Expand Down Expand Up @@ -55,7 +57,8 @@ function getTextWithIgnores(
const message = messageLines[messageLines.length - 1];
const errorExpression = options.useTsIgnore ? 'ts-ignore' : `ts-expect-error`;
const messageLimit = options.messageLimit ?? TS_IGNORE_MESSAGE_LIMIT;
const tsIgnoreCommentText = `@${errorExpression} ts-migrate(${code}) FIXME: ${
const messagePrefixInComment = options.messagePrefix ? ` ${options.messagePrefix}` : '';
const tsIgnoreCommentText = `@${errorExpression}${messagePrefixInComment} ts-migrate(${code}) FIXME: ${
message.length > messageLimit
? `${message.slice(0, messageLimit)}... Remove this comment to see the full error message`
: message
Expand Down
16 changes: 14 additions & 2 deletions packages/ts-migrate/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@ yargs
.command(
'reignore <folder>',
'Re-run ts-ignore on a project',
(cmd) => cmd.positional('folder', { type: 'string' }).require(['folder']),
(cmd) =>
cmd
.option('p', {
alias: 'messagePrefix',
default: '',
type: 'string',
describe:
'A message to add to the ts-expect-error or ts-ignore comments that are inserted.',
})
.positional('folder', { type: 'string' })
.require(['folder']),
async (args) => {
const rootDir = path.resolve(process.cwd(), args.folder);

Expand Down Expand Up @@ -218,7 +228,9 @@ yargs

const config = new MigrateConfig()
.addPlugin(withChangeTracking(stripTSIgnorePlugin), {})
.addPlugin(withChangeTracking(tsIgnorePlugin), {})
.addPlugin(withChangeTracking(tsIgnorePlugin), {
messagePrefix: args.messagePrefix,
})
.addPlugin(eslintFixChangedPlugin, {});

const exitCode = await migrate({ rootDir, config });
Expand Down

0 comments on commit 806b8c8

Please sign in to comment.