Commit Graph

79 Commits

Author SHA1 Message Date
Ryuta Kamizono 4353adab89 Enable `Lint/AmbiguousOperator` and `Lint/AmbiguousRegexpLiteral` cops
To avoid newly adding the warnings, which are frequently addressed.

ac721c8552
951383bd9a
8a0f235fd3

c33c03e80c
424b201983
2019-03-06 10:01:33 +09:00
Ryuta Kamizono 6b8daad038 Enable `Performance/ReverseEach` cop to avoid newly adding `reverse.each`
https://github.com/rails/rails/pull/35451#discussion_r262746834
2019-03-06 09:41:06 +09:00
Ryuta Kamizono 7ebfb319ff Enable `Lint/ErbNewArguments` cop to avoid the deprecated arguments warning
Related 5754a29a97.

And follows Ruby standard library style https://github.com/ruby/ruby/commit/3406c5d.
2019-02-01 14:20:11 +09:00
bogdanvlviv 2bad3f46cd
Add foreign key to active_storage_attachments for `blob_id` via new migration
We need this in order to be able to add this migration for users that
use ActiveStorage during update their apps from Rails 5.2 to Rails 6.0.

Related to #33405

`rake app:update` should update active_storage

`rake app:update` should execute `rake active_storage:update`
if it is used in the app that is being updated.
It will add new active_storage's migrations to users' apps during update Rails.

Context https://github.com/rails/rails/pull/33405#discussion_r204239399

Also, see a related discussion in the Campfire:
https://3.basecamp.com/3076981/buckets/24956/chats/12416418@1236713081
2019-01-16 13:13:23 +00:00
Ryuta Kamizono ea65d92f19
Enable `Lint/UselessAssignment` cop to avoid unused variable warnings (#34904)
* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings

Since we've addressed the warning "assigned but unused variable"
frequently.

370537de05
3040446cec
5ed618e192
76ebafe594

And also, I've found the unused args in c1b14ad which raises no warnings
by the cop, it shows the value of the cop.
2019-01-09 18:09:01 +09:00
yuuji.yaginuma 5df737b7e8 Enable `Lint/DeprecatedClassMethods` cop to avoid using deprecated methods 2019-01-09 12:00:08 +09:00
George Claghorn 0decd2ddc4 Import Action Text 2019-01-04 22:22:49 -05:00
Ryuta Kamizono 6d959017bd Enable `Lint/ShadowingOuterLocalVariable` cop to avoid newly adding the warning
Since we've addressed the warning "warning: shadowing outer local
variable" frequently.

2c325182b8
df76eaa4f1
b86c2a6767
b658743ac2
b18f2fe96d
2018-12-28 07:48:26 +09:00
George Claghorn a5b2fff64c Import Action Mailbox 2018-12-25 21:32:35 -05:00
Ryuta Kamizono 892e38c78e Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Kasper Timm Hansen 1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Ryuta Kamizono f907b418ae Enable `Layout/SpaceAfterSemicolon` cop to avoid newly adding odd spacing
Ref 59ff1ba30d (diff-38fb97fba84b1ef0f311c4110a597c44R35)
2018-12-13 18:06:04 +09:00
Yasuo Honda 4e9703158f Use RuboCop 0.60.0 and remove exclude files for `Style/RedundantFreeze`
Since https://github.com/rubocop-hq/rubocop/pull/6333 has been
included into RuboCop 0.60.0.
2018-11-08 13:06:12 +00:00
Prathamesh Sonpatki 2eb408cc2f Skip node_modules dir in the rubocop check
- Otherwise it is running the check against all files in node_modules
2018-10-05 21:14:15 +05:30
Yasuo Honda aa3dcabd87 Add `Style/RedundantFreeze` to remove redudant `.freeze`
Since Rails 6.0 will support Ruby 2.4.1 or higher
`# frozen_string_literal: true` magic comment is enough to make string object frozen.
This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.

* Exclude these files not to auto correct false positive `Regexp#freeze`
 - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
 - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'

It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.

* Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required

 - 'actionpack/test/controller/test_case_test.rb'
 - 'activemodel/test/cases/type/string_test.rb'
 - 'activesupport/lib/active_support/core_ext/string/strip.rb'
 - 'activesupport/test/core_ext/string_ext_test.rb'
 - 'railties/test/generators/actions_test.rb'
2018-09-29 07:18:44 +00:00
Rafael Mendonça França f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
yuuji.yaginuma 1b86d90136 Enable `Performance/UnfreezeString` cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
Ryuta Kamizono b2c1e29c14 Enable Style/ParenthesesAroundCondition cop
To prevent style check in review like https://github.com/rails/rails/pull/33608#discussion_r211087605.
2018-08-19 08:16:21 +09:00
Ryuta Kamizono 51bdbc2d01 Enable Lint/UriEscapeUnescape cop not to allow using obsolete methods in the future
Follow up #33627.
2018-08-16 13:08:56 +09:00
Bart de Water eb5fea40a4 Enable Start/EndWith and RegexpMatch cops
In cases where the MatchData object is not used, this provides a speed-up:
https://github.com/JuanitoFatas/fast-ruby/#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end
2018-07-28 17:37:17 -04:00
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