Skip to content

Commit 622dd4c

Browse files
committed
improved handling for extensions that are not configured
1 parent 1bde45a commit 622dd4c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tool/lib/license_utils.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,13 @@ class LicenseHeader {
298298
if (!config.shouldExclude(file)) {
299299
includedPathsList.add(file.path);
300300
final extension = p.extension(file.path);
301-
final removeIndices = config.getRemoveIndicesForExtension(extension);
302301
final addIndex = config.getAddIndexForExtension(extension);
302+
if (addIndex == -1) {
303+
// skip if add index doesn't exist for extension
304+
continue;
305+
}
303306
final replacementLicenseText = config.addLicenses[addIndex];
307+
final removeIndices = config.getRemoveIndicesForExtension(extension);
304308
for (final removeIndex in removeIndices) {
305309
final existingLicenseText = config.removeLicenses[removeIndex];
306310
final fileLength = file.lengthSync();

tool/test/license_utils_test.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ late File testFile9;
5252
late File testFile10;
5353
late File excludeFile1;
5454
late File excludeFile2;
55+
late File skippedFile;
5556

5657
void main() {
5758
group('config file tests', () {
@@ -362,7 +363,7 @@ text that should be added to the file. */''',
362363

363364
final includedPaths = results.includedPaths;
364365
expect(includedPaths, isNotNull);
365-
expect(includedPaths.length, equals(7));
366+
expect(includedPaths.length, equals(8));
366367
// Order is not guaranteed
367368
expect(includedPaths.contains(testFile1.path), true);
368369
expect(contentsBeforeUpdate, isNot(equals(contentsAfterUpdate)));
@@ -372,6 +373,7 @@ text that should be added to the file. */''',
372373
expect(includedPaths.contains(testFile8.path), true);
373374
expect(includedPaths.contains(testFile9.path), true);
374375
expect(includedPaths.contains(testFile10.path), true);
376+
expect(includedPaths.contains(skippedFile.path), true);
375377

376378
final updatedPaths = results.updatedPaths;
377379
expect(updatedPaths, isNotNull);
@@ -384,6 +386,7 @@ text that should be added to the file. */''',
384386
expect(updatedPaths.contains(testFile8.path), true);
385387
expect(updatedPaths.contains(testFile9.path), true);
386388
expect(updatedPaths.contains(testFile10.path), true);
389+
expect(updatedPaths.contains(skippedFile.path), false);
387390
});
388391

389392
test('license headers bulk update can be dry run', () async {
@@ -550,6 +553,7 @@ update_paths:
550553
/// repo_root/
551554
/// test1.ext1
552555
/// test2.ext2
556+
/// test.skip
553557
/// .hidden/
554558
/// test3.ext1
555559
/// sub_dir1/
@@ -584,6 +588,10 @@ Future<void> _setupTestDirectoryStructure() async {
584588
..createSync(recursive: true);
585589
testFile2.writeAsStringSync(licenseText3 + extraText, flush: true);
586590

591+
skippedFile = File(p.join(repoRoot.path, 'test.skip'))
592+
..createSync(recursive: true);
593+
skippedFile.writeAsStringSync(extraText, flush: true);
594+
587595
// Setup /repo_root/.hidden directory structure
588596
Directory(p.join(repoRoot.path, '.hidden')).createSync(recursive: true);
589597

0 commit comments

Comments
 (0)