ruby 如何在Rubocop的宝石文件中禁用宝石名称排序?

68de4m5k  于 2023-02-03  发布在  Ruby
关注(0)|答案(1)|浏览(165)

我正在进入一个没有风格指南的遗留代码库。为了不引入太多的更改,有没有办法绕过这个检查?https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Bundler/OrderedGems查看文档和repo没有产生一个解决方案,试图排除rubocop.yml中的Gemfile也没有工作。

AllCops:                                                                                                                                                                                     
  NewCops: enable                                                                                                                                                                                
  Exclude:                                                                                                                                                                                         
    - Gemfile
goqiplq2

goqiplq21#

Bundler::OrderedGems cop的排除项添加到.rubocop.yml

Bundler/OrderedGems:
  Enabled: false

之前:

$ bin/rubocop Gemfile
Inspecting 1 file
C

Offenses:

Gemfile:14:1: C: [Correctable] Bundler/OrderedGems: Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem puma should appear before rails.
gem 'puma'
^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

之后:

$ bin/rubocop Gemfile
Inspecting 1 file
.

1 file inspected, no offenses detected

相关问题