Commit Graph

324 Commits

Author SHA1 Message Date
Javi Martín
32b1fc53e1 Add and appy MultilineOperationIndentation rule
This way it's easier to see when lines are part of multiline
statements and when they belong to `if` statements.
2023-08-18 14:56:16 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Javi Martín
97aca0cf95 Add and apply rules for multi-line arrays
We were already applying these rules in most cases.

Note we aren't enabling the `MultilineArrayLineBreaks` rule because
we've got places with many elements whire it isn't clear whether
having one element per line would make the code more readable.
2023-08-18 14:56:16 +02:00
Javi Martín
1cb6268d4e Add and apply Layout/ClosingHeredocIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
09c63e354c Add and apply Layout/DotPosition rule
Since IRB has improved its support for multiline, the main argument
towars using a trailing dot no longer affects most people.

It still affects me, though, since I use Pry :), but I agree
leading dots are more readable, so I'm enabling the rule anyway.
2023-08-18 14:56:16 +02:00
Javi Martín
7996925644 Allow current way to write respond_to blocks
Not sure exactly since when, but we've started to get rubocop failures
when using the pattern:

respond_to do |format|
  format.js
end

We've been using this pattern for ages, so maybe a recent version of
Rubocop introduced a change that made it report it.

In any case, this is easier to read than respond_to(&:js), so we're
allowing it.
2023-08-07 21:22:27 +02:00
Javi Martín
f298715f78 Add Style/HashExcept Rubocop rule
We were already using it because Rails adds the `Hash#except` method for
Ruby 2.7 and earlier, but since the method wasn't part of Ruby itself,
the Rubocop rule only works with Ruby 3.0 and later.
2023-04-13 16:41:15 +02:00
Javi Martín
5e7b3f72a2 Use File.exist? instead of File.exists?
We've noticed the following warning while testing the upgrade to
Ruby 3.0:

warning: File.exists? is deprecated; use File.exist? instead

We're adding a Rubocop rule so we don't call the deprecated method
in the future.
2023-01-26 17:21:19 +01:00
Javi Martín
efc46fe6c8 Add Performance/StringIdentifierArgument rule
It was added in rubocop-performance 1.13.0. We were already applying it
in most places.

We aren't adding it for performance reasons but in order to make the
code more consistent.
2023-01-11 16:05:20 +01:00
Javi Martín
25435b0297 Make it possible to disable tenants
Note we could use `acts_as_paranoid` with the `without_default_scope`
option, but we aren't doing so because it isn't possible to consider
deleted records in uniqueness validations with the paranoia gem [1].
I've added tests for these cases so we don't accidentally add
`acts_as_paranoid` in the future.

Also note we're extracting a `RowComponent` because, when
enabling/disabling a tenant, we're also enabling/disabling the link
pointing to its URL, and so we need to update the URL column after the
AJAX call.

[1] See issues 285 and 319 in https://github.com/rubysherpas/paranoia/
2022-12-28 14:34:00 +01:00
Javi Martín
e1e16d21c3 Allow having tenants with different domains
Some institutions using CONSUL have expressed interest in this feature
since some of their tenants might already have their own domains.

We've considered many options for the user interface to select whether
we're using a subdomain or a domain, like having two separate fields,
using a check box, ... In the end we've chosen radio buttons because
they make it easier to follow a logical sequence: first you decide
whether you're introducing a domain or subdomain, and then you enter it.

We've also considered hiding this option and assuming "if it's got a
dot, it's a domain". However, this wouldn't work with nested subdomains
and it wouldn't work with domains which are simply machine names.

Note that a group of radio buttons (or check boxes) is difficult to
style when the text of the label might expand over more than one line
(as is the case here on small screens); in this case, most solutions
result in the second line of the label appearing immediately under the
radio button, instead of being aligned with the first line of the label.
That's why I've added a container for the input+label combination.
2022-12-13 13:10:02 +01:00
Javi Martín
0d4a032f52 Add and apply Lint/NonAtomicFileOperation rule
This rule was added in Rubocop 1.31.0; it follows the principles
mentioned in the Ruby Style Guide [1].

https://rubystyle.guide/#atomic-file-operations
2022-10-19 14:26:49 +02:00
Javi Martín
4a851c0d82 Add and apply Style/MapToHash rubocop rule
This rule was added in Rubocop 1.24.0. Applying it slightly simplifies
the code.
2022-10-19 14:26:49 +02:00
Javi Martín
5ec7f4a339 Add and apply FileRead and FileWrite rubocop rules
They were added in Rubocop 1.24.0.

Even if we were already applying FileRead everywhere, this is something
we've manually fixed in the past. Another reason to add it is that these
rules are deeply related.
2022-10-19 14:26:49 +02:00
Javi Martín
f800a02a42 Add Layout/LineEndStringConcatenationIndentation rule
This rule was added in Rubocop 1.18.0, but we didn't add it back then.
Since we're applying it most of the time, we might as well be consistent
and apply it everywhere.
2022-10-19 14:26:49 +02:00
Javi Martín
c8270d58bd Add and apply Rails/DurationArithmetic rubocop rule
This rule was added in rubocop-rails 2.13.0. We were already applying it
most of the time.
2022-08-24 23:24:36 +02:00
Javi Martín
68899c80b6 Add Rails/RedundantTravelBack rubocop rule
This rule was added in rubocop-rails 2.12.0. It doesn't catch the case
we've seen the most in the past, though: using `travel_back` to finish
the test will not raise an offense.

However, it does detect a useless `travel_back` call in `after` blocks,
so I guess it's better than nothing.
2022-08-24 23:24:23 +02:00
Javi Martín
ea3abd6317 Add and apply Rails/Pick rubocop rule
The `pick` method was added in Rails 6.0.
2022-08-24 18:11:56 +02:00
Senén Rodero Rodríguez
c263a6fc2f Configure Rails/I18nLocaleAssignment cop to scan all Ruby files
This cop scans only the tests files by default, but we prefer to scan all
application Ruby files, so when a developer uses the class method
`I18n.locale=`, the cop will embrace using the method
`I18n.with_locale` instead. By doing this way, the cop will help
developers to avoid unexpected translation errors.

Quoting the Rails 6 guides:
> I18n.locale can leak into subsequent requests served by the same
thread/process if it is not consistently set in every controller. For
example executing I18n.locale = :es in one POST requests will have
effects for all later requests to controllers that don't set the locale,
but only in that particular thread/process. For that reason, instead of
I18n.locale = you can use I18n.with_locale which does not have this
leak issue.

Now we enabled the cop for all application Ruby files; we have to
remove the assignments at the controller level to set the request
locale. As Rails 6 guides suggest [1], we can use the `around_action`
controller callback to set each request locale without breaking the
rule.

This cop will warn CONSUL developers when using `I18n.locale`
assignment embracing them to use the `I18n.with_locale`instead.

[1] https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
2022-06-13 15:45:32 +02:00
Senén Rodero Rodríguez
64278c663c Do not exclude spec_helper.rb from Rails/I18nLocaleAssignment cop
Use the around action to set the desired locale so we do not break the rule.
2022-06-08 12:21:41 +02:00
Javi Martín
dc87f9d69a Add Security/Open rubocop rule
The `open` method can be used to open files or URLs and it's deprecated
in Ruby 2.7. In this case, it's clear we're dealing with a URL, so we
can use `URI.parse`.

The code was a bit strange, since it returned a value and had a side
effect: opening the URL. I'm not sure about the intention of the code;
my best guess is we wanted to test the URL exists and was accessible
before returning it (and, if that's the case, IMHO the code should be a
bit more explicit in order to show the intention behind it), but it
could also be an unintended side effect which was there by accident.

Now the URL is no longer opened; if the URL isn't accessible, we'll find
out when trying to connect to it with the Savon client.
2021-11-16 12:37:32 +01:00
Javi Martín
f412ab2c9a Add CKEditor support for ActiveStorage
ActiveStorage support was added to CKEditor in version 5.1.0. However,
we can't upgrade to version 5.0.0 or later because it only supports
loading CKEditor via CDN.

So we're copying the code related to ActiveStorage instead. I tried to
move it to the `vendor/` folder, but couldn't find a way to load it from
there and if I found one I wouldn't be sure it'd work on production
environments.
2021-09-24 13:39:15 +02:00
Javi Martín
720d3530d7 Add and apply Style/HashTransformKeys rubocop rule
The `transform_keys` method is available since Ruby 2.5.
2021-09-03 11:49:53 +02:00
Javi Martín
53aa1770a2 Add and apply Style/HashTransformValues rule
The `transform_values` method is available since Ruby 2.5.
2021-09-03 11:49:53 +02:00
Javi Martín
ac5c9459c7 Add and apply Style/StringChars rubocop rule
This rule was added in Rubocop 1.12.0.
2021-09-03 11:49:53 +02:00
Javi Martín
2bc6018465 Add and apply Style/HashConversion rubocop rule
This rule was added in Rubocop 1.10.0. This style is IMHO clearer and
possible since Ruby 2.1.
2021-09-03 11:49:53 +02:00
Javi Martín
41a9d17c76 Add and apply Lint/SymbolConversion rubocop rule
This rule was added in Rubocop 1.9.0.

We're excluding the Setting model in order to keep the settings
consistent.
2021-09-03 11:49:53 +02:00
Javi Martín
54cced9296 Add and apply Style/IfWithBooleanLiteralBranches
This rule was added in Rubocop 1.9.0.
2021-09-03 11:49:53 +02:00
Javi Martín
1b19e33e55 Add and apply Naming/VariableName rubocop rule
We forgot to use it in one place, and we've found out other institutions
using CONSUL whose developers aren't so familiar with Ruby also break
this rule, so it might be better to add it explicitly.
2021-09-03 11:49:53 +02:00
Javi Martín
bbc3c2d7e7 Add and apply Style/SingleLineMethods rubocop rule
Single line methods are hard to read, at least with this syntax. The
syntax used in Ruby 3.0 is accepted since Rubocop 1.7.0.
2021-09-03 11:49:53 +02:00
Javi Martín
48672a3f35 Add and apply Style/SoleNestedConditional rule
We were already applying it in most places.
2021-09-03 11:49:53 +02:00
Javi Martín
aef1e4660f Add and apply Style/RedundantArgument rubocop rule
This rule was added in rubocop 1.4.0.
2021-09-03 11:49:53 +02:00
Javi Martín
f90c23ca88 Add and apply Lint/DuplicateBranch rubocop rule
This rule was introduced in rubocop 1.3.0.
2021-09-03 11:49:53 +02:00
Javi Martín
2c76f265f8 Add and apply Style/NegatedIfElseCondition rule
This rule was added in Rubocop 1.2.0, and will make developers who hate
negative conditions particularly happy.
2021-09-03 11:49:53 +02:00
Javi Martín
9b61945ee4 Add and apply Lint/EmptyBlock rubocop rule
It was introduced in Rubocop 1.1.0.
2021-09-03 11:49:53 +02:00
Javi Martín
adba81ea89 Add and apply Style/RedundantSelf rubocop rule 2021-09-03 11:49:53 +02:00
Javi Martín
0be6eb9512 Add and apply Style/RedundantParentheses rule
Parentheses make the code harder to read in these cases.
2021-09-03 11:49:52 +02:00
Javi Martín
5abd0466e2 Add Rails/AddColumnIndex rubocop rule
The `column` method in ActiveRecord::ConnectionAdapters::TableDefinition
supports adding the `index:` option. The documentation says:

> Instantiates a new column for the table. See connection.add_column for
> available options.
>
> Additional options are:
>
> :index - Create an index for the column. Can be either true or an
> options hash.

So basically the `connection.add_column` method silently ignores the
`index:` option, and whenever we intended to create an index this way,
we didn't.

We're creating a new migration where we properly add the indexes that
weren't added when we intended to.

Thanks to the rubocop-rails team, who added this cop in version 2.11.0
and helped us notice this bug.
2021-09-03 11:49:52 +02:00
Javi Martín
071bcb7023 Add and apply Rails/I18nLocaleAssignment rule
This rule was added in rubocop-rails 2.11.0.

Although we prevent I18n locale leaking between tests by setting it
before each test, the `with_locale` method makes the scope of the locale
change more obvious.
2021-09-03 11:49:52 +02:00
Javi Martín
2bfa9068f1 Add and apply Rails/HttpStatus rubocop rule
We were already using it in most places. Since rubocop-rails 2.11.0,
this rule also detects offenses when using the `head` method, which we
were using with a plain `404`.
2021-09-03 11:49:52 +02:00
Javi Martín
591b09d6ea Update Capybara and FactoryBot rubocop namespaces
They changed in rubocop-rspec 2.0.0.pre.
2021-09-03 11:49:52 +02:00
dependabot[bot]
ff20b8a02e Bump factory_bot_rails from 4.8.2 to 6.2.0
Note we're changing the parent strategy because its default value
changed in Factory Bot 5. We're keeping the old one so it's compatible
with our test suite.

We're also removing the rubocop rule for static attributes because in
factory bot 5 this syntax is invalid and will raise an error, so there's
no need for rubocop to remind us about it.

Bumps [factory_bot_rails](https://github.com/thoughtbot/factory_bot_rails) from 4.8.2 to 6.2.0.
- [Release notes](https://github.com/thoughtbot/factory_bot_rails/releases)
- [Changelog](https://github.com/thoughtbot/factory_bot_rails/blob/master/NEWS.md)
- [Commits](https://github.com/thoughtbot/factory_bot_rails/compare/v4.8.2...v6.2.0)

---
updated-dependencies:
- dependency-name: factory_bot_rails
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 16:32:36 +02:00
Javi Martín
db4451c7c2 Add Performance/BlockGivenWithExplicitBlock rule
We don't need to use `block_given?` since we specifically pass the block
parameter, particularly since we added the Style/ExplicitBlockArgument
rule in commit a102f3f0a.
2021-08-10 13:31:37 +02:00
Javi Martín
e619ca992c Add and apply Performance/Sum rubocop rule
We're not adding it for performance reasons but because it simplifies
the code.
2021-08-10 13:30:07 +02:00
Javi Martín
ab9e99f45c Merge pull request #4288 from consul/dependabot/bundler/rubocop-rails-2.9.1
Bump rubocop-rails from 2.6.0 to 2.9.1
2021-08-10 13:23:32 +02:00
Javi Martín
884fd2b27b Add and apply Rails/WhereEquals rubocop rule
We were already following this style in most places.
2021-08-09 23:52:47 +02:00
Javi Martín
8ae138aa19 Add and apply Rails/WhereNot rubocop rule
We simplify the code a little bit, and make it more consistent since we
were already using `where.not` in most places.
2021-08-09 23:52:47 +02:00
Javi Martín
69dda19af7 Add and apply Rails/PluckId rubocop rule 2021-08-09 23:52:47 +02:00
Javi Martín
8d47acc12b Add and apply Rails/ActiveRecordCallbacksOrder rule
We were already following it most of the time.
2021-08-09 23:52:34 +02:00
dependabot-preview[bot]
33c962c63c Bump rubocop-rails from 2.6.0 to 2.9.1
Bumps [rubocop-rails](https://github.com/rubocop-hq/rubocop-rails) from 2.6.0 to 2.9.1.
- [Release notes](https://github.com/rubocop-hq/rubocop-rails/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop-rails/compare/v2.6.0...v2.9.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-08-09 22:41:26 +02:00