Skip to content

Instantly share code, notes, and snippets.

@jshirley
Last active May 18, 2016 21:00
Show Gist options
  • Save jshirley/e1cdfd0e5dd04612d112e4675d038a91 to your computer and use it in GitHub Desktop.
Save jshirley/e1cdfd0e5dd04612d112e4675d038a91 to your computer and use it in GitHub Desktop.

Revisions

  1. jshirley revised this gist May 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion broken.rb
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@ def foo
    puts "For really real, it isn't"
    end
    end
    end
    end
  2. jshirley revised this gist May 18, 2016. 2 changed files with 8 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions .rubocop-todo.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Lint/EndAlignment:
    Exclude:
    - 'rel/path/broken.rb'
    5 changes: 5 additions & 0 deletions .rubocop.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    inherit_from:
    - .rubocop-todo.yml

    Documentation:
    Enabled: false
  3. jshirley created this gist May 18, 2016.
    3 changes: 3 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    source 'https://rubygems.org'

    gem 'rubocop'
    30 changes: 30 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    The rubocop [documentation](https://github.com/bbatsov/rubocop/blame/master/README.md#L425) states "Files and directories are specified relative to the .rubocop.yml file.", however that seems to be untrue based on from where you run rubocop from! Oh no!

    To demonstrate the breakage, clone this gist and move the broken.rb to a subdirectory:
    ```
    mkdir -p rel/path
    mv broken.rb rel/path
    ```

    From there, you can confirm that relative paths work from the same directory as .rubocop.yml:

    ```
    bundle
    bundle exec rubocop rel/path/broken.rb
    ```

    All good! `1 files inspected, no offenses detected` But if I rely on the behavior for rubocop to go upwards to find the `.rubocop.yml` (which it does) it loses the `Excludes` configuration.

    ```
    bundle exec rubocop broken.rb
    Inspecting 1 file
    W
    Offenses:
    broken.rb:8:7: W: end at 8, 6 is not aligned with if at 4, 4.
    end
    ^^^
    1 file inspected, 1 offense detected
    ```
    10 changes: 10 additions & 0 deletions broken.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    class Broken
    def foo
    # I'm intentionally broken
    if 1 == 0
    puts "This isn't real code."
    else
    puts "For really real, it isn't"
    end
    end
    end