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

Feature: Allow exclusion of lines matching pattern from indentation #4137

Merged
merged 3 commits into from
Mar 23, 2017
Merged

Feature: Allow exclusion of lines matching pattern from indentation #4137

merged 3 commits into from
Mar 23, 2017

Conversation

jfelchner
Copy link
Contributor

@jfelchner jfelchner commented Mar 17, 2017

This change allows for more fine-grained control over which lines indentation is required. It isn't frequent, but there are occasionally times when the requirement for indentation doesn't quite fit in with the code style you're trying to achieve.

I wasn't entirely sure on what I wanted to do here, however once I saw the change to the LineLength cop which added the IgnoredPatterns option, I knew that's what I wanted for IndentationWidth.

This PR extracts the IgnoredPatterns logic out into a mixin and then adds that to the IndentationWidth cop.

I would recommend reviewing by commit rather than looking at the full diff. The change itself was very minor, however I did a little refactoring to alleviate some rubocop errors.

The end result is that you can have a config like so:

Style/IndentationWidth:
  Width: 2
  IgnoredPatterns:
    - '^\s*module'
    - '^\s*if'

And the following will not throw errors

module Rubocop
class  Foo
  def bar
    if true
                        puts 'true'
    else
      puts 'false'
    end
  end
end
end

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 23, 2017

The changes look good but this should be squashed to 2 or 3 commits on top of the current master.

@jfelchner
Copy link
Contributor Author

@bbatsov definitely can do. I just wanted to make it easier for you to review.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 23, 2017

I appreciate this!

@jfelchner
Copy link
Contributor Author

@bbatsov squashed to 3 commits which I thought was the minimum to tell a good code story.

I also added better documentation for IndentationWidth as it was a little lacking.

Hope this is acceptable!

@jfelchner
Copy link
Contributor Author

BTW, seems like we're getting close to 0.48.0? 😬

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 23, 2017

Looks good, but you'll have to rebase again.

0.48 is right around the corner. :-)

@jfelchner
Copy link
Contributor Author

@bbatsov there ya go!

@bbatsov bbatsov merged commit ae09240 into rubocop:master Mar 23, 2017
@jfelchner jfelchner deleted the feature/allow-exclusion-of-lines-matching-pattern-from-indentation branch March 18, 2018 14:46
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.

2 participants