我正在尝试设置rails项目,以便使贡献者所需的所有验证都在一个命令中,目前我们正在运行:
rake test
但是现在我们也想使用rubocop来进行静态分析:
rubocop -R -a
我希望这可以在一个简单的rake任务中执行。最好重写“rake test”来运行rubocop,然后运行rails项目的标准rake测试材料,因为这样就没有人需要记住更改命令了。但是,如果我必须创建一个单独的rake任务,这也可能是好的。
我见过rubocop集成,但我不知道如何将它与“rake测试”捆绑到一个任务中.有什么想法吗?
我和Rubocop在V码上有问题。我知道错误了
Warning: unrecognized cop Rails/ActionFilter found in /path/to/yml/with/cops
...
Warning: unrecognized cop Rails/Output found in
...
Warning: unrecognized cop Rails/UnknownEnv found in
...
# The list goes on...
I run:
Rubocop版本rubocop-0.76.0
VS-代码版本: 1.39.2
vs代码中的ruby-rubocop
我一直试图让我的管道(遵循rubocop语法)和Linux/ Windows机器感到高兴,但出于某种原因,我被困在退出状态检查中。这引起了问题。
我使用了以下和下面的结果:
$?.exitstatus - NOT OK in rubocop (语法问题);OK在Linux中;OK在Windows中
system() -在rubocop中确定;在Linux中确定;在中不确定(这是not recognized as an internal or external command)
$CHILD_STATUS.exitstatus -在rubocop中为OK;在Linux中为而不是OK (它需要re
我们在我们的项目中使用rubocop,问题是当我使用rubocop时,我得到了182次攻击,而我在同一分支中的团队成员没有得到任何一个,我们有相同的ruby、rails和rubocop版本。
spec/rails_helper.rb:45:4: C: [Correctable] Style/FetchEnvVar: Use ENV.fetch("RAILS_ENV") or ENV.fetch("RAILS_ENV", nil) instead of ENV["RAILS_ENV"].
if ENV["RAILS_ENV"] ==
我使用pundit gem来授权。
在我的文件config/initializers/rails_admin.rb中
RailsAdmin.config do |config|
config.authorize_with :pundit
config.current_user_method(&:current_user)
......
end
我遵循https://github.com/sudosu/rails_admin_pundit中的说明,但在when run代码中,出现错误:
protected method `policy' called for #&l
我正在尝试使用Pundit来验证对一些不需要数据库交互的静态视图的访问:
class StaticController < ApplicationController
include Pundit
authorize :splash, :home?
def home end
end
下面是我的静态策略。home?策略总是返回true,所以我应该能够访问主视图。
class StaticPolicy < Struct.new(:user, :static)
def initialize(user, resource)
@user =
在VSCode中打开拼音文件时,出现以下错误:
.rubocop.yml: Metrics/LineLength has the wrong namespace - should be Layout Error: The `Style/BracesAroundHashParameters` cop has been removed. (obsolete configuration found in .rubocop.yml, please update it)
因此,VSCode中的线条不起作用。原因很明显: rubocop cop在Metrics名称空间下,因为项目使用rubocop 0.7
我可能遗漏了一些明显的东西,但似乎在关闭begin代码块时,Rubocop跳过了end的对齐。
在这种情况下:
begin
# Foo
end
我希望"end“会有一个布局错误:Layout/EndAlignment end is not aligned with begin然而,Rubocop似乎相信这是正确的。
我希望Layout/DefEndAlignment、Layout/EndAlignment和Layout/BlockAlignment中的一个来管理这个行为,但它们中的任何一个选项似乎都没有任何效果。
任何Rubocop专家都知道如何修复这个
我正在尝试使用Github操作设置CI管道。在我的工作流程中,bundle exec rubocop失败了。但是当在rails项目上运行时,该命令完全在本地传递。 name: CI - To check on linters and run test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build-n-test:
runs-on: ubuntu-latest
env:
RAILS_EN
我有一个运行在ruby 2.7.2上的rails应用程序,在Gemfile中包含以下内容: group :development, :test do
gem 'rubocop'
gem 'rubocop-minitest'
gem 'rubocop-performance'
gem 'rubocop-rails'
end 已经运行了bundle install和bundle update。每当我在目录中运行rubocop时,我都会得到以下结果: Could not find 'activesupport&
在我们的项目rubocop.yml中,我们检查了类中的行数:
ClassLength:
Max: 150 # Default 100
lib/utils/foo.rb中有一个已经超过200行的文件。如果我在rubocop分支上运行master检查,那么rubocop运行的很好,没有任何错误。
现在,在我的feature/cool_feature分支中,我向这个lib/utils/foo.rb类添加了5行。现在,如果我在我的分支中运行rubocop,它会失败,有以下错误:
Offenses:
lib/utils/foo.rb:1:1: C: Class has too many lin