Commit Graph

110 Commits

Author SHA1 Message Date
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
taitus
08957b70c2 Add Security/Eval rubocop rule to rubocop_basic.yml 2019-10-23 10:21:41 +02:00
Javi Martín
91c21b0982 Remove instance variables in RSpec
Instance variables might lead to hard-to-detect issues, since using a
nonexistent instance variable will return `nil` instead of raising an
error.
2019-09-30 16:43:10 +02:00
Javi Martín
7e9e1be1aa Remove Bundler/InsecureProtocolSource rubocop rule
Since we're using rubygems as the only source, this rule is not
necessary.
2019-09-10 22:27:33 +02:00
Javi Martín
16b8bee140 Remove unused rspec rubocop rules
We consider these rules either return false positives or we don't have a
strong opinion about them.
2019-09-10 22:27:33 +02:00
Javi Martín
3fa3801a49 Remove unused rails rubocop rules
We consider these rules either return false positives or we don't have a
strong opinion about them.
2019-09-10 22:27:33 +02:00
Javi Martín
d639cd587a Remove unnecessary uniq calls
The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
2019-09-10 22:27:33 +02:00
Javi Martín
9fb1d7df31 Remove obsolete ScopeArgs rubocop rule
This rule doesn't make sense with Rails 5 anymore, since breaking it
will raise an error.
2019-09-10 22:27:33 +02:00
Javi Martín
ea17256e3a Remove gemspec rubocop rules
We don't have a gemspec file, so we don't need these ones.
2019-09-10 22:27:33 +02:00
Javi Martín
9d566a2250 Remove most performance rubocop rules
For performance purposes, we need to find bottlenecks in our
application. Optimizing the performance of small methods doesn't make
the application faster.

I've kept a few cops because applying these ones IMHO make the code
easier to read.
2019-09-10 22:27:33 +02:00
Javi Martín
2243809d2e Move basic RSpec rubocop rules to basic cops
These are rules we were already applying.

We've excluded the `factories` folder for some rules because there's a
factory defining a `context` attribute, which rubocop thought was the
`context` RSpec keyword.
2019-09-10 21:43:39 +02:00
Javi Martín
59e107e565 Apply RSpec/HookArgument rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
9541ce892c Apply Bundler rubocop rules
We're not using the InsecureProtocolSource rule because I don't feel
it's necessary.
2019-09-10 21:43:39 +02:00
Javi Martín
c05b9c2aac Apply Capybara/CurrentPathExpectation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
969a4e21c9 Apply RSpec/RepeatedExample rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
044eabd7ef Apply Rspec/LetSetup rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
58ba517717 Apply RSpec/ExampleWording rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
0788925c1b Apply Rails/Validation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
27c73c22ea Configure Rails/UnknownEnv rubocop rule
We use staging and preproduction environments, which are not valid by
default.

This rule is useful because misspelling the name of an environment might
otherwise go unnoticed.
2019-09-10 21:43:39 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
daa86ca3fc Apply Rails/RequestReferer rubocop rule 2019-09-10 21:43:39 +02:00
Javi Martín
a5ba13b599 Apply Rails/Presence rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
adc5906253 Apply Rails/PluralizationGrammar rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
a27ada662d Move Rails/Date and Rails/TimeZone to basic cops
Using Date.today and Time.now is a common mistake which might lead to
obscure bugs. Now we're making sure we'll receive a warning when a pull
request uses these methods.
2019-08-28 20:32:40 +02:00
Javi Martín
c2869f4887 Move Rails/RelativeDateConstant to basic cops
The reason for this rule is similar to dynamic factories: we want
dynamic dates to be evaluted relative to the current time, and not
relative to the moment the application was loaded.
2019-08-07 19:43:59 +02:00
Javi Martín
444fc524f7 Use the AttributeDefinedStatically rubocop rule
Factory bot has stopped supporting dynamic attributes, and we'll have to
change all factories before upgrading.

In order to apply the rubocop rule, we need to bump rubocop-rspec to its
latest version.
2019-08-07 19:41:45 +02:00
Javi Martín
61be48a6c6 Remove unused and obsolete rubocop rules
These rules are now defined under `Style/`. However, we don't really use
them, so they add noise to the rubocop configuration file without
solving any issues we actually have.
2019-08-07 19:41:45 +02:00
Javi Martín
ae98dbf683 Use Rails 5.1 conventions in tests params 2019-08-07 15:50:00 +02:00
Javi Martín
765d405df1 Use Rails 5 conventions in migrations and models
We forgot to add these changes to pull requests which were in
development before we upgraded to Rails 5.

We're also moving the rubocop rules to the basic files, so we're
notified when we inherit from `ActiveRecord::Base`.
2019-08-07 13:53:27 +02:00
decabeza
15dbfdf6e8 Enable line length rubocop rule 2019-01-09 13:45:42 +01:00
voodoorai2000
c1455cb93c Add not_to Rubocop rule to Hound
https://www.rubydoc.info/gems/rubocop-rspec/1.5.0/RuboCop/Cop/RSpec/NotToNot
2018-12-15 12:41:07 +01:00
Javier Martín
bc77812ae8 Merge pull request #2990 from consul/backport-remove_described_class_cop
Remove described class cop
2018-10-29 14:38:43 +01:00
Javi Martín
4cbe81a142 Remove described class cop
We've agreed `User.new` is easier to read than `described_class.new` and
since we are ignoring Hound's comments regarding this topic, we might as
well remove it.
2018-10-29 13:58:00 +01:00
Javi Martín
4048d17203 Add basic rubocop configuraton for Hound
This way we can ask contributors to follow some basic guidelines like
removing trailing whitespaces while not overwhelming them with all our
rules.
2018-10-26 11:46:17 +02:00
Javi Martín
48140f74e9 Remove rubocop_todo file
No developers are maintaining it anymore.
2018-10-26 11:46:10 +02:00
Javi Martín
f9bfa450d6 Add percent literal delimiters to rubocop rules
As developers agreed upon.
2018-09-26 17:11:59 +02:00
Javi Martín
ad1e044e0a Add trailing newline rule to rubocop
Just like we're suggesting when we do code reviews and like the rule
we've enabled in SCSS-Lint.
2018-09-26 17:11:59 +02:00
Javi Martín
2545d49aed Don't allow trailing whitespaces in rubocop
Luckily we don't have any trailing whitespaces around, but we might
accidentally introduce some.
2018-09-26 17:11:59 +02:00
Bertocq
2bf019f08b Disable DynamicAttributeDefinedStatically cop
rubocop-rspec includes a FactoryBot cop DynamicAttributeDefinedStatically
that enforces declaring dynamic attribute values in a block. It was
decided not to follow this convention. Explicitly disabling it gives
more insight about current rubocop rules.

http://www.rubydoc.info/gems/rubocop-rspec/1.24.0/RuboCop/Cop/RSpec/FactoryBot/DynamicAttributeDefinedStatically
2018-04-04 19:28:15 +02:00
Bertocq
e2c42a3c63 Enable StaticAttributeDefinedDynamically cop & fix
rubocop-rspec gem includes cops for FactoryBot like the new
 FactoryBot/StaticAttributeDefinedDynamically to enforce declaring
 static attribute values without a block.

* http://www.rubydoc.info/gems/rubocop-rspec/1.24.0/RuboCop/Cop/RSpec/FactoryBot/StaticAttributeDefinedDynamically
2018-04-04 19:28:15 +02:00
Bertocq
d3d9573086 Enable new Rails/HttpStatus cop without issues
rubocop-rspec 1.23.0 release introduced the cop RSpec/Rails/HttpStatus
to enforce consistent usage of the status format (numeric or symbolic).
* https://github.com/rubocop-rspec/rubocop-rspec/pull/553
* https://github.com/rubocop-rspec/rubocop-rspec/releases/tag/v1.23.0
2018-04-04 19:28:15 +02:00
Bertocq
b0c0578cbe Remove deprecated Performance/HashEachMethods cop
At release https://github.com/bbatsov/rubocop/releases/tag/v0.53.0 it
has been removed with https://github.com/bbatsov/rubocop/issues/5589
2018-04-04 19:26:31 +02:00
Bertocq
43559981eb Enable rubocop Layout/EndOfLine cop with LF 2018-02-11 10:33:51 +01:00
Bertocq
664db2306c Enable rubocop Rails cops without issues 2018-02-10 21:29:21 +01:00
Bertocq
3f91e920f6 Enable rubocop Performance/RedundantMatch cop & fix issues
Some cop offenses have been stashed into rubocop_todo.yml for now
2018-02-10 21:26:02 +01:00
Bertocq
57743df197 Enable rubocop Performance/HashEachMethods cop & fix issues 2018-02-10 21:22:47 +01:00
Bertocq
307fe18c59 Enable rubocop Performance cops without issues 2018-02-10 21:17:56 +01:00
Bertocq
a419b36ff3 Enable rubocop Security cops without issues 2018-02-10 21:13:03 +01:00
Bertocq
537e6e175d Enable rubocop Gemspec cops without issues 2018-02-10 21:03:50 +01:00