ronantakizawa/codereview-bench huggingface dataset:
Repository: nvbn/thefuck
File: thefuck/rules/git_hook_bypass.py (Python)

Code before:
from thefuck.specific.git import git_support

hooked_commands = ("am", "commit", "push")


@git_support
def match(command):
    return any(
        hooked_command in command.script_parts for hooked_command in hooked_commands
    )


@git_support
def get_new_command(command):
    hooked_command = next(
        hooked_command
        for hooked_command in hooked_commands
        if hooked_command in command.script_parts
    )
    return replace_argument(
        command.script, hooked_command, hooked_command + " --no-verify"
    )


priority = 900
enabled_by_default = True
requires_output = False


Review comment (suggestion):
This can be omitted as `True` is the default value for it:

https://github.com/nvbn/thefuck/blob/6975d30818792f1b37de702fc93c66023c4c50d5/thefuck/types.py#L144

```suggestion
```


Code after:
from thefuck.specific.git import git_support

hooked_commands = ("am", "commit", "push")


@git_support
def match(command):
    return any(
        hooked_command in command.script_parts for hooked_command in hooked_commands
    )


@git_support
def get_new_command(command):
    hooked_command = next(
        hooked_command
        for hooked_command in hooked_commands
        if hooked_command in command.script_parts
    )
    return replace_argument(
        command.script, hooked_command, hooked_command + " --no-verify"
    )


priority = 900
requires_output = False
Repository: nvbn/thefuck
File: thefuck/rules/omnienv_no_such_command.py (Python)

Code before:
import re
from thefuck.utils import (cache, for_app, replace_argument, replace_command,
                           which)
from subprocess import PIPE, Popen


supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv'
enabled_by_default = any(which(a) for a in supported_apps)


COMMON_TYPOS = {
    'list': ['versions', 'install --list'],
    'remove': ['uninstall'],
}


@for_app(*supported_apps, at_least=1)
def match(command):
    return 'env: no such command ' in command.output


def get_app_commands(app):
    proc = Popen([app, 'commands'], stdout=PIPE)
    return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]


def get_new_command(command):
    app = command.script_parts[0]
    app_commands = cache(which(app))(get_app_commands)(app)
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]

Review comment (suggestion):
We can add `jenv` to the list too.

```suggestion
supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv', 'jenv'
```

Code after:
import re
from thefuck.utils import (cache, for_app, replace_argument, replace_command,
                           which)
from subprocess import PIPE, Popen


supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv'
enabled_by_default = any(which(a) for a in supported_apps)


COMMON_TYPOS = {
    'list': ['versions', 'install --list'],
    'remove': ['uninstall'],
}


@for_app(*supported_apps, at_least=1)
def match(command):
    return 'env: no such command ' in command.output


def get_app_commands(app):
    proc = Popen([app, 'commands'], stdout=PIPE)
    return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]


def get_new_command(command):
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]

    app = command.script_parts[0]
Repository: nvbn/thefuck
File: thefuck/rules/omnienv_no_such_command.py (Python)

Code before:
supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv'
enabled_by_default = any(which(a) for a in supported_apps)


COMMON_TYPOS = {
    'list': ['versions', 'install --list'],
    'remove': ['uninstall'],
}


@for_app(*supported_apps, at_least=1)
def match(command):
    return 'env: no such command ' in command.output


def get_app_commands(app):
    proc = Popen([app, 'commands'], stdout=PIPE)
    return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]


def get_new_command(command):
    app = command.script_parts[0]
    app_commands = cache(which(app))(get_app_commands)(app)
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]
    matched.extend(replace_command(command, broken, app_commands))
    return matched


Review comment (bug):
Separating out the two blocks of matching logic into different code blocks should be more readable.

```suggestion
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]

    app = command.script_parts[0]
    app_commands = cache(which(app))(get_app_commands)(app)
```

Code after:
supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv'
enabled_by_default = any(which(a) for a in supported_apps)


COMMON_TYPOS = {
    'list': ['versions', 'install --list'],
    'remove': ['uninstall'],
}


@for_app(*supported_apps, at_least=1)
def match(command):
    return 'env: no such command ' in command.output


def get_app_commands(app):
    proc = Popen([app, 'commands'], stdout=PIPE)
    return [line.decode('utf-8').strip() for line in proc.stdout.readlines()]


def get_new_command(command):
    broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0]
    matched = [replace_argument(command.script, broken, common_typo)
               for common_typo in COMMON_TYPOS.get(broken, [])]

    app = command.script_parts[0]
    app_commands = cache(which(app))(get_app_commands)(app)
    matched.extend(replace_command(command, broken, app_commands))
    return matched
Repository: nvbn/thefuck
File: tests/rules/test_git_clone_git_clone.py (Python)

Code before:
from thefuck.rules.git_clone_git_clone import match, get_new_command
from thefuck.types import Command


output_clean = """
fatal: Too many arguments.

usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    -n, --no-checkout     don't create a checkout
    --bare                create a bare repository
    --mirror              create a mirror repository (implies bare)
    -l, --local           to clone from a local repository
    --no-hardlinks        don't use local hardlinks, always copy
    -s, --shared          setup as shared repository
    --recurse-submodules[=<pathspec>]
                          initialize submodules in the clone
    --recursive ...       alias of --recurse-submodules
    -j, --jobs <n>        number of submodules cloned in parallel
    --template <template-directory>
                          directory from which templates will be used
    --reference <repo>    reference repository
    --reference-if-able <repo>
                          reference repository
    --dissociate          use --reference only while cloning
    -o, --origin <name>   use <name> instead of 'origin' to track upstream
    -b, --branch <branch>
                          checkout <branch> instead of the remote's HEAD
    -u, --upload-pack <path>
                          path to git-upload-pack on the remote
    --depth <depth>       create a shallow clone of that depth

Review comment (suggestion):
Nit: The output doesn't actually need to be this long. How about limiting it to the first three lines? As in:
```python
output_clean = """fatal: Too many arguments.

usage: git clone [<options>] [--] <repo> [<dir>]

(snip)
"""
```

Code after:
from thefuck.rules.git_clone_git_clone import match, get_new_command
from thefuck.types import Command


output_clean = """
fatal: Too many arguments.

usage: git clone [<options>] [--] <repo> [<dir>]
"""


def test_match():
    assert match(Command('git clone git clone foo', output_clean))


def test_not_match():
    assert not match(Command('', ''))
    assert not match(Command('git branch', ''))
    assert not match(Command('git clone foo', ''))
    assert not match(Command('git clone foo bar baz', output_clean))


def test_get_new_command():
    assert get_new_command(Command('git clone git clone foo', output_clean)) == 'git clone foo'
Repository: nvbn/thefuck
File: thefuck/rules/composer_not_command.py (Python)

Code before:
import re
from thefuck.utils import replace_argument, for_app


@for_app('composer')
def match(command):
    return (('did you mean this?' in command.output.lower()
             or 'did you mean one of these?' in command.output.lower())) or (
        "install" in command.script_parts and "composer require" in command.output.lower()
    )


def get_new_command(command):
    if "install" in command.script_parts and "composer require" in command.output.lower():
        broken_cmd = "install"
        new_cmd = "require"
    else:
        broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0]
        new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output)
        if not new_cmd:
            new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output)
        new_cmd = new_cmd[0].strip()
    return replace_argument(command.script, broken_cmd, new_cmd)


Review comment (bug):
[Nit](https://google.github.io/eng-practices/review/reviewer/standard.html):

```suggestion
        broken_cmd, new_cmd = "install", "require"
```

Code after:
import re
from thefuck.utils import replace_argument, for_app


@for_app('composer')
def match(command):
    return (('did you mean this?' in command.output.lower()
             or 'did you mean one of these?' in command.output.lower())) or (
        "install" in command.script_parts and "composer require" in command.output.lower()
    )


def get_new_command(command):
    if "install" in command.script_parts and "composer require" in command.output.lower():
        broken_cmd, new_cmd = "install", "require"
    else:
        broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0]
        new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output)
        if not new_cmd:
            new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output)
        new_cmd = new_cmd[0].strip()
    return replace_argument(command.script, broken_cmd, new_cmd)
Repository: nvbn/thefuck
File: thefuck/rules/conda_mistype.py (Python)

Code before:
import re
from thefuck.utils import replace_command


def match(command):
    '''
    Match a mistyped command
    '''
    return 'conda' in command.script and "Did you mean 'conda" in command.output


def get_new_command(command):
    match = re.findall(r"'conda ([^']*)'", command.output)
    broken_cmd = match[0]
    correct_cmd = match[1]
    return replace_command(command, broken_cmd, [correct_cmd])


Review comment (suggestion):
```suggestion
from thefuck.utils import for_app
from thefuck.utils import replace_command


@for_app("conda")
def match(command):
    """
    Match a mistyped command
    """
    return "Did you mean 'conda" in command.output
```

Code after:
import re
from thefuck.utils import replace_command, for_app


@for_app("conda")
def match(command):
    """
    Match a mistyped command
    """
    return "Did you mean 'conda" in command.output


def get_new_command(command):
    match = re.findall(r"'conda ([^']*)'", command.output)
    broken_cmd = match[0]
    correct_cmd = match[1]
    return replace_command(command, broken_cmd, [correct_cmd])
Repository: nvbn/thefuck
File: thefuck/rules/conda_mistype.py (Python)

Code before:
import re
from thefuck.utils import replace_command, for_app


@for_app("conda")
def match(command):
    """
    Match a mistyped command
    """
    return "conda" in command.script and "Did you mean 'conda" in command.output


def get_new_command(command):
    match = re.findall(r"'conda ([^']*)'", command.output)
    broken_cmd = match[0]
    correct_cmd = match[1]
    return replace_command(command, broken_cmd, [correct_cmd])


Review comment (suggestion):
Once the function is anotated with `@for_app("conda")` there's no need to check if it is included in `command.script`.
```suggestion
    return "Did you mean 'conda" in command.output
```

Code after:
import re
from thefuck.utils import replace_command, for_app


@for_app("conda")
def match(command):
    """
    Match a mistyped command
    """
    return "Did you mean 'conda" in command.output


def get_new_command(command):
    match = re.findall(r"'conda ([^']*)'", command.output)
    broken_cmd = match[0]
    correct_cmd = match[1]
    return replace_command(command, broken_cmd, [correct_cmd])
Repository: nvbn/thefuck
File: thefuck/rules/python_module_error.py (Python)

Code before:
import re
from thefuck.shells import shell

MISSING_MODULE = r"No module named '([a-zA-Z_][a-zA-Z0-9_]*)'"


def match(command):
    return "ModuleNotFoundError" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)


Review comment (suggestion):
Would a simpler regex work? Also, how about including the whole prefix not only in the regex but also in `match`? (see below)
```suggestion
MISSING_MODULE = r"ModuleNotFoundError: No module named '([^']+)'"
```

Code after:
import re
from thefuck.shells import shell

MISSING_MODULE = r"ModuleNotFoundError: No module named '([^']+)'"


def match(command):
    return "ModuleNotFoundError: No module named '" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)
Repository: nvbn/thefuck
File: thefuck/rules/python_module_error.py (Python)

Code before:
import re
from thefuck.shells import shell

MISSING_MODULE = r"No module named '([a-zA-Z_][a-zA-Z0-9_]*)'"


def match(command):
    return "ModuleNotFoundError" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)


Review comment (suggestion):
Looking for the whole prefix would reduce the chances of the first line of `get_new_command` raising an `IndexError`.
```suggestion
    return "ModuleNotFoundError: No module named '" in command.output
```

Code after:
import re
from thefuck.shells import shell

MISSING_MODULE = r"ModuleNotFoundError: No module named '([^']+)'"


def match(command):
    return "ModuleNotFoundError: No module named '" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)
Repository: nvbn/thefuck
File: thefuck/rules/python_module_error.py (Python)

Code before:
import re
from thefuck.shells import shell

MISSING_MODULE = r"No module named '([a-zA-Z_][a-zA-Z0-9_]*)'"


def match(command):
    return "ModuleNotFoundError" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)


Review comment (suggestion):
```suggestion
    return shell.and_(u"pip install {}".format(missing_module), command.script)
```

Nit: add a unicode test case for `get_new_command` with `# -*- coding: utf-8 -*-` file header.

Code after:
import re
from thefuck.shells import shell

MISSING_MODULE = r"ModuleNotFoundError: No module named '([^']+)'"


def match(command):
    return "ModuleNotFoundError: No module named '" in command.output


def get_new_command(command):
    missing_module = re.findall(MISSING_MODULE, command.output)[0]
    return shell.and_("pip install {}".format(missing_module), command.script)
Repository: nvbn/thefuck
File: thefuck/rules/cd_cs.py (Python)

Code before:
# Redirects cs to cd when there is a typo
# Due to the proximity of the keys - d and s, I found this to be a common problem for me
# > cs /etc/
# cs: command not found


def match(command):
    if command.script_parts[0] == 'cs':
        return True


def get_new_command(command):
    return 'cd' + ''.join(command.script[2:])


priority = 900


Review comment (suggestion):
Nit: can I suggest a more informative head comment?
```suggestion
# Redirects cs to cd when there is a typo
# Due to the proximity of the keys — d and s — this seems like a common typo
# ~ > cs /etc/
# cs: command not found
# ~ > fuck
# cd /etc/ [enter/↑/↓/ctrl+c]
# /etc >
```

Code after:
# -*- encoding: utf-8 -*-

# Redirects cs to cd when there is a typo
# Due to the proximity of the keys - d and s - this seems like a common typo
# ~ > cs /etc/
# cs: command not found
# ~ > fuck
# cd /etc/ [enter/↑/↓/ctrl+c]
# /etc >


def match(command):
    if command.script_parts[0] == 'cs':
        return True


def get_new_command(command):
    return 'cd' + ''.join(command.script[2:])


priority = 900
Repository: nvbn/thefuck
File: thefuck/rules/cd_cs.py (Python)

Code before:
# Redirects cs to cd when there is a typo
# Due to the proximity of the keys - d and s - this seems like a common typo
# ~ > cs /etc/
# cs: command not found
# ~ > fuck
# cd /etc/ [enter/↑/↓/ctrl+c]
# /etc >


def match(command):
    if command.script_parts[0] == 'cs':
        return True


def get_new_command(command):
    return 'cd' + ''.join(command.script[2:])


priority = 900


Review comment (suggestion):
This should fix it:

```suggestion
# -*- encoding: utf-8 -*-

# Redirects cs to cd when there is a typo
```

Code after:
# -*- encoding: utf-8 -*-

# Redirects cs to cd when there is a typo
# Due to the proximity of the keys - d and s - this seems like a common typo
# ~ > cs /etc/
# cs: command not found
# ~ > fuck
# cd /etc/ [enter/↑/↓/ctrl+c]
# /etc >


def match(command):
    if command.script_parts[0] == 'cs':
        return True


def get_new_command(command):
    return 'cd' + ''.join(command.script[2:])


priority = 900
Repository: nvbn/thefuck
File: thefuck/rules/git_main_master.py (Python)

Code before:
from thefuck.specific.git import git_support


@git_support
def match(command):
    return "'master'" in command.output.lower() or "'main'" in command.output.lower()


@git_support
def get_new_command(command):
    if "'master'" in command.output.lower():
        return command.script.replace("master", "main")
    else:
        return command.script.replace("main", "master")


Review comment (suggestion):
```suggestion
    return command.script.replace("main", "master")
```

Code after:
from thefuck.specific.git import git_support


@git_support
def match(command):
    return "'master'" in command.output or "'main'" in command.output


@git_support
def get_new_command(command):
    if "'master'" in command.output:
        return command.script.replace("master", "main")
    return command.script.replace("main", "master")


priority = 1200
Repository: nvbn/thefuck
File: thefuck/rules/rails_migrations_pending.py (Python)

Code before:
import re


SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n"


def match(command):
    return ("Migrations are pending. To resolve this issue, run:" in command.output)


def get_new_command(command):
    return re.search(SUGGESTION_REGEX, command.output).group(1)


Review comment (suggestion):
```suggestion
    return "Migrations are pending. To resolve this issue, run:" in command.output
```

Code after:
import re
from thefuck.shells import shell


SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n"


def match(command):
    return "Migrations are pending. To resolve this issue, run:" in command.output


def get_new_command(command):
    migration_script = re.search(SUGGESTION_REGEX, command.output).group(1)
    return shell.and_(migration_script, command.script)
Repository: nvbn/thefuck
File: tests/rules/test_rails_migrations_pending.py (Python)

Code before:
@pytest.mark.parametrize(
    "command",
    [
        Command("", output_env_development),
        Command("", output_env_test),
    ],
)
def test_match(command):
    assert match(command)


@pytest.mark.parametrize(
    "command",
    [
        Command("Environment data not found in the schema. To resolve this issue, run: \n\n", ""),
    ],
)
def test_not_match(command):
    assert not match(command)


@pytest.mark.parametrize(
    "command, new_command",
    [
        (Command("", output_env_development), "rails db:migrate RAILS_ENV=development"),
        (Command("", output_env_test), "bin/rails db:migrate RAILS_ENV=test"),
    ],
)
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command


Review comment (suggestion):
Reviewing it again, I thought that the corrected command could include the one initially intended by the user.

```suggestion
        (Command("bin/rspec", output_env_development), "rails db:migrate RAILS_ENV=development && bin/rspec"),
        (Command("bin/rspec", output_env_test), "bin/rails db:migrate RAILS_ENV=test && bin/rspec"),
```

Make sure to use `shell._and` to join the commands together.

Code after:
@pytest.mark.parametrize(
    "command",
    [
        Command("", output_env_development),
        Command("", output_env_test),
    ],
)
def test_match(command):
    assert match(command)


@pytest.mark.parametrize(
    "command",
    [
        Command("Environment data not found in the schema. To resolve this issue, run: \n\n", ""),
    ],
)
def test_not_match(command):
    assert not match(command)


@pytest.mark.parametrize(
    "command, new_command",
    [
        (Command("bin/rspec", output_env_development), "rails db:migrate RAILS_ENV=development && bin/rspec"),
        (Command("bin/rspec", output_env_test), "bin/rails db:migrate RAILS_ENV=test && bin/rspec"),
    ],
)
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command
Repository: nvbn/thefuck
File: thefuck/rules/rails_migrations_pending.py (Python)

Code before:
import re


SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n"


def match(command):
    return "Migrations are pending. To resolve this issue, run:" in command.output


def get_new_command(command):
    return re.search(SUGGESTION_REGEX, command.output).group(1)


Review comment (suggestion):
Nit: should this rule be used only for `bin/rspec`?

```suggestion
@for_app("bin/rspec")
def match(command):
    return "Migrations are pending. To resolve this issue, run:" in command.output
```

Code after:
import re
from thefuck.shells import shell


SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n"


def match(command):
    return "Migrations are pending. To resolve this issue, run:" in command.output


def get_new_command(command):
    migration_script = re.search(SUGGESTION_REGEX, command.output).group(1)
    return shell.and_(migration_script, command.script)