Empty string test can be improved CRT-A0004
Anti-pattern
Major
5 months ago4 years old
replace len(shell) == 0 with shell == ""
11// ExecCommand executes the given command with $SHELL
12func ExecCommand(command string, setpgid bool) *exec.Cmd {
13	shell := os.Getenv("SHELL")
14	if len(shell) == 0 {15		shell = "sh"
16	}
17	return ExecCommandWith(shell, command, setpgid)
replace len(env) == 0 with env == ""
254
255func getEnv(name string, defaultValue int) int {
256	env := os.Getenv(name)
257	if len(env) == 0 {258		return defaultValue
259	}
260	return atoi(env, defaultValue)
replace len(cmd) == 0 with cmd == ""
100		// The default command for *nix requires bash
101		shell := "bash"
102		cmd := os.Getenv("FZF_DEFAULT_COMMAND")
103		if len(cmd) == 0 {104			success = r.readFromCommand(&shell, defaultCommand)
105		} else {
106			success = r.readFromCommand(nil, cmd)
replace len(opts.JumpLabels) == 0 with opts.JumpLabels == ""
1326		errorExit("tab stop must be a positive integer")
1327	}
1328
1329	if len(opts.JumpLabels) == 0 {1330		errorExit("empty jump labels")
1331	}
1332
replace len(spec) == 0 with spec == ""
1090			parseKeymap(opts.Keymap, nextString(allArgs, &i, "bind expression required"))
1091		case "--color":
1092			spec := optionalNextString(allArgs, &i)
1093			if len(spec) == 0 {1094				opts.Theme = tui.EmptyTheme()
1095			} else {
1096				opts.Theme = parseTheme(opts.Theme, spec)