Skip to content

Commit

Permalink
chore: Join some long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Dec 26, 2023
1 parent f42337b commit 7ae528f
Show file tree
Hide file tree
Showing 81 changed files with 341 additions and 907 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ lint: ensure-actionlint ensure-editorconfig-checker ensure-find-typos ensure-gol

.PHONY: format
format: ensure-gofumpt ensure-golines
find . -name \*.go | xargs ./bin/golines --base-formatter="./bin/gofumpt -extra" -w
find . -name \*.go | xargs ./bin/golines --base-formatter="./bin/gofumpt -extra" --max-len=128 --write-output
find . -name \*.txtar | xargs ${GO} run ./internal/cmds/lint-txtar -w

.PHONY: format-yaml
Expand Down
7 changes: 1 addition & 6 deletions internal/chezmoi/actualstateentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ type ActualStateSymlink struct {

// NewActualStateEntry returns a new ActualStateEntry populated with absPath
// from system.
func NewActualStateEntry(
system System,
absPath AbsPath,
fileInfo fs.FileInfo,
err error,
) (ActualStateEntry, error) {
func NewActualStateEntry(system System, absPath AbsPath, fileInfo fs.FileInfo, err error) (ActualStateEntry, error) {
if fileInfo == nil {
fileInfo, err = system.Lstat(absPath)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/chezmoi/ageencryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ func (e *AgeEncryption) EncryptFile(plaintextAbsPath AbsPath) ([]byte, error) {
return e.builtinEncrypt(plaintext)
}

cmd := exec.Command( //nolint:gosec
e.Command,
append(append(e.encryptArgs(), e.Args...), plaintextAbsPath.String())...)
args := append(append(e.encryptArgs(), e.Args...), plaintextAbsPath.String())
cmd := exec.Command(e.Command, args...) //nolint:gosec
cmd.Stderr = os.Stderr
return chezmoilog.LogCmdOutput(cmd)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/chezmoi/archivereadersystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ type ArchiveReaderSystemOptions struct {
// NewArchiveReaderSystem returns a new ArchiveReaderSystem reading from data
// and using archivePath as a hint for the archive format.
func NewArchiveReaderSystem(
archivePath string, data []byte, format ArchiveFormat, options ArchiveReaderSystemOptions,
archivePath string,
data []byte,
format ArchiveFormat,
options ArchiveReaderSystemOptions,
) (*ArchiveReaderSystem, error) {
s := &ArchiveReaderSystem{
fileInfos: make(map[AbsPath]fs.FileInfo),
Expand Down
14 changes: 5 additions & 9 deletions internal/chezmoi/archivereadersystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ func TestArchiveReaderSystemTar(t *testing.T) {
})
assert.NoError(t, err)

archiveReaderSystem, err := NewArchiveReaderSystem(
"archive.tar",
data,
ArchiveFormatTar,
ArchiveReaderSystemOptions{
RootAbsPath: NewAbsPath("/home/user"),
StripComponents: 1,
},
)
options := ArchiveReaderSystemOptions{
RootAbsPath: NewAbsPath("/home/user"),
StripComponents: 1,
}
archiveReaderSystem, err := NewArchiveReaderSystem("archive.tar", data, ArchiveFormatTar, options)
assert.NoError(t, err)

for _, tc := range []struct {
Expand Down
4 changes: 1 addition & 3 deletions internal/chezmoi/autotemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ func autoTemplate(contents []byte, data map[string]any) ([]byte, bool) {

// appendVariables appends all template variables in data to variables
// and returns variables. data is assumed to be rooted at parent.
func appendVariables(
variables []templateVariable, parent []string, data map[string]any,
) []templateVariable {
func appendVariables(variables []templateVariable, parent []string, data map[string]any) []templateVariable {
for name, value := range data {
switch value := value.(type) {
case string:
Expand Down
6 changes: 1 addition & 5 deletions internal/chezmoi/boltpersistentstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ type BoltPersistentState struct {
}

// NewBoltPersistentState returns a new BoltPersistentState.
func NewBoltPersistentState(
system System,
path AbsPath,
mode BoltPersistentStateMode,
) (*BoltPersistentState, error) {
func NewBoltPersistentState(system System, path AbsPath, mode BoltPersistentStateMode) (*BoltPersistentState, error) {
empty := false
switch _, err := system.Stat(path); {
case errors.Is(err, fs.ErrNotExist):
Expand Down
7 changes: 2 additions & 5 deletions internal/chezmoi/boltpersistentstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ func TestBoltPersistentStateGeneric(t *testing.T) {
testPersistentState(t, func() PersistentState {
tempDir, err := os.MkdirTemp("", "chezmoi-test")
assert.NoError(t, err)
b, err := NewBoltPersistentState(
system,
NewAbsPath(tempDir).JoinString("chezmoistate.boltdb"),
BoltPersistentStateReadWrite,
)
absPath := NewAbsPath(tempDir).JoinString("chezmoistate.boltdb")
b, err := NewBoltPersistentState(system, absPath, BoltPersistentStateReadWrite)
assert.NoError(t, err)
return b
})
Expand Down
9 changes: 3 additions & 6 deletions internal/chezmoi/chezmoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ func FQDNHostname(fileSystem vfs.FS) (string, error) {
}

// FlagCompletionFunc returns a flag completion function.
func FlagCompletionFunc(allCompletions []string) func(*cobra.Command, []string, string) (
[]string, cobra.ShellCompDirective,
) {
func FlagCompletionFunc(allCompletions []string) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var completions []string
for _, completion := range allCompletions {
Expand Down Expand Up @@ -201,9 +199,8 @@ func SuspiciousSourceDirEntry(base string, fileInfo fs.FileInfo, encryptedSuffix
return true
}
for _, encryptedSuffix := range encryptedSuffixes {
if fileAttr := parseFileAttr(fileInfo.Name(), encryptedSuffix); knownTargetFiles.contains(
fileAttr.TargetName,
) {
fileAttr := parseFileAttr(fileInfo.Name(), encryptedSuffix)
if knownTargetFiles.contains(fileAttr.TargetName) {
return true
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/chezmoi/debugpersistentstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type DebugPersistentState struct {

// NewDebugPersistentState returns a new debugPersistentState that logs methods
// on persistentState to logger.
func NewDebugPersistentState(
persistentState PersistentState,
logger *zerolog.Logger,
) *DebugPersistentState {
func NewDebugPersistentState(persistentState PersistentState, logger *zerolog.Logger) *DebugPersistentState {
return &DebugPersistentState{
logger: logger,
persistentState: persistentState,
Expand Down
7 changes: 1 addition & 6 deletions internal/chezmoi/debugsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ func (s *DebugSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *DebugSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *DebugSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
err := s.system.RunScript(scriptname, dir, data, options)
s.logger.Err(err).
Stringer("scriptname", scriptname).
Expand Down
6 changes: 1 addition & 5 deletions internal/chezmoi/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ func (p *gitDiffPatch) Message() string { return p.message }

// DiffPatch returns a github.com/go-git/go-git/plumbing/format/diff.Patch for
// path from the given data and mode to the given data and mode.
func DiffPatch(
path RelPath,
fromData []byte, fromMode fs.FileMode,
toData []byte, toMode fs.FileMode,
) (diff.Patch, error) {
func DiffPatch(path RelPath, fromData []byte, fromMode fs.FileMode, toData []byte, toMode fs.FileMode) (diff.Patch, error) {
isBinary := isBinary(fromData) || isBinary(toData)

var from diff.File
Expand Down
7 changes: 1 addition & 6 deletions internal/chezmoi/dryrunsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ func (s *DryRunSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *DryRunSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *DryRunSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
s.setModified()
return nil
}
Expand Down
7 changes: 1 addition & 6 deletions internal/chezmoi/dumpsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ func (s *DumpSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *DumpSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *DumpSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
scriptnameStr := scriptname.String()
scriptData := &scriptData{
Type: dataTypeScript,
Expand Down
10 changes: 4 additions & 6 deletions internal/chezmoi/dumpsystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ func TestDumpSystem(t *testing.T) {

dumpSystem := NewDumpSystem()
persistentState := NewMockPersistentState()
assert.NoError(
t,
s.applyAll(dumpSystem, system, persistentState, EmptyAbsPath, ApplyOptions{
Filter: NewEntryTypeFilter(EntryTypesAll, EntryTypesNone),
}),
)
err := s.applyAll(dumpSystem, system, persistentState, EmptyAbsPath, ApplyOptions{
Filter: NewEntryTypeFilter(EntryTypesAll, EntryTypesNone),
})
assert.NoError(t, err)
expectedData := map[string]any{
".dir": &dirData{
Type: dataTypeDir,
Expand Down
4 changes: 1 addition & 3 deletions internal/chezmoi/entrytypeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ func StringSliceToEntryTypeSetHookFunc() mapstructure.DecodeHookFunc {
}

// EntryTypeSetFlagCompletionFunc completes EntryTypeSet flags.
func EntryTypeSetFlagCompletionFunc(
cmd *cobra.Command, args []string, toComplete string,
) ([]string, cobra.ShellCompDirective) {
func EntryTypeSetFlagCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var completions []string
entryTypes := strings.Split(toComplete, ",")
lastEntryType := entryTypes[len(entryTypes)-1]
Expand Down
13 changes: 3 additions & 10 deletions internal/chezmoi/entrytypeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,10 @@ func TestEntryTypeSetFlagCompletionFunc(t *testing.T) {
},
} {
t.Run(tc.toComplete, func(t *testing.T) {
completions, shellCompDirective := EntryTypeSetFlagCompletionFunc(
nil,
nil,
tc.toComplete,
)
completions, shellCompDirective := EntryTypeSetFlagCompletionFunc(nil, nil, tc.toComplete)
assert.Equal(t, tc.expectedCompletions, completions)
assert.Equal(
t,
cobra.ShellCompDirectiveNoSpace|cobra.ShellCompDirectiveNoFileComp,
shellCompDirective,
)
expectedShellCompDirective := cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp
assert.Equal(t, expectedShellCompDirective, shellCompDirective)
})
}
}
7 changes: 1 addition & 6 deletions internal/chezmoi/erroronwritesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ func (s *ErrorOnWriteSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *ErrorOnWriteSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *ErrorOnWriteSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
return s.err
}

Expand Down
14 changes: 4 additions & 10 deletions internal/chezmoi/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ type TooOldError struct {
}

func (e *TooOldError) Error() string {
return fmt.Sprintf(
"source state requires chezmoi version %s or later, chezmoi is version %s",
e.Need,
e.Have,
)
format := "source state requires chezmoi version %s or later, chezmoi is version %s"
return fmt.Sprintf(format, e.Need, e.Have)
}

type inconsistentStateError struct {
Expand All @@ -37,11 +34,8 @@ type inconsistentStateError struct {
}

func (e *inconsistentStateError) Error() string {
return fmt.Sprintf(
"%s: inconsistent state (%s)",
e.targetRelPath,
strings.Join(e.origins, ", "),
)
format := "%s: inconsistent state (%s)"
return fmt.Sprintf(format, e.targetRelPath, strings.Join(e.origins, ", "))
}

type NotInAbsDirError struct {
Expand Down
7 changes: 1 addition & 6 deletions internal/chezmoi/externaldiffsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,7 @@ func (s *ExternalDiffSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *ExternalDiffSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *ExternalDiffSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
bits := EntryTypeScripts
if options.Condition == ScriptConditionAlways {
bits |= EntryTypeAlways
Expand Down
8 changes: 2 additions & 6 deletions internal/chezmoi/findexecutable_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ func TestFindExecutable(t *testing.T) {
}

for _, test := range tests {
name := fmt.Sprintf(
"FindExecutable %#v in %#v as %#v",
test.files,
test.paths,
test.expected,
)
format := "FindExecutable %#v in %#v as %#v"
name := fmt.Sprintf(format, test.files, test.paths, test.expected)
t.Run(name, func(t *testing.T) {
actual, err := FindExecutable(test.files, test.paths)
assert.NoError(t, err)
Expand Down
8 changes: 2 additions & 6 deletions internal/chezmoi/findexecutable_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ func TestFindExecutable(t *testing.T) {
}

for _, test := range tests {
name := fmt.Sprintf(
"FindExecutable %#v in %#v as %#v",
test.files,
test.paths,
test.expected,
)
format := "FindExecutable %#v in %#v as %#v"
name := fmt.Sprintf(format, test.files, test.paths, test.expected)
t.Run(name, func(t *testing.T) {
actual, err := FindExecutable(test.files, test.paths)
assert.NoError(t, err)
Expand Down
14 changes: 2 additions & 12 deletions internal/chezmoi/gitdiffsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ type GitDiffSystemOptions struct {
// NewGitDiffSystem returns a new GitDiffSystem. Output is written to w, the
// dirAbsPath is stripped from paths, and color controls whether the output
// contains ANSI color escape sequences.
func NewGitDiffSystem(
system System,
w io.Writer,
dirAbsPath AbsPath,
options *GitDiffSystemOptions,
) *GitDiffSystem {
func NewGitDiffSystem(system System, w io.Writer, dirAbsPath AbsPath, options *GitDiffSystemOptions) *GitDiffSystem {
unifiedEncoder := diff.NewUnifiedEncoder(w, diff.DefaultContextLines)
if options.Color {
unifiedEncoder.SetColor(diff.NewColorConfig())
Expand Down Expand Up @@ -206,12 +201,7 @@ func (s *GitDiffSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *GitDiffSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) error {
func (s *GitDiffSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) error {
bits := EntryTypeScripts
if options.Condition == ScriptConditionAlways {
bits |= EntryTypeAlways
Expand Down
10 changes: 4 additions & 6 deletions internal/chezmoi/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ func (s lstatFS) Stat(name string) (fs.FileInfo, error) {
// Glob is like github.com/bmatcuk/doublestar/v4.Glob except that it does not
// follow symlinks.
func Glob(fileSystem vfs.FS, prefix string) ([]string, error) {
return doublestar.Glob(
lstatFS{
wrapped: fileSystem,
},
prefix,
fsys := lstatFS{wrapped: fileSystem}
opts := []doublestar.GlobOption{
doublestar.WithFailOnIOErrors(),
doublestar.WithNoFollow(),
)
}
return doublestar.Glob(fsys, prefix, opts...)
}
7 changes: 1 addition & 6 deletions internal/chezmoi/realsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ func (s *RealSystem) RunCmd(cmd *exec.Cmd) error {
}

// RunScript implements System.RunScript.
func (s *RealSystem) RunScript(
scriptname RelPath,
dir AbsPath,
data []byte,
options RunScriptOptions,
) (err error) {
func (s *RealSystem) RunScript(scriptname RelPath, dir AbsPath, data []byte, options RunScriptOptions) (err error) {
// Create the script temporary directory, if needed.
s.createScriptTempDirOnce.Do(func() {
if !s.scriptTempDir.Empty() {
Expand Down
Loading

0 comments on commit 7ae528f

Please sign in to comment.