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

Add ruby fixer using rubocop --auto-correct #689

Merged
merged 5 commits into from Jun 25, 2017

Conversation

lynndylanhurley
Copy link
Contributor

This does seem to work as expected, but I was not able to create a vader test for this. Maybe someone familiar with the test env can give me some advice?

Here was my attempt:

Before:
  Save g:ale_fixers

After:
  Restore

Given ruby(Ruby code with bad indentation):
  def inc(x)
      x + 1
  end

Execute(Fix the file):
  let g:ale_fixers = {'ruby': ['rubocop']}
  ALEFix

Expect ruby(Ruby code with correct indentation):
  def inc(x)
    x + 1
  end

This fails with the following error:

  Starting Vader: /testplugin/test/fixers/test_rubocop_fixer.vader
    (1/1) [  GIVEN] Ruby code with bad indentation
    (1/1) [EXECUTE] Fix the file
    (1/1) [ EXPECT] (X) Ruby code with correct indentation
      - Expected:
          def inc(x)
            x + 1
          end
      - Got:
          def inc(x)
              x + 1
          end
  Success/Total: 0/1

But the fixer does run when used with actual code in an editor.

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

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

You can run the test suite on any system which runs Bash by using ./run-tests, supposing you have installed Docker. Install Docker via your package manager and follow post-installation steps: https://docs.docker.com/engine/installation/linux/linux-postinstall/

For testing this, add some tests which use AssertEqual for the function you added, and include a test which searches for a local rubocop directory. Look at existing tests for examples, include the rubocop linter tests.

\ . ' --auto-correct %t',
\ 'read_temporary_file': 1,
\}
endfunction
Copy link
Member

Choose a reason for hiding this comment

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

Your indentation needs to be fixed here to match the other files. The test output mentions this somewhat.

@lynndylanhurley
Copy link
Contributor Author

@w0rp - just pushed the following updates:

  1. Fixed the indentation to match the rest of the codebase.
  2. Added a vader test modeled after the existing fixer tests. Still not 100% sure how the tests work, but it's passing and the fixer is working.

Thanks for taking the time to review this PR.

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

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

Cool. I might fix up the Vader test file so I can run it directly in GVim, but this is good. 👍

@w0rp w0rp merged commit 7f6e5dc into dense-analysis:master Jun 25, 2017
@w0rp
Copy link
Member

w0rp commented Jun 25, 2017

Cheers! 🍻

@lynndylanhurley
Copy link
Contributor Author

Thanks!! 😃

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.

None yet

2 participants