Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Preserve pedantic include in analysis_options.yaml #11

Merged
merged 7 commits into from
Feb 27, 2019

Conversation

robbecker-wf
Copy link
Member

Overview

Fixes #7
If an analysis options YAML has an include key it should be preserved in the output yaml file.
Some internal methods were modified to ease testing the update functionality

Testing

  • CI passes

@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

final YamlMap currentAnalysisOptions =
loadAnalysisOptions(renameDeprecatedFilename: true);
final String currentAnalysisOptionsString = loadAnalysisOptionsAsString();
Future<String> updateAnalysisOption(YamlMap abideYaml,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the return type to return the analysis options file contents as a String. This aids in testing since you don't actually have to do filesystem operations. Before it would assume it would read and write the file to the current directory. While that was convenient, it made running tests difficult. Changing the working directory changes it for the whole process. That meant tests couldn't be run concurrently. Instead, I changed the functions to return the content and have a flag on whether or not to actually write to the filesystem and the path to the file to read from.

if (currentInclude != null && currentInclude.isNotEmpty) {
sb.writeln('include: $currentInclude');
}
sb.write('''
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the meat of this PR. Store the existing include if it is there, and emit it back to the file if present.

currentAnalysisOptionsString: currentAnalysisOptionsString);
lintErrorCounts = await getLintErrorCounts(abideYaml: abideYaml);
}
return writeAnalyisOptionsFile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda weird that it runs this function twice. Would it make more sense to return an object that reflects the changes to be made and then have a separate function that writes them to disk? That would also keep the filesystem code paths separate from the more testable non-filesystem code paths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It always ran twice before. The getLintErrorCounts runs the command line dart analyzer to get the number of lints for each rule. That tool needs the analysis options file written to disk. So the first run writes a file with ALL the rules enabled to collect counts for all the rules. Then the 2nd writes it with some commented out due to the recommendations or existing lints hit.
The change here was to not do the first run while testing because we're not writing to disk. (The writeToFile option is only for testing)

String finalOutput = sb.toString();
if (writeToFile) {
new File(analysisOptionsFilename).writeAsStringSync(finalOutput);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like just returning the value instead of optionally writing it might make the code cleaner. The actual file operation could be totally separate then, and it could even be tested on its own pretty easily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true it does feel weird to have a write to file option in a function named writeAnalysisOptions.

@robbecker-wf
Copy link
Member Author

@georgelesica-wf I changed some things up based on your suggestion. How's this look?

@georgelesica-wf
Copy link
Contributor

+1 lgtm

@robbecker-wf
Copy link
Member Author

@Workiva/release-management-pp

@rmconsole4-wk rmconsole4-wk merged commit af10c68 into master Feb 27, 2019
@rmconsole4-wk rmconsole4-wk deleted the preserve_includes branch February 27, 2019 22:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants