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: Failed to execute rubocop fixer on other machine #3916

Merged

Conversation

uplus
Copy link
Contributor

@uplus uplus commented Sep 23, 2021

Expectation

I want to apply the fixer of rubocop in the container to the Ruby file that is volume mounted by docker-compose.
Use b:ale_command_wrapper and b:ale_filename_mappings to run fixer inside docker.

let b:ale_command_wrapper = 'docker-compose exec -T api bundle exec'
let b:ale_filename_mappings = { '*': [['/home/uplus/project', '/usr/src/app']] }

Problem

Linter succeeded, but Fixer failed.

Linter Log(succeeded)

['/bin/sh', '-c', 'docker-compose exec -T api bundle exec ''rubocop'' --format json --force-exclusion  --stdin ''/usr/src/app/Rakefile'' < ''/tmp/nvimSHY0Hz/2/Rakefile''']

Fixer Log(failed)

['/bin/sh', '-c', 'docker-compose exec -T api bundle exec ''rubocop'' --config ''/home/uplus/project/.rubocop.yml'' --auto-correct --force-exclusion --stdin ''/usr/src/app/Rakefile'' < ''/tmp/nvimSHY0Hz/3/Rakefile''']

Cause

Fixer fails because host filepath is passed to --config of rubocop in the container.
Files targeted by Fixer are mapped as specified in b:ale_filename_mappings, but file path of --config are not mapped.
Rubocop does not work because --config specified an invalid file path.

['/bin/sh', '-c', 'docker-compose exec -T api bundle exec ''rubocop'' --config ''/home/uplus/project/.rubocop.yml'' --auto-correct --force-exclusion --stdin ''/usr/src/app/Rakefile'' < ''/tmp/nvimSHY0Hz/3/Rakefile''']
                                                                                 ^^^^^^^^^^^^^^^^^^^                                                           ^^^^^^^^^^^^
                                                                                 Host machine filepath(not mapped)                                             Container filepath(mapped)

Solution

This problem can be resolved by removing --config.

Fixer Log(succeeded)

['/bin/sh', '-c', 'docker-compose exec -T api bundle exec ''rubocop'' --auto-correct --force-exclusion --stdin ''/usr/src/app/Rakefile'' < ''/tmp/nvimwyKaEQ/6/Rakefile''']

According to the commit log, ALE specifies --config to resolve #732.
At that time, there seemed to be a problem that .rubocop.yml was not loaded when using rubocop fixer from ALE.

However current rubocop fixer reads .rubocop.yml even if ALE doesn't specify --config.
Also, in previous implementations, fixer specified --config, but linter did not specify --config, so the behavior could be different.

If ALE user wants to specify --config, it can be specified with g:ale_ruby_rubocop_options.

Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fix looks good.

@hsanson hsanson merged commit c9c89a1 into dense-analysis:master Sep 23, 2021
@uplus uplus deleted the fix-rubocop-fixer-on-othere-machine branch September 23, 2021 10:24
@uplus
Copy link
Contributor Author

uplus commented Sep 23, 2021

Thanks for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ALE doesn't fix certain files with rubocop
2 participants