Commit Graph

323 Commits

Author SHA1 Message Date
Javi Martín
99bbad9b1e Add and apply Style/RedundantCondition rule
This is a rule we generally follow all the time but accidentally forgot
in one place.
2021-08-09 19:21:31 +02:00
Javi Martín
4e33664055 Add and apply Lint/BooleanSymbol rubocop rule 2021-08-09 18:54:44 +02:00
Javi Martín
57d8a59d10 Add an apply Style/RaiseArgs rubocop rule
We were already applying it most of the time.
2021-08-09 17:32:46 +02:00
Javi Martín
535a039a31 Add and apply RSpec/FilePath rubocop rule
This way we make sure editors which support navigating between one class
and its test file can find the alternative files.
2021-08-09 16:51:59 +02:00
Javi Martín
21021f5054 Remove instance variables in has_filters spec
This was a false positive in Rubocop, but we can avoid it by using the
attribute reader method we've just added.
2021-01-19 15:05:37 +01:00
Javi Martín
4658e18db5 Re-add and apply Rails/UniqBeforePluck rule
We removed it in commit d639cd58 because it recommended using `uniq`
where `distinct` was more appropriate. This has been fixed in
rubocop-rails 2.6.0.
2020-10-26 11:26:34 +01:00
Javi Martín
d7e6a5c6bf Add Rails/UniqueValidationWithoutIndex rule
This is something we should do everywhere because concurrent requests
might bypass Rails uniqueness validations. However, since there are
places where we aren't applying this rule and adding a unique index
means we also need to destroy any hypothetical duplicate records, it's
something we aren't going to solve right now. Therefore we use the
"refactor" severity so existing offenses don't get in our way.

In any case, we're adding the rule so we don't make the same mistake in
the future.
2020-10-26 11:26:34 +01:00
Javi Martín
dd7d6440ec Add and apply Capybara/VisibilityMatcher rule
This rule was added in rubocop-rspec 1.39.0. The `visible: false` option
is equivalent to `visible: :all`, but we generally use it meaning
`visible: :hidden` for positive expectations and `visible: :all` for
negative expectations.

The only exceptations are tests where we count the number of map icons
present. I'm assuming in this case we care about the number of map icons
independently on whether they are currently shown in the map, so I'm
keeping the `visible: :all` behavior in this case.
2020-10-25 14:23:53 +01:00
Javi Martín
d348e4b688 Add and apply RSpec/EmptyHook rule
This rule was added in rubocop-rspec 1.39.0. Now leaving an empty block
by accident like I did in commit 91c21b09 is harder :).
2020-10-25 14:23:53 +01:00
Javi Martín
cef54b4e59 Add and apply RepeatedExampleGroupDescription rule
This rule was added in rubocop-rspec 1.38.0. Thanks to it we've detected
we had one method tested in two different places.
2020-10-25 14:23:53 +01:00
Javi Martín
f4a6830a1b Add and appy RSpec/RepeatedExampleGroupBody rule
This rule is available since rubocop-rspec 1.38.0. Thanks to it, we've
found out we were testing topics behave like notifiable twice.
2020-10-25 14:23:53 +01:00
Javi Martín
40244d6411 Add and apply FactoryBot/FactoryClassName rule
This rule is available since rubocop-rspec 1.37.0. We were already
applying the same principle in the models since commit 234a5108.
2020-10-25 14:23:53 +01:00
Javi Martín
b6a095ced7 Add and apply RSpec/EmptyLineAfterExample rule
It was introduced in rubocop-rspec 1.36.0. We were already applying it
almost everywhere.
2020-10-25 14:23:53 +01:00
Javi Martín
4865cbeb59 Add and apply RSpec/ContextMethod rubocop rule
This rule is available since rubocop-rspec 1.36.0. We were already
applying it in most cases.
2020-10-25 14:23:53 +01:00
Javi Martín
b27d0a8e92 Add and apply ConstantDefinitionInBlock rule
This rule was added in Rubocop 0.91.0. A similar rule named
LeakyConstantDeclaration was added in rubocop-rspec 1.34.0.

Note using the FILENAMES constant did not result in an offense using the
ConstantDefinitionInBlock rule but did result in an offense using the
LeakyConstantDeclaration rule. I've simplified the code to get rid of
the constant; not sure why we were adding a constant with `||=` in the
middle of a spec.
2020-10-23 12:04:22 +02:00
Javi Martín
f632c5bfca Add and apply EmptyFile rubocop rule
This rule was added in Rubocop 0.90.0.
2020-10-23 12:01:39 +02:00
Javi Martín
efd8f47596 Add and apply ArrayCoercion rubocop rule
This rule was added in Rubocop 0.88.0.
2020-10-23 12:01:39 +02:00
Javi Martín
7275fc9aa2 Add and apply RedundantFileExtensionInRequire rule
This rule was added in Rubocop 0.88.0.
2020-10-23 12:01:39 +02:00
Javi Martín
02ecdf6acc Add and apply Style/AccessorGrouping rubocop rule
This rule was added in Rubocop 0.87.0. We were already grouping
accessors in most places.
2020-10-23 12:01:39 +02:00
dependabot-preview[bot]
e5f4869c02 Bump rubocop from 0.83.0 to 0.91.0
Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.83.0 to 0.91.0.
- [Release notes](https://github.com/rubocop-hq/rubocop/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.83.0...v0.91.0)

The `ConsiderPunctuation` option in the `OrderedGems` rule now defaults
to false. We're changing it to true so we keep the existing behavior and
because that's the way programs like vim sort lines.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-10-23 12:01:39 +02:00
Javi Martín
3267c81ba0 Upgrade to Rails 5.2
All the code in the `bin/` and the `config/` folder has been generated
running `rake app:update`, except the `escape_javascript_fix` file,
which we've removed since the code there is already included in Rails
5.2.
2020-10-15 14:46:20 +02:00
Javi Martín
727e743887 Remove autoload trigger
I'm not sure why the code didn't work without this line, but it doesn't
seem to be necessary anymore (maybe after upgrading Ruby or Rails?).

I'm removing it now because... why not now? :) The Ruby interpreter is
raising a warning due to this line, and in Ruby 2.5 constant lookup has
changed slightly (although I don't think this line is affected by that
change).

Note about the change in the Setting model: Ruby actually ignores return
values in setter methods, so the line isn't necessary.
2020-07-08 12:39:25 +02:00
Javi Martín
4bb906f0be Apply Layout/SpaceAroundMethodCallOperator rule
This rule was added in rubocop 0.82.
2020-06-16 13:47:38 +02:00
Javi Martín
5315f34c72 Remove Performance/Detect rubocop rule
After upgrading the rubocop-performance gem, we're asked to change this
code:

milestones.select { |milestone| milestone.image.present? }.last

To:

milestones.reverse.find { |milestone| milestone.image.present? }

IMHO the original code is easier to read, so the performance gain isn't
worth it.
2020-06-16 13:47:38 +02:00
Javi Martín
199d8ff609 Bump rubocop from 0.75.0 to 0.83.0
Recent versions introduce the `Layout/SpaceAroundMethodCallOperator`,
which we are going to use. We aren't upgrading to the latest rubocop
version because it conflicts with the version of Capybara we're using
and because it isn't supported by Hound.

Some rules have been renamed:

Layout/IndentAssignment is now Layout/AssignmentIndentation
Layout/IndentHeredoc is now Layout/HeredocIndentation
Layout/LeadingBlankLines is now Layout/LeadingEmptyLines
Layout/Tab is now Layout/IndentationStyle
Layout/TrailingBlankLines is now Layout/TrailingEmptyLines
Lint/StringConversionInInterpolation is now Lint/RedundantStringCoercion
Metrics/LineLength is now Layout/LineLength

Note after upgrading we get a new "offense" in the `StartWith` rule, so
we're changing the code in order to fix it.
2020-06-16 13:47:38 +02:00
Javi Martín
e71052a5f1 Increase severity of DynamicFindBy rubocop rule
Back in commit 49e55b4d we lowered its severity because there were a
few false positives. Back then, I didn't realize we could just whitelist
the methods causing false positives.

Thanks taitus for the tip.
2020-04-24 18:55:42 +02:00
Javi Martín
31fa6b8bde Upgrade Rails to 5.1
Note we need to upgrade the bullet gem, although another option would be
to remove it completely.

Now we don't need the rubocop rules for deprecated methods, since using
them will raise an error and we'll be notified immediately.
2020-04-23 18:49:43 +02:00
Javi Martín
03c135e5fd Apply escape_javascript security patch
This patch was included in the Rails 5.2.x series, but since we haven't
upgraded yet, we need to apply it manually.
2020-04-06 16:19:44 +02:00
Javi Martín
ea2aeab383 Apply rubocop Rails/FindBy rule everywhere
We didn't detect these cases because by default the rule only searches
for offenses in `app/models/`.
2019-11-08 19:15:04 +01:00
Javi Martín
45fedfe410 Enable Lint/SafeNavigationChain rubocop rule
We didn't add it before because we weren't following it in the code
related to votation types, but we've removed that code.
2019-11-07 13:17:26 +01:00
Javi Martín
ed223e0bd1 Use audited to track investment changes
Our manual implementation had a few issues. In particular, it didn't
track changes related to associations, which became more of an issue
when we made investments translatable.

Using audited gives us more functionality while at the same time
simplifies our code. However, it adds one more external dependency to
our project.

The reason for choosing audited over paper trail is audited seems to
make it easier to handle associations.
2019-11-05 13:02:37 +01:00
Javi Martín
88c70366a7 Apply rubocop rules for trailing commas 2019-10-26 20:10:33 +02:00
Javi Martín
a727dcc031 Apply Style/SymbolProc rubocop rule
This style is much more concise.
2019-10-26 20:10:32 +02:00
Javi Martín
34e66acdda Apply Style/StringLiteralsInInterpolation rubocop rule
We were already using it in most places.
2019-10-26 13:37:36 +02:00
Javi Martín
8e3bfa0d72 Apply Style/RedundantReturn rubocop rule
We were already following this pattern most of the time.
2019-10-26 13:26:35 +02:00
Javi Martín
ddb37f89ae Apply Style/Proc rubocop rule
While I tend to use `Proc.new`, using `proc` is shorter and more
consistent since we also use `lambda`.
2019-10-26 13:22:49 +02:00
Javi Martín
69c01df63e Apply Style/OrAssignment rubocop rule 2019-10-26 13:22:44 +02:00
Javi Martín
8b5cca746c Apply rubocop rules to freeze constants
Added by popular demand among our team members.
2019-10-26 13:21:36 +02:00
Javi Martín
1ba929b4dd Apply Style/MethodDefParentheses rubocop rule
This is an obvious one, but there was one place where we weren't
following it.
2019-10-26 13:03:49 +02:00
Javi Martín
01fe31c5e3 Apply Style/IdenticalConditionalBranches rule 2019-10-26 13:03:49 +02:00
Javi Martín
b5eeb3f32f Apply Style/HashSyntax rubocop rule
We were already using it almost everywhere.
2019-10-26 13:03:49 +02:00
Javi Martín
eafb4018bf Apply Style/CollectionMethods rubocop rule
We were already using `map` and `reduce` almost everywhere.
2019-10-26 13:03:49 +02:00
Javi Martín
e3bfcbcd25 Apply Style/ClassVars rubocop rule
Class variables in Ruby are not the same as instance variables of a
class. They're particularly tricky when it comes to inheritance and
modules.

In the case of the Measurable module, for example, using a class
variable will make all classes including the Measurable module share
the same value. However, that's not what we want; we want the variable
to be different for every class. And that's accomplished using a class
instance variable.

Although in this case it would probably be better to remove the caching
variable. I don't think these methods are called more than once during a
request, and even if they did it's highly unlikely the would become a
bottleneck.
2019-10-26 13:03:49 +02:00
Javi Martín
dfe9ab2c69 Apply Style/ClassCheck rubocop rule
We were already using `is_a?` almost everywhere.
2019-10-26 13:03:49 +02:00
Javi Martín
a5def0cdb5 Apply Style/AndOr and Style/Not rubocop rules
The `and` and `or` keywords are not equivalent to `&&` and `||` and its
use is counterintuitive. Here's an example

```
good = true && false # good if false
bad = true and false # bad is true
```

The reason is `and` and `or` are control flow operators. So the code:

```
bad = true and false
```

Is equivalent to:


```
if bad = true
  false
end
```
2019-10-26 13:03:49 +02:00
Javi Martín
f07c422f21 Apply Layout/SpaceInLambdaLiteral rubocop rule
I had mixed feelings about this rule, since I like spaces where
possible.

However, I changed my mind when I realized writing `->(thing) { }` was
similar to defining a method, and we don't have a space before the
parenthesis when defining a method.
2019-10-26 13:03:49 +02:00
Javi Martín
a0554f5bba Apply Layout/LeadingBlankLines rubocop rule
This rule is pretty obvious. However, we weren't following it in a
couple of places.
2019-10-26 13:03:48 +02:00
Javi Martín
d218e09654 Use squiggly heredocs
This is a feature which was introduced in Ruby 2.3, and makes it much
easier to write readable heredocs.
2019-10-26 13:03:48 +02:00
Javi Martín
e21565628f Apply Layout/IndentAssignment rubocop rule
There was one place where we weren't applying it.
2019-10-26 13:03:48 +02:00
Javi Martín
621523cfd9 Merge basic and standard rubocop files in one file
A bit of history in order to understand this change.

A year ago we introduced Hound so it would review our pull requests and
warn contributors when they weren't following our coding style.

However, back then we had many rules we hadn't reviewed yet, and we
weren't sure we wanted to ask contributors to follow them.

So we decided to split these files: .rubocop_basic.yml would contain
rules we had already agreed on and wanted contributors to respect, and
.rubocop.yml would contain rules we still had to review.

Now we've finally gone through all these rules. We've removed some of
them, kept some of them, added new ones, and applied them.

Now all rules with a severity level of "convention" or higher return no
offenses. The rules with "severity: refactor" return some offenses,
though:

* Metrics/LineLenght can only be properly accomplished when we define
better multi-line indentation standards, while in some cases long lines
indicate we need to refactor the code
* Rails/DynamicFindBy returns a few false positives
* Rails/HasManyOrHasOneDependent should by all means be implemented,
although it will not be a trivial task
* Rails/SaveBang returns a few false positives and there are a couple of
places where we skip it on purpose

There are also rules excluding some files:

* Rails/InverseOf returns a false positive
* Rails/OutputSafety is ignored on purpose when we add auto-links to a
text we trust
* RSpec/InstanceVariable returns false positives in two files

Other than that, everything works as expected.
2019-10-25 23:23:27 +02:00