Skip to content

docs: fix GetTabWidth comment on the unset return value#706

Open
sueun-dev wants to merge 1 commit into
charmbracelet:mainfrom
sueun-dev:docs-gettabwidth-default
Open

docs: fix GetTabWidth comment on the unset return value#706
sueun-dev wants to merge 1 commit into
charmbracelet:mainfrom
sueun-dev:docs-gettabwidth-default

Conversation

@sueun-dev

Copy link
Copy Markdown

The doc comment on GetTabWidth says an unset tab width returns 4:

If no value is set 4 is returned which is the implicit default.

It returns 0, not 4. The getter is return s.getAsInt(tabWidthKey), and getAsInt returns 0 for an unset key, so NewStyle().GetTabWidth() is 0. The default of 4 is applied later, in maybeConvertTabs at render time, not by the getter. TestStyleUnset already asserts GetTabWidth() != 4 after UnsetTabWidth, so the current return value is intended and the comment is the part that's wrong.

This corrects the comment to match the behavior: the getter returns the configured value (0 when unset), and tabs still expand to 4 spaces at render time when no width is set.

gofmt, go vet, go build, and go test ./... are clean.

GetTabWidth's comment said an unset tab width returns 4, but the getter
returns getAsInt(tabWidthKey), which is 0 when no width has been set. The
implicit default of 4 is applied at render time in maybeConvertTabs, not by
the getter; TestStyleUnset already asserts GetTabWidth() != 4 after Unset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant