70 Commits

Author SHA1 Message Date
David Rodríguez
4c6d894bc0 Bump RuboCop to 1.86.6
There were a few changes needed:

* Plugins are now specified through `plugin:` config keyword.
* All plugin gems need to be specified explicitly in Gemfile since they
  are no longer dependencies of plugins already specified explicitly.
* All plugin gems need to be updated in other to use the new APIs.
* One cop was renamed.
* New offenses safe to correct were corrected directly with `bundle exec
  rubocop -a`.
* New offenses unsafe to correct were added to the TODO configuration
  with `bundle exec rubocop --auto-gen-config --auto-gen-only-exclude
  --exclude-limit 1400 --no-auto-gen-timestamp`.
2025-10-27 11:30:33 +01:00
Maikel Linke
c0924fbe5e Use new Undercover formatter for :nocov: support 2025-07-31 14:56:17 +10:00
cyrillefr
0fcf161889 Requested changes: menu_xx are to be ignored from cop 2025-05-12 17:16:15 +02:00
David Cook
0225db6840 Refactor without setter methods
This class was originally built to flexibly accept paramters in any order. It also allowed you to specify multiple of the same type of parameter, with the later one overriding the earlier.

This is too flexible and likely to cause mistakes. And besides, we don't use that feature!
2025-05-05 12:59:27 +10:00
cyrillefr
fbb4954ff7 Fixes Rubocop Naming NamingMemoizedInstanceVariableName cop 2025-04-29 13:27:47 +02:00
cyrillefr
a66a6197c7 Disable cop Rails LexicallyScopedActionFilter 2025-04-15 14:12:46 +02:00
Maikel Linke
971d5bea44 Police new migrations 2025-01-21 11:19:58 +11:00
Maikel Linke
042cc238c8 Modernise db default scripts 2025-01-21 11:17:31 +11:00
Maikel Linke
25a90a44f9 Modernise seeds file 2025-01-21 11:17:29 +11:00
Maikel Linke
8383441f79 List ignored files more explicitely 2025-01-21 11:12:59 +11:00
cyrillefr
b09f41136f Fixes Rails/UnknownEnv offense
- Cop: Rails/UnknownEnv
- Cf. https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsunknownenv
- Rails.env.typo? will always return false and will not return an error
- The way to check this is to add environments in the Environments config parameter
- in the rubocop file.
2024-06-25 10:18:45 +02:00
cyrillefr
654fda89ca Fix Rails/RedundantActiveRecordAllMethod issues
- Cop: Rails/RedundantActiveRecordAllMethod
- if receiver is an Active Record object, ".all" can be safely removed
- There are 2 allowed receivers that are listed in the
  styleguide file (those are defaults cf. cop documentation).
2024-06-19 14:32:21 +02:00
cyrillefr
456905e69f Fix Rails/WhereExists rubocop offenses
- after discussion, dev team decided not to follow
- this particular rule, but rather to enforce the where().exists? rule
  instead.
- cf. https://github.com/openfoodfoundation/openfoodnetwork/pull/12363
2024-04-17 10:37:18 +02:00
Maikel Linke
cac9b515e0 Let Rubocop suggest extensions
We are using all suggested extensions already and it's not suggesting
anything at the moment. Using the default value for suggesting
extensions will mean that Rubocop will tell us when there's a new
recommended extension for our code base.
2024-04-12 12:06:31 +10:00
David Cook
6f2b29eeec Move rspec styleguide to separate file 2024-02-28 16:17:49 +11:00
David Cook
eaacaf42aa Enforce block style for rspec .change
As discussed in https://github.com/openfoodfoundation/openfoodnetwork/pull/11208#discussion_r1280049281
2024-02-23 12:09:50 +11:00
David Cook
0091a60a6e Install rubocop-rspec
Why not enforce more consistency in our specs also?

Some of them generated way too many violations, so I relaxed them a bit.
2024-02-23 12:03:55 +11:00
David Cook
715e8253ff Disable buggy cop
Although it says it supports safe autocorrection, it requires a manual fix. I was going to manually fix the violation, but found it didn't really make the code more readable. So i'm making the call to get rid of it 🔥
2024-02-23 11:28:23 +11:00
David Cook
6bb48f2c74 Sort/format yaml
I found a plugin that promised to retain comments while sorting, so gave it a try: https://marketplace.visualstudio.com/items?itemName=PascalReitermann93.vscode-yaml-sort

It didn't really save any time, because some comments were still stripped so I had to manually fix it up. Also it reprocesses the yaml and removed other formatting like extra line breaks. So I wouldn't recommend it for this case.

Still, it could be useful for maintaining formatting of a large yaml file like our I18n file.
2024-02-23 11:21:46 +11:00
David Cook
6a2d2c581b Cleanup comments
(to make sorting with a plugin easier)

These settings have been here long enough that I think we can safely say they're accepted. There's no need to have a separate category of contested settings anyway in my opinion.
2024-02-23 11:13:50 +11:00
David Cook
e53960bae7 Disable Rails/OutputSafety for specs
This cop is to protect against user input. There's no user input (or users) in specs.
2023-11-24 16:35:45 +11:00
Maikel Linke
07ac381a97 Ignore block length of response blocks
In Rswag request specs, the `response` block is like `describe` and is
just used to group several other blocks. It can be long and that's okay.
2023-09-21 09:19:21 +10:00
Maikel Linke
ff18270898 Allow has_and_belongs_to_many to reduce code
The Rails/HasAndBelongsToMany rule wants model classes for all
many-to-many relationship tables in the database. But our team thinks
that it's useful to declare has_and_belongs_to_many relationships which
don't require an additional model.
2023-08-21 10:12:33 +10:00
Maikel Linke
fc46dbacdc Spec DFC Connector import behaviour around context
The DFC updated the URLs in their context, basically changing the ids of
all data types. I'll add a hacky workaround in the next commit.
2023-07-03 16:05:18 +10:00
Maikel Linke
5a4efdbce3 Separate DFC API swagger config
This allows us to run the specs separately to generate the
documentation. It's more efficient this way and the separate swagger doc
file is easier to read.

The engine-specific swagger helper also allows us to simplify the spec
files.

Added an exception to our styleguide because it's intended and useful to
have a complete (lengthy) description of the API in one block.
2023-07-03 12:37:23 +10:00
Maikel Linke
828b2f6f44 Replace too long list of arguments with keywords
Rubocop was complaining about too many arguments. But
`ApplicationJob#perform` needs all arguments handled in one call. While
we could allow the `perform` method generally to have more arguments,
there could be other methods called `perform` which should still be
scrutinised. Instead, it seems acceptable to me to have more arguments
as long as they are clearly named as keyword arguments. Rails uses this
a lot to document all options including their default values, for
example in Active Storage. It's better then bundling several arguments
in an undocumented hash just to reduce the number of given arguments.

And once we upgraded to Ruby 3.1, we can clean the method calls up as
well. `call(user: user)` becomes `call(user:)` without repetition.
2023-06-09 14:44:54 +10:00
Jean-Baptiste Bellet
2cc509de15 Do not check Metrics/BlockLength for shared_examples_for block
They can contains a lot of `it` tests
2023-04-21 11:59:24 +02:00
Maikel Linke
b19df0dfbf Enable new Rubocop cops
This detects an additional 639 offenses which I added to the todo file.
From now on, when Dependabot bumps rubocop the build may fail due to new
cops. But that's a great opportunity to utilise those new cops and fix
violations straight away. Otherwise we'll never get to them and lose out
on useful autocorrection, for example for updating deprecated syntax.
2023-04-14 16:28:20 +10:00
Maikel Linke
33409725a5 Run rubocop-rails with current Rails version 7.0
This adds three new issues I will address in the next commits.

```
Offenses:

app/json_schemas/json_api_schema.rb:40:7: C: [Correctable] Rails/IndexWith: Prefer index_with over to_h { ... }.
      relationships.to_h { |name| [name, relationship_schema(name)] }
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/enterprise_fee_summary/base.rb:18:11: C: [Correctable] Rails/IndexWith: Prefer index_with over map { ... }.to_h.
          data_attributes.map { |attr| [attr, I18n.t("header.#{attr}", scope: i18n_scope)] }.to_h
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/sales_tax/sales_tax_totals_by_order.rb:140:14: C: [Correctable] Rails/Pick: Prefer pick('sum(amount)') over pluck('sum(amount)').first.
            .pluck('sum(amount)').first || 0
             ^^^^^^^^^^^^^^^^^^^^^^^^^^

1404 files inspected, 3 offenses detected, 3 offenses autocorrectable
```
2023-04-14 16:15:13 +10:00
Maikel Linke
286dade66f Don't enforce ApplicationRecord in migrations
We shouldn't use app code in migrations because app code changes while
migrations should always do the same to enable old servers to upgrade.

We have some existing migrations which use ApplicationRecord but I found
that changing them retrospectively breaks them already. So let's leave
them alone.
2022-09-27 13:14:51 +10:00
Maikel Linke
17afdb5912 Update rubocop config to avoid deprecation 2022-08-29 15:31:18 +10:00
filipefurtad0
f525a9f5da Adds inclusive tax-spec 2022-08-15 16:13:36 +10:00
Jean-Baptiste Bellet
b60eeb8dc4 Exclude ViewComponents from MissingSuper rule as it's unnecessary
Source: https://viewcomponent.org/#whats-a-viewcomponent
2022-04-15 14:36:42 +02:00
Maikel Linke
51420934f3 Add billing and shipping address to customer 2022-03-28 10:58:18 +11:00
Matt-Yorkley
76f14a03c6 Add specs and JSON schemas
Include test helpers
2022-03-02 11:55:46 +11:00
Maikel Linke
cee6a0f17f Declare blocklength rules as agreed upon
The acceptance of this pull request will be the "agree" part. :-)
2022-02-25 11:57:43 +11:00
Maikel Linke
7acae6522b Relax cyclomatic complexity to community default
Why should we be more strict than the rest of the world?
2022-02-25 11:56:33 +11:00
Maikel Linke
2d1e746c64 Remove default values from contested settings
We can just use what the Rubocop community uses as default and we don't
need to spell it out again.
2022-02-25 11:51:35 +11:00
Maikel Linke
3382c1d0bb Relax some contested metrics rules
Rubocop often complains while we think that the code is totally fine. I
would like to achieve the default values one day but there are more
important issues at the moment.
2022-02-25 11:45:15 +11:00
Maikel Linke
b999673dfc Remove old version of relaxed styled guide
We had an old version under "contested settings" and it looks like some
of them were modified. I hope that our new, separate file will
discourage manual tweaks.

We can include the relaxed rules from a gem as well. Let's see if we
need that complexity one day.
2022-02-25 10:51:54 +11:00
Maikel Linke
decab911bd Use relaxed Rubocop styleguide as basis
We then refine it with our own rules.
2022-02-25 10:44:32 +11:00
Maikel Linke
33969de371 Allow shared_examples to have more than 25 lines 2022-02-16 11:41:28 +11:00
Matt-Yorkley
f0f5a1a2da Allow methods which skip validations in Rubocop
There are plenty of places where we use methods which skip validations for perfectly good reasons...
2021-12-27 16:36:45 +00:00
Maikel Linke
8f79fe2768 Use the same config on Code Climate as locally
We configured Code Climate to be aware of all open issues instead of
ignoring open issues via the rubocop todo lists. We were hoping that
Code Climate could give us some nice stats like progress if it's aware
of all our open issues. But the graphs don't tell us anything. So it's
better to have one source of truth for our open style issues and that is
our rubocop config in this repository. It contains two todo lists that
document all violations we would like to fix in the future but it's okay
to submit pull requests that don't fix those.

Instead of accepting new style issues in Code Climate, every pull
request with new violations has to add them to the rubocop config. I
hope that this will make rubocop more useful and encourage developers to
reduce code style debt.
2021-03-31 15:25:19 +11:00
Maikel Linke
49eaee05a2 Deactivate cop Naming/PredicateName
It picked up matcher helpers in specs like `have_in_cart` which is a
useful name here.
2021-03-25 18:10:57 +11:00
Maikel Linke
853b250afa Disable Rubocop suggestions to avoid noise 2021-03-25 17:44:46 +11:00
Maikel Linke
74fce2d2f1 Disable new Rubo-Cops
We have enough violations already. Let's add them as we see fit and
avoid the warnings for now.
2021-03-25 17:41:45 +11:00
Maikel Linke
f2103e923f Update Rails version for Rubocop 2021-03-25 17:41:05 +11:00
Maikel Linke
0133cb4d22 Update deprecated Rubocop option 2021-03-25 17:40:09 +11:00
Luis Ramos
42fff560fb Attempt at rails 5 upgrade 2021-01-08 22:40:47 +00:00