Update find-unused-settings script (#34252)
* Move more tests over to vitest * Add exception for test_setting * Update find-unused-settings script To not consider usage in tests as real usage * Remove legacy font settings They have been being migrated for over 2 years at this point and are flagged by the script as unused * Re-add test
This commit is contained in:
Regular → Executable
+12
-10
@@ -22,10 +22,15 @@ const ROOT = path.resolve(__dirname, "..");
|
||||
const SETTINGS_DIR = path.join(ROOT, "apps/web/src/settings");
|
||||
const SETTINGS_FILE = path.join(SETTINGS_DIR, "Settings.tsx");
|
||||
|
||||
// Only the settings *definitions* directory should be excluded from the usage search -
|
||||
// there are plenty of other directories literally named "settings" (e.g.
|
||||
// apps/web/src/components/views/settings/) which hold real usages and must stay included.
|
||||
const SETTINGS_DIR_RELATIVE = path.relative(ROOT, SETTINGS_DIR);
|
||||
const EXCLUDE_GLOBS = [
|
||||
// Only the settings *definitions* directory should be excluded from the usage search -
|
||||
// there are plenty of other directories literally named "settings" (e.g.
|
||||
// apps/web/src/components/views/settings/) which hold real usages and must stay included.
|
||||
"apps/web/src/settings/**",
|
||||
"*/*/test/**",
|
||||
"*-test.*",
|
||||
"*.test.*",
|
||||
].map((pattern) => path.relative(ROOT, pattern));
|
||||
|
||||
// See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
|
||||
const SETTINGS_FILE_RELATIVE = path.relative(ROOT, SETTINGS_FILE);
|
||||
@@ -151,12 +156,9 @@ function findControllerText(settingValue: ts.Expression, sourceFile: ts.SourceFi
|
||||
*/
|
||||
function isUsedOutsideSettings(searchTerms: string[]): boolean {
|
||||
const patternArgs = searchTerms.flatMap((term) => ["-e", term]);
|
||||
const excludeArgs = EXCLUDE_GLOBS.map((term) => `:(exclude)${term}`);
|
||||
try {
|
||||
execFileSync(
|
||||
"git",
|
||||
["grep", "-F", "-q", ...patternArgs, "--", "apps", `:(exclude)${SETTINGS_DIR_RELATIVE}/**`],
|
||||
{ cwd: ROOT },
|
||||
);
|
||||
execFileSync("git", ["grep", "-F", "-q", ...patternArgs, "--", "apps", ...excludeArgs], { cwd: ROOT });
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (typeof (e as { status?: number }).status === "number") return false;
|
||||
@@ -205,7 +207,7 @@ function reportUnused(unused: DeclaredSetting[]): void {
|
||||
for (const { name, line } of unused) {
|
||||
console.error(` Settings.tsx:${line}: "${name}"`);
|
||||
if (process.env.GITHUB_ACTIONS === "true") {
|
||||
printAnnotation(line, `Setting "${name}" is declared but never used outside ${SETTINGS_DIR_RELATIVE}/`);
|
||||
printAnnotation(line, `Setting "${name}" is declared but never used outside ${EXCLUDE_GLOBS}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user