Skip to content

Commit

Permalink
CLI: throw and handle error in eslint-plugin automigrate
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Nov 12, 2021
1 parent 05e426e commit b177b3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 8 additions & 12 deletions lib/cli/src/automigrate/fixes/eslint-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,14 @@ export const eslintPlugin: Fix<EslintPluginRunOptions> = {
if (!dryRun) packageManager.addDependencies({ installAsDevDependencies: true }, deps);

if (!dryRun && unsupportedExtension) {
logger.warn(
dedent(`
⚠️ The plugin was successfuly installed but failed to configure.
Found an .eslintrc config file with an unsupported automigration format: ${unsupportedExtension}.
Supported formats for automigration are: ${SUPPORTED_ESLINT_EXTENSIONS.join(', ')}.
Please refer to https://github.com/storybookjs/eslint-plugin-storybook#usage to finish setting up the plugin manually.
`)
);

return;
throw new Error(dedent`
⚠️ The plugin was successfuly installed but failed to configure.
Found an .eslintrc config file with an unsupported automigration format: ${unsupportedExtension}.
Supported formats for automigration are: ${SUPPORTED_ESLINT_EXTENSIONS.join(', ')}.
Please refer to https://github.com/storybookjs/eslint-plugin-storybook#usage to finish setting up the plugin manually.
`);
}

const eslint = await readConfig(eslintFile);
Expand Down
10 changes: 8 additions & 2 deletions lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ export const automigrate = async ({ fixId, dryRun, yes }: FixOptions = {}) => {
]);

if (runAnswer.fix) {
await f.run({ result, packageManager, dryRun });
logger.info(`✅ fixed ${chalk.cyan(f.id)}`);
try {
await f.run({ result, packageManager, dryRun });
logger.info(`✅ fixed ${chalk.cyan(f.id)}`);
} catch (error) {
logger.info(`❌ error in ${chalk.cyan(f.id)}:`);
logger.info(error.message);
logger.info();
}
} else {
logger.info(`Skipping the ${chalk.cyan(f.id)} fix.`);
logger.info();
Expand Down

0 comments on commit b177b3e

Please sign in to comment.