fix(core): warn for invalid eslintrc
This commit is contained in:
parent
d6b2201a21
commit
4d4749c9b1
@ -50,4 +50,9 @@ describe('Eslintrc Migration', () => {
|
||||
const eslintrc = readJsonInTree(result, 'project2/.eslintrc');
|
||||
expect(eslintrc.parserOptions.project).toEqual('./tsconfig.json');
|
||||
});
|
||||
|
||||
it('should not fail for a non-json eslintrc', async () => {
|
||||
tree.overwrite('project2/.eslintrc', 'not-json');
|
||||
await runMigration('migrate-eslintrc-tsconfig', {}, tree);
|
||||
});
|
||||
});
|
||||
|
||||
@ -10,21 +10,30 @@ export default function (schema: any): Rule {
|
||||
return;
|
||||
}
|
||||
|
||||
return updateJsonInTree(file, (json) => {
|
||||
const tsconfig = json?.parserOptions?.project;
|
||||
if (tsconfig) {
|
||||
const tsconfigPath = join(dirname(file), tsconfig);
|
||||
if (tsconfigPath === 'tsconfig.json') {
|
||||
json.parserOptions.project = json.parserOptions.project.replace(
|
||||
/tsconfig.json$/,
|
||||
'tsconfig.base.json'
|
||||
);
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return json;
|
||||
return (host, context) => {
|
||||
try {
|
||||
updateJsonInTree(file, (json) => {
|
||||
const tsconfig = json?.parserOptions?.project;
|
||||
if (tsconfig) {
|
||||
const tsconfigPath = join(dirname(file), tsconfig);
|
||||
if (tsconfigPath === 'tsconfig.json') {
|
||||
json.parserOptions.project = json.parserOptions.project.replace(
|
||||
/tsconfig.json$/,
|
||||
'tsconfig.base.json'
|
||||
);
|
||||
}
|
||||
return json;
|
||||
} else {
|
||||
return json;
|
||||
}
|
||||
})(host, context);
|
||||
} catch (e) {
|
||||
context.logger.warn(
|
||||
`${file} could not be migrated because it is not valid JSON`
|
||||
);
|
||||
context.logger.error(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}),
|
||||
formatFiles(),
|
||||
]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user