Skip to content

Commit

Permalink
Don't check licenses of generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Dec 12, 2024
1 parent b25118a commit d9ba42f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkgs/firehose/lib/src/health/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Future<List<String>> getFilesWithoutLicenses(
if (ignoredFiles.none((glob) =>
glob.matches(path.relative(file.path, from: repositoryDir.path)))) {
var fileContents = File(file.path).readAsStringSync();
var fileContainsCopyright = fileContents.contains('// Copyright (c)');
if (!fileContainsCopyright) {
if (!fileIsGenerated(fileContents) &&
!fileContainsCopyright(fileContents)) {
print(relativePath);
return relativePath;
}
Expand All @@ -40,3 +40,11 @@ Future<List<String>> getFilesWithoutLicenses(
Done, found ${filesWithoutLicenses.length} files without license headers''');
return filesWithoutLicenses;
}

bool fileIsGenerated(String fileContents) => fileContents
.split('\n')
.takeWhile((line) => line.startsWith('//') || line.isEmpty)
.any((line) => line.toLowerCase().contains('generate'));

bool fileContainsCopyright(String fileContents) =>
fileContents.contains('// Copyright (c)');
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SOME COMMENT
// THIS IS A GENERATED FILE

int calculateUnused() {
return 6 * 7;
}

0 comments on commit d9ba42f

Please sign in to comment.