Skip to content

Commit

Permalink
fix(linter): do not break migration if eslint file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 22, 2023
1 parent 231a998 commit d019de0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/linter/src/generators/init/init-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ export function migrateConfigToMonorepoStyle(
projects.forEach((project) => {
const lintTarget = findLintTarget(project);
if (lintTarget) {
const projectEslintPath = joinPathFragments(
project.root,
lintTarget.options.eslintConfig || findEslintFile(tree, project.root)
);
migrateEslintFile(projectEslintPath, tree);
const eslintFile =
lintTarget.options.eslintConfig || findEslintFile(tree, project.root);
if (eslintFile) {
const projectEslintPath = joinPathFragments(project.root, eslintFile);
migrateEslintFile(projectEslintPath, tree);
}
}
});
}

export function findLintTarget(
project: ProjectConfiguration
): TargetConfiguration {
return Object.entries(project.targets ?? {}).find(
([name, target]) =>
name === 'lint' ||
return Object.values(project.targets ?? {}).find(
(target) =>
target.executor === '@nx/linter:eslint' ||
target.executor === '@nrwl/linter:eslint'
)?.[1];
);
}

function migrateEslintFile(projectEslintPath: string, tree: Tree) {
Expand Down Expand Up @@ -99,6 +99,6 @@ function migrateEslintFile(projectEslintPath: string, tree: Tree) {
console.warn('YAML eslint config is not supported yet for migration');
}
if (projectEslintPath.endsWith('.js') || projectEslintPath.endsWith('.cjs')) {
console.warn('YAML eslint config is not supported yet for migration');
console.warn('JS eslint config is not supported yet for migration');
}
}
4 changes: 4 additions & 0 deletions packages/linter/src/generators/utils/eslint-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ export const eslintConfigFileWhitelist = [
];

export const baseEsLintConfigFile = '.eslintrc.base.json';
export const baseEsLintFlatConfigFile = 'eslint.base.config.js';

export function findEslintFile(tree: Tree, projectRoot = ''): string | null {
if (projectRoot === '' && tree.exists(baseEsLintConfigFile)) {
return baseEsLintConfigFile;
}
if (projectRoot === '' && tree.exists(baseEsLintFlatConfigFile)) {
return baseEsLintFlatConfigFile;
}
for (const file of eslintConfigFileWhitelist) {
if (tree.exists(joinPathFragments(projectRoot, file))) {
return file;
Expand Down

0 comments on commit d019de0

Please sign in to comment.