diff --git a/__tests__/testData/recursionStart/sub/dummyDoc.md b/__tests__/testData/recursionStart/sub/dummyDoc.md
index a56e6a6..b40a834 100644
--- a/__tests__/testData/recursionStart/sub/dummyDoc.md
+++ b/__tests__/testData/recursionStart/sub/dummyDoc.md
@@ -1,6 +1,7 @@
# Dummy Doc
This file dummyDoc.md is for unit tests in __tests__/ like e.g. fakeName.cpp or main.test.ts.
+The file main.ts shall be mentioned here and below.
All tags that do not exist should contain 'fake' to help the unit tests.
## Related files and folders
@@ -9,3 +10,4 @@ All tags that do not exist should contain 'fake' to help the unit tests.
- utils.ts
- script/
- __tests__/testData/taggedFolder/
+- script/
diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts
index 258c501..29c5176 100644
--- a/__tests__/utils.test.ts
+++ b/__tests__/utils.test.ts
@@ -3,10 +3,11 @@
*/
import {
+ assertNonNull,
getUrlToFile,
getUrlToChanges,
findFileByName,
- assertNonNull
+ uniqueFilter
} from '../src/utils'
import * as github from '@actions/github'
import { expect } from '@jest/globals'
@@ -132,4 +133,14 @@ describe('utils.ts context dependent', () => {
// Calling the function with this context should throw an error.
expect(() => getUrlToChanges(filePath)).toThrow()
})
+
+ it('uniqueFilter(): Test functionality', () => {
+ const noDuplicates = [0, 1, 2, 3, 4]
+ const noDuplicatesFiltered = noDuplicates.filter(uniqueFilter)
+ expect(noDuplicatesFiltered).toEqual(noDuplicates)
+
+ const duplicates = [0, 1, 2, 2, 3, 4, 2]
+ const duplicatesFiltered = duplicates.filter(uniqueFilter)
+ expect(duplicatesFiltered).toEqual(noDuplicates)
+ })
})
diff --git a/badges/coverage.svg b/badges/coverage.svg
index b66aca4..1e3bde8 100644
--- a/badges/coverage.svg
+++ b/badges/coverage.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index 4233535..3d530e5 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -28943,7 +28943,7 @@ const path = __importStar(__nccwpck_require__(1017));
const utils_1 = __nccwpck_require__(1314);
/**
* Checks if file extensions start with a '.' and then only consist of letters and numbers.
- * @param extensions Array of extensions to check.
+ * @param extension The extensions to check.
* @return True if extension matches the sane pattern.
*/
function extensionsIsSane(extension) {
@@ -28963,7 +28963,7 @@ function extractFileTags(fileContent, srcFileExtensions) {
.map(f => f.substring(1, f.length))
.join('|');
const srcFileRegex = new RegExp(`[^/\\s]+\\.(${extensionsCombined})\\b`, 'g');
- return Array.from(fileContent.match(srcFileRegex) || []);
+ return Array.from(fileContent.match(srcFileRegex)?.filter(utils_1.uniqueFilter) || []);
}
/**
* Get the list of directory tags in the given file.
@@ -28979,7 +28979,8 @@ function extractDirectoryTags(fileContent) {
// If there is nothing after the tag default to undefined and thus to []
// Else match anything that ends on a '/'
// \S = anything but whitespace
- ?.match(/[\S]+\/(?!\S)/g) || []);
+ ?.match(/[\S]+\/(?!\S)/g)
+ ?.filter(utils_1.uniqueFilter) || []);
}
/**
* Checks that if any tagged source file was changed, its corresponding doc file was changed too.
@@ -29008,7 +29009,7 @@ function checkDocumentation(userdocs, changes, docFileExtensions, srcFileExtensi
// Append the content of all directories to the tags.
for (const tag of directoryTags) {
if (!fs.existsSync(tag)) {
- // If the dir can not be found it's an unknown tag.
+ // If the dir can not be found it's an unknown tag. Duplicates here are intentional.
unknownTagsLocal.push(tag);
}
else {
@@ -29025,6 +29026,8 @@ function checkDocumentation(userdocs, changes, docFileExtensions, srcFileExtensi
directoryTags.concat(dirs);
}
}
+ // Make sure all tags are only listed once
+ fileTags = fileTags.filter(utils_1.uniqueFilter);
// Analyze all file tags for doc changes.
for (const tag of fileTags) {
// If any tag appears in the changes, the doc file also has to be in the changes.
@@ -29303,11 +29306,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.getUrlToChanges = exports.getUrlToFile = exports.findFileByName = exports.assertNonNull = void 0;
+exports.getUrlToChanges = exports.getUrlToFile = exports.findFileByName = exports.assertNonNull = exports.uniqueFilter = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
const github = __importStar(__nccwpck_require__(5438));
const crypto_1 = __importDefault(__nccwpck_require__(6113));
+/**
+ * Filter function to remove duplicates in an array.
+ * @param value Value to check for duplication
+ * @param index Known index of first occurrence of value.
+ * @param container Array to filter.
+ */
+function uniqueFilter(value, index, container) {
+ return container.indexOf(value) === index;
+}
+exports.uniqueFilter = uniqueFilter;
/**
* Retrieves the value of an optional type.
* If value is undefined or null an Error is thrown.
diff --git a/src/main.ts b/src/main.ts
index 1a52a77..fa5f20b 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -6,12 +6,13 @@ import {
assertNonNull,
findFileByName,
getUrlToChanges,
- getUrlToFile
+ getUrlToFile,
+ uniqueFilter
} from './utils'
/**
* Checks if file extensions start with a '.' and then only consist of letters and numbers.
- * @param extensions Array of extensions to check.
+ * @param extension The extensions to check.
* @return True if extension matches the sane pattern.
*/
function extensionsIsSane(extension: string): boolean {
@@ -35,7 +36,7 @@ function extractFileTags(
.map(f => f.substring(1, f.length))
.join('|')
const srcFileRegex = new RegExp(`[^/\\s]+\\.(${extensionsCombined})\\b`, 'g')
- return Array.from(fileContent.match(srcFileRegex) || [])
+ return Array.from(fileContent.match(srcFileRegex)?.filter(uniqueFilter) || [])
}
/**
@@ -53,7 +54,8 @@ function extractDirectoryTags(fileContent: string): string[] {
// If there is nothing after the tag default to undefined and thus to []
// Else match anything that ends on a '/'
// \S = anything but whitespace
- ?.match(/[\S]+\/(?!\S)/g) || []
+ ?.match(/[\S]+\/(?!\S)/g)
+ ?.filter(uniqueFilter) || []
)
}
@@ -94,7 +96,7 @@ function checkDocumentation(
// Append the content of all directories to the tags.
for (const tag of directoryTags) {
if (!fs.existsSync(tag)) {
- // If the dir can not be found it's an unknown tag.
+ // If the dir can not be found it's an unknown tag. Duplicates here are intentional.
unknownTagsLocal.push(tag)
} else {
// Read the content of the directory and split it in files and dirs.
@@ -113,6 +115,9 @@ function checkDocumentation(
}
}
+ // Make sure all tags are only listed once
+ fileTags = fileTags.filter(uniqueFilter)
+
// Analyze all file tags for doc changes.
for (const tag of fileTags) {
// If any tag appears in the changes, the doc file also has to be in the changes.
diff --git a/src/utils.ts b/src/utils.ts
index 053bb47..cb92dac 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -3,6 +3,20 @@ import * as path from 'path'
import * as github from '@actions/github'
import crypto from 'crypto'
+/**
+ * Filter function to remove duplicates in an array.
+ * @param value Value to check for duplication
+ * @param index Known index of first occurrence of value.
+ * @param container Array to filter.
+ */
+export function uniqueFilter(
+ value: T,
+ index: number,
+ container: T[]
+): boolean {
+ return container.indexOf(value) === index
+}
+
/**
* Retrieves the value of an optional type.
* If value is undefined or null an Error is thrown.