Commit Graph

93 Commits

Author SHA1 Message Date
Kamil Trzciński 650f40865e Forbid the use of `#reload` and prefer `#reset`
The `#reload` makes to load all objects into memory,
and the main purpose of `#reload` is to drop the association cache.

The `#reset` seems to solve exactly that case.
2019-04-15 13:05:14 +02:00
Heinrich Lee Yu f234d9f12d Properly handle `ee` migration specs 2019-03-28 05:48:53 +08:00
Rémy Coutable 941f95ec7c Merge branch 'fix-rubocop-ee-module-injection-detection' into 'master'
Fix detecting nested EE constants in RuboCop

See merge request gitlab-org/gitlab-ce!24430
2019-01-16 18:10:38 +00:00
Yorick Peterse 9722158c15
Fix detecting nested EE constants in RuboCop
The InjectEnterpriseEditionModule cop would not detect certain nested EE
constants such as `EE::Foo::Bar::Baz`. This could result in it not
enforcing `prepend` being placed on the last line. This commit fixes
this by just performing a string match on the line, instead of relying
on AST matching.
2019-01-16 16:48:18 +01:00
Bob Van Landuyt 7c801333a0 Prevent factories in background migration specs
The Background migration specs also run against a certain version of
the database. So we should avoid using factories.
2019-01-16 13:15:33 +01:00
Yorick Peterse 7c58055631
Added Cop for injecting EE modules
This Cop enforces the rule that injecting EE modules (using prepend,
include, or extend) is done by placing the injection on the last line of
a file, instead of somewhere in the middle. By placing these lines at
the very end, merge conflicts will not happen.
2018-12-13 16:09:21 +01:00
Toon Claes 54b639195d Make add_reference cop accept a hash for :index
It might happen you want to make the reference column have a unique
value, or you want to create partial indexes. So instead of only
accepting a `true` value, also accept a hash of options.
2018-11-27 11:40:38 +01:00
Jarka Košanová 186b2143ab Add cop prohibiting params argument in url_for 2018-11-22 10:08:18 +01:00
Douglas Barbosa Alexandre 01d8c1f6f0
Whitelist none method from ActiveRecord::Querying 2018-10-31 15:46:36 -03:00
Rémy Coutable 02c47f2f73
Add a new QA::ElementWithPattern cop
This cop forbids the use of `element :foo, 'pattern'` and
`element :bar, /pattern/` in QA files.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2018-10-15 14:28:03 +02:00
Tiago Botelho 81d949f656 Applies the CE backport of EE#657 2018-09-24 12:02:01 +01:00
Sanad Liaquat 0896d6942d Fix leading slash in redirects and add cop 2018-09-21 14:10:20 +00:00
Bob Van Landuyt 23d5501500 Remove unused constant
This removes an unused constant from the
`RubyInterpolationInTranslation`. The constant was used in a first
implementation of this class.
2018-09-19 15:01:27 +02:00
Yorick Peterse 8a72f5c427
Added FromUnion to easily select from a UNION
This commit adds the module `FromUnion`, which provides the class method
`from_union`. This simplifies the process of selecting data from the
result of a UNION, and reduces the likelihood of making mistakes. As a
result, instead of this:

    union = Gitlab::SQL::Union.new([foo, bar])

    Foo.from("(#{union.to_sql}) #{Foo.table_name}")

We can now write this instead:

    Foo.from_union([foo, bar])

This commit also includes some changes to make this new setup work
properly. For example, a bug in Rails 4
(https://github.com/rails/rails/issues/24193) would break the use of
`from("sub-query-here").includes(:relation)` in certain cases. There was
also a CI query which appeared to repeat a lot of conditions from an
outer query on an inner query, which isn't necessary.

Finally, we include a RuboCop cop to ensure developers use this new
module, instead of using Gitlab::SQL::Union directly.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/51307
2018-09-17 12:39:43 +02:00
Yorick Peterse 91c40973dc
Added RuboCop cops to enforce code reuse rules
These Cops enforces the code reuse rules as defined in merge request
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21254.
2018-09-11 15:00:18 +02:00
Robert Speicher 24fc237710
Fix LineBreakAroundConditionalBlock cop for a conditional after rescue
Previously this would violate on the `if`:

    def a_method
      do_something
    rescue
      if condition
        do_something
      end
    end
2018-09-05 09:34:11 -07:00
Jacopo 4a37cd0dc0 Minor renames for clarity 2018-08-29 16:56:34 +02:00
Jacopo e3e746623b Handles when ClassMethods is used inside a class 2018-08-29 16:56:34 +02:00
Jacopo a1cad13b92 Fixes rubocop chain ordinary method after safe navigation operator 2018-08-29 16:56:34 +02:00
Jacopo 8af40870e2 Applies rule only when extending ActiveSupport::Concern 2018-08-29 16:56:34 +02:00
Jacopo 2f0327b7d8 Adds Rubocop rule to enforce class_methods over module ClassMethods 2018-08-29 16:56:34 +02:00
Bob Van Landuyt 08c0a1b852 Reject ruby interpolation in externalized strings
When using ruby interpolation in externalized strings, they can't be
detected. Which means they will never be presented to be translated.

To mix variables into translations we need to use `sprintf`
instead.

Instead of:

    _("Hello #{subject}")

Use:

    _("Hello %{subject}) % { subject: 'world' }
2018-08-25 18:43:21 +02:00
Yorick Peterse 96ce2da74e
Blacklist the use of "destroy_all"
This method usually has really bad performance implications, as it loads
rows into memory and deletes them one by one.
2018-08-16 17:29:33 +02:00
Andreas Brandl e3ff390986 Add rubocop check for add_reference to require index. 2018-08-08 23:30:48 +02:00
Lin Jen-Shin 612f5e63b3 Update rubocop to get rid of a warning in other MR 2018-07-09 21:12:31 +08:00
Grzegorz Bizon d30596226d Merge branch 'update-large-tables-cop' into 'master'
Disallow methods that copy data on large tables

See merge request gitlab-org/gitlab-ce!20021
2018-06-22 13:22:15 +00:00
Sean McGivern 03ccd39a0c Add more large tables to cop
These are all over 20 GB on GitLab.com. merge_request_diff_commits is several
hundred gigabytes in size.
2018-06-22 12:08:39 +01:00
Bob Van Landuyt f3f1df1476 Add a cop for `FinderMethods`
This notifies developers when calling `find(_by!)` chained on
`execute`. And suggests using the methods from `FinderMethods`. These
will perform the correct authorization checks on the resource when it
is found.
2018-06-20 18:13:13 +02:00
Sean McGivern eb086a4bfd Disallow methods that copy data on large tables
{change_column_type,rename_column}_concurrently both copy data from one column
to another during a migration, which should not be done on GitLab.com. Instead,
we should use background migrations.
2018-06-19 17:18:15 +01:00
Rémy Coutable 1c5106fadf
Allow comment after if/unless clause
Signed-off-by: Rémy Coutable <remy@rymai.me>
2018-05-29 10:38:59 +02:00
Rémy Coutable d2aee809ed
Introduce spec/fast_spec_helper.rb to run spec files that don't rely on the whole Rails env
Signed-off-by: Rémy Coutable <remy@rymai.me>
2018-04-23 12:20:30 +02:00
Yorick Peterse 6f292eaa69
Revert the addition of goldiloader
This reverts the addition of the "goldiloader" Gem and all use of it.
While this Gem is very promising it's causing a variety of problems on
GitLab.com due to it eager-loading too much data in places where we
don't expect/can handle this. At least for the time being this means we
have to go back to manually fixing N+1 query problems, but at least
those should not cause a negative impact on availability.
2018-04-18 15:51:39 +02:00
🙈 jacopo beschi 🙉 c6b1043e9d Resolve "Make a Rubocop that forbids returning from a block" 2018-04-18 09:19:40 +00:00
Sean McGivern 4ef3e3491e Add cop for has_many :through without disabled autoloading
Goldiloader is great, but has several issues with has_many :through relations:

* https://github.com/salsify/goldiloader/issues/12
* https://github.com/salsify/goldiloader/issues/14
* https://github.com/salsify/goldiloader/issues/18

Rather than try to figure out which applies in each case, we should just do the
drudge work of manually disabling autoloading for all relations of this type. We
can always use regular preloading for specific cases, but this way we avoid
generating invalid queries through Goldiloader's magic.
2018-04-09 12:47:04 +01:00
Rémy Coutable 4b035896c4
Introduce a new FactoriesInMigrationSpecs cop
Signed-off-by: Rémy Coutable <remy@rymai.me>
2018-04-06 17:41:52 +02:00
Douwe Maan 95ced3bb5f Merge branch 'fj-15329-services-callbacks-ssrf' into 'security-10-6'
Server Side Request Forgery in Services and Web Hooks

See merge request gitlab/gitlabhq!2337
2018-03-21 14:39:21 +00:00
Gabriel Mazetto 5c7a738105 [CE] Add Naming/FileName rule checking expected class/module per filename 2018-03-08 12:56:54 +00:00
Takuya Noguchi 2b6307f6ad Enable RuboCop Style/RegexpLiteral 2018-02-01 02:06:07 +09:00
Lin Jen-Shin 4f00a05152 Introduce PredicateMemoization cop and fix offenses
with StrongMemoize
2018-01-12 17:54:55 +08:00
🙈 jacopo beschi 🙉 729f05f0e3 Adds Rubocop rule for line break around conditionals 2018-01-11 16:34:01 +00:00
Lin Jen-Shin cc7a7aad80 Require our own custom cops; Remove missing cops
Also try to use the same config from EE
2017-12-26 16:30:36 +08:00
Rémy Coutable a2d39b8010 Use gitlab-styles
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-12-22 08:34:44 -06:00
Lin Jen-Shin 59ac184fcf Merge remote-tracking branch 'upstream/master' into no-ivar-in-modules
* upstream/master: (671 commits)
  Make rubocop happy
  Use guard clause
  Improve language
  Prettify
  Use temp branch
  Pass info about who started the job and which job triggered it
  Docs: add indexes for monitoring and performance monitoring
  clearer-documentation-on-inline-diffs
  Add docs for commit diff discussion in merge requests
  sorting for tags api
  Clear BatchLoader after each spec to prevent holding onto records longer than necessary
  Include project in BatchLoader key to prevent returning blobs for the wrong project
  moved lfs_blob_ids method into ExtractsPath module
  Converted JS modules into exported modules
  spec fixes
  Bump gitlab-shell version to 5.10.3
  Clear caches before updating MR diffs
  Use new Ruby version 2.4 in GitLab QA images
  moved lfs blob fetch from extractspath file
  Update GitLab QA dependencies
  ...
2017-12-15 17:14:26 +08:00
Douwe Maan 3cad04cd51 Add rubocops to ensure Sidekiq workers include ApplicationWorker and don't manually set their queue 2017-12-13 16:28:26 +01:00
Sean McGivern 1ab33b15d1 Add cop for use of remove_column
remove_column should only be used in the up (or change) step of a migration if
it's a post-deployment migration. Otherwise there will be downtime due to the
ActiveRecord column cache, which we can avoid by using the IgnorableColumn
concern in combination with a post-deployment migration.
2017-12-11 16:34:51 +00:00
Lin Jen-Shin 663593e87e Merge remote-tracking branch 'upstream/master' into no-ivar-in-modules
* upstream/master: (126 commits)
  Update VERSION to 10.3.0-pre
  Update CHANGELOG.md for 10.2.0
  default fill color for SVGs
  ignore hashed repos (for now) when using `rake gitlab:cleanup:repos`
  Use Redis cache for branch existence checks
  Update CONTRIBUTING.md: Link definition of done to criteria
  Use `make install` for Gitaly setups in non-test environments
  FileUploader should check for hashed_storage?(:attachments) to use disk_path
  Set the default gitlab-shell timeout to 3 hours
  Update composite pipelines index to include "id"
  Use arrays in Pipeline#latest_builds_with_artifacts
  Fix blank states using old css
  Skip confirmation user api
  Custom issue tracker
  Revert "check for `read_only?` first before seeing if request is disallowed"
  add `#with_metadata` scope to remove a N+1 from the notes' API
  Fix promoting milestone updating all issuables without milestone
  Batchload blobs for diff generation
  check for `read_only?` first before seeing if request is disallowed
  use `Gitlab::Routing.url_helpers` instead of `Rails.application.routes.url_helpers`
  ...
2017-11-22 17:07:01 +08:00
Lin Jen-Shin 07d3d44775 Move ModuleWithInstanceVariables to Gitlab namespace
And use .rubocop.yml to exclude paths we don't care,
rather than using the cop itself to exclude.
2017-11-22 17:06:57 +08:00
Lin Jen-Shin 15edf741a1 Explain how to disable it in the doc 2017-11-22 17:06:57 +08:00
Lin Jen-Shin 45568bed36 Updates based on feedback 2017-11-22 00:59:38 +08:00
Rémy Coutable 4f09d099e9 Merge branch '18040-rubocop-line-break-after-guard-clause' into 'master'
Adds Rubocop rule for line break after guard clause

Closes #18040

See merge request gitlab-org/gitlab-ce!15188
2017-11-20 09:22:14 +00:00