From d9ba42f26b3b038a91068135604f779c357c3a05 Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 12 Dec 2024 16:00:39 +0100 Subject: [PATCH] Don't check licenses of generated files --- pkgs/firehose/lib/src/health/license.dart | 12 ++++++++++-- .../test_repo/pkgs/package2/lib/anotherLib.dart | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkgs/firehose/lib/src/health/license.dart b/pkgs/firehose/lib/src/health/license.dart index 18a1e433..8492ee46 100644 --- a/pkgs/firehose/lib/src/health/license.dart +++ b/pkgs/firehose/lib/src/health/license.dart @@ -26,8 +26,8 @@ Future> 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; } @@ -40,3 +40,11 @@ Future> 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)'); diff --git a/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart b/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart index af52fa18..5bee8739 100644 --- a/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart +++ b/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart @@ -1,3 +1,6 @@ +// SOME COMMENT +// THIS IS A GENERATED FILE + int calculateUnused() { return 6 * 7; }