-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(template functions): Use function Title instead of ToTitle #165
Conversation
2178224
to
da9bcc7
Compare
Hey @anmoel - thanks for taking the time to look into this. I think you are right ( You need to initialize a caser, doing something like: package main
import (
"fmt"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func main() {
str := "my Odly cAsed striNg"
caser := cases.Title(language.Und)
fmt.Println("ToLower: ", strings.ToLower(str))
fmt.Println("ToUpper: ", strings.ToUpper(str))
fmt.Println("ToTitle: ", strings.ToTitle(str))
fmt.Println("Title: ", strings.Title(str))
fmt.Println("Caser: ", caser.String(str))
} |
I will add a test in my branch and will check this |
da9bcc7
to
97e2e48
Compare
Hi @detro, i fixed the code and added tests for some template functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for this.
A few things to address though:
- removal of
testify
- update of the CHANGELOG to add a new bugfix entry
- version should be
v0.12.1
- update of the README to point at which function, with which casing, is used for the
title
template function
internal/provider/template_test.go
Outdated
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a long standing position of HC to try to avoid dependency that are not required.
Please use go-cmp
that is already part of the codebase for these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is done
97e2e48
to
6fa0f54
Compare
… Capitalize strings instead of upper strings using cases.Title because the strings.Title function is deprecated and refs to cases.Title
6fa0f54
to
7fe092f
Compare
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestRenderStringTemplate(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks so much for those tests. Really appreciated.
| `title` | Equivalent to [`cases.Title`](https://pkg.go.dev/golang.org/x/text/cases#Title). | | ||
| `tffile` | A special case of the `codefile` function, designed for Terraform files (i.e. `.tf`). | | ||
| `trimspace` | Equivalent to [`strings.TrimSpace`](https://pkg.go.dev/strings#TrimSpace). | | ||
| `upper` | Equivalent to [`strings.ToLower`](https://pkg.go.dev/strings#ToUpper). | | ||
| `upper` | Equivalent to [`strings.ToUpper`](https://pkg.go.dev/strings#ToUpper). | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well spotted!
* cmd/tfplugindocs: Use existing Terraform CLI binary if available on PATH, otherwise download latest Terraform CLI binary (<https://github.com/hashicorp/terraform-plugin-docs/pull/124>). | ||
* cmd/tfplugindocs: Added `tf-version` flag for specifying Terraform CLI binary version to download, superseding the PATH lookup (<https://github.com/hashicorp/terraform-plugin-docs/pull/124>). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* cmd/tfplugindocs: Use existing Terraform CLI binary if available on PATH, otherwise download latest Terraform CLI binary (<https://github.com/hashicorp/terraform-plugin-docs/pull/124>). | |
* cmd/tfplugindocs: Added `tf-version` flag for specifying Terraform CLI binary version to download, superseding the PATH lookup (<https://github.com/hashicorp/terraform-plugin-docs/pull/124>). | |
* cmd/tfplugindocs: Use existing Terraform CLI binary if available on PATH, otherwise download latest Terraform CLI binary ([#124](https://github.com/hashicorp/terraform-plugin-docs/pull/124)). | |
* cmd/tfplugindocs: Added `tf-version` flag for specifying Terraform CLI binary version to download, superseding the PATH lookup ([#124](https://github.com/hashicorp/terraform-plugin-docs/pull/124)). |
* cmd/tfplugindocs: Swapped `.Type` and `.Name` resource and data source template fields so they correctly align (<https://github.com/hashicorp/terraform-plugin-docs/pull/44>). | ||
* schemamd: Switched attribute name rendering from bold text to code blocks so the Terraform Registry treats them as anchor links (<https://github.com/hashicorp/terraform-plugin-docs/pull/59>). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* cmd/tfplugindocs: Swapped `.Type` and `.Name` resource and data source template fields so they correctly align (<https://github.com/hashicorp/terraform-plugin-docs/pull/44>). | |
* schemamd: Switched attribute name rendering from bold text to code blocks so the Terraform Registry treats them as anchor links (<https://github.com/hashicorp/terraform-plugin-docs/pull/59>). | |
* cmd/tfplugindocs: Swapped `.Type` and `.Name` resource and data source template fields so they correctly align ([#44](https://github.com/hashicorp/terraform-plugin-docs/pull/44)). | |
* schemamd: Switched attribute name rendering from bold text to code blocks so the Terraform Registry treats them as anchor links ([#59](https://github.com/hashicorp/terraform-plugin-docs/pull/59)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting those, but the format should be [#NUM](URL_to_NUM)
(as you correctly used above)
# 0.12.1 (July 04, 2022) | ||
|
||
BUG FIXES: | ||
|
||
* template functions: funtion `title` creates capitalize strings instead of upper strings ([#165](https://github.com/hashicorp/terraform-plugin-docs/pull/165)). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another PR landed so I think you need to rebase and put this in the 0.13.0
section, but still under BUG FIXES
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments and suggestions/corrections, but I think we are pretty much there.
It needs rebasing though.
@anmoel I tried to do the rebasing locally, and it's really just about the CHANGELOG. Once you rebase, we can merge and then I'll start the release process. |
Hi @anmoel - as I'd like to fix the bug, I'm happy to take it upon myself to import your commit locally, do the tweaks and rebasing, and open a new PR that superseeds this one. If you can't get to it today, I'll try to do this either tomorrow or Monday at the latest. |
Superseeded by #168 Thank you so much for your fix: I have made sure your commit was correctly adjudicated. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Use function Title instead of ToTitle to get capitalize strings instead of upper strings
Using
cases.Title
because thestrings.Title
function is deprecated and refs tocases.Title
resolves #164