Skip to content
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: enforce consistent shell redirection format #1533

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commands/reshim.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ remove_shim_for_version() {
local count_installed
count_installed=$(list_installed_versions "$plugin_name" | wc -l)

if ! grep -x "# asdf-plugin: $plugin_name $version" "$shim_path" >/dev/null 2>&1; then
if ! grep -x "# asdf-plugin: $plugin_name $version" "$shim_path" &>/dev/null; then
return 0
fi

Expand Down
4 changes: 2 additions & 2 deletions lib/functions/installs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ install_command() {
}

get_concurrency() {
if command -v nproc >/dev/null 2>&1; then
if command -v nproc &>/dev/null; then
nproc
elif command -v sysctl >/dev/null 2>&1 && sysctl hw.ncpu >/dev/null 2>&1; then
elif command -v sysctl &>/dev/null && sysctl hw.ncpu &>/dev/null; then
sysctl -n hw.ncpu
elif [ -f /proc/cpuinfo ]; then
grep -c processor /proc/cpuinfo
Expand Down
25 changes: 25 additions & 0 deletions scripts/checkstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def noFunctionKeywordFixer(line: str, m: Any) -> str:

return f'{prestr}{midstr}() {poststr}'

# Before: >/dev/null 2>&1
# After: &>/dev/null
# ---
# Before: 2>/dev/null 1>&2
# After: &>/dev/null
def noVerboseRedirectionFixer(line: str, m: Any) -> str:
prestr, _, poststr = utilGetStrs(line, m)

return f'{prestr}&>/dev/null{poststr}'

def lintfile(filepath: Path, rules: List[Rule], options: Dict[str, Any]):
content_arr = filepath.read_text().split('\n')

Expand Down Expand Up @@ -172,6 +182,21 @@ def main():
],
'found': 0
},
{
'name': 'no-verbose-redirection',
'regex': '(?P<match>(>/dev/null 2>&1|2>/dev/null 1>&2))',
'reason': 'Use `&>/dev/null` instead of `>/dev/null 2>&1` or `2>/dev/null 1>&2` for consistency',
'fixerFn': noVerboseRedirectionFixer,
'testPositiveMatches': [
'echo woof >/dev/null 2>&1',
'echo woof 2>/dev/null 1>&2',
],
'testNegativeMatches': [
'echo woof &>/dev/null',
'echo woof >&/dev/null',
],
'found': 0
}
]

parser = argparse.ArgumentParser()
Expand Down