1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-07 22:04:21 +00:00

refactor: improve code quality and test coverage

This commit addresses several code quality issues identified in the
recent bash 3.2 compatibility fixes:

1. Remove redundant array length check in is_whitelisted()
   - The second check for array length > 0 is unnecessary after
     already checking for length == 0

2. Clean up commented dangerous cleanup code in dev.sh
   - Replace commented-out code with clear documentation
   - Add explicit notes explaining why certain paths are excluded
   - Improves maintainability by preventing confusion

3. Enhance test coverage for excluded paths
   - Add tests to verify Mix archives are NOT cleaned
   - Add tests to verify Stack programs are NOT cleaned
   - Add tests to verify VS Code workspace storage is NOT cleaned
   - These tests ensure critical data remains protected

All changes pass ShellCheck, syntax validation, and formatting checks.
This commit is contained in:
Tw93
2026-01-12 10:07:42 +08:00
parent 35234ff194
commit 1a40875b80
3 changed files with 50 additions and 16 deletions

View File

@@ -256,24 +256,24 @@ clean_sqlite_temp_files() {
return 0
}
# Elixir/Erlang ecosystem.
# Note: ~/.mix/archives contains installed Mix tools - excluded from cleanup
clean_dev_elixir() {
# safe_clean ~/.mix/archives/* "Mix cache"
safe_clean ~/.hex/cache/* "Hex cache"
}
# Haskell ecosystem.
# Note: ~/.stack/programs contains Stack-installed GHC compilers - excluded from cleanup
clean_dev_haskell() {
safe_clean ~/.cabal/packages/* "Cabal install cache"
# safe_clean ~/.stack/programs/* "Stack cache"
}
# OCaml ecosystem.
clean_dev_ocaml() {
safe_clean ~/.opam/download-cache/* "Opam cache"
}
# Editor caches.
# Note: ~/Library/Application Support/Code/User/workspaceStorage contains workspace settings - excluded from cleanup
clean_dev_editors() {
safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data"
safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data"
# safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage"
safe_clean ~/Library/Caches/Zed/* "Zed cache"
}
# Main developer tools cleanup sequence.

View File

@@ -248,15 +248,13 @@ is_whitelisted() {
return 1
fi
if [[ ${#CURRENT_WHITELIST_PATTERNS[@]} -gt 0 ]]; then
for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do
local existing_expanded="${existing/#\~/$HOME}"
# Only use exact string match to prevent glob expansion security issues
if [[ "$check_pattern" == "$existing_expanded" ]]; then
return 0
fi
done
fi
for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do
local existing_expanded="${existing/#\~/$HOME}"
# Only use exact string match to prevent glob expansion security issues
if [[ "$check_pattern" == "$existing_expanded" ]]; then
return 0
fi
done
return 1
}