Commit Graph

59 Commits

Author SHA1 Message Date
bogdanvlviv
09ec075f1e
Remove Rubocop's comments from Rails code base
PR#32381 added Rubocop's comments to some tests files in order to
exclude `Performance/RedundantMerge`.

Turn off `Performance` cops for tests files via `Exclude`
in `.rubocop.yml`.

Context https://github.com/rails/rails/pull/32381#discussion_r205212331
2018-07-26 23:37:31 +03:00
Koichi ITO
211b10aea6 Bump RuboCop to 0.58.2
## Summary

RuboCop 0.58.2 was released.
https://github.com/rubocop-hq/rubocop/releases/tag/v0.58.2

And rubocop-0-58 channel is available in Code Climate.
https://github.com/codeclimate/codeclimate/releases/tag/v0.76.0
https://github.com/codeclimate/codeclimate/commit/38f21f0

In addition, the following changes are made in this PR.

- Replace Custom cops with Rails cops
- Add jaro_winkler gem to Gemfile.lock

### Replace Custom cops with Rails cops

These are compatible replacements.

- Replace `CustomCops/AssertNot` cop with `Rails/AssertNot` cop.
- Replace `CustomCops/RefuteNot` cop with `Rails/RefuteMethods` cop.

With this replacement, it was decided to use cop of RuboCop itself.
It removes the code related to CustomCops accordingly.

### Add jaro_winkler gem to Gemfile.lock

Since RuboCop 0.57.0 depends on jaro_winkler gem,
it has been added to Gemfile.lock.
2018-07-26 17:48:07 +09:00
Dillon Welch
d108288c2f
Turn on performance based cops
Use attr_reader/attr_writer instead of methods

method is 12% slower

Use flat_map over map.flatten(1)

flatten is 66% slower

Use hash[]= instead of hash.merge! with single arguments

merge! is 166% slower

See https://github.com/rails/rails/pull/32337 for more conversation
2018-07-23 15:37:06 -07:00
Ryuta Kamizono
6f58b2cfc9 Enable Layout/EmptyLinesAroundBlockBody to reduce review cost in the future
We sometimes ask "✂️ extra blank lines" to a contributor in reviews like
https://github.com/rails/rails/pull/33337#discussion_r201509738.

It is preferable to deal automatically without depending on manpower.
2018-07-12 21:29:48 +09:00
Ryuta Kamizono
a77447f4da Enable Lint/StringConversionInInterpolation rubocop rule
To prevent redundant `to_s` like https://github.com/rails/rails/pull/32923#discussion_r189460008
automatically in the future.
2018-05-21 21:10:14 +09:00
Bart de Water
e236454a1a Rubocop 0.54
Fix `.rubocop.yml: Lint/EndAlignment has the wrong namespace - should be Layout` warning
2018-04-21 13:18:50 -04:00
bogdanvlviv
1a42d87e3b
Allow rubocop check more files
This commit fix pattern of filenames for `CustomCops/AssertNot` and
`CustomCops/RefuteNot`.

rubocop should check every file under `test/`.

Related to #32441, #32605
2018-04-19 23:25:39 +03:00
Rafael França
6fec9c27e5
Merge pull request #32605 from composerinteralia/assert-not
Add RuboCop for `assert_not` over `assert !`
2018-04-19 15:03:28 -04:00
Yoshiyuki Hirano
4e1972e1ca Add exculude condition in rubocop.yml
* Excluded `railties/test/fixtures/tmp/**/*` from rubocop inspect files
* These files are generated after running test in railties
2018-04-20 00:20:33 +09:00
Daniel Colson
087e0ccb72 Add RuboCop for assert_not over assert !
We added `assert_not` in f75addd "to replace warty 'assert !foo'".
fa8d35b agrees that it is warty, and so do I. This custom Rubocop rule
turns the wart into a violation.

As with my last custom cop, https://github.com/rails/rails/pull/32441,
I want to make sure this looks right on code climate before pushing
another commit to autocorrect everything.

@toshimaru I just noticed
https://github.com/toshimaru/rubocop-rails/pull/26
Is there a better way to add these custom cops, or were you saying we
shouldn't have custom cops at all?
2018-04-19 08:11:28 -04:00
Daniel Colson
f88f5a457c Add custom RuboCop for assert_not over refute
Since at least cf4afc4 we have preferred `assert_not` methods over
`refute` methods. I have seen plenty of comments in PRs about this,
and we have tried to fix it a few times (5294ad8, e45f176, 8910f12,
41f50be, d4cfd54, 48a183e, and 211adb4), but the `refute` methods
keep sneaking back in.

This custom RuboCop will take care of enforcing this preference, so we
don't have to think about it again. I suspect there are other similar
stylistic preferences that could be solved with some custom RuboCops, so
I will definitely keep my eyes open. `assert_not` over `assert !` might
be a good candidate, for example.

I wasn't totally sure if `ci/custom_cops` was the best place to put
this, but nothing else seemed quite right. At one point I had it set up
as a gem, but I think custom cops like this would have limited value
in another context.

I want to see how code climate handles the new cops before
autocorrecting the existing violations. If things go as expected, I will
push another commit with those corrections.
2018-04-03 22:35:34 -04:00
Andrew White
9c0c90979a Add cop for preferring 'Foo.method' over 'Foo::method' 2018-02-22 06:26:48 +00:00
Jeremy Daer
d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
Rafael Mendonça França
89bcca59e9 Remove usage of strip_heredoc in the framework in favor of <<~
Some places we can't remove because Ruby still don't have a method
equivalent to strip_heredoc to be called in an already existent string.
2018-02-16 19:28:30 -05:00
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