refactor(reference): remove redundant documentation classifiers (#17380)

This commit is contained in:
Vincent Koc
2026-12-06 12:29:36 +08:00
committed by GitHub
parent 7a12719fbe
commit d634b7c7f2
+16 -43
View File
@@ -151,31 +151,15 @@ const DOCUMENTATION_EXTENSIONS = new Set([
const DOCUMENTATION_FILENAMES = new Set([
"readme",
"readme.md",
"readme.markdown",
"readme.txt",
"changelog",
"changelog.md",
"changes.md",
"history.md",
"news.md",
"license",
"license.md",
"license.txt",
"copying",
"copying.md",
"authors",
"authors.md",
"contributing",
"contributing.md",
"code_of_conduct",
"code_of_conduct.md",
"security",
"security.md",
"support",
"support.md",
"faq",
"faq.md",
]);
const GENERATED_DIRECTORY_NAMES = new Set([
@@ -265,22 +249,21 @@ const DOCUMENTATION_DIRECTORY_NAMES = new Set([
]);
const filenameIsTest = (filename: string): boolean => {
const lower = filename.toLowerCase();
if (lower.includes(".test.") || lower.includes(".spec.")) return true;
if (lower.startsWith("test_") || lower.startsWith("spec_")) return true;
if (lower.endsWith("_test") || lower.endsWith("_spec")) return true;
const stem = basenameParts(lower).base;
if (filename.includes(".test.") || filename.includes(".spec.")) return true;
if (filename.startsWith("test_") || filename.startsWith("spec_")) return true;
if (filename.endsWith("_test") || filename.endsWith("_spec")) return true;
const stem = basenameParts(filename).base;
return stem.endsWith("_test") || stem.endsWith("_spec");
};
const filenameIsGenerated = (filename: string): boolean => {
const lower = filename.toLowerCase();
if (lower.endsWith(".min.js") || lower.endsWith(".min.css")) return true;
if (lower.endsWith(".map")) return true;
if (lower.endsWith(".lock")) return true;
if (lower.endsWith(".d.ts")) return true;
if (lower.endsWith(".d.mts")) return true;
if (lower.endsWith(".d.cts")) return true;
if (filename.endsWith(".min.js") || filename.endsWith(".min.css"))
return true;
if (filename.endsWith(".map")) return true;
if (filename.endsWith(".lock")) return true;
if (filename.endsWith(".d.ts")) return true;
if (filename.endsWith(".d.mts")) return true;
if (filename.endsWith(".d.cts")) return true;
return false;
};
@@ -300,11 +283,6 @@ const sourceExtension = (filename: string): string => {
: ext;
};
const basenameMatch = (filename: string, set: ReadonlySet<string>): boolean => {
const lower = filename.toLowerCase();
return set.has(lower);
};
const isPathUnderAny = (
parts: readonly string[],
names: ReadonlySet<string>,
@@ -367,11 +345,7 @@ export const classifyReferenceSourcePath = (
classifications.add("source");
}
if (classifications.size === 0) {
if (filename === "license" || filename === "copying")
classifications.add("documentation");
else classifications.add("unknown");
}
if (classifications.size === 0) classifications.add("unknown");
return [...classifications].sort();
};
@@ -398,15 +372,14 @@ const addFilenameClassifications = (
filename: string,
classifications: Set<ReferenceSourceClassification>,
): void => {
const extension = sourceExtension(filename).toLowerCase();
const extension = sourceExtension(filename);
if (filenameIsTest(filename)) classifications.add("test");
if (filenameIsGenerated(filename)) classifications.add("generated");
if (basenameMatch(filename, MANIFEST_FILENAMES))
classifications.add("manifest");
if (basenameMatch(filename, CONFIG_FILENAMES)) classifications.add("config");
if (MANIFEST_FILENAMES.has(filename)) classifications.add("manifest");
if (CONFIG_FILENAMES.has(filename)) classifications.add("config");
if (DOCUMENTATION_EXTENSIONS.has(extension))
classifications.add("documentation");
if (DOCUMENTATION_FILENAMES.has(filename.toLowerCase()))
if (DOCUMENTATION_FILENAMES.has(filename))
classifications.add("documentation");
if (CODE_LANGUAGE_BY_EXTENSION.has(extension)) classifications.add("source");
};