Skip to content

Commit 50769f6

Browse files
committed
chore(constants): introduce ExtBat and replace bare ".bat" literals
The `goconst` linter flagged ".bat" as a repeated string literal across manager.go, manager_test.go, and path.go. Add `constants.ExtBat` alongside the existing ExtExe / ExtCmd constants and replace the bare literals (and the bare ".exe"/".cmd" alongside them in the same files) with the named constants.
1 parent f039b06 commit 50769f6

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/internal/constants/platform.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ const (
3434
const (
3535
ExtExe = ".exe"
3636
ExtCmd = ".cmd"
37+
ExtBat = ".bat"
3738
)

src/internal/path/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func LookPathExcludingShims(execName string) string {
180180
func findExecutableInDir(dir, execName string) string {
181181
if runtime.GOOS == constants.OSWindows {
182182
// Windows: try .exe, .cmd, .bat extensions
183-
for _, ext := range []string{".exe", ".cmd", ".bat"} {
183+
for _, ext := range []string{constants.ExtExe, constants.ExtCmd, constants.ExtBat} {
184184
candidate := filepath.Join(dir, execName+ext)
185185
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
186186
return candidate

src/internal/shim/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (m *Manager) ListShims() ([]string, error) {
169169
if runtime.GOOS == constants.OSWindows {
170170
ext := filepath.Ext(name)
171171
// Skip .cmd/.bat wrappers — only list .exe shims
172-
if ext == constants.ExtCmd || ext == ".bat" {
172+
if ext == constants.ExtCmd || ext == constants.ExtBat {
173173
continue
174174
}
175175
name = name[:len(name)-len(ext)]
@@ -397,7 +397,7 @@ func findExecutables(dir string) ([]string, error) {
397397
// On Windows, check for executable extensions
398398
if runtime.GOOS == constants.OSWindows {
399399
ext := filepath.Ext(name)
400-
if ext == ".exe" || ext == ".cmd" || ext == ".bat" {
400+
if ext == constants.ExtExe || ext == constants.ExtCmd || ext == constants.ExtBat {
401401
// Remove extension for shim name
402402
baseName := name[:len(name)-len(ext)]
403403
executables = append(executables, baseName)

src/internal/shim/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func TestListShims_SkipsCmdFiles(t *testing.T) {
426426
}
427427
name := entry.Name()
428428
ext := filepath.Ext(name)
429-
if ext == constants.ExtCmd || ext == ".bat" {
429+
if ext == constants.ExtCmd || ext == constants.ExtBat {
430430
continue
431431
}
432432
shims = append(shims, name[:len(name)-len(ext)])

0 commit comments

Comments
 (0)