-
Notifications
You must be signed in to change notification settings - Fork 59
refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check #2611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check #2611
Changes from 1 commit
dcc6eea
a237354
c7a1a84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,18 +88,6 @@ export function main( | |
|
|
||
| Log.info(green(` Current number of cycles: ${yellow(cycles.length.toString())}`)); | ||
|
|
||
| if (goldenFile && approve) { | ||
| writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); | ||
| Log.info(green('✔ Updated golden file.')); | ||
| return 0; | ||
| } else if (!goldenFile) { | ||
| Log.error(`x Circular dependency goldens are not allowed.`); | ||
| return 1; | ||
| } else if (!existsSync(goldenFile)) { | ||
| Log.error(`x Could not find golden file: ${goldenFile}`); | ||
| return 1; | ||
| } | ||
|
|
||
| const warningsCount = analyzer.unresolvedFiles.size + analyzer.unresolvedModules.size; | ||
|
|
||
| // By default, warnings for unresolved files or modules are not printed. This is because | ||
|
|
@@ -119,6 +107,34 @@ export function main( | |
| Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`); | ||
| } | ||
|
|
||
| if (goldenFile) { | ||
| // Golden file exists | ||
| if (approve) { | ||
| writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); | ||
| Log.info(green('✔ Updated golden file.')); | ||
| return 0; | ||
| } | ||
| if (!existsSync(goldenFile)) { | ||
| Log.error(`x Could not find golden file: ${goldenFile}`); | ||
| return 1; | ||
| } | ||
| } else { | ||
| if (approve) { | ||
| Log.error( | ||
| `x Cannot approve circular depdencies within this repository as no golden file exists.`, | ||
| ); | ||
| return 1; | ||
| } | ||
| // No golden file exists | ||
josephperrott marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (cycles.length > 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be outside? What if there is a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is within the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But shouldn't this fail? if there are cycles and
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it will happen automatically below with the comparison. That's the thing I missed. Very confusing :D
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the case where there is no golden file, and there are cycles here. This fails as it returns a For cases where there is a golden file to do the comparison to later, we check the specifics. |
||
| Log.error(`x No circular dependencies are allow within this repository.`); | ||
| return 1; | ||
| } | ||
|
|
||
| Log.info(green('✔ No circular dependencies found in this repository.')); | ||
| return 0; | ||
| } | ||
|
|
||
| const expected = goldenFile ? (JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden) : []; | ||
| const {fixedCircularDeps, newCircularDeps} = compareGoldens(actual, expected); | ||
| const isMatching = fixedCircularDeps.length === 0 && newCircularDeps.length === 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIt: I'd prefer if we guard by
approveat the first condition, as that would make it easier to follow IMO.(maybe that's just me though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that going based on the golden makes sense because its essentially shortcutting the rest of the logic below when no golden exists.
I reordered some things that I think end sup making it a bit better, let me know what you think.