- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么 rubocop 没有忽略我的 db/schema.rb 文件?
.rubocop.yml
require: rubocop-rails
require: rubocop-performance
AllCops:
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- 'bin/{rails,rake}'
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
- 'Gemfile.lock'
Rails:
Enabled: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
Max: 20
Metrics/BlockLength:
ExcludedMethods: ['describe', 'context', 'FactoryBot.define']
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
Max: 1500
# No space makes the method definition shorter and differentiates
# from a regular assignment.
Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space
Naming/VariableNumber:
EnforcedStyle: normalcase
# Single quotes being faster is hardly measurable and only affects parse time.
# Enforcing double quotes reduces the times where you need to change them
# when introducing an interpolation. Use single quotes only if their semantics
# are needed.
Style/StringLiterals:
EnforcedStyle: double_quotes
# We do not need to support Ruby 1.9, so this is good to use.
Style/SymbolArray:
Enabled: true
# Most readable form.
Layout/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
# Mixing the styles looks just silly.
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
# has_key? and has_value? are far more readable than key? and value?
Style/PreferredHashMethods:
Enabled: false
# String#% is by far the least verbose and only object oriented variant.
Style/FormatString:
EnforcedStyle: percent
Style/CollectionMethods:
Enabled: true
PreferredMethods:
# inject seems more common in the community.
reduce: "inject"
# Either allow this style or don't. Marking it as safe with parenthesis
# is silly. Let's try to live without them for now.
Style/ParenthesesAroundCondition:
AllowSafeAssignment: false
Lint/AssignmentInCondition:
AllowSafeAssignment: false
# A specialized exception class will take one or more arguments and construct the message from it.
# So both variants make sense.
Style/RaiseArgs:
Enabled: false
# Indenting the chained dots beneath each other is not supported by this cop,
# see https://github.com/bbatsov/rubocop/issues/1633
Layout/MultilineOperationIndentation:
Enabled: false
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
# The argument that fail should be used to abort the program is wrong too,
# there's Kernel#abort for that.
Style/SignalException:
EnforcedStyle: only_raise
# Suppressing exceptions can be perfectly fine, and be it to avoid to
# explicitly type nil into the rescue since that's what you want to return,
# or suppressing LoadError for optional dependencies
Lint/HandleExceptions:
Enabled: false
Layout/SpaceInsideBlockBraces:
# The space here provides no real gain in readability while consuming
# horizontal space that could be used for a better parameter name.
# Also {| differentiates better from a hash than { | does.
SpaceBeforeBlockParameters: false
# No trailing space differentiates better from the block:
# foo} means hash, foo } means block.
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
Style/BlockDelimiters:
Enabled: false
# do / end blocks should be used for side effects,
# methods that run a block for side effects and have
# a useful return value are rare, assign the return
# value to a local variable for those cases.
Style/MethodCalledOnDoEndBlock:
Enabled: true
# Enforcing the names of variables? To single letter ones? Just no.
Style/SingleLineBlockParams:
Enabled: false
# Shadowing outer local variables with block parameters is often useful
# to not reinvent a new name for the same thing, it highlights the relation
# between the outer variable and the parameter. The cases where it's actually
# confusing are rare, and usually bad for other reasons already, for example
# because the method is too long.
Lint/ShadowingOuterLocalVariable:
Enabled: false
# Check with yard instead.
Style/Documentation:
Enabled: false
# This is just silly. Calling the argument `other` in all cases makes no sense.
Naming/BinaryOperatorParameterName:
Enabled: false
# There are valid cases, for example debugging Cucumber steps,
# also they'll fail CI anyway
Lint/Debugger:
Enabled: false
# Style preference
Style/MethodDefParentheses:
Enabled: false
最佳答案
就我而言,我只添加了
AllCops:
Excludes:
- config/unicorn.rb
- db/**
Style/Documentation:
...
和 rubocop 工作
关于Rubocop 不忽略 db/schema.rb 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57165782/
下面是activeresource.rb的全部内容: require 'active_resource' 谁能解释一下这其中的逻辑? 为什么不简单地让 activeresource.rb 包含 act
Neo4j.rb 中是否有针对 Rails 6 的开发?在一个新的 Rails 6(rc1) 项目中,如果我创建几个脚手架然后运行“rake neo4j:migrate:all”,我会收到一个错误,当
对此很陌生,所以我一直在尝试解决这个问题,但无法找到答案。 gem update --system 安装 rb-appscript 时出现以下错误。 gem install rb-appscript
我正在为涉及选中/取消选中框的场景编写步骤定义。在步骤定义中,我尝试使用 web_steps.rb 中的现有步骤。但是我收到错误:未定义的步骤:“我检查'评级'”。我必须做些什么才能让我的 myfea
为什么 Controller 命名为“users_controller.rb”而模型不命名为“user_model.rb”? 为什么有“application_controller.rb”但在view
我对 Ruby on Rails 完全陌生,正在运行以下命令$rails生成设备用户 我期望生成文件 _devise_create_users.rb 。但是它会生成文件 _add_devise_to_
我的 Rails 应用程序(在 Heroku 上运行)有一个暂存和生产环境。目前,我必须在每个文件中分别定义 staging.rb 和 production.rb 中的很多内容,例如: # Cod
我是 Rails 新手,并且对 ASP.net 有很好的了解。在 ASP.net Web 应用程序中,我有一个 web.config 来完成所有设置,但在 Rails 中,有几个配置文件,我现在想知道
预先感谢您的帮助。 我正在尝试在 env.rb 中创建变量 File_path =("#{File.dirname(__FILE__)}/../../features/TestData/Testdat
按照这里的例子: http://rspec.info 但是它失败了: kernel_require.rb:45:in `require': cannot load such file -- bowli
我在使用 Ruby 时遇到了一个我无法解释的奇怪问题。我有以下脚本,它抓取剪贴板中当前的任何代码,通过语法高亮器运行它,然后将新版本放回剪贴板: #!/usr/bin/ruby1.9.1 requir
假设我想通过表单将此代码嵌入到单独的 ruby.rb 文件中: print "Hello, Please enter a value:" var = gets.to_i if var == 1
我正在从“MongoDB in Action”一书中学习 Mongodb 和 ruby 我已经安装好 Mongodb 并设法在其上执行了许多命令。 我可能没有正确安装 ruby。 我正在使用 Ub
更多新手问题。 我知道,如果我在我的应用程序帮助程序中定义了一个方法,那么整个应用程序代码都可以使用它。 在我的应用程序助手中,我有: def primary_user_is_admin if c
尝试将此代码块授予 capistrano 的版本 3 但无济于事。一切都变了。任何人都可以帮助我在正确的轨道上进行转换吗? 旧版本 2 deploy.rb: #require 'new_relic/r
我正在第二次学习 Rails 教程。当我输入这个 rails generate integration_test static_pages 我得到 spec/rails_helper.rb 和 spe
请问这个env.rb错误是什么意思? root# rake db:migrate WARNING: Cucumber-rails required outside of env.rb. The re
我已经看到这个问题出现在许多不同的情况下,并希望获得在 StackOverflow 上修复/调试它的最佳实践。 今天早上我想到了一个现实世界的例子: expected announcement.rb
这是我在 StackOverflow 上的第一个问题,请耐心等待...... 当我在Listing 8.6中使用authentication_pages_spec.rb时我的测试通过了。然后我在'sp
有谁知道在 JRuby 中是如何处理 tempfile.rb 的。它在 Ruby 中,但不在 JRuby 中。 有人有任何想法吗? 干杯 埃夫 最佳答案 您仍然可以“要求'tempfile'”并且它会
我是一名优秀的程序员,十分优秀!