v2.1.3: Code quality, documentation, and test improvements - #16
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR is a v2.1.3 maintenance release focused on documentation, test clarity, and a backwards-compatible rename of the sentinel error variable. It renames Error to ErrorUnableToCast (keeping Error as a deprecated alias), adds doc comments to previously undocumented symbols, fixes several doc inaccuracies, renames example functions from snake_case suffixes to camelCase so godoc surfaces them, and adds new godoc examples.
Changes:
- Rename sentinel error
Error→ErrorUnableToCast(with deprecated alias) and update all test assertions. - Documentation fixes/additions across
to.go,to.type.go,to.struct.go,to.slice.go,util.reflect.go, including correcting the global/local flag lists (FORMAT/DECODE). - Rename example functions and add new godoc examples (map/struct conversions, duplicate-key, strict mode, private fields).
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| to.type.go | Adds ErrorUnableToCast, deprecated Error alias, doc comments for sentinel/format strings, ops/Tmap/parseOps doc fixes. |
| to.go | Doc grammar fixes for To/ToE. |
| to.struct.go | Doc clarifies *struct source; switches to ErrorUnableToCast. |
| to.slice.go | Rewritten toSlice doc comment. |
| util.reflect.go | Adds dispatch order doc to castToType. |
| test.examples_test.go | Renames examples to camelCase, adds new examples, removes commented-out block. |
| CHANGELOG.md | Adds v2.1.3 entry. |
| to.*_test.go (many) | Mechanical rename of cast.Error → cast.ErrorUnableToCast in assertions and messages, minor gofmt alignment. |
| test.panic_test.go, test.options_test.go | Same rename in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Added
TmaptypeErrorSignedToUnsigned,ErrorInvalidOption,ErrorStrErrorCastingFunc,ErrorStrUnableToCast(clarifying the string vars are format strings, not error values)castToType— all 8 dispatch cases documentedExampleTo_map,ExampleTo_struct,ExampleToE_mapDuplicateKeyError,ExampleToE_structNested,ExampleToE_structStrict,ExampleToE_mapToPrivateStruct.Changed
ErrortoErrorUnableToCast.Erroris retained as a deprecated alias with a// Deprecated:godoc annotation for backward compatibility.snake_casetocamelCase(e.g.ExampleToE_mapFromMap) so all examples appear in godoc. Suffixes containing underscores are silently dropped by godoc.Fixed
ToEdoc referenced non-existent typeOps(correct type isOp) and contained double word "the the" — corrected.ToStructEdoc omitted*structas a valid source type — corrected.toSlicedoc was circular and meaningless — rewritten.ops.Globaldoc omittedFORMATfrom the global flag list andDECODEfrom the local flag list — corrected.parseOpsdoc omittedFORMATandDECODEfrom its description of preserved values — corrected.opsstruct doc incorrectly stated all non-default flags are pre-parsed tobool;FORMATandDECODEare stored as strings — corrected.TestPointerDerefLoop"pointer-to-interface" sub-test usederrors.Newwhose concrete pointer type is opaque; replaced with a localptrReceiverErrortype that hasError()on*Tonly, making the pointer-receiver guard explicit and self-documenting.