fix: code quality improvements and runValidation tests#22
Open
fix: code quality improvements and runValidation tests#22
Conversation
Bugs fixed: - classifyTarget: handle EvalSymlinks error instead of silently discarding it (fall back to raw source path) - validate: replace os.Exit inside RunE with ExitError type so Execute() controls the exit code — fixes testability and double-print - All unchecked fmt.Fprintf calls now use _, _ = (errcheck) Design: - loadConfig: use DefaultKnotfilePath (~/.dotfiles/Knotfile, $KNOT_DIR) instead of upward CWD walk (FindConfigFile) - config: add KnownOS, DefaultDir, DefaultKnotfilePath, KnotfileName, EnvKnotDir; document ~/path resolution asymmetry in Load - resolver: document that ShouldIgnore matches base name only Code quality: - Execute: set SilenceErrors=true, print errors once with "Error:" prefix - --config flag description now mentions $HOME/.dotfiles/Knotfile and KNOT_DIR - resolvePackageArgs: remove duplicate package-name validation (linker already validates); sort --all output alphabetically - validate: extract runValidation() for testability; use config.KnownOS; sort packages alphabetically; set SilenceUsage=true - Status: sort package names alphabetically before printing https://claude.ai/code/session_018s5iF8MKZAobUjAuR1AHJ4
14 cases covering all validation paths: - empty packages → warning - valid package (absolute + ~/... source) → clean - missing source / target / both fields - source is a file not a directory - source path does not exist - known and unknown condition.os values - nil and empty condition - valid and invalid ignore glob patterns - ~/... home expansion via the home argument - alphabetical sort of error output across packages https://claude.ai/code/session_018s5iF8MKZAobUjAuR1AHJ4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
classifyTargetsilently discarded afilepath.EvalSymlinkserror — now falls back to the raw source pathvalidatecalledos.ExitinsideRunE, bypassing Cobra's error handling — replaced with anExitErrortype that carries the exit code out toExecute()fmt.Fprintfcalls now use_, _ =(errcheck)loadConfignow usesconfig.DefaultKnotfilePath(~/.dotfiles/Knotfile, overridable via$KNOT_DIR) instead of walking upward from CWDconfigpackage gainsKnownOS,DefaultDir,DefaultKnotfilePath,KnotfileName,EnvKnotDir;Loaddocuments the~/path-resolution asymmetryExecute()setsSilenceErrors = trueand prints errors once with anError:prefix (fixes double-print)--configflag description now mentions the default path andKNOT_DIRresolvePackageArgssimplified — duplicate package-name validation removed (linker already validates);--alloutput is now sorted alphabeticallyvalidaterefactored —runValidation()extracted for testability, usesconfig.KnownOS, sorts packages alphabetically, setsSilenceUsage = trueStatus()sorts package names before printingShouldIgnoredoc comment clarifies base-name-only matchingrunValidationcovering all validation pathsTest plan
go test ./...passesgolangci-lint run ./...reports 0 issuesknot statusoutput is alphabetically sortedknot validateexits 2 on warnings-only, 1 on errors, 0 on cleanknot tie unknown-pkgprintsError: unknown packageexactly onceKNOT_DIR=/tmp/dots knot statusreads/tmp/dots/Knotfileknot --config /path/to/Knotfile tie pkgstill workshttps://claude.ai/code/session_018s5iF8MKZAobUjAuR1AHJ4
Generated by Claude Code