go-sprout / sprout

From sprig to sprout - Useful template functions for Go templates with steroids
https://sprout.atom.codes
MIT License
86 stars 4 forks source link

feat: safe funcs, follow go template standards and sprout conventions #65

Closed 42atomys closed 6 days ago

42atomys commented 2 weeks ago

Description

This pull request updates all signatures to follow Go template standards and Sprout conventions, and add the safe behavior for functions instead of must as discussed on #32

[!IMPORTANT] The signature changes do not introduce breaking changes. A deprecation notice will be displayed instead. Two types of warn :

  1. Warn of renamed function :
    WARN Template function `mustDateModify` is deprecated: please use `dateModify` instead
  2. Warn of signature changes:
    WARN Template function `without` is deprecated: 
    The signature of `without` has changed from `{{ without list 1 2 }}` to `{{ list | without 1 2 }}`,
    please update your code before next upgrade.
    This change will simplify the usage of the function and
    respect go/template conventions and allow usage of pipe (`|`).

[!NOTE] This will spam the logger but will inform and prevent any breaking changes in the code. The signature migrations are encapsulated by banners in the codebase to avoid missing them when we remove the old signatures.

Documentation are available here : https://docs.atom.codes/sprout/~/changes/1eETtqCYtVeEPVLnbGs0?r=W7cRL8cXHka2XCuOcvBs

Checklist

Additional Information

Registry Name Respect Function Signature Respect Pipe Syntax Notes
backward This registry are deprecated and cannot be migrated
checksum
conversion Deprecation of must functions
crypto This registry are deprecated and cannot be migrated
encoding Deprecation of must functions
env
_example
filesystem
maps Changes in signature parameters, Deprecation of must functions
numeric Changes in signature parameters, Deprecation of must functions
random
reflect Deprecation of must functions
regexp Deprecation of must functions
semver
slices Changes in signature parameters
std
strings
time Deprecation of must functions
uniqueid
42atomys commented 1 week ago

Actually I need to update documentation site with new signature and examples to prevent have deprecated example 🔢

42atomys commented 1 week ago

Documentation are updated : https://docs.atom.codes/sprout/~/changes/1eETtqCYtVeEPVLnbGs0?r=W7cRL8cXHka2XCuOcvBs

ccoVeille commented 1 week ago

You should consider running testifylint on your codebase.

You can enable it via golangci-lint

42atomys commented 1 week ago

hi @ccoVeille, review returns done, one discussion stay open to let you read and react : https://github.com/go-sprout/sprout/pull/65#discussion_r1744610362

Thanks for your time :)

codecov[bot] commented 6 days ago

Codecov Report

Attention: Patch coverage is 98.36957% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
registry/backward/functions.go 66.6% 3 Missing and 1 partial :warning:
registry/encoding/functions.go 89.1% 4 Missing :warning:
registry/random/functions.go 25.0% 2 Missing and 1 partial :warning:
registry/backward/backward.go 0.0% 1 Missing :warning:
Files with missing lines Coverage Δ
deprecated/deprecated.go 100.0% <100.0%> (ø)
error.go 100.0% <100.0%> (ø)
handler.go 100.0% <100.0%> (ø)
internal/runtime/safecall.go 100.0% <100.0%> (ø)
notice.go 100.0% <100.0%> (ø)
pesticide/rand_test_helpers.go 100.0% <100.0%> (ø)
pesticide/test_helpers.go 100.0% <100.0%> (ø)
registry/checksum/functions.go 100.0% <100.0%> (ø)
registry/conversion/conversion.go 92.0% <100.0%> (+2.0%) :arrow_up:
registry/conversion/functions.go 100.0% <100.0%> (ø)
... and 24 more