Commit Graph

145 Commits

Author SHA1 Message Date
Koichi ITO
5ac6ec54a6 Enable autocorrect for Lint/EndAlignment cop
### Summary

This PR changes .rubocop.yml.

Regarding the code using `if ... else ... end`, I think the coding style
that Rails expects is as follows.

```ruby
var = if cond
  a
else
  b
end
```

However, the current .rubocop.yml setting does not offense for the
following code.

```ruby
var = if cond
        a
      else
        b
      end
```

I think that the above code expects offense to be warned.
Moreover, the layout by autocorrect is unnatural.

```ruby
var = if cond
  a
      else
        b
      end
```

This PR adds a setting to .rubocop.yml to make an offense warning and
autocorrect as expected by the coding style.
And this change also fixes `case ... when ... end` together.

Also this PR itself is an example that arranges the layout using
`rubocop -a`.

### Other Information

Autocorrect of `Lint/EndAlignment` cop is `false` by default.
https://github.com/bbatsov/rubocop/blob/v0.51.0/config/default.yml#L1443

This PR changes this value to `true`.

Also this PR has changed it together as it is necessary to enable
`Layout/ElseAlignment` cop to make this behavior.
2018-01-18 17:19:13 +09:00
Ryuta Kamizono
245c1dafa8 Enable Layout/LeadingCommentSpace to not allow cosmetic changes in the future
Follow up of #31432.
2017-12-14 17:30:54 +09:00
Ryuta Kamizono
2b35826389 Enable Layout/SpaceBeforeComma rubocop rule, and fixed more
Follow up of #31390.
2017-12-12 20:00:50 +09:00
Ryuta Kamizono
7ce8a6af1b Enable Style/DefWithParentheses rubocop rule
The def with blank `()` was newly added in #31176, but we have not used
the blank `()` style in most part of our code base.
So I've enabled `Style/DefWithParentheses` to prevent to newly added the
code.
2017-11-27 15:16:12 +09:00
Ryuta Kamizono
146b1c2e33 Enable Style/RedundantReturn rubocop rule, and fixed a couple more
Follow up of #31004.
2017-11-01 07:32:04 +09:00
Matthew Draper
7d264ba8cd Merge pull request #31005 from shuheiktgw/remove_unnecessary_semicolons
Removed unnecessary semicolons
2017-10-28 22:55:34 +10:30
bogdanvlviv
43f452f23b
Remove frozen_string_literal comment from activestorage's migration
The activestorage's migration is used as template for apps
Related to #30348
2017-08-22 08:32:27 +03:00
Koichi ITO
7c260ae201 Fix RuboCop offenses
And enable `context_dependent` of Style/BracesAroundHashParameters cop.
2017-08-16 17:55:25 +09:00
Pat Allan
acea68de02 Adding frozen_string_literal pragma to Railties. 2017-08-14 19:08:09 +02:00
Koichi ITO
3281300e79 Remove unnecessary Include parameter in rubocop.yml 2017-08-14 01:57:29 +09:00
Koichi ITO
d17264d93f Use frozen string literal in root files 2017-08-13 22:14:24 +09:00
Koichi ITO
0ea00bb5b0 Use frozen string literal in ci/ 2017-08-13 22:07:54 +09:00
Koichi ITO
7d85e0f95c Use frozen string literal in tools/ 2017-08-13 22:04:59 +09:00
Koichi ITO
ef2016f888 Use frozen string literal in tasks/ 2017-08-13 22:04:42 +09:00
Koichi ITO
1f37d846a9 Use frozen string literal in guides/ 2017-08-13 22:04:09 +09:00
Koichi ITO
d02844f249 Use frozen string literal in Active Storage 2017-08-12 21:43:42 +09:00
Rafael Mendonça França
77be872819 Do not change the entire codebase style only because of active_storage
We are already removing the braces around hash parameters in the last
argument in other places so we should not change the entire codebase
because of two places.
2017-08-03 17:45:58 -04:00
Rafael Mendonça França
b76f4e47e8 Fix all rubocop violations 2017-08-03 17:32:59 -04:00
Kir Shatrov
dfcc766163 Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
Kir Shatrov
424117281e Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
Kir Shatrov
385825fb70 Use frozen string literal in actioncable/ 2017-07-23 23:30:29 +03:00
Kir Shatrov
82df8c2ca5 Use frozen string literal in actionmailer/ 2017-07-23 18:17:19 +03:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Ryuta Kamizono
4183d5dfa1 Enable Layout/FirstParameterIndentation cop
We have some indentation cops. But now there is a little inconsistent
params indentations. Enable `Layout/FirstParameterIndentation` cop to
prevent newly inconsistent indentation added and auto-correct to
existing violations.
2017-07-17 14:08:32 +09:00
Kir Shatrov
d7b1521db8 Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
Koichi ITO
2adb2b19fc Enable Layout/EmptyLineAfterMagicComment cop 2017-07-11 13:12:32 +09:00
Kir Shatrov
14ece5e429 Use frozen-string-literal in ActiveJob 2017-07-09 20:50:52 +03:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Yasuo Honda
0d4977beec rubocop namespace changes from Style to Layout
Refer 54166bf76b
for the commit

```
/path/to/rails/.rubocop.yml: Style/CaseIndentation has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/CommentIndentation has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/EmptyLines has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/EmptyLinesAroundClassBody has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/EmptyLinesAroundMethodBody has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/EmptyLinesAroundModuleBody has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/IndentationConsistency has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/IndentationWidth has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceAfterColon has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceAfterComma has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceAroundEqualsInParameterDefault has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceAroundKeyword has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceAroundOperators has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceBeforeFirstArg has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceBeforeBlockBraces has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceInsideBlockBraces has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceInsideHashLiteralBraces has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/SpaceInsideParens has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/Tab has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/TrailingBlankLines has the wrong namespace - should be Layout
/path/to/rails/.rubocop.yml: Style/TrailingWhitespace has the wrong namespace - should be Layout
```
2017-05-24 18:40:04 +00:00
Ryuta Kamizono
16ee3ccc9c Add Style/EmptyLinesAroundMethodBody in .rubocop.yml and remove extra empty lines 2017-02-12 20:44:15 +09:00
toshimaru
9304912559 Rename AlignWith to EnforcedStyleAlignWith 2017-01-16 15:36:57 +09:00
Matthew Draper
4273ab34c4 Shave a couple of allocations off Journey scan & parse 2016-12-25 01:04:08 +10:30
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Igor Zubkov
b16a0750db Set target ruby version for rubocop to 2.2 instead 2.3.
This change will help to catch ruby 2.3+ syntax in code base. Right now, minimal ruby version set to 2.2.2 in gemspecs.

Rubocop output before:

$ rubocop
Inspecting 2133 files
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................CC.........................................................................................................................................................................................................................................................

Offenses:

activerecord/test/cases/schema_dumper_test.rb:454:32: C: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
    output = dump_table_schema('infinity_defaults')
                               ^^^^^^^^^^^^^^^^^^^
guides/bug_report_templates/active_record_migrations_gem.rb:65:4: C: Final newline missing.
end

guides/bug_report_templates/active_record_migrations_master.rb:64:4: C: Final newline missing.
end

2133 files inspected, 3 offenses detected
$

After:
$ rubocop
Inspecting 2133 files
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................CC.........................................................................................................................................................................................................................................................

Offenses:

activerecord/test/cases/schema_dumper_test.rb:454:32: C: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
    output = dump_table_schema('infinity_defaults')
                               ^^^^^^^^^^^^^^^^^^^
guides/bug_report_templates/active_record_migrations_gem.rb:65:4: C: Final newline missing.
end

guides/bug_report_templates/active_record_migrations_master.rb:64:4: C: Final newline missing.
end

2133 files inspected, 3 offenses detected
$
2016-10-11 10:16:48 +03:00
Ryuta Kamizono
3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Vijay Dev
8f26f31934 Fix a typo 2016-08-07 16:36:51 +05:30
Ryuta Kamizono
762e3f05f3 Add Style/EmptyLines in .rubocop.yml and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria
77eb40dab6 adds a few cops and sorts 2016-08-06 18:10:50 +02:00
Xavier Noria
58283b5acd explain the meaning of some RuboCop config options [ci skip]
For consistency mainly.

Also, some have a name that could make the reader think they
enforce the opposite of what they do, because the default is
not visible there.
2016-07-21 13:52:30 +02:00
Rafael Mendonça França
0f96d01758
Add a new rule to rubocop 2016-07-20 00:35:11 -03:00
Rafael Mendonça França
2384317465
Enable a few more rubocop rules 2016-07-17 04:11:51 -03:00
Jon Moss
80e819586b
Move code style configuration files to root directory
I think these are meant to be in the root directory, not in
`/activerecord`? 😬

r? @sgrif

[ci skip]
2016-06-16 22:17:46 -04:00