Commit Graph

134 Commits

Author SHA1 Message Date
Akhil G Krishnan 6499683ebd Removed Performance/UnfreezeString cop 2023-11-20 20:31:17 +05:30
fatkodima af8f002c88 Enable `Lint/InterpolationCheck` rubocop's cop 2023-10-26 15:33:59 +03:00
Nikita Vasilevsky 19f8ab2e7d
[Tests only] Enable `Minitest/AssertPredicate` rule 2023-10-13 19:26:47 +00:00
fatkodima b8829cabec Enable `Style/RedundantDoubleSplatHashBraces` rubocop cop 2023-10-11 14:55:00 +03:00
fatkodima a7ee313d91 Enable raising when running `rubocop-md` against invalid ruby snippets 2023-09-27 23:12:48 +03:00
fatkodima 7ef86b6a49 Enable `Lint/RedundantSafeNavigation` rubocop cop 2023-09-27 14:55:07 +03:00
zzak 5c2a112d37
Import rails-bin to internal tools/
Co-authored-by: zzak <zzakscott@gmail.com>
2023-09-13 01:57:16 +00:00
Shouichi Kamiya 51ac8b9f6f Enable Minitest/LiteralAsActualArgument
There are assertions that expected/actual arguments are passed in the
reversed order by mistake. Enabling the LiteralAsActualArgument rule
prevents this mistake from happening.

The existing tests were auto-corrected by rubocop with a bit of
indentation adjustment.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-09-13 10:09:32 +09:00
zzak dadf46de36
Add rubocop-md for linting guides snippets 2023-03-15 10:48:19 +09:00
Hartley McGuire 11c59f7243
Regenerate Active Storage dummy app
Generated using the following script and manually reviewed after:
skipkayhil/rails-bin@cbad7eddcb

The active_storage configuration had to be moved to the dummy app
because of the changed eager_load config. Now, the whole app is eagerly
loaded when the app's environment file is required which means that
changing configuration in the test_helper is too late.
2023-02-18 17:51:27 -05:00
Hartley McGuire 978993e880
Enable Style/EvalWithLocation
Ref: ad39d6b

Ensure that all evals include file and line number to identify their
source.

Two of the evals reported by this cop were unneccesary and replaced with
non-eval alternatives: xml is set as a local variable in
Template::Handlers::Builder#call, and instance_eval isn't needed to get
the current binding.

There are additionally 27 offenses in test directories, but since it
seems less important to fix those they are currently ignored.
2023-01-11 18:46:09 -05:00
Koichi ITO d0ef331087 Enable `Lint/DuplicateMagicComment` cop
This PR enables `Lint/DuplicateMagicComment` cop to resolve
the background of https://github.com/rubocop/rubocop/issues/11043.

And this PR bumps RuboCop version because the cop was introduced in RuboCop 1.37.0:
https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md#1370-2022-10-20
2022-11-14 16:04:25 +09:00
Hartley McGuire d68e36beab
Enable Minitest/SkipEnsure
I believe this was supposed to be included in 1b736a8
2022-09-20 21:20:17 -04:00
Hartley McGuire c62dcf54eb
fix remaining asserts that should be assert_equal
Found using Minitest/AssertWithExpectedArgument.

Also enabled the rule per feedback and fixed 29 additional violations
2022-09-09 19:22:21 -04:00
Koichi ITO 9c56d087fc Enable `Minitest/AssertRaisesWithRegexpArgument` cop
Follow up #45965.

The commit to enable `Minitest/AssertRaisesWithRegexpArgument` cop was forgotten.
2022-09-08 18:25:57 +09:00
fatkodima 3158bbb9f6 Update `rubocop-performance` and enable more performance-related cops 2022-08-26 15:07:11 +03:00
fatkodima 86519996f9 Enable `Style/RedundantCondition` cop 2022-08-11 11:38:14 +03:00
Koichi ITO 819871cc4e Enable `Style/MapToHash` cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
Gannon McGibbon 03293da4e9 Enable Performance/OpenStruct 2022-02-17 17:16:42 -05:00
Nikita Vasilevsky 8a943a27d8 Enable Lint/EnsureReturn cop 2022-02-05 23:58:07 +00:00
Nikita Vasilevsky 2a00c89a7d
Enable Lint/DuplicateMethods rubocop rule 2021-11-15 13:51:28 -05:00
Jean Boussier 532ef0d13c Add back Lint/UselessAssignment
Fix: #43169
2021-09-06 16:24:37 +02:00
Jean Boussier c91c266872 Enable `Style/ExplicitBlockArgument` cop
This reduce the stack size which is beneficial for
exceptions performance.

See: https://gist.github.com/byroot/cb3bcadcc3701c2518d002fb8d3a4e7a

However the cop is unsafe because it might change the block arity,
so it can run into some false positives.
2021-09-05 17:06:19 +02:00
David Heinemeier Hansson 82e4432058
Javascript generator option with choices (#43160)
* Switch to a single controller option for choosing JavaScript approach

* Remove remnants of webpacker specific work within Rails

* No longer used

* Missing space

* Raise if unknown option is passed

* Style

* Use latest versions

* Make channels setup generic to all node setups

* Make Action Text installer work with any node package manager

* Explaining variables are not useless

* Rubocop pleasing

* Don't rely on Rails.root

Tests don't like it!

* Rubocopping

* Assume importmap

* No longer relevant

* Another cop

* Style

* Correct installation notice

* Add dependencies for action cable when adding a channel

* Fix paths to be relative to generator

* Just go straight to yarn, forget about binstub

* Fix tests

* Fixup installer, only yarn once

* Test generically with run

* Style

* Fix reference and reversibility

* Style

* Fix test

* Test pinning dependencies

* Remove extra space

* Add more tests

* Use latest dependencies

* Relegated this to controllers

* Refactor ChannelGenerator + more tests

Use a uniform level of abstraction
2021-09-04 11:53:57 +02:00
Koichi ITO 65af100ddd Tweak unreachable assertion tests in the block of `assert_raises`
I found an unexpected use of assertion in the block of `assert_raise`
when I implemented https://github.com/rubocop/rubocop-minitest/pull/137.
It is expected to be asserted after an exception is raised in
`assert_raise` block, but in actually it is not asserted after an
exception is raised. Therefore, this PR removes or updates assertions
that have not been asserted after an exception has raised.

This PR will add `rubocop-minitest` and enable
`Minitest/UnreachableAssertion` cop to able similar auto-detection,
but will remove `rubocop-minitest` from this PR if you don't like it.
2021-08-17 20:33:08 +09:00
Ryuta Kamizono d7fce6c996 Fix odd closing parenthesis by enabling the `Layout/ClosingParenthesisIndentation` cop 2021-07-02 18:01:50 +09:00
Hartley McGuire a3e5e8d909 use ruby 2.7's filter_map instead of select + map
Related: c3d7794, bbbc861
2021-04-26 17:55:33 -04:00
Ryuta Kamizono c0c77e28ad Enable `Layout/EndOfLine` to prevent \r\n is included in the future
Follow up to a1afc7726b.
2021-04-24 23:59:19 +09:00
Ryuta Kamizono bbbc861f71 Enable `Performance/MapCompact` cop
Follow up to #42053.
2021-04-23 16:33:02 +09:00
Ryuta Kamizono c4b944a273 Enable `Performance/StringReplacement` cop
Follow up to #42054.
2021-04-23 16:17:55 +09:00
David Heinemeier Hansson ab8e3d22cb
Extract ActiveStorage::Streaming so your own controllers can use it (#41440)
Extract ActiveStorage::Streaming so your own controller can use it
2021-02-19 15:40:56 +01:00
Ryuta Kamizono 6515d6985d Use `bind_call(obj, ...)` instead of `bind(obj).call(...)`
`bind_call(obj, ...)` is a faster alternative to `bind(obj).call(...)`.

https://bugs.ruby-lang.org/issues/15955

Also, enable `Performance/BindCall` cop to detect those in the future.
2021-02-08 17:01:23 +09:00
Ryuta Kamizono 2e9c0e04c5 Update `TargetRubyVersion` to 2.7 in `.rubocop.yml` 2021-02-05 12:23:33 +09:00
Ryuta Kamizono ba97e9f918 Remove `Lint/ShadowingOuterLocalVariable` cop
"shadowing outer local variable" warning was removed in Ruby 2.6.

c9d720b873
https://bugs.ruby-lang.org/issues/12490
2021-02-05 12:08:14 +09:00
Rafael Mendonça França 458f19a0f7
Disable rubocop suggestions 2021-01-27 00:28:55 +00:00
Ryuta Kamizono cbf72c119e Enable `Lint/DuplicateRequire` cop
Closes #40644.

Co-authored-by: luccafort <konishi.tatsuro@moneyforward.co.jp>
2021-01-09 14:40:47 +09:00
KapilSachdev a908d06c85
feat(rubocop): Add Style/RedundantRegexpEscape
- This cop will help in removing unnecessary escaping inside Regexp literals.
2020-12-08 18:57:09 +00:00
Ryuta Kamizono 92ff708476 Re-enable `Layout/SpaceAroundOperators` cop
We prefer space around operators, but `Layout/SpaceAroundOperators` cop
was temporarily disabled in #36943 since that cop changed to check
alignment strictly somehow.

In RuboCop 1.0.0, that is fixed by https://github.com/rubocop-hq/rubocop/pull/8906.

Related https://github.com/rails/rails/pull/38034#discussion_r359845661,
https://github.com/rails/rails/pull/39770#discussion_r448829561.
2020-10-23 16:12:15 +09:00
Utkarsh Gupta cd9ab098c4 Update RuboCop to v0.90
Signed-off-by: Utkarsh Gupta <utkarsh@debian.org>
2020-09-06 06:37:04 +05:30
dug c74c52c4b0
Remove redundant Exclude in .rubocop.yml
All `/tmp/` dirs are already excluded by line 11.
2020-06-29 16:06:48 -07:00
fatkodima e24d6ecbfd Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops 2020-05-24 12:51:35 +03:00
Eugene Kenny a9fc2d4daa Enable Rails/IndexBy and Rails/IndexWith cops
Followup to d3599d8aff, which applied this
style to the existing codebase.
2020-04-19 23:36:05 +01:00
Tejas Bubane cf1abb775e
Bump rubocop to 0.82 (#38980)
* Bump rubocop to 0.82

The `Layout/Tab` cop has been renamed to `Layout/IndentationStyle`
ref: https://github.com/rubocop-hq/rubocop/releases/tag/v0.82.0

No other code changes required.

* Bump rubocop-rails to 2.5.2

No code-changes required.

[Tejas Bubane + Rafael Mendonça França]
2020-04-17 14:24:33 -04:00
Eugene Kenny 9e40348645 Enable HashTransformKeys and HashTransformValues cops
Followup to 88fe76e693.

These are new in RuboCop 0.80.0, and enforce a style we already prefer
for performance reasons (see df81f2e5f5).
2020-02-20 22:37:32 +00:00
Yasuo Honda 78c209a693 Bump RuboCop version to 0.77
https://github.com/rubocop-hq/rubocop/releases/tag/v0.77.0

* Update cop names to changed as follows:

```
$ bundle exec rubocop
Error: The `Layout/IndentFirstArgument` cop has been renamed to `Layout/FirstArgumentIndentation`.
(obsolete configuration found in .rubocop.yml, please update it)
The `Layout/TrailingBlankLines` cop has been renamed to `Layout/TrailingEmptyLines`.
(obsolete configuration found in .rubocop.yml, please update it)
The `Lint/StringConversionInInterpolation` cop has been renamed to `Lint/RedundantStringCoercion`.
(obsolete configuration found in .rubocop.yml, please update it)
$
```

* Auto correct these offenses:

```
$ bundle exec rubocop -a
... snip ...
Offenses:

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:104:11: C: [Corrected] Style/RedundantReturn: Redundant return detected.
          return true
          ^^^^^^
activerecord/lib/active_record/reflection.rb:622:15: C: [Corrected] Style/RedundantReturn: Redundant return detected.
              return inverse_name
              ^^^^^^
activerecord/lib/active_record/table_metadata.rb:48:9: C: [Corrected] Style/RedundantReturn: Redundant return detected.
        return self
        ^^^^^^

2812 files inspected, 3 offenses detected, 3 offenses corrected
$
```
2019-11-27 23:58:49 +00:00
Ryuta Kamizono 9b8fb3fc04 Enable `Layout/ClosingHeredocIndentation` cop 2019-11-24 09:44:32 +09:00
Yasuo Honda ce9a220fdc Enabled GitHub Actions to run the latest RuboCop 0.76.0
Updated the default Ruby workflow:

* Trigger this action for pull request and push
* Install requried OS packages for Active Record connection adapters
* Removing `gem install bundler` because Ruby 2.6 already installs it
* Run RuboCop in parallel by `bundle exec rubocop --parallel`
* Rename `ruby.yml` to `rubocop.yml` to represent the workflow

Bump RuboCop to 0.76.0 and rename `Style/UnneededPercentQ` to `Style/RedundantPercentQ`

```ruby
$ bundle exec rubocop
Error: The `Style/UnneededPercentQ` cop has been renamed to `Style/RedundantPercentQ`.
(obsolete configuration found in .rubocop.yml
```

Removed `.codeclimate.yml`
2019-10-30 23:21:09 +00:00
Kasper Timm Hansen 245b037734
Less Pure Copping: cop-out tmp folders for generated Rails apps
After having run the railties tests locally and running Rubocop, you'd
see lots of violations for the Rails apps generated in tmp folders.

Don't consider those violations as violating.
2019-10-07 02:15:32 +02:00
Ryuta Kamizono 0770c025bd Do not enforce no braces for hash argument
Non-kwargs parameters should be to be braced for https://github.com/ruby/ruby/pull/2395.
See https://bugs.ruby-lang.org/issues/14183 for details.

`Style/BracesAroundHashParameters` cop conflicts with that.

This removes `Style/BracesAroundHashParameters` cop and auto-correct to
following changes.

d94263f...5665fb5
2019-09-04 08:49:36 +09:00
Koichi ITO 1c66e047f6 Bump RuboCop to 0.74.0
### Summary

RuboCop 0.74.0 has been released.
https://github.com/rubocop-hq/rubocop/releases/tag/v0.74.0

And rubocop-0-74 channel is available in Code Climate.
https://github.com/codeclimate/codeclimate/releases/tag/v0.85.5

This PR specifies the same RuboCop Performance (1.3.0) and RuboCop Rails (2.0.0)
versions as Code Climate's Gemfile.lock.
https://github.com/codeclimate/codeclimate-rubocop/blob/channel/rubocop-0-74/Gemfile.lock#L51-L55

Also, the `EnforcedStyle` of `Layout/IndentationConsistency` has been renamed
from `EnforcedStyle: rails` to `EnforcedStyle: indented_internal_methods`

- https://github.com/rubocop-hq/rubocop/pull/7113
- https://github.com/rubocop-hq/rubocop/pull/7163

And this commit disables `Layout/SpaceAroundOperators`
that was changed from RuboCop 0.74 by rubocop-hq/rubocop#7211.

cf. https://github.com/rails/rails/pull/36943#issuecomment-521659529
2019-08-15 23:28:06 +09:00