diff --git a/.circleci/config.yml b/.circleci/config.yml index f785ebc8..2cfccdd8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,8 @@ version: 2.1 orbs: - codacy: codacy/base@2.6.2 - codacy_plugins_test: codacy/plugins-test@0.14.5 + codacy: codacy/base@5.1.3 + codacy_plugins_test: codacy/plugins-test@0.14.6 workflows: version: 2 @@ -13,14 +13,12 @@ workflows: - codacy/sbt: name: publish_docker_local cmd: | - docker build -t codacy-rubocop-base . sbt "set scalafmtUseIvy in ThisBuild := false; - scalafmt::test; - test:scalafmt::test; - sbt:scalafmt::test; - set name := \"$CIRCLE_PROJECT_REPONAME\"; - set version in Docker := \"latest\"; - docker:publishLocal" + scalafmt::test; + test:scalafmt::test; + sbt:scalafmt::test; + universal:stage" + docker build -t $CIRCLE_PROJECT_REPONAME:latest . docker save --output docker-image.tar $CIRCLE_PROJECT_REPONAME:latest persist_to_workspace: true requires: diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3c5a047c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +# Ignore everything +** + +# Allow files and directories +!/Gemfile* +!/target/universal/stage +!/docs + +# Ignore unnecessary files inside allowed directories +# This should go after the allowed directories +**/.DS_Store diff --git a/.gitattributes b/.gitattributes index bb947843..5633b1ea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ -src/main/resources/docs/description/* linguist-generated=true -src/main/resources/docs/tool-description.md linguist-generated=true +docs/description/* linguist-generated=true +docs/tool-description.md linguist-generated=true diff --git a/.gitignore b/.gitignore index f904f658..7f85be78 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,7 @@ /project/target/ /target/ /vendor -/doc/ -/src/main/resources/docs/tests/target/ +/docs/tests/target/ .idea .DS_Store .bundle/ diff --git a/Dockerfile b/Dockerfile index 0cc04fa5..c7d19501 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.12 +FROM alpine:3.13 as base RUN apk add --no-cache ruby ruby-etc ruby-dev ruby-irb ruby-rake ruby-io-console \ ruby-bigdecimal make gcc ruby-json libstdc++ tzdata bash \ @@ -8,7 +8,16 @@ COPY Gemfile . COPY Gemfile.lock . RUN echo 'gem: --no-document' > /etc/gemrc \ - && gem install bundler -v 2.1.4 \ + && gem install bundler -v 2.2.7 \ && bundle install \ && gem cleanup \ && rm -rf /tmp/* /var/cache/apk/* + +RUN apk --no-cache add openjdk11 +COPY docs /docs +RUN adduser --uid 2004 --disabled-password --gecos "" docker +COPY target/universal/stage/ /workdir/ +RUN chmod +x /workdir/bin/codacy-rubocop +USER docker +WORKDIR /workdir +ENTRYPOINT ["bin/codacy-rubocop"] diff --git a/Gemfile b/Gemfile index a392de6e..8606929c 100644 --- a/Gemfile +++ b/Gemfile @@ -7,17 +7,16 @@ end gem "yard" gem "rake" -gem "rdoc", "6.3.0" +gem "rdoc" gem "activesupport" -gem "parser", "3.0.0.0" +gem "parser" gem "pry" gem "safe_yaml" gem "dark_finger" -gem "rubocop-migrations", "0.1.2" -gem "rubocop-github", "0.16.0" -gem "rubocop", "0.82.0" +gem "rubocop-migrations" +gem "rubocop", "1.9.1" #Rubocop official modules -gem "rubocop-performance", "1.7.1" -gem "rubocop-rails", "2.6.0" -gem "rubocop-rake", "0.5.1" -gem "rubocop-rspec", "1.41.0" +gem "rubocop-performance" +gem "rubocop-rails" +gem "rubocop-rake" +gem "rubocop-rspec" diff --git a/Gemfile.lock b/Gemfile.lock index 21cd6f68..e55ecec5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,14 +7,13 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - ast (2.4.1) + ast (2.4.2) coderay (1.1.3) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) dark_finger (0.6.1) rubocop (>= 0.51.0) - i18n (1.8.7) + i18n (1.8.8) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.4) method_source (1.0.0) minitest (5.14.3) parallel (1.20.1) @@ -27,36 +26,38 @@ GEM rainbow (3.0.0) rake (13.0.3) rdoc (6.3.0) + regexp_parser (2.0.3) rexml (3.2.4) - rubocop (0.82.0) - jaro_winkler (~> 1.5.1) + rubocop (1.9.1) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) rexml + rubocop-ast (>= 1.2.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-github (0.16.0) - rubocop (<= 0.82.0) - rubocop-performance (~> 1.0) - rubocop-rails (~> 2.0) - rubocop-migrations (0.1.2) - rubocop (~> 0.41) - rubocop-performance (1.7.1) - rubocop (>= 0.82.0) - rubocop-rails (2.6.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.4.1) + parser (>= 2.7.1.5) + rubocop-migrations (0.1.0) + rubocop (>= 0.42.0) + rubocop-performance (1.9.2) + rubocop (>= 0.90.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rails (2.9.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.82.0) + rubocop (>= 0.90.0, < 2.0) rubocop-rake (0.5.1) rubocop - rubocop-rspec (1.41.0) - rubocop (>= 0.68.1) + rubocop-rspec (2.2.0) + rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) ruby-progressbar (1.11.0) safe_yaml (1.0.5) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (1.7.0) + unicode-display_width (2.0.0) yard (0.9.26) zeitwerk (2.4.2) @@ -66,19 +67,18 @@ PLATFORMS DEPENDENCIES activesupport dark_finger - parser (= 3.0.0.0) + parser pry rake - rdoc (= 6.3.0) - rubocop (= 0.82.0) - rubocop-github (= 0.16.0) - rubocop-migrations (= 0.1.2) - rubocop-performance (= 1.7.1) - rubocop-rails (= 2.6.0) - rubocop-rake (= 0.5.1) - rubocop-rspec (= 1.41.0) + rdoc + rubocop (= 1.9.1) + rubocop-migrations + rubocop-performance + rubocop-rails + rubocop-rake + rubocop-rspec safe_yaml yard BUNDLED WITH - 2.1.4 + 2.2.7 diff --git a/README.md b/README.md index 45c803b4..5d3a2e42 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ See the [codacy-engine-scala-seed](/~https://github.com/codacy/codacy-engine-scala You can create the docker by doing: ``` -docker build -t codacy-rubocop-base . -sbt docker:publishLocal +sbt universal:stage +docker build -t codacy-rubocops . ``` The docker is ran with the following command: @@ -36,7 +36,7 @@ There are some important details to take into consideration: + private val plugins: List[String] = List("rubocop-performance", "rubocop-style") ``` -- Add it to src/main/ruby/rubocop_doc/generator.rb +- Add it to doc_generation/codacy/rubocop/generator.rb ```diff - $plugins = ["rubocop-performance"] @@ -57,7 +57,8 @@ You can follow the instructions there to make sure your tool is working as expec ```sh bundle update -bundle install --path vendor/bundle +bundle config set --local path 'vendor/bundle' +bundle install ./scripts/doc_generate.sh ``` diff --git a/build.sbt b/build.sbt index e91b2df5..dece15c9 100644 --- a/build.sbt +++ b/build.sbt @@ -1,70 +1,12 @@ -import com.typesafe.sbt.packager.docker.Cmd -import sjsonnew.BasicJsonProtocol._ -import sjsonnew._ -import sjsonnew.support.scalajson.unsafe._ - name := "codacy-rubocop" -scalaVersion := "2.13.1" +scalaVersion := "2.13.4" libraryDependencies ++= Seq( - "org.scala-lang.modules" %% "scala-xml" % "1.2.0" withSources (), - "com.codacy" %% "codacy-engine-scala-seed" % "5.0.1", - "com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.8.4", + "org.scala-lang.modules" %% "scala-xml" % "1.3.0", + "com.codacy" %% "codacy-engine-scala-seed" % "5.0.3", + "com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.12.1", "com.typesafe.play" %% "play-json" % "2.8.1" ) enablePlugins(JavaAppPackaging) - -enablePlugins(DockerPlugin) - -lazy val toolVersion = settingKey[String]("The version of the underlying tool retrieved from patterns.json") - -toolVersion := { - case class Patterns(name: String, version: String) - implicit val patternsIso: IsoLList[Patterns] = - LList.isoCurried((p: Patterns) => ("name", p.name) :*: ("version", p.version) :*: LNil) { - case (_, n) :*: (_, v) :*: LNil => Patterns(n, v) - } - - val jsonFile = (resourceDirectory in Compile).value / "docs" / "patterns.json" - val json = Parser.parseFromFile(jsonFile) - val patterns = json.flatMap(Converter.fromJson[Patterns]) - patterns.get.version -} - -mappings in Universal ++= (resourceDirectory in Compile).map { resourceDir: File => - val src = resourceDir / "docs" - val dest = "/docs" - - for { - path <- src.allPaths.get if !path.isDirectory - } yield path -> path.toString.replaceFirst(src.toString, dest) -}.value - -val dockerUser = "docker" -val dockerGroup = "docker" - -daemonUser in Docker := dockerUser -daemonGroup in Docker := dockerGroup - -dockerBaseImage := "codacy-rubocop-base" - -mappings in Universal += file("scripts/doc_generate.sh") -> "scripts/doc_generate.sh" -mappings in Universal += file("Gemfile") -> "Gemfile" -mappings in Universal += file("doc_generation/codacy/rubocop/generator.rb") -> "doc_generation/codacy/rubocop/generator.rb" -mappings in Universal += file("doc_generation/rubocop_doc/generator.rb") -> "doc_generation/rubocop_doc/generator.rb" - -dockerCommands := { - dockerCommands.value.flatMap { - case cmd @ (Cmd("ADD", _)) => - Seq( - Cmd("RUN", s"adduser -u 2004 -D $dockerUser"), - cmd, - Cmd("RUN", "sh scripts/doc_generate.sh $PWD"), - Cmd("RUN", "apk del ruby-dev make gcc"), - Cmd("RUN", "mv /opt/docker/docs /docs") - ) - case other => Seq(other) - } -} diff --git a/doc_generation/codacy/rubocop/generator.rb b/doc_generation/codacy/rubocop/generator.rb index 14523b63..b4616dba 100755 --- a/doc_generation/codacy/rubocop/generator.rb +++ b/doc_generation/codacy/rubocop/generator.rb @@ -26,7 +26,7 @@ def self.info_url(cop_data) "http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/#{cop_data[:name]}" end - def self.run(baseDir = "src/main/resources", file_path = "rubocop-doc.yml") + def self.run(baseDir = "", file_path = "rubocop-doc.yml") @baseDir = baseDir cops_data = YAML.load_file(file_path) cops_data.each do |cop_data| @@ -70,7 +70,7 @@ def self.parameters(cop_data) end end - def self.run(baseDir = "src/main/resources", file_path = "rubocop-doc.yml") + def self.run(baseDir = "", file_path = "rubocop-doc.yml") @baseDir = baseDir cops_data = YAML.load_file(file_path) descriptions = cops_data.map do |cop_data| @@ -145,7 +145,7 @@ def self.parameters(cop_data) end end - def self.run(default_patterns, baseDir = "src/main/resources", file_path = "rubocop-doc.yml") + def self.run(default_patterns, baseDir = "", file_path = "rubocop-doc.yml") @baseDir=baseDir cops_data = YAML.load_file(file_path) patterns = cops_data.map do |cop_data| @@ -171,7 +171,7 @@ def self.run(default_patterns, baseDir = "src/main/resources", file_path = "rubo end end -baseDir="src/main/resources" +baseDir="" if ARGV.length == 1 baseDir=ARGV[0] end diff --git a/src/main/resources/docs/description/Bundler_DuplicatedGem.md b/docs/description/Bundler_DuplicatedGem.md similarity index 63% rename from src/main/resources/docs/description/Bundler_DuplicatedGem.md rename to docs/description/Bundler_DuplicatedGem.md index 910ba190..6b21f7e7 100644 --- a/src/main/resources/docs/description/Bundler_DuplicatedGem.md +++ b/docs/description/Bundler_DuplicatedGem.md @@ -24,6 +24,15 @@ end # good gem 'rubocop', groups: [:development, :test] + +# good - conditional declaration +if Dir.exist?(local) + gem 'rubocop', path: local +elsif ENV['RUBOCOP_VERSION'] == 'master' + gem 'rubocop', git: '/~https://github.com/rubocop-hq/rubocop.git' +else + gem 'rubocop', '~> 0.90.0' +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Bundler/DuplicatedGem) \ No newline at end of file diff --git a/docs/description/Bundler_GemComment.md b/docs/description/Bundler_GemComment.md new file mode 100644 index 00000000..8490eb6f --- /dev/null +++ b/docs/description/Bundler_GemComment.md @@ -0,0 +1,54 @@ + +Add a comment describing each gem in your Gemfile. + +Optionally, the "OnlyFor" configuration +can be used to only register offenses when the gems +use certain options or have version specifiers. +Add "version_specifiers" and/or the gem option names +you want to check. + +A useful use-case is to enforce a comment when using +options that change the source of a gem: + +- `bitbucket` +- `gist` +- `git` +- `github` +- `source` + +For a full list of options supported by bundler, +you can check the https://bundler.io/man/gemfile.5.html[official documentation]. + +# Examples + +```ruby +# bad + +gem 'foo' + +# good + +# Helpers for the foo things. +gem 'foo'# bad + +gem 'foo', '< 2.1' + +# good + +# Version 2.1 introduces breaking change baz +gem 'foo', '< 2.1'# bad + +gem 'foo', github: 'some_account/some_fork_of_foo' + +gem 'bar', '< 2.1' + +# good + +# Using this fork because baz +gem 'foo', github: 'some_account/some_fork_of_foo' + +# Version 2.1 introduces breaking change baz +gem 'bar', '< 2.1' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Bundler/GemComment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Bundler_InsecureProtocolSource.md b/docs/description/Bundler_InsecureProtocolSource.md similarity index 100% rename from src/main/resources/docs/description/Bundler_InsecureProtocolSource.md rename to docs/description/Bundler_InsecureProtocolSource.md diff --git a/src/main/resources/docs/description/Bundler_OrderedGems.md b/docs/description/Bundler_OrderedGems.md similarity index 100% rename from src/main/resources/docs/description/Bundler_OrderedGems.md rename to docs/description/Bundler_OrderedGems.md diff --git a/src/main/resources/docs/description/Gemspec_DuplicatedAssignment.md b/docs/description/Gemspec_DuplicatedAssignment.md similarity index 100% rename from src/main/resources/docs/description/Gemspec_DuplicatedAssignment.md rename to docs/description/Gemspec_DuplicatedAssignment.md diff --git a/src/main/resources/docs/description/Gemspec_OrderedDependencies.md b/docs/description/Gemspec_OrderedDependencies.md similarity index 100% rename from src/main/resources/docs/description/Gemspec_OrderedDependencies.md rename to docs/description/Gemspec_OrderedDependencies.md diff --git a/src/main/resources/docs/description/Gemspec_RequiredRubyVersion.md b/docs/description/Gemspec_RequiredRubyVersion.md similarity index 63% rename from src/main/resources/docs/description/Gemspec_RequiredRubyVersion.md rename to docs/description/Gemspec_RequiredRubyVersion.md index 281eeb47..cc013a0a 100644 --- a/src/main/resources/docs/description/Gemspec_RequiredRubyVersion.md +++ b/docs/description/Gemspec_RequiredRubyVersion.md @@ -1,6 +1,6 @@ -Checks that `required_ruby_version` of gemspec and `TargetRubyVersion` -of .rubocop.yml are equal. +Checks that `required_ruby_version` of gemspec is specified and +equal to `TargetRubyVersion` of .rubocop.yml. Thereby, RuboCop to perform static analysis working on the version required by gemspec. @@ -9,6 +9,11 @@ required by gemspec. ```ruby # When `TargetRubyVersion` of .rubocop.yml is `2.5`. +# bad +Gem::Specification.new do |spec| + # no `required_ruby_version` specified +end + # bad Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.4.0' @@ -29,10 +34,16 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5' end -# good +# accepted but not recommended Gem::Specification.new do |spec| spec.required_ruby_version = ['>= 2.5.0', '< 2.7.0'] end + +# accepted but not recommended, since +# Ruby does not really follow semantic versionning +Gem::Specification.new do |spec| + spec.required_ruby_version = '~> 2.5' +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Gemspec/RequiredRubyVersion) \ No newline at end of file diff --git a/src/main/resources/docs/description/Gemspec_RubyVersionGlobalsUsage.md b/docs/description/Gemspec_RubyVersionGlobalsUsage.md similarity index 100% rename from src/main/resources/docs/description/Gemspec_RubyVersionGlobalsUsage.md rename to docs/description/Gemspec_RubyVersionGlobalsUsage.md diff --git a/src/main/resources/docs/description/Layout_AccessModifierIndentation.md b/docs/description/Layout_AccessModifierIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_AccessModifierIndentation.md rename to docs/description/Layout_AccessModifierIndentation.md diff --git a/src/main/resources/docs/description/Layout_ArgumentAlignment.md b/docs/description/Layout_ArgumentAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_ArgumentAlignment.md rename to docs/description/Layout_ArgumentAlignment.md diff --git a/src/main/resources/docs/description/Layout_ArrayAlignment.md b/docs/description/Layout_ArrayAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_ArrayAlignment.md rename to docs/description/Layout_ArrayAlignment.md diff --git a/src/main/resources/docs/description/Layout_AssignmentIndentation.md b/docs/description/Layout_AssignmentIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_AssignmentIndentation.md rename to docs/description/Layout_AssignmentIndentation.md diff --git a/docs/description/Layout_BeginEndAlignment.md b/docs/description/Layout_BeginEndAlignment.md new file mode 100644 index 00000000..c36914ea --- /dev/null +++ b/docs/description/Layout_BeginEndAlignment.md @@ -0,0 +1,37 @@ + +This cop checks whether the end keyword of `begin` is aligned properly. + +Two modes are supported through the `EnforcedStyleAlignWith` configuration +parameter. If it's set to `start_of_line` (which is the default), the +`end` shall be aligned with the start of the line where the `begin` +keyword is. If it's set to `begin`, the `end` shall be aligned with the +`begin` keyword. + +`Layout/EndAlignment` cop aligns with keywords (e.g. `if`, `while`, `case`) +by default. On the other hand, `||= begin` that this cop targets tends to +align with the start of the line, it defaults to `EnforcedStyleAlignWith: start_of_line`. +These style can be configured by each cop. + +# Examples + +```ruby +# bad +foo ||= begin + do_something + end + +# good +foo ||= begin + do_something +end# bad +foo ||= begin + do_something +end + +# good +foo ||= begin + do_something + end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/BeginEndAlignment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_BlockAlignment.md b/docs/description/Layout_BlockAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_BlockAlignment.md rename to docs/description/Layout_BlockAlignment.md diff --git a/src/main/resources/docs/description/Layout_BlockEndNewline.md b/docs/description/Layout_BlockEndNewline.md similarity index 100% rename from src/main/resources/docs/description/Layout_BlockEndNewline.md rename to docs/description/Layout_BlockEndNewline.md diff --git a/src/main/resources/docs/description/Layout_CaseIndentation.md b/docs/description/Layout_CaseIndentation.md similarity index 82% rename from src/main/resources/docs/description/Layout_CaseIndentation.md rename to docs/description/Layout_CaseIndentation.md index 317d94a6..9436d0e5 100644 --- a/src/main/resources/docs/description/Layout_CaseIndentation.md +++ b/docs/description/Layout_CaseIndentation.md @@ -1,8 +1,8 @@ -This cop checks how the *when*s of a *case* expression -are indented in relation to its *case* or *end* keyword. +This cop checks how the ``when``s of a `case` expression +are indented in relation to its `case` or `end` keyword. -It will register a separate offense for each misaligned *when*. +It will register a separate offense for each misaligned `when`. # Examples diff --git a/src/main/resources/docs/description/Layout_ClassStructure.md b/docs/description/Layout_ClassStructure.md similarity index 82% rename from src/main/resources/docs/description/Layout_ClassStructure.md rename to docs/description/Layout_ClassStructure.md index 73f58526..21ba0bee 100644 --- a/src/main/resources/docs/description/Layout_ClassStructure.md +++ b/docs/description/Layout_ClassStructure.md @@ -4,22 +4,24 @@ Checks if the code style follows the ExpectedOrder configuration: `Categories` allows us to map macro names into a category. Consider an example of code style that covers the following order: -- Module inclusion (include, prepend, extend) -- Constants -- Associations (has_one, has_many) -- Public attribute macros (attr_accessor, attr_writer, attr_reader) -- Other macros (validates, validate) -- Public class methods -- Initializer -- Public instance methods -- Protected attribute macros (attr_accessor, attr_writer, attr_reader) -- Protected instance methods -- Private attribute macros (attr_accessor, attr_writer, attr_reader) -- Private instance methods + +* Module inclusion (include, prepend, extend) +* Constants +* Associations (has_one, has_many) +* Public attribute macros (attr_accessor, attr_writer, attr_reader) +* Other macros (validates, validate) +* Public class methods +* Initializer +* Public instance methods +* Protected attribute macros (attr_accessor, attr_writer, attr_reader) +* Protected instance methods +* Private attribute macros (attr_accessor, attr_writer, attr_reader) +* Private instance methods You can configure the following order: -```yaml +[source,yaml] +---- Layout/ClassStructure: ExpectedOrder: - module_inclusion @@ -36,13 +38,14 @@ You can configure the following order: - private_attribute_macros - private_delegate - private_methods -``` +---- Instead of putting all literals in the expected order, is also possible to group categories of macros. Visibility levels are handled automatically. -```yaml +[source,yaml] +---- Layout/ClassStructure: Categories: association: @@ -59,7 +62,7 @@ automatically. - include - prepend - extend -``` +---- # Examples diff --git a/src/main/resources/docs/description/Layout_ClosingHeredocIndentation.md b/docs/description/Layout_ClosingHeredocIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_ClosingHeredocIndentation.md rename to docs/description/Layout_ClosingHeredocIndentation.md diff --git a/src/main/resources/docs/description/Layout_ClosingParenthesisIndentation.md b/docs/description/Layout_ClosingParenthesisIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_ClosingParenthesisIndentation.md rename to docs/description/Layout_ClosingParenthesisIndentation.md diff --git a/src/main/resources/docs/description/Layout_CommentIndentation.md b/docs/description/Layout_CommentIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_CommentIndentation.md rename to docs/description/Layout_CommentIndentation.md diff --git a/src/main/resources/docs/description/Layout_ConditionPosition.md b/docs/description/Layout_ConditionPosition.md similarity index 100% rename from src/main/resources/docs/description/Layout_ConditionPosition.md rename to docs/description/Layout_ConditionPosition.md diff --git a/src/main/resources/docs/description/Layout_DefEndAlignment.md b/docs/description/Layout_DefEndAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_DefEndAlignment.md rename to docs/description/Layout_DefEndAlignment.md diff --git a/src/main/resources/docs/description/Layout_DotPosition.md b/docs/description/Layout_DotPosition.md similarity index 100% rename from src/main/resources/docs/description/Layout_DotPosition.md rename to docs/description/Layout_DotPosition.md diff --git a/src/main/resources/docs/description/Layout_ElseAlignment.md b/docs/description/Layout_ElseAlignment.md similarity index 83% rename from src/main/resources/docs/description/Layout_ElseAlignment.md rename to docs/description/Layout_ElseAlignment.md index a866935c..d616f6d2 100644 --- a/src/main/resources/docs/description/Layout_ElseAlignment.md +++ b/docs/description/Layout_ElseAlignment.md @@ -1,6 +1,6 @@ This cop checks the alignment of else keywords. Normally they should -be aligned with an if/unless/while/until/begin/def keyword, but there +be aligned with an if/unless/while/until/begin/def/rescue keyword, but there are special cases when they should follow the same rules as the alignment of end. diff --git a/src/main/resources/docs/description/Layout_EmptyComment.md b/docs/description/Layout_EmptyComment.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyComment.md rename to docs/description/Layout_EmptyComment.md diff --git a/src/main/resources/docs/description/Layout_EmptyLineAfterGuardClause.md b/docs/description/Layout_EmptyLineAfterGuardClause.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLineAfterGuardClause.md rename to docs/description/Layout_EmptyLineAfterGuardClause.md diff --git a/src/main/resources/docs/description/Layout_EmptyLineAfterMagicComment.md b/docs/description/Layout_EmptyLineAfterMagicComment.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLineAfterMagicComment.md rename to docs/description/Layout_EmptyLineAfterMagicComment.md diff --git a/docs/description/Layout_EmptyLineAfterMultilineCondition.md b/docs/description/Layout_EmptyLineAfterMultilineCondition.md new file mode 100644 index 00000000..94972445 --- /dev/null +++ b/docs/description/Layout_EmptyLineAfterMultilineCondition.md @@ -0,0 +1,53 @@ + +This cop enforces empty line after multiline condition. + +# Examples + +```ruby +# bad +if multiline && + condition + do_something +end + +# good +if multiline && + condition + + do_something +end + +# bad +case x +when foo, + bar + do_something +end + +# good +case x +when foo, + bar + + do_something +end + +# bad +begin + do_something +rescue FooError, + BarError + handle_error +end + +# good +begin + do_something +rescue FooError, + BarError + + handle_error +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EmptyLineAfterMultilineCondition) \ No newline at end of file diff --git a/docs/description/Layout_EmptyLineBetweenDefs.md b/docs/description/Layout_EmptyLineBetweenDefs.md new file mode 100644 index 00000000..54130270 --- /dev/null +++ b/docs/description/Layout_EmptyLineBetweenDefs.md @@ -0,0 +1,68 @@ + +This cop checks whether class/module/method definitions are +separated by one or more empty lines. + +`NumberOfEmptyLines` can be an integer (default is 1) or +an array (e.g. [1, 2]) to specify a minimum and maximum +number of empty lines permitted. + +`AllowAdjacentOneLineDefs` configures whether adjacent +one-line definitions are considered an offense. + +# Examples + +```ruby +# checks for empty lines between method definitions. + +# bad +def a +end +def b +end +# good +def a +end + +def b +end# checks for empty lines between class definitions. + +# bad +class A +end +class B +end +def b +end +# good +class A +end + +class B +end + +def b +end# checks for empty lines between module definitions. + +# bad +module A +end +module B +end +def b +end +# good +module A +end + +module B +end + +def b +end +# good +class ErrorA < BaseError; end +class ErrorB < BaseError; end +class ErrorC < BaseError; end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EmptyLineBetweenDefs) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_EmptyLines.md b/docs/description/Layout_EmptyLines.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLines.md rename to docs/description/Layout_EmptyLines.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundAccessModifier.md b/docs/description/Layout_EmptyLinesAroundAccessModifier.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundAccessModifier.md rename to docs/description/Layout_EmptyLinesAroundAccessModifier.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundArguments.md b/docs/description/Layout_EmptyLinesAroundArguments.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundArguments.md rename to docs/description/Layout_EmptyLinesAroundArguments.md diff --git a/docs/description/Layout_EmptyLinesAroundAttributeAccessor.md b/docs/description/Layout_EmptyLinesAroundAttributeAccessor.md new file mode 100644 index 00000000..1a320d66 --- /dev/null +++ b/docs/description/Layout_EmptyLinesAroundAttributeAccessor.md @@ -0,0 +1,53 @@ + +Checks for a newline after an attribute accessor or a group of them. +`alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are allowed +by default. These are customizable with `AllowAliasSyntax` and `AllowedMethods` options. + +# Examples + +```ruby +# bad +attr_accessor :foo +def do_something +end + +# good +attr_accessor :foo + +def do_something +end + +# good +attr_accessor :foo +attr_reader :bar +attr_writer :baz +attr :qux + +def do_something +end# good +attr_accessor :foo +alias :foo? :foo + +def do_something +end# bad +attr_accessor :foo +alias :foo? :foo + +def do_something +end + +# good +attr_accessor :foo + +alias :foo? :foo + +def do_something +end# good +attr_accessor :foo +private :foo + +def do_something +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EmptyLinesAroundAttributeAccessor) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundBeginBody.md b/docs/description/Layout_EmptyLinesAroundBeginBody.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundBeginBody.md rename to docs/description/Layout_EmptyLinesAroundBeginBody.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundBlockBody.md b/docs/description/Layout_EmptyLinesAroundBlockBody.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundBlockBody.md rename to docs/description/Layout_EmptyLinesAroundBlockBody.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundClassBody.md b/docs/description/Layout_EmptyLinesAroundClassBody.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundClassBody.md rename to docs/description/Layout_EmptyLinesAroundClassBody.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundExceptionHandlingKeywords.md b/docs/description/Layout_EmptyLinesAroundExceptionHandlingKeywords.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundExceptionHandlingKeywords.md rename to docs/description/Layout_EmptyLinesAroundExceptionHandlingKeywords.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundMethodBody.md b/docs/description/Layout_EmptyLinesAroundMethodBody.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundMethodBody.md rename to docs/description/Layout_EmptyLinesAroundMethodBody.md diff --git a/src/main/resources/docs/description/Layout_EmptyLinesAroundModuleBody.md b/docs/description/Layout_EmptyLinesAroundModuleBody.md similarity index 100% rename from src/main/resources/docs/description/Layout_EmptyLinesAroundModuleBody.md rename to docs/description/Layout_EmptyLinesAroundModuleBody.md diff --git a/src/main/resources/docs/description/Layout_EndAlignment.md b/docs/description/Layout_EndAlignment.md similarity index 75% rename from src/main/resources/docs/description/Layout_EndAlignment.md rename to docs/description/Layout_EndAlignment.md index cb7681a4..f9c44e01 100644 --- a/src/main/resources/docs/description/Layout_EndAlignment.md +++ b/docs/description/Layout_EndAlignment.md @@ -13,6 +13,11 @@ left-hand-side of the variable assignment, if there is one. If it's set to `start_of_line`, the `end` shall be aligned with the start of the line where the matching keyword appears. +This `Layout/EndAlignment` cop aligns with keywords (e.g. `if`, `while`, `case`) +by default. On the other hand, `Layout/BeginEndAlignment` cop aligns with +`EnforcedStyleAlignWith: start_of_line` by default due to `||= begin` tends +to align with the start of the line. These style can be configured by each cop. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Layout_EndOfLine.md b/docs/description/Layout_EndOfLine.md similarity index 100% rename from src/main/resources/docs/description/Layout_EndOfLine.md rename to docs/description/Layout_EndOfLine.md diff --git a/src/main/resources/docs/description/Layout_ExtraSpacing.md b/docs/description/Layout_ExtraSpacing.md similarity index 100% rename from src/main/resources/docs/description/Layout_ExtraSpacing.md rename to docs/description/Layout_ExtraSpacing.md diff --git a/src/main/resources/docs/description/Layout_FirstArgumentIndentation.md b/docs/description/Layout_FirstArgumentIndentation.md similarity index 87% rename from src/main/resources/docs/description/Layout_FirstArgumentIndentation.md rename to docs/description/Layout_FirstArgumentIndentation.md index 45605b87..860ab071 100644 --- a/src/main/resources/docs/description/Layout_FirstArgumentIndentation.md +++ b/docs/description/Layout_FirstArgumentIndentation.md @@ -1,10 +1,13 @@ This cop checks the indentation of the first argument in a method call. -Arguments after the first one are checked by Layout/ArgumentAlignment, +Arguments after the first one are checked by `Layout/ArgumentAlignment`, not by this cop. -For indenting the first parameter of method *definitions*, check out -Layout/FirstParameterIndentation. +For indenting the first parameter of method _definitions_, check out +`Layout/FirstParameterIndentation`. + +This cop will respect `Layout/ArgumentAlignment` and will not work when +`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`. # Examples diff --git a/src/main/resources/docs/description/Layout_FirstArrayElementIndentation.md b/docs/description/Layout_FirstArrayElementIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstArrayElementIndentation.md rename to docs/description/Layout_FirstArrayElementIndentation.md diff --git a/src/main/resources/docs/description/Layout_FirstArrayElementLineBreak.md b/docs/description/Layout_FirstArrayElementLineBreak.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstArrayElementLineBreak.md rename to docs/description/Layout_FirstArrayElementLineBreak.md diff --git a/src/main/resources/docs/description/Layout_FirstHashElementIndentation.md b/docs/description/Layout_FirstHashElementIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstHashElementIndentation.md rename to docs/description/Layout_FirstHashElementIndentation.md diff --git a/src/main/resources/docs/description/Layout_FirstHashElementLineBreak.md b/docs/description/Layout_FirstHashElementLineBreak.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstHashElementLineBreak.md rename to docs/description/Layout_FirstHashElementLineBreak.md diff --git a/src/main/resources/docs/description/Layout_FirstMethodArgumentLineBreak.md b/docs/description/Layout_FirstMethodArgumentLineBreak.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstMethodArgumentLineBreak.md rename to docs/description/Layout_FirstMethodArgumentLineBreak.md diff --git a/src/main/resources/docs/description/Layout_FirstMethodParameterLineBreak.md b/docs/description/Layout_FirstMethodParameterLineBreak.md similarity index 100% rename from src/main/resources/docs/description/Layout_FirstMethodParameterLineBreak.md rename to docs/description/Layout_FirstMethodParameterLineBreak.md diff --git a/src/main/resources/docs/description/Layout_FirstParameterIndentation.md b/docs/description/Layout_FirstParameterIndentation.md similarity index 86% rename from src/main/resources/docs/description/Layout_FirstParameterIndentation.md rename to docs/description/Layout_FirstParameterIndentation.md index 24a8db46..8fd46876 100644 --- a/src/main/resources/docs/description/Layout_FirstParameterIndentation.md +++ b/docs/description/Layout_FirstParameterIndentation.md @@ -3,9 +3,9 @@ This cop checks the indentation of the first parameter in a method definition. Parameters after the first one are checked by Layout/ParameterAlignment, not by this cop. -For indenting the first argument of method *calls*, check out +For indenting the first argument of method _calls_, check out Layout/FirstArgumentIndentation, which supports options related to -nesting that are irrelevant for method *definitions*. +nesting that are irrelevant for method _definitions_. # Examples diff --git a/src/main/resources/docs/description/Layout_HashAlignment.md b/docs/description/Layout_HashAlignment.md similarity index 86% rename from src/main/resources/docs/description/Layout_HashAlignment.md rename to docs/description/Layout_HashAlignment.md index 3dc082b0..8686e4d1 100644 --- a/src/main/resources/docs/description/Layout_HashAlignment.md +++ b/docs/description/Layout_HashAlignment.md @@ -3,16 +3,16 @@ Check that the keys, separators, and values of a multi-line hash literal are aligned according to configuration. The configuration options are: - - key (left align keys, one space before hash rockets and values) - - separator (align hash rockets and colons, right align keys) - - table (left align keys, hash rockets, and values) +* key (left align keys, one space before hash rockets and values) +* separator (align hash rockets and colons, right align keys) +* table (left align keys, hash rockets, and values) The treatment of hashes passed as the last argument to a method call can also be configured. The options are: - - always_inspect - - always_ignore - - ignore_implicit (without curly braces) +* always_inspect +* always_ignore +* ignore_implicit (without curly braces) Alternatively you can specify multiple allowed styles. That's done by passing a list of styles to EnforcedStyles. diff --git a/src/main/resources/docs/description/Layout_HeredocArgumentClosingParenthesis.md b/docs/description/Layout_HeredocArgumentClosingParenthesis.md similarity index 100% rename from src/main/resources/docs/description/Layout_HeredocArgumentClosingParenthesis.md rename to docs/description/Layout_HeredocArgumentClosingParenthesis.md diff --git a/docs/description/Layout_HeredocIndentation.md b/docs/description/Layout_HeredocIndentation.md new file mode 100644 index 00000000..5b405d45 --- /dev/null +++ b/docs/description/Layout_HeredocIndentation.md @@ -0,0 +1,23 @@ + +This cop checks the indentation of the here document bodies. The bodies +are indented one step. + +Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default), + this cop does not add any offenses for long here documents to + avoid `Layout/LineLength`'s offenses. + +# Examples + +```ruby +# bad +<<-RUBY +something +RUBY + +# good +<<~RUBY + something +RUBY +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/HeredocIndentation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_IndentationConsistency.md b/docs/description/Layout_IndentationConsistency.md similarity index 100% rename from src/main/resources/docs/description/Layout_IndentationConsistency.md rename to docs/description/Layout_IndentationConsistency.md diff --git a/src/main/resources/docs/description/Layout_IndentationStyle.md b/docs/description/Layout_IndentationStyle.md similarity index 100% rename from src/main/resources/docs/description/Layout_IndentationStyle.md rename to docs/description/Layout_IndentationStyle.md diff --git a/src/main/resources/docs/description/Layout_IndentationWidth.md b/docs/description/Layout_IndentationWidth.md similarity index 100% rename from src/main/resources/docs/description/Layout_IndentationWidth.md rename to docs/description/Layout_IndentationWidth.md diff --git a/src/main/resources/docs/description/Layout_InitialIndentation.md b/docs/description/Layout_InitialIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_InitialIndentation.md rename to docs/description/Layout_InitialIndentation.md diff --git a/src/main/resources/docs/description/Layout_LeadingCommentSpace.md b/docs/description/Layout_LeadingCommentSpace.md similarity index 100% rename from src/main/resources/docs/description/Layout_LeadingCommentSpace.md rename to docs/description/Layout_LeadingCommentSpace.md diff --git a/src/main/resources/docs/description/Layout_LeadingEmptyLines.md b/docs/description/Layout_LeadingEmptyLines.md similarity index 100% rename from src/main/resources/docs/description/Layout_LeadingEmptyLines.md rename to docs/description/Layout_LeadingEmptyLines.md diff --git a/src/main/resources/docs/description/Layout_LineLength.md b/docs/description/Layout_LineLength.md similarity index 70% rename from src/main/resources/docs/description/Layout_LineLength.md rename to docs/description/Layout_LineLength.md index d4e5d643..6e6f0d57 100644 --- a/src/main/resources/docs/description/Layout_LineLength.md +++ b/docs/description/Layout_LineLength.md @@ -15,23 +15,23 @@ If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.) - - ArgumentAlignment - - BlockAlignment - - BlockDelimiters - - BlockEndNewline - - ClosingParenthesisIndentation - - FirstArgumentIndentation - - FirstArrayElementIndentation - - FirstHashElementIndentation - - FirstParameterIndentation - - HashAlignment - - IndentationWidth - - MultilineArrayLineBreaks - - MultilineBlockLayout - - MultilineHashBraceLayout - - MultilineHashKeyLineBreaks - - MultilineMethodArgumentLineBreaks - - ParameterAlignment +* ArgumentAlignment +* BlockAlignment +* BlockDelimiters +* BlockEndNewline +* ClosingParenthesisIndentation +* FirstArgumentIndentation +* FirstArrayElementIndentation +* FirstHashElementIndentation +* FirstParameterIndentation +* HashAlignment +* IndentationWidth +* MultilineArrayLineBreaks +* MultilineBlockLayout +* MultilineHashBraceLayout +* MultilineHashKeyLineBreaks +* MultilineMethodArgumentLineBreaks +* ParameterAlignment Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns diff --git a/src/main/resources/docs/description/Layout_MultilineArrayBraceLayout.md b/docs/description/Layout_MultilineArrayBraceLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineArrayBraceLayout.md rename to docs/description/Layout_MultilineArrayBraceLayout.md diff --git a/src/main/resources/docs/description/Layout_MultilineArrayLineBreaks.md b/docs/description/Layout_MultilineArrayLineBreaks.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineArrayLineBreaks.md rename to docs/description/Layout_MultilineArrayLineBreaks.md diff --git a/src/main/resources/docs/description/Layout_MultilineAssignmentLayout.md b/docs/description/Layout_MultilineAssignmentLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineAssignmentLayout.md rename to docs/description/Layout_MultilineAssignmentLayout.md diff --git a/src/main/resources/docs/description/Layout_MultilineBlockLayout.md b/docs/description/Layout_MultilineBlockLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineBlockLayout.md rename to docs/description/Layout_MultilineBlockLayout.md diff --git a/src/main/resources/docs/description/Layout_MultilineHashBraceLayout.md b/docs/description/Layout_MultilineHashBraceLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineHashBraceLayout.md rename to docs/description/Layout_MultilineHashBraceLayout.md diff --git a/src/main/resources/docs/description/Layout_MultilineHashKeyLineBreaks.md b/docs/description/Layout_MultilineHashKeyLineBreaks.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineHashKeyLineBreaks.md rename to docs/description/Layout_MultilineHashKeyLineBreaks.md diff --git a/src/main/resources/docs/description/Layout_MultilineMethodArgumentLineBreaks.md b/docs/description/Layout_MultilineMethodArgumentLineBreaks.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineMethodArgumentLineBreaks.md rename to docs/description/Layout_MultilineMethodArgumentLineBreaks.md diff --git a/src/main/resources/docs/description/Layout_MultilineMethodCallBraceLayout.md b/docs/description/Layout_MultilineMethodCallBraceLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineMethodCallBraceLayout.md rename to docs/description/Layout_MultilineMethodCallBraceLayout.md diff --git a/src/main/resources/docs/description/Layout_MultilineMethodCallIndentation.md b/docs/description/Layout_MultilineMethodCallIndentation.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineMethodCallIndentation.md rename to docs/description/Layout_MultilineMethodCallIndentation.md diff --git a/src/main/resources/docs/description/Layout_MultilineMethodDefinitionBraceLayout.md b/docs/description/Layout_MultilineMethodDefinitionBraceLayout.md similarity index 100% rename from src/main/resources/docs/description/Layout_MultilineMethodDefinitionBraceLayout.md rename to docs/description/Layout_MultilineMethodDefinitionBraceLayout.md diff --git a/docs/description/Layout_MultilineOperationIndentation.md b/docs/description/Layout_MultilineOperationIndentation.md new file mode 100644 index 00000000..4fb02fc3 --- /dev/null +++ b/docs/description/Layout_MultilineOperationIndentation.md @@ -0,0 +1,40 @@ + +This cop checks the indentation of the right hand side operand in +binary operations that span more than one line. + +The `aligned` style checks that operators are aligned if they are part +of an `if` or `while` condition, a `return` statement, etc. In other +contexts, the second operand should be indented regardless of enforced +style. + +# Examples + +```ruby +# bad +if a + + b + something && + something_else +end + +# good +if a + + b + something && + something_else +end# bad +if a + + b + something && + something_else +end + +# good +if a + + b + something && + something_else +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/MultilineOperationIndentation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_ParameterAlignment.md b/docs/description/Layout_ParameterAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_ParameterAlignment.md rename to docs/description/Layout_ParameterAlignment.md diff --git a/src/main/resources/docs/description/Layout_RescueEnsureAlignment.md b/docs/description/Layout_RescueEnsureAlignment.md similarity index 100% rename from src/main/resources/docs/description/Layout_RescueEnsureAlignment.md rename to docs/description/Layout_RescueEnsureAlignment.md diff --git a/src/main/resources/docs/description/Layout_SpaceAfterColon.md b/docs/description/Layout_SpaceAfterColon.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAfterColon.md rename to docs/description/Layout_SpaceAfterColon.md diff --git a/src/main/resources/docs/description/Layout_SpaceAfterComma.md b/docs/description/Layout_SpaceAfterComma.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAfterComma.md rename to docs/description/Layout_SpaceAfterComma.md diff --git a/src/main/resources/docs/description/Layout_SpaceAfterMethodName.md b/docs/description/Layout_SpaceAfterMethodName.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAfterMethodName.md rename to docs/description/Layout_SpaceAfterMethodName.md diff --git a/src/main/resources/docs/description/Layout_SpaceAfterNot.md b/docs/description/Layout_SpaceAfterNot.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAfterNot.md rename to docs/description/Layout_SpaceAfterNot.md diff --git a/src/main/resources/docs/description/Layout_SpaceAfterSemicolon.md b/docs/description/Layout_SpaceAfterSemicolon.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAfterSemicolon.md rename to docs/description/Layout_SpaceAfterSemicolon.md diff --git a/src/main/resources/docs/description/Layout_SpaceAroundBlockParameters.md b/docs/description/Layout_SpaceAroundBlockParameters.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAroundBlockParameters.md rename to docs/description/Layout_SpaceAroundBlockParameters.md diff --git a/src/main/resources/docs/description/Layout_SpaceAroundEqualsInParameterDefault.md b/docs/description/Layout_SpaceAroundEqualsInParameterDefault.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAroundEqualsInParameterDefault.md rename to docs/description/Layout_SpaceAroundEqualsInParameterDefault.md diff --git a/src/main/resources/docs/description/Layout_SpaceAroundKeyword.md b/docs/description/Layout_SpaceAroundKeyword.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAroundKeyword.md rename to docs/description/Layout_SpaceAroundKeyword.md diff --git a/src/main/resources/docs/description/Layout_SpaceAroundMethodCallOperator.md b/docs/description/Layout_SpaceAroundMethodCallOperator.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceAroundMethodCallOperator.md rename to docs/description/Layout_SpaceAroundMethodCallOperator.md diff --git a/src/main/resources/docs/description/Layout_SpaceAroundOperators.md b/docs/description/Layout_SpaceAroundOperators.md similarity index 88% rename from src/main/resources/docs/description/Layout_SpaceAroundOperators.md rename to docs/description/Layout_SpaceAroundOperators.md index 9dbe93af..32dd77f9 100644 --- a/src/main/resources/docs/description/Layout_SpaceAroundOperators.md +++ b/docs/description/Layout_SpaceAroundOperators.md @@ -1,6 +1,8 @@ Checks that operators have space around them, except for ** which should or shouldn't have surrounding space depending on configuration. +It allows vertical alignment consisting of one or more whitespace +around operators. This cop has `AllowForAlignment` option. When `true`, allows most uses of extra spacing if the intent is to align with an operator on diff --git a/src/main/resources/docs/description/Layout_SpaceBeforeBlockBraces.md b/docs/description/Layout_SpaceBeforeBlockBraces.md similarity index 83% rename from src/main/resources/docs/description/Layout_SpaceBeforeBlockBraces.md rename to docs/description/Layout_SpaceBeforeBlockBraces.md index bf6f6aa2..b04d09e1 100644 --- a/src/main/resources/docs/description/Layout_SpaceBeforeBlockBraces.md +++ b/docs/description/Layout_SpaceBeforeBlockBraces.md @@ -21,7 +21,15 @@ foo.map { |a| # good foo.map{ |a| a.bar.to_s -} +}# bad +7.times{} + +# good +7.times {}# bad +7.times {} + +# good +7.times{} ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/SpaceBeforeBlockBraces) \ No newline at end of file diff --git a/docs/description/Layout_SpaceBeforeBrackets.md b/docs/description/Layout_SpaceBeforeBrackets.md new file mode 100644 index 00000000..e3579fa1 --- /dev/null +++ b/docs/description/Layout_SpaceBeforeBrackets.md @@ -0,0 +1,16 @@ + +Checks for space between the name of a receiver and a left +brackets. + +# Examples + +```ruby + +# bad +collection [index_or_key] + +# good +collection[index_or_key] +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/SpaceBeforeBrackets) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_SpaceBeforeComma.md b/docs/description/Layout_SpaceBeforeComma.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceBeforeComma.md rename to docs/description/Layout_SpaceBeforeComma.md diff --git a/src/main/resources/docs/description/Layout_SpaceBeforeComment.md b/docs/description/Layout_SpaceBeforeComment.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceBeforeComment.md rename to docs/description/Layout_SpaceBeforeComment.md diff --git a/src/main/resources/docs/description/Layout_SpaceBeforeFirstArg.md b/docs/description/Layout_SpaceBeforeFirstArg.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceBeforeFirstArg.md rename to docs/description/Layout_SpaceBeforeFirstArg.md diff --git a/src/main/resources/docs/description/Layout_SpaceBeforeSemicolon.md b/docs/description/Layout_SpaceBeforeSemicolon.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceBeforeSemicolon.md rename to docs/description/Layout_SpaceBeforeSemicolon.md diff --git a/src/main/resources/docs/description/Layout_SpaceInLambdaLiteral.md b/docs/description/Layout_SpaceInLambdaLiteral.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInLambdaLiteral.md rename to docs/description/Layout_SpaceInLambdaLiteral.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideArrayLiteralBrackets.md b/docs/description/Layout_SpaceInsideArrayLiteralBrackets.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideArrayLiteralBrackets.md rename to docs/description/Layout_SpaceInsideArrayLiteralBrackets.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideArrayPercentLiteral.md b/docs/description/Layout_SpaceInsideArrayPercentLiteral.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideArrayPercentLiteral.md rename to docs/description/Layout_SpaceInsideArrayPercentLiteral.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideBlockBraces.md b/docs/description/Layout_SpaceInsideBlockBraces.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideBlockBraces.md rename to docs/description/Layout_SpaceInsideBlockBraces.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideHashLiteralBraces.md b/docs/description/Layout_SpaceInsideHashLiteralBraces.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideHashLiteralBraces.md rename to docs/description/Layout_SpaceInsideHashLiteralBraces.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideParens.md b/docs/description/Layout_SpaceInsideParens.md similarity index 82% rename from src/main/resources/docs/description/Layout_SpaceInsideParens.md rename to docs/description/Layout_SpaceInsideParens.md index a6624478..e32d80f1 100644 --- a/src/main/resources/docs/description/Layout_SpaceInsideParens.md +++ b/docs/description/Layout_SpaceInsideParens.md @@ -9,10 +9,12 @@ Checks for spaces inside ordinary round parentheses. # bad f( 3) g = (a + 3 ) +f( ) # good f(3) -g = (a + 3)# The `space` style enforces that parentheses have a space at the +g = (a + 3) +f()# The `space` style enforces that parentheses have a space at the # beginning and end. # Note: Empty parentheses should not have spaces. diff --git a/src/main/resources/docs/description/Layout_SpaceInsidePercentLiteralDelimiters.md b/docs/description/Layout_SpaceInsidePercentLiteralDelimiters.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsidePercentLiteralDelimiters.md rename to docs/description/Layout_SpaceInsidePercentLiteralDelimiters.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideRangeLiteral.md b/docs/description/Layout_SpaceInsideRangeLiteral.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideRangeLiteral.md rename to docs/description/Layout_SpaceInsideRangeLiteral.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideReferenceBrackets.md b/docs/description/Layout_SpaceInsideReferenceBrackets.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideReferenceBrackets.md rename to docs/description/Layout_SpaceInsideReferenceBrackets.md diff --git a/src/main/resources/docs/description/Layout_SpaceInsideStringInterpolation.md b/docs/description/Layout_SpaceInsideStringInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Layout_SpaceInsideStringInterpolation.md rename to docs/description/Layout_SpaceInsideStringInterpolation.md diff --git a/src/main/resources/docs/description/Layout_TrailingEmptyLines.md b/docs/description/Layout_TrailingEmptyLines.md similarity index 100% rename from src/main/resources/docs/description/Layout_TrailingEmptyLines.md rename to docs/description/Layout_TrailingEmptyLines.md diff --git a/src/main/resources/docs/description/Layout_TrailingWhitespace.md b/docs/description/Layout_TrailingWhitespace.md similarity index 79% rename from src/main/resources/docs/description/Layout_TrailingWhitespace.md rename to docs/description/Layout_TrailingWhitespace.md index c160dbe3..69ffc84b 100644 --- a/src/main/resources/docs/description/Layout_TrailingWhitespace.md +++ b/docs/description/Layout_TrailingWhitespace.md @@ -14,6 +14,17 @@ x = 0# The line in this example contains spaces after the 0. # bad code = <<~RUBY x = 0 +RUBY + +# ok +code = <<~RUBY + x = 0 #{} +RUBY + +# good +trailing_whitespace = ' ' +code = <<~RUBY + x = 0#{trailing_whitespace} RUBY# The line in this example contains spaces after the 0. # good code = <<~RUBY diff --git a/docs/description/Lint_AmbiguousAssignment.md b/docs/description/Lint_AmbiguousAssignment.md new file mode 100644 index 00000000..41f39dfc --- /dev/null +++ b/docs/description/Lint_AmbiguousAssignment.md @@ -0,0 +1,20 @@ + +This cop checks for mistyped shorthand assignments. + +# Examples + +```ruby +# bad +x =- y +x =+ y +x =* y +x =! y + +# good +x -= y # or x = -y +x += y # or x = +y +x *= y # or x = *y +x != y # or x = !y +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/AmbiguousAssignment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_AmbiguousBlockAssociation.md b/docs/description/Lint_AmbiguousBlockAssociation.md similarity index 89% rename from src/main/resources/docs/description/Lint_AmbiguousBlockAssociation.md rename to docs/description/Lint_AmbiguousBlockAssociation.md index 8683a4a2..b477806b 100644 --- a/src/main/resources/docs/description/Lint_AmbiguousBlockAssociation.md +++ b/docs/description/Lint_AmbiguousBlockAssociation.md @@ -10,6 +10,8 @@ when param passed without parentheses. some_method a { |val| puts val } # good # With parentheses, there's no ambiguity. +some_method(a { |val| puts val }) +# or (different meaning) some_method(a) { |val| puts val } # good diff --git a/src/main/resources/docs/description/Lint_AmbiguousOperator.md b/docs/description/Lint_AmbiguousOperator.md similarity index 100% rename from src/main/resources/docs/description/Lint_AmbiguousOperator.md rename to docs/description/Lint_AmbiguousOperator.md diff --git a/src/main/resources/docs/description/Lint_AmbiguousRegexpLiteral.md b/docs/description/Lint_AmbiguousRegexpLiteral.md similarity index 100% rename from src/main/resources/docs/description/Lint_AmbiguousRegexpLiteral.md rename to docs/description/Lint_AmbiguousRegexpLiteral.md diff --git a/src/main/resources/docs/description/Lint_AssignmentInCondition.md b/docs/description/Lint_AssignmentInCondition.md similarity index 100% rename from src/main/resources/docs/description/Lint_AssignmentInCondition.md rename to docs/description/Lint_AssignmentInCondition.md diff --git a/src/main/resources/docs/description/Lint_BigDecimalNew.md b/docs/description/Lint_BigDecimalNew.md similarity index 100% rename from src/main/resources/docs/description/Lint_BigDecimalNew.md rename to docs/description/Lint_BigDecimalNew.md diff --git a/docs/description/Lint_BinaryOperatorWithIdenticalOperands.md b/docs/description/Lint_BinaryOperatorWithIdenticalOperands.md new file mode 100644 index 00000000..39662338 --- /dev/null +++ b/docs/description/Lint_BinaryOperatorWithIdenticalOperands.md @@ -0,0 +1,34 @@ + +This cop checks for places where binary operator has identical operands. + +It covers arithmetic operators: `+`, `-`, `*`, `/`, `%`, `**`; +comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`; +bitwise operators: `|`, `^`, `&`, `<<`, `>>`; +boolean operators: `&&`, `||` +and "spaceship" operator - `<=>`. + +This cop is marked as unsafe as it does not consider side effects when calling methods +and thus can generate false positives: + if wr.take_char == '\0' && wr.take_char == '\0' + +# Examples + +```ruby +# bad +x / x +x.top >= x.top + +if a.x != 0 && a.x != 0 + do_something +end + +def childs? + left_child || left_child +end + +# good +x + x +1 << 1 +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/BinaryOperatorWithIdenticalOperands) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_BooleanSymbol.md b/docs/description/Lint_BooleanSymbol.md similarity index 100% rename from src/main/resources/docs/description/Lint_BooleanSymbol.md rename to docs/description/Lint_BooleanSymbol.md diff --git a/src/main/resources/docs/description/Lint_CircularArgumentReference.md b/docs/description/Lint_CircularArgumentReference.md similarity index 100% rename from src/main/resources/docs/description/Lint_CircularArgumentReference.md rename to docs/description/Lint_CircularArgumentReference.md diff --git a/docs/description/Lint_ConstantDefinitionInBlock.md b/docs/description/Lint_ConstantDefinitionInBlock.md new file mode 100644 index 00000000..7554b6ef --- /dev/null +++ b/docs/description/Lint_ConstantDefinitionInBlock.md @@ -0,0 +1,60 @@ + +Do not define constants within a block, since the block's scope does not +isolate or namespace the constant in any way. + +If you are trying to define that constant once, define it outside of +the block instead, or use a variable or method if defining the constant +in the outer scope would be problematic. + +For meta-programming, use `const_set`. + +# Examples + +```ruby +# bad +task :lint do + FILES_TO_LINT = Dir['lib/*.rb'] +end + +# bad +describe 'making a request' do + class TestRequest; end +end + +# bad +module M + extend ActiveSupport::Concern + included do + LIST = [] + end +end + +# good +task :lint do + files_to_lint = Dir['lib/*.rb'] +end + +# good +describe 'making a request' do + let(:test_request) { Class.new } + # see also `stub_const` for RSpec +end + +# good +module M + extend ActiveSupport::Concern + included do + const_set(:LIST, []) + end +end# good + +# `enums` for Typed Enums via `T::Enum` in Sorbet. +# https://sorbet.org/docs/tenum +class TestEnum < T::Enum + enums do + Foo = new("foo") + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ConstantDefinitionInBlock) \ No newline at end of file diff --git a/docs/description/Lint_ConstantResolution.md b/docs/description/Lint_ConstantResolution.md new file mode 100644 index 00000000..8e352357 --- /dev/null +++ b/docs/description/Lint_ConstantResolution.md @@ -0,0 +1,51 @@ + +Check that certain constants are fully qualified. + +This is not enabled by default because it would mark a lot of offenses +unnecessarily. + +Generally, gems should fully qualify all constants to avoid conflicts with +the code that uses the gem. Enable this cop without using `Only`/`Ignore` + +Large projects will over time end up with one or two constant names that +are problematic because of a conflict with a library or just internally +using the same name a namespace and a class. To avoid too many unnecessary +offenses, Enable this cop with `Only: [The, Constant, Names, Causing, Issues]` + +# Examples + +```ruby +# By default checks every constant + +# bad +User + +# bad +User::Login + +# good +::User + +# good +::User::Login# Restrict this cop to only being concerned about certain constants + +# bad +Login + +# good +::Login + +# good +User::Login# Restrict this cop not being concerned about certain constants + +# bad +User + +# good +::User::Login + +# good +Login +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ConstantResolution) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_Debugger.md b/docs/description/Lint_Debugger.md similarity index 82% rename from src/main/resources/docs/description/Lint_Debugger.md rename to docs/description/Lint_Debugger.md index 7a1243d4..f584e066 100644 --- a/src/main/resources/docs/description/Lint_Debugger.md +++ b/docs/description/Lint_Debugger.md @@ -1,5 +1,6 @@ This cop checks for calls to debugger or pry. +The cop can be configured to define which methods and receivers must be fixed. # Examples diff --git a/src/main/resources/docs/description/Lint_DeprecatedClassMethods.md b/docs/description/Lint_DeprecatedClassMethods.md similarity index 100% rename from src/main/resources/docs/description/Lint_DeprecatedClassMethods.md rename to docs/description/Lint_DeprecatedClassMethods.md diff --git a/docs/description/Lint_DeprecatedConstants.md b/docs/description/Lint_DeprecatedConstants.md new file mode 100644 index 00000000..79b22ead --- /dev/null +++ b/docs/description/Lint_DeprecatedConstants.md @@ -0,0 +1,32 @@ + +This cop checks for deprecated constants. + +It has `DeprecatedConstants` config. If there is an alternative method, you can set +alternative value as `Alternative`. And you can set the deprecated version as +`DeprecatedVersion`. These options can be omitted if they are not needed. + + DeprecatedConstants: + 'DEPRECATED_CONSTANT': + Alternative: 'alternative_value' + DeprecatedVersion: 'deprecated_version' + +By default, `NIL`, `TRUE`, `FALSE` and `Random::DEFAULT` are configured. + +# Examples + +```ruby + +# bad +NIL +TRUE +FALSE +Random::DEFAULT # Return value of Ruby 2 is `Random` instance, Ruby 3.0 is `Random` class. + +# good +nil +true +false +Random.new # `::DEFAULT` has been deprecated in Ruby 3, `.new` is compatible with Ruby 2. +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DeprecatedConstants) \ No newline at end of file diff --git a/docs/description/Lint_DeprecatedOpenSSLConstant.md b/docs/description/Lint_DeprecatedOpenSSLConstant.md new file mode 100644 index 00000000..04fc042c --- /dev/null +++ b/docs/description/Lint_DeprecatedOpenSSLConstant.md @@ -0,0 +1,33 @@ + +Algorithmic constants for `OpenSSL::Cipher` and `OpenSSL::Digest` +deprecated since OpenSSL version 2.2.0. Prefer passing a string +instead. + +# Examples + +```ruby + +# Example for OpenSSL::Cipher instantiation. + +# bad +OpenSSL::Cipher::AES.new(128, :GCM) + +# good +OpenSSL::Cipher.new('aes-128-gcm') +# Example for OpenSSL::Digest instantiation. + +# bad +OpenSSL::Digest::SHA256.new + +# good +OpenSSL::Digest.new('SHA256') +# Example for ::Digest inherited class methods. + +# bad +OpenSSL::Digest::SHA256.digest('foo') + +# good +OpenSSL::Digest.digest('SHA256', 'foo') +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DeprecatedOpenSSLConstant) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_DisjunctiveAssignmentInConstructor.md b/docs/description/Lint_DisjunctiveAssignmentInConstructor.md similarity index 100% rename from src/main/resources/docs/description/Lint_DisjunctiveAssignmentInConstructor.md rename to docs/description/Lint_DisjunctiveAssignmentInConstructor.md diff --git a/docs/description/Lint_DuplicateBranch.md b/docs/description/Lint_DuplicateBranch.md new file mode 100644 index 00000000..b94f4316 --- /dev/null +++ b/docs/description/Lint_DuplicateBranch.md @@ -0,0 +1,79 @@ + +This cop checks that there are no repeated bodies +within `if/unless`, `case-when` and `rescue` constructs. + +With `IgnoreLiteralBranches: true`, branches are not registered +as offenses if they return a basic literal value (string, symbol, +integer, float, rational, complex, `true`, `false`, or `nil`), or +return an array, hash, regexp or range that only contains one of +the above basic literal values. + +With `IgnoreConstantBranches: true`, branches are not registered +as offenses if they return a constant value. + +# Examples + +```ruby +# bad +if foo + do_foo + do_something_else +elsif bar + do_foo + do_something_else +end + +# good +if foo || bar + do_foo + do_something_else +end + +# bad +case x +when foo + do_foo +when bar + do_foo +else + do_something_else +end + +# good +case x +when foo, bar + do_foo +else + do_something_else +end + +# bad +begin + do_something +rescue FooError + handle_error +rescue BarError + handle_error +end + +# good +begin + do_something +rescue FooError, BarError + handle_error +end# good +case size +when "small" then 100 +when "medium" then 250 +when "large" then 1000 +else 250 +end# good +case size +when "small" then SMALL_SIZE +when "medium" then MEDIUM_SIZE +when "large" then LARGE_SIZE +else MEDIUM_SIZE +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DuplicateBranch) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_DuplicateCaseCondition.md b/docs/description/Lint_DuplicateCaseCondition.md similarity index 100% rename from src/main/resources/docs/description/Lint_DuplicateCaseCondition.md rename to docs/description/Lint_DuplicateCaseCondition.md diff --git a/docs/description/Lint_DuplicateElsifCondition.md b/docs/description/Lint_DuplicateElsifCondition.md new file mode 100644 index 00000000..9a248eb0 --- /dev/null +++ b/docs/description/Lint_DuplicateElsifCondition.md @@ -0,0 +1,22 @@ + +This cop checks that there are no repeated conditions used in if 'elsif'. + +# Examples + +```ruby +# bad +if x == 1 + do_something +elsif x == 1 + do_something_else +end + +# good +if x == 1 + do_something +elsif x == 2 + do_something_else +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DuplicateElsifCondition) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_DuplicateHashKey.md b/docs/description/Lint_DuplicateHashKey.md similarity index 100% rename from src/main/resources/docs/description/Lint_DuplicateHashKey.md rename to docs/description/Lint_DuplicateHashKey.md diff --git a/src/main/resources/docs/description/Lint_DuplicateMethods.md b/docs/description/Lint_DuplicateMethods.md similarity index 100% rename from src/main/resources/docs/description/Lint_DuplicateMethods.md rename to docs/description/Lint_DuplicateMethods.md diff --git a/docs/description/Lint_DuplicateRegexpCharacterClassElement.md b/docs/description/Lint_DuplicateRegexpCharacterClassElement.md new file mode 100644 index 00000000..05a21c33 --- /dev/null +++ b/docs/description/Lint_DuplicateRegexpCharacterClassElement.md @@ -0,0 +1,21 @@ + +This cop checks for duplicate elements in Regexp character classes. + +# Examples + +```ruby + +# bad +r = /[xyx]/ + +# bad +r = /[0-9x0-9]/ + +# good +r = /[xy]/ + +# good +r = /[0-9x]/ +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DuplicateRegexpCharacterClassElement) \ No newline at end of file diff --git a/docs/description/Lint_DuplicateRequire.md b/docs/description/Lint_DuplicateRequire.md new file mode 100644 index 00000000..21e2df0b --- /dev/null +++ b/docs/description/Lint_DuplicateRequire.md @@ -0,0 +1,21 @@ + +This cop checks for duplicate `require`s and `require_relative`s. + +# Examples + +```ruby +# bad +require 'foo' +require 'bar' +require 'foo' + +# good +require 'foo' +require 'bar' + +# good +require 'foo' +require_relative 'foo' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DuplicateRequire) \ No newline at end of file diff --git a/docs/description/Lint_DuplicateRescueException.md b/docs/description/Lint_DuplicateRescueException.md new file mode 100644 index 00000000..678a268f --- /dev/null +++ b/docs/description/Lint_DuplicateRescueException.md @@ -0,0 +1,27 @@ + +This cop checks that there are no repeated exceptions +used in 'rescue' expressions. + +# Examples + +```ruby +# bad +begin + something +rescue FirstException + handle_exception +rescue FirstException + handle_other_exception +end + +# good +begin + something +rescue FirstException + handle_exception +rescue SecondException + handle_other_exception +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/DuplicateRescueException) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_EachWithObjectArgument.md b/docs/description/Lint_EachWithObjectArgument.md similarity index 100% rename from src/main/resources/docs/description/Lint_EachWithObjectArgument.md rename to docs/description/Lint_EachWithObjectArgument.md diff --git a/docs/description/Lint_ElseLayout.md b/docs/description/Lint_ElseLayout.md new file mode 100644 index 00000000..7f34a432 --- /dev/null +++ b/docs/description/Lint_ElseLayout.md @@ -0,0 +1,40 @@ + +This cop checks for odd `else` block layout - like +having an expression on the same line as the `else` keyword, +which is usually a mistake. + +Its auto-correction tweaks layout to keep the syntax. So, this auto-correction +is compatible correction for bad case syntax, but if your code makes a mistake +with `elsif` and `else`, you will have to correct it manually. + +# Examples + +```ruby + +# bad + +if something + # ... +else do_this + do_that +end +# good + +# This code is compatible with the bad case. It will be auto-corrected like this. +if something + # ... +else + do_this + do_that +end + +# This code is incompatible with the bad case. +# If `do_this` is a condition, `elsif` should be used instead of `else`. +if something + # ... +elsif do_this + do_that +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ElseLayout) \ No newline at end of file diff --git a/docs/description/Lint_EmptyBlock.md b/docs/description/Lint_EmptyBlock.md new file mode 100644 index 00000000..98aae6d7 --- /dev/null +++ b/docs/description/Lint_EmptyBlock.md @@ -0,0 +1,38 @@ + +This cop checks for blocks without a body. +Such empty blocks are typically an oversight or we should provide a comment +be clearer what we're aiming for. + +Empty lambdas are ignored by default. + +# Examples + +```ruby +# bad +items.each { |item| } + +# good +items.each { |item| puts item }# good +items.each do |item| + # TODO: implement later (inner comment) +end + +items.each { |item| } # TODO: implement later (inline comment)# bad +items.each do |item| + # TODO: implement later (inner comment) +end + +items.each { |item| } # TODO: implement later (inline comment)# good +allow(subject).to receive(:callable).and_return(-> {}) + +placeholder = lambda do +end +(callable || placeholder).call# bad +allow(subject).to receive(:callable).and_return(-> {}) + +placeholder = lambda do +end +(callable || placeholder).call +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyBlock) \ No newline at end of file diff --git a/docs/description/Lint_EmptyClass.md b/docs/description/Lint_EmptyClass.md new file mode 100644 index 00000000..84311dad --- /dev/null +++ b/docs/description/Lint_EmptyClass.md @@ -0,0 +1,65 @@ + +This cop checks for classes and metaclasses without a body. +Such empty classes and metaclasses are typically an oversight or we should provide a comment +to be clearer what we're aiming for. + +# Examples + +```ruby +# bad +class Foo +end + +class Bar + class << self + end +end + +class << obj +end + +# good +class Foo + def do_something + # ... code + end +end + +class Bar + class << self + attr_reader :bar + end +end + +class << obj + attr_reader :bar +end# bad +class Foo + # TODO: implement later +end + +class Bar + class << self + # TODO: implement later + end +end + +class << obj + # TODO: implement later +end# good +class Foo + # TODO: implement later +end + +class Bar + class << self + # TODO: implement later + end +end + +class << obj + # TODO: implement later +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyClass) \ No newline at end of file diff --git a/docs/description/Lint_EmptyConditionalBody.md b/docs/description/Lint_EmptyConditionalBody.md new file mode 100644 index 00000000..91526720 --- /dev/null +++ b/docs/description/Lint_EmptyConditionalBody.md @@ -0,0 +1,49 @@ + +This cop checks for the presence of `if`, `elsif` and `unless` branches without a body. + +# Examples + +```ruby +# bad +if condition +end + +# bad +unless condition +end + +# bad +if condition + do_something +elsif other_condition +end + +# good +if condition + do_something +end + +# good +unless condition + do_something +end + +# good +if condition + do_something +elsif other_condition + do_something_else +end# good +if condition + do_something +elsif other_condition + # noop +end# bad +if condition + do_something +elsif other_condition + # noop +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyConditionalBody) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_EmptyEnsure.md b/docs/description/Lint_EmptyEnsure.md similarity index 100% rename from src/main/resources/docs/description/Lint_EmptyEnsure.md rename to docs/description/Lint_EmptyEnsure.md diff --git a/src/main/resources/docs/description/Lint_EmptyExpression.md b/docs/description/Lint_EmptyExpression.md similarity index 100% rename from src/main/resources/docs/description/Lint_EmptyExpression.md rename to docs/description/Lint_EmptyExpression.md diff --git a/docs/description/Lint_EmptyFile.md b/docs/description/Lint_EmptyFile.md new file mode 100644 index 00000000..fcae36f1 --- /dev/null +++ b/docs/description/Lint_EmptyFile.md @@ -0,0 +1,16 @@ + +This cop enforces that Ruby source files are not empty. + +# Examples + +```ruby +# bad +# Empty file + +# good +# File containing non commented source lines# good +# File consisting only of comments# bad +# File consisting only of comments +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyFile) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_EmptyInterpolation.md b/docs/description/Lint_EmptyInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Lint_EmptyInterpolation.md rename to docs/description/Lint_EmptyInterpolation.md diff --git a/docs/description/Lint_EmptyWhen.md b/docs/description/Lint_EmptyWhen.md new file mode 100644 index 00000000..aaa3aaf0 --- /dev/null +++ b/docs/description/Lint_EmptyWhen.md @@ -0,0 +1,37 @@ + +This cop checks for the presence of `when` branches without a body. + +# Examples + +```ruby + +# bad +case foo +when bar + do_something +when baz +end +# good +case condition +when foo + do_something +when bar + nil +end +# good +case condition +when foo + do_something +when bar + # noop +end +# bad +case condition +when foo + do_something +when bar + # do nothing +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyWhen) \ No newline at end of file diff --git a/docs/description/Lint_EnsureReturn.md b/docs/description/Lint_EnsureReturn.md new file mode 100644 index 00000000..f0569726 --- /dev/null +++ b/docs/description/Lint_EnsureReturn.md @@ -0,0 +1,44 @@ + +This cop checks for `return` from an `ensure` block. +`return` from an ensure block is a dangerous code smell as it +will take precedence over any exception being raised, +and the exception will be silently thrown away as if it were rescued. + +If you want to rescue some (or all) exceptions, best to do it explicitly + +# Examples + +```ruby + +# bad + +def foo + do_something +ensure + cleanup + return self +end +# good + +def foo + do_something + self +ensure + cleanup +end + +# also good + +def foo + begin + do_something + rescue SomeException + # Let's ignore this exception + end + self +ensure + cleanup +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EnsureReturn) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ErbNewArguments.md b/docs/description/Lint_ErbNewArguments.md similarity index 100% rename from src/main/resources/docs/description/Lint_ErbNewArguments.md rename to docs/description/Lint_ErbNewArguments.md diff --git a/docs/description/Lint_FlipFlop.md b/docs/description/Lint_FlipFlop.md new file mode 100644 index 00000000..9a251764 --- /dev/null +++ b/docs/description/Lint_FlipFlop.md @@ -0,0 +1,25 @@ + +This cop looks for uses of flip-flop operator +based on the Ruby Style Guide. + +Here is the history of flip-flops in Ruby. +flip-flop operator is deprecated in Ruby 2.6.0 and +the deprecation has been reverted by Ruby 2.7.0 and +backported to Ruby 2.6. +See: https://bugs.ruby-lang.org/issues/5400 + +# Examples + +```ruby +# bad +(1..20).each do |x| + puts x if (x == 5) .. (x == 10) +end + +# good +(1..20).each do |x| + puts x if (x >= 5) && (x <= 10) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/FlipFlop) \ No newline at end of file diff --git a/docs/description/Lint_FloatComparison.md b/docs/description/Lint_FloatComparison.md new file mode 100644 index 00000000..e9191f76 --- /dev/null +++ b/docs/description/Lint_FloatComparison.md @@ -0,0 +1,30 @@ + +This cop checks for the presence of precise comparison of floating point numbers. + +Floating point values are inherently inaccurate, and comparing them for exact equality +is almost never the desired semantics. Comparison via the `==/!=` operators checks +floating-point value representation to be exactly the same, which is very unlikely +if you perform any arithmetic operations involving precision loss. + +# Examples + +```ruby +# bad +x == 0.1 +x != 0.1 + +# good - using BigDecimal +x.to_d == 0.1.to_d + +# good +(x - 0.1).abs < Float::EPSILON + +# good +tolerance = 0.0001 +(x - 0.1).abs < tolerance + +# Or some other epsilon based type of comparison: +# https://www.embeddeduse.com/2019/08/26/qt-compare-two-floats/ +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/FloatComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_FloatOutOfRange.md b/docs/description/Lint_FloatOutOfRange.md similarity index 100% rename from src/main/resources/docs/description/Lint_FloatOutOfRange.md rename to docs/description/Lint_FloatOutOfRange.md diff --git a/src/main/resources/docs/description/Lint_FormatParameterMismatch.md b/docs/description/Lint_FormatParameterMismatch.md similarity index 54% rename from src/main/resources/docs/description/Lint_FormatParameterMismatch.md rename to docs/description/Lint_FormatParameterMismatch.md index 706f75ed..cdfc8a40 100644 --- a/src/main/resources/docs/description/Lint_FormatParameterMismatch.md +++ b/docs/description/Lint_FormatParameterMismatch.md @@ -3,6 +3,10 @@ This lint sees if there is a mismatch between the number of expected fields for format/sprintf/#% and what is actually passed as arguments. +In addition it checks whether different formats are used in the same +format string. Do not mix numbered, unnumbered, and named formats in +the same format string. + # Examples ```ruby @@ -13,6 +17,12 @@ format('A value: %s and another: %i', a_value) # good format('A value: %s and another: %i', a_value, another) +# bad + +format('Unnumbered format: %s and numbered: %2$s', a_value, another) +# good + +format('Numbered format: %1$s and numbered %2$s', a_value, another) ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/FormatParameterMismatch) \ No newline at end of file diff --git a/docs/description/Lint_HashCompareByIdentity.md b/docs/description/Lint_HashCompareByIdentity.md new file mode 100644 index 00000000..18591e7d --- /dev/null +++ b/docs/description/Lint_HashCompareByIdentity.md @@ -0,0 +1,21 @@ + +Prefer using `Hash#compare_by_identity` than using `object_id` for hash keys. + +This cop is marked as unsafe as a hash possibly can contain other keys +besides `object_id`s. + +# Examples + +```ruby +# bad +hash = {} +hash[foo.object_id] = :bar +hash.key?(baz.object_id) + +# good +hash = {}.compare_by_identity +hash[foo] = :bar +hash.key?(baz) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/HashCompareByIdentity) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_HeredocMethodCallPosition.md b/docs/description/Lint_HeredocMethodCallPosition.md similarity index 100% rename from src/main/resources/docs/description/Lint_HeredocMethodCallPosition.md rename to docs/description/Lint_HeredocMethodCallPosition.md diff --git a/docs/description/Lint_IdentityComparison.md b/docs/description/Lint_IdentityComparison.md new file mode 100644 index 00000000..0194399d --- /dev/null +++ b/docs/description/Lint_IdentityComparison.md @@ -0,0 +1,17 @@ + +Prefer `equal?` over `==` when comparing `object_id`. + +`Object#equal?` is provided to compare objects for identity, and in contrast +`Object#==` is provided for the purpose of doing value comparison. + +# Examples + +```ruby +# bad +foo.object_id == bar.object_id + +# good +foo.equal?(bar) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/IdentityComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ImplicitStringConcatenation.md b/docs/description/Lint_ImplicitStringConcatenation.md similarity index 100% rename from src/main/resources/docs/description/Lint_ImplicitStringConcatenation.md rename to docs/description/Lint_ImplicitStringConcatenation.md diff --git a/src/main/resources/docs/description/Lint_IneffectiveAccessModifier.md b/docs/description/Lint_IneffectiveAccessModifier.md similarity index 100% rename from src/main/resources/docs/description/Lint_IneffectiveAccessModifier.md rename to docs/description/Lint_IneffectiveAccessModifier.md diff --git a/src/main/resources/docs/description/Lint_InheritException.md b/docs/description/Lint_InheritException.md similarity index 100% rename from src/main/resources/docs/description/Lint_InheritException.md rename to docs/description/Lint_InheritException.md diff --git a/src/main/resources/docs/description/Lint_InterpolationCheck.md b/docs/description/Lint_InterpolationCheck.md similarity index 100% rename from src/main/resources/docs/description/Lint_InterpolationCheck.md rename to docs/description/Lint_InterpolationCheck.md diff --git a/docs/description/Lint_LambdaWithoutLiteralBlock.md b/docs/description/Lint_LambdaWithoutLiteralBlock.md new file mode 100644 index 00000000..8c101fd5 --- /dev/null +++ b/docs/description/Lint_LambdaWithoutLiteralBlock.md @@ -0,0 +1,27 @@ + +This cop checks uses of lambda without a literal block. +It emulates the following warning in Ruby 3.0: + + % ruby -vwe 'lambda(&proc {})' + ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] + -e:1: warning: lambda without a literal block is deprecated; use the proc without + lambda instead + +This way, proc object is never converted to lambda. +Auto-correction replaces with compatible proc argument. + +# Examples + +```ruby + +# bad +lambda(&proc { do_something }) +lambda(&Proc.new { do_something }) + +# good +proc { do_something } +Proc.new { do_something } +lambda { do_something } # If you use lambda. +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/LambdaWithoutLiteralBlock) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_LiteralAsCondition.md b/docs/description/Lint_LiteralAsCondition.md similarity index 80% rename from src/main/resources/docs/description/Lint_LiteralAsCondition.md rename to docs/description/Lint_LiteralAsCondition.md index e3e39e0e..2968ff1a 100644 --- a/src/main/resources/docs/description/Lint_LiteralAsCondition.md +++ b/docs/description/Lint_LiteralAsCondition.md @@ -8,20 +8,25 @@ if/while/until. ```ruby # bad - if 20 do_something end -# bad +# bad if some_var && true do_something end -# good +# good if some_var && some_condition do_something end + +# good +# When using a boolean value for an infinite loop. +while true + break if condition +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/LiteralAsCondition) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_LiteralInInterpolation.md b/docs/description/Lint_LiteralInInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Lint_LiteralInInterpolation.md rename to docs/description/Lint_LiteralInInterpolation.md diff --git a/src/main/resources/docs/description/Lint_Loop.md b/docs/description/Lint_Loop.md similarity index 56% rename from src/main/resources/docs/description/Lint_Loop.md rename to docs/description/Lint_Loop.md index cbac1a7d..53e330cb 100644 --- a/src/main/resources/docs/description/Lint_Loop.md +++ b/docs/description/Lint_Loop.md @@ -1,5 +1,9 @@ -This cop checks for uses of *begin...end while/until something*. +This cop checks for uses of `begin...end while/until something`. + +The cop is marked as unsafe because behaviour can change in some cases, including +if a local variable inside the loop body is accessed outside of it, or if the +loop body raises a `StopIteration` exception (which `Kernel#loop` rescues). # Examples diff --git a/src/main/resources/docs/description/Lint_MissingCopEnableDirective.md b/docs/description/Lint_MissingCopEnableDirective.md similarity index 100% rename from src/main/resources/docs/description/Lint_MissingCopEnableDirective.md rename to docs/description/Lint_MissingCopEnableDirective.md diff --git a/docs/description/Lint_MissingSuper.md b/docs/description/Lint_MissingSuper.md new file mode 100644 index 00000000..82d40125 --- /dev/null +++ b/docs/description/Lint_MissingSuper.md @@ -0,0 +1,44 @@ + +This cop checks for the presence of constructors and lifecycle callbacks +without calls to `super`. + +This cop does not consider `method_missing` (and `respond_to_missing?`) +because in some cases it makes sense to overtake what is considered a +missing method. In other cases, the theoretical ideal handling could be +challenging or verbose for no actual gain. + +# Examples + +```ruby +# bad +class Employee < Person + def initialize(name, salary) + @salary = salary + end +end + +# good +class Employee < Person + def initialize(name, salary) + super(name) + @salary = salary + end +end + +# bad +class Parent + def self.inherited(base) + do_something + end +end + +# good +class Parent + def self.inherited(base) + super + do_something + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/MissingSuper) \ No newline at end of file diff --git a/docs/description/Lint_MixedRegexpCaptureTypes.md b/docs/description/Lint_MixedRegexpCaptureTypes.md new file mode 100644 index 00000000..545cb878 --- /dev/null +++ b/docs/description/Lint_MixedRegexpCaptureTypes.md @@ -0,0 +1,22 @@ + +Do not mix named captures and numbered captures in a Regexp literal +because numbered capture is ignored if they're mixed. +Replace numbered captures with non-capturing groupings or +named captures. + + # bad + /(?FOO)(BAR)/ + + # good + /(?FOO)(?BAR)/ + + # good + /(?FOO)(?:BAR)/ + + # good + /(FOO)(BAR)/ + +# Examples + + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/MixedRegexpCaptureTypes) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_MultipleComparison.md b/docs/description/Lint_MultipleComparison.md similarity index 100% rename from src/main/resources/docs/description/Lint_MultipleComparison.md rename to docs/description/Lint_MultipleComparison.md diff --git a/src/main/resources/docs/description/Lint_NestedMethodDefinition.md b/docs/description/Lint_NestedMethodDefinition.md similarity index 100% rename from src/main/resources/docs/description/Lint_NestedMethodDefinition.md rename to docs/description/Lint_NestedMethodDefinition.md diff --git a/src/main/resources/docs/description/Lint_NestedPercentLiteral.md b/docs/description/Lint_NestedPercentLiteral.md similarity index 56% rename from src/main/resources/docs/description/Lint_NestedPercentLiteral.md rename to docs/description/Lint_NestedPercentLiteral.md index 276481d2..c6adcfdd 100644 --- a/src/main/resources/docs/description/Lint_NestedPercentLiteral.md +++ b/docs/description/Lint_NestedPercentLiteral.md @@ -13,6 +13,19 @@ attributes = { valid_attributes: %i[name content], nested_attributes: %i[name content %i[incorrectly nested]] } + +# good + +# Neither is incompatible with the bad case, but probably the intended code. +attributes = { + valid_attributes: %i[name content], + nested_attributes: [:name, :content, %i[incorrectly nested]] +} + +attributes = { + valid_attributes: %i[name content], + nested_attributes: [:name, :content, [:incorrectly, :nested]] +} ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NestedPercentLiteral) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_NextWithoutAccumulator.md b/docs/description/Lint_NextWithoutAccumulator.md similarity index 100% rename from src/main/resources/docs/description/Lint_NextWithoutAccumulator.md rename to docs/description/Lint_NextWithoutAccumulator.md diff --git a/docs/description/Lint_NoReturnInBeginEndBlocks.md b/docs/description/Lint_NoReturnInBeginEndBlocks.md new file mode 100644 index 00000000..eaa261a8 --- /dev/null +++ b/docs/description/Lint_NoReturnInBeginEndBlocks.md @@ -0,0 +1,39 @@ + +Checks for the presence of a `return` inside a `begin..end` block +in assignment contexts. +In this situation, the `return` will result in an exit from the current +method, possibly leading to unexpected behavior. + +# Examples + +```ruby + +# bad + +@some_variable ||= begin + return some_value if some_condition_is_met + + do_something +end +# good + +@some_variable ||= begin + if some_condition_is_met + some_value + else + do_something + end +end + +# good + +some_variable = if some_condition_is_met + return if another_condition_is_met + + some_value + else + do_something + end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NoReturnInBeginEndBlocks) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_NonDeterministicRequireOrder.md b/docs/description/Lint_NonDeterministicRequireOrder.md similarity index 55% rename from src/main/resources/docs/description/Lint_NonDeterministicRequireOrder.md rename to docs/description/Lint_NonDeterministicRequireOrder.md index 64320aeb..49343449 100644 --- a/src/main/resources/docs/description/Lint_NonDeterministicRequireOrder.md +++ b/docs/description/Lint_NonDeterministicRequireOrder.md @@ -7,6 +7,11 @@ such as requiring files, can lead to intermittent failures that are hard to debug. To ensure this doesn't happen, always sort the list. +`Dir.glob` and `Dir[]` sort globbed results by default in Ruby 3.0. +So all bad cases are acceptable when Ruby 3.0 or higher are used. + +This cop will be deprecated and removed when supporting only Ruby 3.0 and higher. + # Examples ```ruby @@ -20,6 +25,7 @@ end Dir["./lib/**/*.rb"].sort.each do |file| require file end + # bad Dir.glob(Rails.root.join(__dir__, 'test', '*.rb')) do |file| require file @@ -29,6 +35,21 @@ end Dir.glob(Rails.root.join(__dir__, 'test', '*.rb')).sort.each do |file| require file end + +# bad +Dir['./lib/**/*.rb'].each(&method(:require)) + +# good +Dir['./lib/**/*.rb'].sort.each(&method(:require)) + +# bad +Dir.glob(Rails.root.join('test', '*.rb'), &method(:require)) + +# good +Dir.glob(Rails.root.join('test', '*.rb')).sort.each(&method(:require)) + +# good - Respect intent if `sort` keyword option is specified in Ruby 3.0 or higher. +Dir.glob(Rails.root.join(__dir__, 'test', '*.rb'), sort: false).each(&method(:require)) ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NonDeterministicRequireOrder) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_NonLocalExitFromIterator.md b/docs/description/Lint_NonLocalExitFromIterator.md similarity index 77% rename from src/main/resources/docs/description/Lint_NonLocalExitFromIterator.md rename to docs/description/Lint_NonLocalExitFromIterator.md index 8c422410..9b1c4995 100644 --- a/src/main/resources/docs/description/Lint_NonLocalExitFromIterator.md +++ b/docs/description/Lint_NonLocalExitFromIterator.md @@ -2,13 +2,13 @@ This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions: - - No value is returned, - - the block is preceded by a method chain, - - the block has arguments, - - the method which receives the block is not `define_method` - or `define_singleton_method`, - - the return is not contained in an inner scope, e.g. a lambda or a - method definition. +* No value is returned, +* the block is preceded by a method chain, +* the block has arguments, +* the method which receives the block is not `define_method` +or `define_singleton_method`, +* the return is not contained in an inner scope, e.g. a lambda or a +method definition. # Examples diff --git a/docs/description/Lint_NumberConversion.md b/docs/description/Lint_NumberConversion.md new file mode 100644 index 00000000..07b7c500 --- /dev/null +++ b/docs/description/Lint_NumberConversion.md @@ -0,0 +1,44 @@ + +This cop warns the usage of unsafe number conversions. Unsafe +number conversion can cause unexpected error if auto type conversion +fails. Cop prefer parsing with number class instead. + +Conversion with `Integer`, `Float`, etc. will raise an `ArgumentError` +if given input that is not numeric (eg. an empty string), whereas +`to_i`, etc. will try to convert regardless of input (`''.to_i => 0`). +As such, this cop is disabled by default because it's not necessarily +always correct to raise if a value is not numeric. + +NOTE: Some values cannot be converted properly using one of the `Kernel` +method (for instance, `Time` and `DateTime` values are allowed by this +cop by default). Similarly, Rails' duration methods do not work well +with `Integer()` and can be ignored with `IgnoredMethods`. + +# Examples + +```ruby + +# bad + +'10'.to_i +'10.2'.to_f +'10'.to_c +['1', '2', '3'].map(&:to_i) +foo.try(:to_f) +bar.send(:to_c) + +# good + +Integer('10', 10) +Float('10.2') +Complex('10') +['1', '2', '3'].map { |i| Integer(i, 10) } +foo.try { |i| Float(i) } +bar.send { |i| Complex(i) } +# good +10.minutes.to_i +# good +Time.now.to_datetime.to_i +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NumberConversion) \ No newline at end of file diff --git a/docs/description/Lint_NumberedParameterAssignment.md b/docs/description/Lint_NumberedParameterAssignment.md new file mode 100644 index 00000000..1a67cdf4 --- /dev/null +++ b/docs/description/Lint_NumberedParameterAssignment.md @@ -0,0 +1,29 @@ + +This cop checks for uses of numbered parameter assignment. +It emulates the following warning in Ruby 2.7: + + % ruby -ve '_1 = :value' + ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19] + -e:1: warning: `_1' is reserved for numbered parameter; consider another name + +Assiging to numbered parameter (from `_1` to `_9`) cause an error in Ruby 3.0. + + % ruby -ve '_1 = :value' + ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] + -e:1: _1 is reserved for numbered parameter + +NOTE: The parametered parameters are from `_1` to `_9`. This cop checks `_0`, and over `_10` +as well to prevent confusion. + +# Examples + +```ruby + +# bad +_1 = :value + +# good +non_numbered_parameter_name = :value +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NumberedParameterAssignment) \ No newline at end of file diff --git a/docs/description/Lint_OrAssignmentToConstant.md b/docs/description/Lint_OrAssignmentToConstant.md new file mode 100644 index 00000000..72d36c9f --- /dev/null +++ b/docs/description/Lint_OrAssignmentToConstant.md @@ -0,0 +1,22 @@ + +This cop checks for unintended or-assignment to a constant. + +Constants should always be assigned in the same location. And its value +should always be the same. If constants are assigned in multiple +locations, the result may vary depending on the order of `require`. + +Also, if you already have such an implementation, auto-correction may +change the result. + +# Examples + +```ruby + +# bad +CONST ||= 1 + +# good +CONST = 1 +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/OrAssignmentToConstant) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_OrderedMagicComments.md b/docs/description/Lint_OrderedMagicComments.md similarity index 100% rename from src/main/resources/docs/description/Lint_OrderedMagicComments.md rename to docs/description/Lint_OrderedMagicComments.md diff --git a/docs/description/Lint_OutOfRangeRegexpRef.md b/docs/description/Lint_OutOfRangeRegexpRef.md new file mode 100644 index 00000000..c76c76e7 --- /dev/null +++ b/docs/description/Lint_OutOfRangeRegexpRef.md @@ -0,0 +1,20 @@ + +This cops looks for references of Regexp captures that are out of range +and thus always returns nil. + +# Examples + +```ruby + +/(foo)bar/ =~ 'foobar' + +# bad - always returns nil + +puts $2 # => nil + +# good + +puts $1 # => foo +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/OutOfRangeRegexpRef) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ParenthesesAsGroupedExpression.md b/docs/description/Lint_ParenthesesAsGroupedExpression.md similarity index 70% rename from src/main/resources/docs/description/Lint_ParenthesesAsGroupedExpression.md rename to docs/description/Lint_ParenthesesAsGroupedExpression.md index babf4ded..adf6a93c 100644 --- a/src/main/resources/docs/description/Lint_ParenthesesAsGroupedExpression.md +++ b/docs/description/Lint_ParenthesesAsGroupedExpression.md @@ -7,11 +7,12 @@ parenthesis. ```ruby # bad +do_something (foo) -puts (x + y) # good - -puts(x + y) +do_something(foo) +do_something (2 + 3) * 4 +do_something (foo * bar).baz ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ParenthesesAsGroupedExpression) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_PercentStringArray.md b/docs/description/Lint_PercentStringArray.md similarity index 100% rename from src/main/resources/docs/description/Lint_PercentStringArray.md rename to docs/description/Lint_PercentStringArray.md diff --git a/src/main/resources/docs/description/Lint_PercentSymbolArray.md b/docs/description/Lint_PercentSymbolArray.md similarity index 100% rename from src/main/resources/docs/description/Lint_PercentSymbolArray.md rename to docs/description/Lint_PercentSymbolArray.md diff --git a/src/main/resources/docs/description/Lint_RaiseException.md b/docs/description/Lint_RaiseException.md similarity index 100% rename from src/main/resources/docs/description/Lint_RaiseException.md rename to docs/description/Lint_RaiseException.md diff --git a/src/main/resources/docs/description/Lint_RandOne.md b/docs/description/Lint_RandOne.md similarity index 100% rename from src/main/resources/docs/description/Lint_RandOne.md rename to docs/description/Lint_RandOne.md diff --git a/src/main/resources/docs/description/Lint_RedundantCopEnableDirective.md b/docs/description/Lint_RedundantCopEnableDirective.md similarity index 100% rename from src/main/resources/docs/description/Lint_RedundantCopEnableDirective.md rename to docs/description/Lint_RedundantCopEnableDirective.md diff --git a/docs/description/Lint_RedundantDirGlobSort.md b/docs/description/Lint_RedundantDirGlobSort.md new file mode 100644 index 00000000..5c7e8898 --- /dev/null +++ b/docs/description/Lint_RedundantDirGlobSort.md @@ -0,0 +1,24 @@ + +Sort globbed results by default in Ruby 3.0. +This cop checks for redundant `sort` method to `Dir.glob` and `Dir[]`. + +# Examples + +```ruby + +# bad +Dir.glob('./lib/**/*.rb').sort.each do |file| +end + +Dir['./lib/**/*.rb'].sort.each do |file| +end + +# good +Dir.glob('./lib/**/*.rb').each do |file| +end + +Dir['./lib/**/*.rb'].each do |file| +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/RedundantDirGlobSort) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_RedundantRequireStatement.md b/docs/description/Lint_RedundantRequireStatement.md similarity index 67% rename from src/main/resources/docs/description/Lint_RedundantRequireStatement.md rename to docs/description/Lint_RedundantRequireStatement.md index 64099342..c5bd1722 100644 --- a/src/main/resources/docs/description/Lint_RedundantRequireStatement.md +++ b/docs/description/Lint_RedundantRequireStatement.md @@ -4,9 +4,9 @@ Checks for unnecessary `require` statement. The following features are unnecessary `require` statement because they are already loaded. -ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }' -ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13] -["enumerator.so", "rational.so", "complex.so", "thread.rb"] + ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }' + ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13] + ["enumerator.so", "rational.so", "complex.so", "thread.rb"] This cop targets Ruby 2.2 or higher containing these 4 features. diff --git a/docs/description/Lint_RedundantSafeNavigation.md b/docs/description/Lint_RedundantSafeNavigation.md new file mode 100644 index 00000000..4d8b287c --- /dev/null +++ b/docs/description/Lint_RedundantSafeNavigation.md @@ -0,0 +1,36 @@ + +This cop checks for redundant safe navigation calls. +`instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`, and `equal?` methods +are checked by default. These are customizable with `AllowedMethods` option. + +This cop is marked as unsafe, because auto-correction can change the +return type of the expression. An offending expression that previously +could return `nil` will be auto-corrected to never return `nil`. + +In the example below, the safe navigation operator (`&.`) is unnecessary +because `NilClass` has methods like `respond_to?` and `is_a?`. + +# Examples + +```ruby +# bad +do_something if attrs&.respond_to?(:[]) + +# good +do_something if attrs.respond_to?(:[]) + +# bad +while node&.is_a?(BeginNode) + node = node.parent +end + +# good +while node.is_a?(BeginNode) + node = node.parent +end + +# good - without `&.` this will always return `true` +foo&.respond_to?(:to_a) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/RedundantSafeNavigation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_RedundantSplatExpansion.md b/docs/description/Lint_RedundantSplatExpansion.md similarity index 66% rename from src/main/resources/docs/description/Lint_RedundantSplatExpansion.md rename to docs/description/Lint_RedundantSplatExpansion.md index 9e0319ca..d953ccf9 100644 --- a/src/main/resources/docs/description/Lint_RedundantSplatExpansion.md +++ b/docs/description/Lint_RedundantSplatExpansion.md @@ -6,44 +6,59 @@ This cop checks for unneeded usages of splat expansion ```ruby # bad - a = *[1, 2, 3] a = *'a' a = *1 +['a', 'b', *%w(c d e), 'f', 'g'] -begin - foo -rescue *[StandardError, ApplicationError] - bar -end - -case foo -when *[1, 2, 3] - bar -else - baz -end # good - c = [1, 2, 3] a = *c a, b = *c a, *b = *c a = *1..10 a = ['a'] +['a', 'b', 'c', 'd', 'e', 'f', 'g'] +# bad +do_something(*['foo', 'bar', 'baz']) + +# good +do_something('foo', 'bar', 'baz') + +# bad +begin + foo +rescue *[StandardError, ApplicationError] + bar +end + +# good begin foo rescue StandardError, ApplicationError bar end +# bad +case foo +when *[1, 2, 3] + bar +else + baz +end + +# good case foo when 1, 2, 3 bar else baz end +# good +do_something(*%w[foo bar baz]) +# bad +do_something(*%w[foo bar baz]) ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/RedundantSplatExpansion) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_RedundantStringCoercion.md b/docs/description/Lint_RedundantStringCoercion.md similarity index 100% rename from src/main/resources/docs/description/Lint_RedundantStringCoercion.md rename to docs/description/Lint_RedundantStringCoercion.md diff --git a/src/main/resources/docs/description/Lint_RedundantWithIndex.md b/docs/description/Lint_RedundantWithIndex.md similarity index 100% rename from src/main/resources/docs/description/Lint_RedundantWithIndex.md rename to docs/description/Lint_RedundantWithIndex.md diff --git a/src/main/resources/docs/description/Lint_RedundantWithObject.md b/docs/description/Lint_RedundantWithObject.md similarity index 100% rename from src/main/resources/docs/description/Lint_RedundantWithObject.md rename to docs/description/Lint_RedundantWithObject.md diff --git a/src/main/resources/docs/description/Lint_RegexpAsCondition.md b/docs/description/Lint_RegexpAsCondition.md similarity index 100% rename from src/main/resources/docs/description/Lint_RegexpAsCondition.md rename to docs/description/Lint_RegexpAsCondition.md diff --git a/src/main/resources/docs/description/Lint_RequireParentheses.md b/docs/description/Lint_RequireParentheses.md similarity index 100% rename from src/main/resources/docs/description/Lint_RequireParentheses.md rename to docs/description/Lint_RequireParentheses.md diff --git a/src/main/resources/docs/description/Lint_RescueException.md b/docs/description/Lint_RescueException.md similarity index 79% rename from src/main/resources/docs/description/Lint_RescueException.md rename to docs/description/Lint_RescueException.md index e29110b1..4637a39e 100644 --- a/src/main/resources/docs/description/Lint_RescueException.md +++ b/docs/description/Lint_RescueException.md @@ -1,5 +1,5 @@ -This cop checks for *rescue* blocks targeting the Exception class. +This cop checks for `rescue` blocks targeting the Exception class. # Examples diff --git a/src/main/resources/docs/description/Lint_RescueType.md b/docs/description/Lint_RescueType.md similarity index 100% rename from src/main/resources/docs/description/Lint_RescueType.md rename to docs/description/Lint_RescueType.md diff --git a/src/main/resources/docs/description/Lint_ReturnInVoidContext.md b/docs/description/Lint_ReturnInVoidContext.md similarity index 100% rename from src/main/resources/docs/description/Lint_ReturnInVoidContext.md rename to docs/description/Lint_ReturnInVoidContext.md diff --git a/src/main/resources/docs/description/Lint_SafeNavigationChain.md b/docs/description/Lint_SafeNavigationChain.md similarity index 100% rename from src/main/resources/docs/description/Lint_SafeNavigationChain.md rename to docs/description/Lint_SafeNavigationChain.md diff --git a/src/main/resources/docs/description/Lint_SafeNavigationConsistency.md b/docs/description/Lint_SafeNavigationConsistency.md similarity index 100% rename from src/main/resources/docs/description/Lint_SafeNavigationConsistency.md rename to docs/description/Lint_SafeNavigationConsistency.md diff --git a/src/main/resources/docs/description/Lint_SafeNavigationWithEmpty.md b/docs/description/Lint_SafeNavigationWithEmpty.md similarity index 100% rename from src/main/resources/docs/description/Lint_SafeNavigationWithEmpty.md rename to docs/description/Lint_SafeNavigationWithEmpty.md diff --git a/src/main/resources/docs/description/Lint_ScriptPermission.md b/docs/description/Lint_ScriptPermission.md similarity index 100% rename from src/main/resources/docs/description/Lint_ScriptPermission.md rename to docs/description/Lint_ScriptPermission.md diff --git a/docs/description/Lint_SelfAssignment.md b/docs/description/Lint_SelfAssignment.md new file mode 100644 index 00000000..5e62d623 --- /dev/null +++ b/docs/description/Lint_SelfAssignment.md @@ -0,0 +1,18 @@ + +This cop checks for self-assignments. + +# Examples + +```ruby +# bad +foo = foo +foo, bar = foo, bar +Foo = Foo + +# good +foo = bar +foo, bar = bar, foo +Foo = Bar +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/SelfAssignment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_SendWithMixinArgument.md b/docs/description/Lint_SendWithMixinArgument.md similarity index 100% rename from src/main/resources/docs/description/Lint_SendWithMixinArgument.md rename to docs/description/Lint_SendWithMixinArgument.md diff --git a/src/main/resources/docs/description/Lint_ShadowedArgument.md b/docs/description/Lint_ShadowedArgument.md similarity index 100% rename from src/main/resources/docs/description/Lint_ShadowedArgument.md rename to docs/description/Lint_ShadowedArgument.md diff --git a/src/main/resources/docs/description/Lint_ShadowedException.md b/docs/description/Lint_ShadowedException.md similarity index 100% rename from src/main/resources/docs/description/Lint_ShadowedException.md rename to docs/description/Lint_ShadowedException.md diff --git a/docs/description/Lint_ShadowingOuterLocalVariable.md b/docs/description/Lint_ShadowingOuterLocalVariable.md new file mode 100644 index 00000000..225b2326 --- /dev/null +++ b/docs/description/Lint_ShadowingOuterLocalVariable.md @@ -0,0 +1,39 @@ + +This cop checks for the use of local variable names from an outer scope +in block arguments or block-local variables. This mirrors the warning +given by `ruby -cw` prior to Ruby 2.6: +"shadowing outer local variable - foo". + +NOTE: Shadowing of variables in block passed to `Ractor.new` is allowed +because `Ractor` should not access outer variables. +eg. following syle is encouraged: + + worker_id, pipe = env + Ractor.new(worker_id, pipe) do |worker_id, pipe| + end + +# Examples + +```ruby + +# bad + +def some_method + foo = 1 + + 2.times do |foo| # shadowing outer `foo` + do_something(foo) + end +end +# good + +def some_method + foo = 1 + + 2.times do |bar| + do_something(bar) + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ShadowingOuterLocalVariable) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_StructNewOverride.md b/docs/description/Lint_StructNewOverride.md similarity index 100% rename from src/main/resources/docs/description/Lint_StructNewOverride.md rename to docs/description/Lint_StructNewOverride.md diff --git a/src/main/resources/docs/description/Lint_SuppressedException.md b/docs/description/Lint_SuppressedException.md similarity index 91% rename from src/main/resources/docs/description/Lint_SuppressedException.md rename to docs/description/Lint_SuppressedException.md index 3e12479c..dd8096ae 100644 --- a/src/main/resources/docs/description/Lint_SuppressedException.md +++ b/docs/description/Lint_SuppressedException.md @@ -1,5 +1,5 @@ -This cop checks for *rescue* blocks with no body. +This cop checks for `rescue` blocks with no body. # Examples diff --git a/docs/description/Lint_SymbolConversion.md b/docs/description/Lint_SymbolConversion.md new file mode 100644 index 00000000..2027b6af --- /dev/null +++ b/docs/description/Lint_SymbolConversion.md @@ -0,0 +1,23 @@ + +This cop checks for uses of literal strings converted to +a symbol where a literal symbol could be used instead. + +# Examples + +```ruby +# bad +'string'.to_sym +:symbol.to_sym +'underscored_string'.to_sym +:'underscored_symbol' +'hyphenated-string'.to_sym + +# good +:string +:symbol +:underscored_string +:underscored_symbol +:'hyphenated-string' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/SymbolConversion) \ No newline at end of file diff --git a/docs/description/Lint_Syntax.md b/docs/description/Lint_Syntax.md new file mode 100644 index 00000000..27ca7eb8 --- /dev/null +++ b/docs/description/Lint_Syntax.md @@ -0,0 +1,8 @@ + +This cop repacks Parser's diagnostics/errors +into RuboCop's offenses. + +# Examples + + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/Syntax) \ No newline at end of file diff --git a/docs/description/Lint_ToEnumArguments.md b/docs/description/Lint_ToEnumArguments.md new file mode 100644 index 00000000..ec842967 --- /dev/null +++ b/docs/description/Lint_ToEnumArguments.md @@ -0,0 +1,20 @@ + +This cop ensures that `to_enum`/`enum_for`, called for the current method, +has correct arguments. + +# Examples + +```ruby +# bad +def foo(x, y = 1) + return to_enum(__callee__, x) # `y` is missing +end + +# good +def foo(x, y = 1) + return to_enum(__callee__, x, y) + # alternatives to `__callee__` are `__method__` and `:foo` +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ToEnumArguments) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ToJSON.md b/docs/description/Lint_ToJSON.md similarity index 56% rename from src/main/resources/docs/description/Lint_ToJSON.md rename to docs/description/Lint_ToJSON.md index ed1ab0cb..b8ccf05a 100644 --- a/src/main/resources/docs/description/Lint_ToJSON.md +++ b/docs/description/Lint_ToJSON.md @@ -7,12 +7,23 @@ for an optional argument, your method should too. # Examples ```ruby -# bad -def to_json -end +class Point + attr_reader :x, :y + + # bad, incorrect arity + def to_json + JSON.generate([x, y]) + end + + # good, preserving args + def to_json(*args) + JSON.generate([x, y], *args) + end -# good -def to_json(*_args) + # good, discarding args + def to_json(*_args) + JSON.generate([x, y]) + end end ``` diff --git a/docs/description/Lint_TopLevelReturnWithArgument.md b/docs/description/Lint_TopLevelReturnWithArgument.md new file mode 100644 index 00000000..2d86d995 --- /dev/null +++ b/docs/description/Lint_TopLevelReturnWithArgument.md @@ -0,0 +1,14 @@ + +This cop checks for top level return with arguments. If there is a +top-level return statement with an argument, then the argument is +always ignored. This is detected automatically since Ruby 2.7. + +# Examples + +```ruby + +# Detected since Ruby 2.7 +return 1 # 1 is always ignored. +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/TopLevelReturnWithArgument) \ No newline at end of file diff --git a/docs/description/Lint_TrailingCommaInAttributeDeclaration.md b/docs/description/Lint_TrailingCommaInAttributeDeclaration.md new file mode 100644 index 00000000..0cd00993 --- /dev/null +++ b/docs/description/Lint_TrailingCommaInAttributeDeclaration.md @@ -0,0 +1,29 @@ + +This cop checks for trailing commas in attribute declarations, such as +`#attr_reader`. Leaving a trailing comma will nullify the next method +definition by overriding it with a getter method. + +# Examples + +```ruby + +# bad +class Foo + attr_reader :foo, + + def bar + puts "Unreachable." + end +end + +# good +class Foo + attr_reader :foo + + def bar + puts "No problem!" + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/TrailingCommaInAttributeDeclaration) \ No newline at end of file diff --git a/docs/description/Lint_TripleQuotes.md b/docs/description/Lint_TripleQuotes.md new file mode 100644 index 00000000..4889d3d6 --- /dev/null +++ b/docs/description/Lint_TripleQuotes.md @@ -0,0 +1,42 @@ + +This cop checks for "triple quotes" (strings delimted by any odd number +of quotes greater than 1). + +Ruby allows multiple strings to be implicitly concatenated by just +being adjacent in a statement (ie. `"foo""bar" == "foobar"`). This sometimes +gives the impression that there is something special about triple quotes, but +in fact it is just extra unnecessary quotes and produces the same string. Each +pair of quotes produces an additional concatenated empty string, so the result +is still only the "actual" string within the delimiters. + +NOTE: Although this cop is called triple quotes, the same behavior is present +for strings delimited by 5, 7, etc. quotation marks. + +# Examples + +```ruby +# bad +""" + A string +""" + +# bad +''' + A string +''' + +# good +" + A string +" + +# good +< b } +values.sort { |*x| x[0] <=> x[1] } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UnexpectedBlockArity) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_UnifiedInteger.md b/docs/description/Lint_UnifiedInteger.md similarity index 100% rename from src/main/resources/docs/description/Lint_UnifiedInteger.md rename to docs/description/Lint_UnifiedInteger.md diff --git a/docs/description/Lint_UnmodifiedReduceAccumulator.md b/docs/description/Lint_UnmodifiedReduceAccumulator.md new file mode 100644 index 00000000..80f4897d --- /dev/null +++ b/docs/description/Lint_UnmodifiedReduceAccumulator.md @@ -0,0 +1,65 @@ + +Looks for `reduce` or `inject` blocks where the value returned (implicitly or +explicitly) does not include the accumulator. A block is considered valid as +long as at least one return value includes the accumulator. + +If the accumulator is not included in the return value, then the entire +block will just return a transformation of the last element value, and +could be rewritten as such without a loop. + +Also catches instances where an index of the accumulator is returned, as +this may change the type of object being retained. + +NOTE: For the purpose of reducing false positives, this cop only flags +returns in `reduce` blocks where the element is the only variable in +the expression (since we will not be able to tell what other variables +relate to via static analysis). + +# Examples + +```ruby + +# bad +(1..4).reduce(0) do |acc, el| + el * 2 +end + +# bad, may raise a NoMethodError after the first iteration +%w(a b c).reduce({}) do |acc, letter| + acc[letter] = true +end + +# good +(1..4).reduce(0) do |acc, el| + acc + el * 2 +end + +# good, element is returned but modified using the accumulator +values.reduce do |acc, el| + el << acc + el +end + +# good, returns the accumulator instead of the index +%w(a b c).reduce({}) do |acc, letter| + acc[letter] = true + acc +end + +# good, at least one branch returns the accumulator +values.reduce(nil) do |result, value| + break result if something? + value +end + +# good, recursive +keys.reduce(self) { |result, key| result[key] } + +# ignored as the return value cannot be determined +enum.reduce do |acc, el| + x = foo(acc, el) + bar(x) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UnmodifiedReduceAccumulator) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_UnreachableCode.md b/docs/description/Lint_UnreachableCode.md similarity index 86% rename from src/main/resources/docs/description/Lint_UnreachableCode.md rename to docs/description/Lint_UnreachableCode.md index 12808137..3caef564 100644 --- a/src/main/resources/docs/description/Lint_UnreachableCode.md +++ b/docs/description/Lint_UnreachableCode.md @@ -1,7 +1,7 @@ This cop checks for unreachable code. The check are based on the presence of flow of control -statement in non-final position in *begin*(implicit) blocks. +statement in non-final position in `begin` (implicit) blocks. # Examples diff --git a/docs/description/Lint_UnreachableLoop.md b/docs/description/Lint_UnreachableLoop.md new file mode 100644 index 00000000..605cab37 --- /dev/null +++ b/docs/description/Lint_UnreachableLoop.md @@ -0,0 +1,83 @@ + +This cop checks for loops that will have at most one iteration. + +A loop that can never reach the second iteration is a possible error in the code. +In rare cases where only one iteration (or at most one iteration) is intended behavior, +the code should be refactored to use `if` conditionals. + +NOTE: Block methods that are used with `Enumerable`s are considered to be loops. + +`IgnoredPatterns` can be used to match against the block receiver in order to allow +code that would otherwise be registered as an offense (eg. `times` used not in an +`Enumerable` context). + +# Examples + +```ruby +# bad +while node + do_something(node) + node = node.parent + break +end + +# good +while node + do_something(node) + node = node.parent +end + +# bad +def verify_list(head) + item = head + begin + if verify(item) + return true + else + return false + end + end while(item) +end + +# good +def verify_list(head) + item = head + begin + if verify(item) + item = item.next + else + return false + end + end while(item) + + true +end + +# bad +def find_something(items) + items.each do |item| + if something?(item) + return item + else + raise NotFoundError + end + end +end + +# good +def find_something(items) + items.each do |item| + if something?(item) + return item + end + end + raise NotFoundError +end + +# bad +2.times { raise ArgumentError } +# good +exactly(2).times { raise StandardError } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UnreachableLoop) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_UnusedBlockArgument.md b/docs/description/Lint_UnusedBlockArgument.md similarity index 100% rename from src/main/resources/docs/description/Lint_UnusedBlockArgument.md rename to docs/description/Lint_UnusedBlockArgument.md diff --git a/src/main/resources/docs/description/Lint_UnusedMethodArgument.md b/docs/description/Lint_UnusedMethodArgument.md similarity index 100% rename from src/main/resources/docs/description/Lint_UnusedMethodArgument.md rename to docs/description/Lint_UnusedMethodArgument.md diff --git a/src/main/resources/docs/description/Lint_UriEscapeUnescape.md b/docs/description/Lint_UriEscapeUnescape.md similarity index 100% rename from src/main/resources/docs/description/Lint_UriEscapeUnescape.md rename to docs/description/Lint_UriEscapeUnescape.md diff --git a/src/main/resources/docs/description/Lint_UriRegexp.md b/docs/description/Lint_UriRegexp.md similarity index 100% rename from src/main/resources/docs/description/Lint_UriRegexp.md rename to docs/description/Lint_UriRegexp.md diff --git a/src/main/resources/docs/description/Lint_UselessAccessModifier.md b/docs/description/Lint_UselessAccessModifier.md similarity index 100% rename from src/main/resources/docs/description/Lint_UselessAccessModifier.md rename to docs/description/Lint_UselessAccessModifier.md diff --git a/src/main/resources/docs/description/Lint_UselessAssignment.md b/docs/description/Lint_UselessAssignment.md similarity index 100% rename from src/main/resources/docs/description/Lint_UselessAssignment.md rename to docs/description/Lint_UselessAssignment.md diff --git a/src/main/resources/docs/description/Lint_UselessElseWithoutRescue.md b/docs/description/Lint_UselessElseWithoutRescue.md similarity index 86% rename from src/main/resources/docs/description/Lint_UselessElseWithoutRescue.md rename to docs/description/Lint_UselessElseWithoutRescue.md index 79685fc6..2c8918a0 100644 --- a/src/main/resources/docs/description/Lint_UselessElseWithoutRescue.md +++ b/docs/description/Lint_UselessElseWithoutRescue.md @@ -1,7 +1,7 @@ This cop checks for useless `else` in `begin..end` without `rescue`. -Note: This syntax is no longer valid on Ruby 2.6 or higher and +NOTE: This syntax is no longer valid on Ruby 2.6 or higher and this cop is going to be removed at some point the future. # Examples diff --git a/docs/description/Lint_UselessMethodDefinition.md b/docs/description/Lint_UselessMethodDefinition.md new file mode 100644 index 00000000..6bcb7f14 --- /dev/null +++ b/docs/description/Lint_UselessMethodDefinition.md @@ -0,0 +1,36 @@ + +This cop checks for useless method definitions, specifically: empty constructors +and methods just delegating to `super`. + +This cop is marked as unsafe as it can trigger false positives for cases when +an empty constructor just overrides the parent constructor, which is bad anyway. + +# Examples + +```ruby +# bad +def initialize + super +end + +def method + super +end + +# good - with default arguments +def initialize(x = Object.new) + super +end + +# good +def initialize + super + initialize_internals +end + +def method(*args) + super(:extra_arg, *args) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UselessMethodDefinition) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_UselessSetterCall.md b/docs/description/Lint_UselessSetterCall.md similarity index 76% rename from src/main/resources/docs/description/Lint_UselessSetterCall.md rename to docs/description/Lint_UselessSetterCall.md index 390ff1cd..3ea4f304 100644 --- a/src/main/resources/docs/description/Lint_UselessSetterCall.md +++ b/docs/description/Lint_UselessSetterCall.md @@ -1,8 +1,9 @@ This cop checks for setter call to local variable as the final expression of a function definition. +Its auto-correction is marked as unsafe because return value will be changed. -Note: There are edge cases in which the local variable references a +NOTE: There are edge cases in which the local variable references a value that is also accessible outside the local scope. This is not detected by the cop, and it can yield a false positive. diff --git a/docs/description/Lint_UselessTimes.md b/docs/description/Lint_UselessTimes.md new file mode 100644 index 00000000..cd73d307 --- /dev/null +++ b/docs/description/Lint_UselessTimes.md @@ -0,0 +1,23 @@ + +This cop checks for uses of `Integer#times` that will never yield +(when the integer <= 0) or that will only ever yield once +(`1.times`). + +This cop is marked as unsafe as `times` returns its receiver, which +is *usually* OK, but might change behavior. + +# Examples + +```ruby +# bad +-5.times { do_something } +0.times { do_something } +1.times { do_something } +1.times { |i| do_something(i) } + +# good +do_something +do_something(1) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UselessTimes) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_Void.md b/docs/description/Lint_Void.md similarity index 100% rename from src/main/resources/docs/description/Lint_Void.md rename to docs/description/Lint_Void.md diff --git a/docs/description/Metrics_AbcSize.md b/docs/description/Metrics_AbcSize.md new file mode 100644 index 00000000..26459faa --- /dev/null +++ b/docs/description/Metrics_AbcSize.md @@ -0,0 +1,31 @@ + +This cop checks that the ABC size of methods is not higher than the +configured maximum. The ABC size is based on assignments, branches +(method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric +and https://en.wikipedia.org/wiki/ABC_Software_Metric. + +You can have repeated "attributes" calls count as a single "branch". +For this purpose, attributes are any method with no argument; no attempt +is meant to distinguish actual `attr_reader` from other methods. + +This cop also takes into account `IgnoredMethods` (defaults to `[]`) + +# Examples + +```ruby + +# `model` and `current_user`, refenced 3 times each, +# are each counted as only 1 branch each if +# `CountRepeatedAttributes` is set to 'false' + +def search + @posts = model.active.visible_by(current_user) + .search(params[:q]) + @posts = model.some_process(@posts, current_user) + @posts = model.another_process(@posts, current_user) + + render 'pages/search/page' +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/AbcSize) \ No newline at end of file diff --git a/docs/description/Metrics_BlockLength.md b/docs/description/Metrics_BlockLength.md new file mode 100644 index 00000000..5ebee1c6 --- /dev/null +++ b/docs/description/Metrics_BlockLength.md @@ -0,0 +1,38 @@ + +This cop checks if the length of a block exceeds some maximum value. +Comment lines can optionally be ignored. +The maximum allowed length is configurable. +The cop can be configured to ignore blocks passed to certain methods. + +You can set literals you want to fold with `CountAsOne`. +Available are: 'array', 'hash', and 'heredoc'. Each literal +will be counted as one line regardless of its actual size. + + +NOTE: The `ExcludedMethods` configuration is deprecated and only kept +for backwards compatibility. Please use `IgnoredMethods` instead. + +NOTE: This cop does not apply for `Struct` definitions. + +# Examples + +```ruby + +something do + array = [ # +1 + 1, + 2 + ] + + hash = { # +3 + key: 'value' + } + + msg = <<~HEREDOC # +1 + Heredoc + content. + HEREDOC +end # 5 points +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/BlockLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_BlockNesting.md b/docs/description/Metrics_BlockNesting.md similarity index 100% rename from src/main/resources/docs/description/Metrics_BlockNesting.md rename to docs/description/Metrics_BlockNesting.md diff --git a/docs/description/Metrics_ClassLength.md b/docs/description/Metrics_ClassLength.md new file mode 100644 index 00000000..b1c27cf8 --- /dev/null +++ b/docs/description/Metrics_ClassLength.md @@ -0,0 +1,33 @@ + +This cop checks if the length a class exceeds some maximum value. +Comment lines can optionally be ignored. +The maximum allowed length is configurable. + +You can set literals you want to fold with `CountAsOne`. +Available are: 'array', 'hash', and 'heredoc'. Each literal +will be counted as one line regardless of its actual size. + +NOTE: This cop also applies for `Struct` definitions. + +# Examples + +```ruby + +class Foo + ARRAY = [ # +1 + 1, + 2 + ] + + HASH = { # +3 + key: 'value' + } + + MSG = <<~HEREDOC # +1 + Heredoc + content. + HEREDOC +end # 5 points +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ClassLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_CyclomaticComplexity.md b/docs/description/Metrics_CyclomaticComplexity.md similarity index 54% rename from src/main/resources/docs/description/Metrics_CyclomaticComplexity.md rename to docs/description/Metrics_CyclomaticComplexity.md index ced67742..8980d2a1 100644 --- a/src/main/resources/docs/description/Metrics_CyclomaticComplexity.md +++ b/docs/description/Metrics_CyclomaticComplexity.md @@ -9,6 +9,22 @@ else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. +Blocks that are calls to builtin iteration methods +(e.g. `ary.map{...}) also add one, others are ignored. + + def each_child_node(*types) # count begins: 1 + unless block_given? # unless: +1 + return to_enum(__method__, *types) + + children.each do |child| # each{}: +1 + next unless child.is_a?(Node) # unless: +1 + + yield child if types.empty? || # if: +1, ||: +1 + types.include?(child.type) + end + + self + end # total: 6 # Examples diff --git a/docs/description/Metrics_MethodLength.md b/docs/description/Metrics_MethodLength.md new file mode 100644 index 00000000..04997381 --- /dev/null +++ b/docs/description/Metrics_MethodLength.md @@ -0,0 +1,34 @@ + +This cop checks if the length of a method exceeds some maximum value. +Comment lines can optionally be ignored. +The maximum allowed length is configurable. + +You can set literals you want to fold with `CountAsOne`. +Available are: 'array', 'hash', and 'heredoc'. Each literal +will be counted as one line regardless of its actual size. + +NOTE: The `ExcludedMethods` configuration is deprecated and only kept +for backwards compatibility. Please use `IgnoredMethods` instead. + +# Examples + +```ruby + +def m + array = [ # +1 + 1, + 2 + ] + + hash = { # +3 + key: 'value' + } + + <<~HEREDOC # +1 + Heredoc + content. + HEREDOC +end # 5 points +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/MethodLength) \ No newline at end of file diff --git a/docs/description/Metrics_ModuleLength.md b/docs/description/Metrics_ModuleLength.md new file mode 100644 index 00000000..2a22eaa7 --- /dev/null +++ b/docs/description/Metrics_ModuleLength.md @@ -0,0 +1,31 @@ + +This cop checks if the length a module exceeds some maximum value. +Comment lines can optionally be ignored. +The maximum allowed length is configurable. + +You can set literals you want to fold with `CountAsOne`. +Available are: 'array', 'hash', and 'heredoc'. Each literal +will be counted as one line regardless of its actual size. + +# Examples + +```ruby + +module M + ARRAY = [ # +1 + 1, + 2 + ] + + HASH = { # +3 + key: 'value' + } + + MSG = <<~HEREDOC # +1 + Heredoc + content. + HEREDOC +end # 5 points +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ModuleLength) \ No newline at end of file diff --git a/docs/description/Metrics_ParameterLists.md b/docs/description/Metrics_ParameterLists.md new file mode 100644 index 00000000..8f14cc66 --- /dev/null +++ b/docs/description/Metrics_ParameterLists.md @@ -0,0 +1,37 @@ + +This cop checks for methods with too many parameters. + +The maximum number of parameters is configurable. +Keyword arguments can optionally be excluded from the total count, +as they add less complexity than positional or optional parameters. + +This cop also checks for the maximum number of optional parameters. +This can be configured using the `MaxOptionalParameters` config option. + +# Examples + +```ruby +# good +def foo(a, b, c = 1) +end# bad +def foo(a, b, c = 1) +end# counts keyword args towards the maximum + +# bad (assuming Max is 3) +def foo(a, b, c, d: 1) +end + +# good (assuming Max is 3) +def foo(a, b, c: 1) +end# don't count keyword args towards the maximum + +# good (assuming Max is 3) +def foo(a, b, c, d: 1) +end# good +def foo(a = 1, b = 2, c = 3) +end# bad +def foo(a = 1, b = 2, c = 3) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ParameterLists) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_PerceivedComplexity.md b/docs/description/Metrics_PerceivedComplexity.md similarity index 100% rename from src/main/resources/docs/description/Metrics_PerceivedComplexity.md rename to docs/description/Metrics_PerceivedComplexity.md diff --git a/src/main/resources/docs/description/Migration_DepartmentName.md b/docs/description/Migration_DepartmentName.md similarity index 100% rename from src/main/resources/docs/description/Migration_DepartmentName.md rename to docs/description/Migration_DepartmentName.md diff --git a/docs/description/Naming_AccessorMethodName.md b/docs/description/Naming_AccessorMethodName.md new file mode 100644 index 00000000..4126d3a8 --- /dev/null +++ b/docs/description/Naming_AccessorMethodName.md @@ -0,0 +1,38 @@ + +This cop makes sure that accessor methods are named properly. Applies +to both instance and class methods. + +NOTE: Offenses are only registered for methods with the expected +arity. Getters (`get_attribute`) must have no arguments to be +registered, and setters (`set_attribute(value)`) must have exactly +one. + +# Examples + +```ruby +# bad +def set_attribute(value) +end + +# good +def attribute=(value) +end + +# bad +def get_attribute +end + +# good +def attribute +end + +# accepted, incorrect arity for getter +def get_value(attr) +end + +# accepted, incorrect arity for setter +def set_value +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/AccessorMethodName) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_AsciiIdentifiers.md b/docs/description/Naming_AsciiIdentifiers.md similarity index 62% rename from src/main/resources/docs/description/Naming_AsciiIdentifiers.md rename to docs/description/Naming_AsciiIdentifiers.md index 6b70a8a4..5d2f9af9 100644 --- a/src/main/resources/docs/description/Naming_AsciiIdentifiers.md +++ b/docs/description/Naming_AsciiIdentifiers.md @@ -1,5 +1,7 @@ -This cop checks for non-ascii characters in identifier names. +This cop checks for non-ascii characters in identifier and constant names. +Identifiers are always checked and whether constants are checked +can be controlled using AsciiConstants config. # Examples @@ -30,7 +32,15 @@ height = 10 params[:عرض_gteq] # Arabic character (non-ascii) # good -params[:width_gteq] +params[:width_gteq]# bad +class Foö +end + +FOÖ = "foo"# good +class Foö +end + +FOÖ = "foo" ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/AsciiIdentifiers) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_BinaryOperatorParameterName.md b/docs/description/Naming_BinaryOperatorParameterName.md similarity index 100% rename from src/main/resources/docs/description/Naming_BinaryOperatorParameterName.md rename to docs/description/Naming_BinaryOperatorParameterName.md diff --git a/src/main/resources/docs/description/Naming_BlockParameterName.md b/docs/description/Naming_BlockParameterName.md similarity index 100% rename from src/main/resources/docs/description/Naming_BlockParameterName.md rename to docs/description/Naming_BlockParameterName.md diff --git a/docs/description/Naming_ClassAndModuleCamelCase.md b/docs/description/Naming_ClassAndModuleCamelCase.md new file mode 100644 index 00000000..51e8a8ad --- /dev/null +++ b/docs/description/Naming_ClassAndModuleCamelCase.md @@ -0,0 +1,29 @@ + +This cop checks for class and module names with +an underscore in them. + +`AllowedNames` config takes an array of permitted names. +Its default value is `['module_parent']`. +These names can be full class/module names or part of the name. +eg. Adding `my_class` to the `AllowedNames` config will allow names like +`my_class`, `my_class::User`, `App::my_class`, `App::my_class::User`, etc. + +# Examples + +```ruby +# bad +class My_Class +end +module My_Module +end + +# good +class MyClass +end +module MyModule +end +class module_parent::MyModule +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/ClassAndModuleCamelCase) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_ConstantName.md b/docs/description/Naming_ConstantName.md similarity index 100% rename from src/main/resources/docs/description/Naming_ConstantName.md rename to docs/description/Naming_ConstantName.md diff --git a/src/main/resources/docs/description/Naming_FileName.md b/docs/description/Naming_FileName.md similarity index 100% rename from src/main/resources/docs/description/Naming_FileName.md rename to docs/description/Naming_FileName.md diff --git a/src/main/resources/docs/description/Naming_HeredocDelimiterCase.md b/docs/description/Naming_HeredocDelimiterCase.md similarity index 100% rename from src/main/resources/docs/description/Naming_HeredocDelimiterCase.md rename to docs/description/Naming_HeredocDelimiterCase.md diff --git a/src/main/resources/docs/description/Naming_HeredocDelimiterNaming.md b/docs/description/Naming_HeredocDelimiterNaming.md similarity index 100% rename from src/main/resources/docs/description/Naming_HeredocDelimiterNaming.md rename to docs/description/Naming_HeredocDelimiterNaming.md diff --git a/src/main/resources/docs/description/Naming_MemoizedInstanceVariableName.md b/docs/description/Naming_MemoizedInstanceVariableName.md similarity index 59% rename from src/main/resources/docs/description/Naming_MemoizedInstanceVariableName.md rename to docs/description/Naming_MemoizedInstanceVariableName.md index 6fba1983..b5e68b28 100644 --- a/src/main/resources/docs/description/Naming_MemoizedInstanceVariableName.md +++ b/docs/description/Naming_MemoizedInstanceVariableName.md @@ -1,6 +1,8 @@ This cop checks for memoized methods whose instance variable name -does not match the method name. +does not match the method name. Applies to both regular methods +(defined with `def`) and dynamic methods (defined with +`define_method` or `define_singleton_method`). This cop can be configured with the EnforcedStyleForLeadingUnderscores directive. It can be configured to allow for memoized instance variables @@ -18,6 +20,11 @@ def foo @something ||= calculate_expensive_thing end +def foo + return @something if defined?(@something) + @something = calculate_expensive_thing +end + # good def _foo @foo ||= calculate_expensive_thing @@ -39,6 +46,17 @@ end def foo helper_variable = something_we_need_to_calculate_foo @foo ||= calculate_expensive_thing(helper_variable) +end + +# good +define_method(:foo) do + @foo ||= calculate_expensive_thing +end + +# good +define_method(:foo) do + return @foo if defined?(@foo) + @foo = calculate_expensive_thing end# bad def foo @something ||= calculate_expensive_thing @@ -49,6 +67,11 @@ def foo @foo ||= calculate_expensive_thing end +def foo + return @foo if defined?(@foo) + @foo = calculate_expensive_thing +end + # good def foo @_foo ||= calculate_expensive_thing @@ -57,6 +80,22 @@ end # good def _foo @_foo ||= calculate_expensive_thing +end + +def foo + return @_foo if defined?(@_foo) + @_foo = calculate_expensive_thing +end + +# good +define_method(:foo) do + @_foo ||= calculate_expensive_thing +end + +# good +define_method(:foo) do + return @_foo if defined?(@_foo) + @_foo = calculate_expensive_thing end# bad def foo @something ||= calculate_expensive_thing @@ -76,6 +115,22 @@ end def _foo @_foo ||= calculate_expensive_thing end + +# good +def foo + return @_foo if defined?(@_foo) + @_foo = calculate_expensive_thing +end + +# good +define_method(:foo) do + @foo ||= calculate_expensive_thing +end + +# good +define_method(:foo) do + @_foo ||= calculate_expensive_thing +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/MemoizedInstanceVariableName) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_MethodName.md b/docs/description/Naming_MethodName.md similarity index 100% rename from src/main/resources/docs/description/Naming_MethodName.md rename to docs/description/Naming_MethodName.md diff --git a/src/main/resources/docs/description/Naming_MethodParameterName.md b/docs/description/Naming_MethodParameterName.md similarity index 100% rename from src/main/resources/docs/description/Naming_MethodParameterName.md rename to docs/description/Naming_MethodParameterName.md diff --git a/src/main/resources/docs/description/Naming_PredicateName.md b/docs/description/Naming_PredicateName.md similarity index 100% rename from src/main/resources/docs/description/Naming_PredicateName.md rename to docs/description/Naming_PredicateName.md diff --git a/src/main/resources/docs/description/Naming_RescuedExceptionsVariableName.md b/docs/description/Naming_RescuedExceptionsVariableName.md similarity index 100% rename from src/main/resources/docs/description/Naming_RescuedExceptionsVariableName.md rename to docs/description/Naming_RescuedExceptionsVariableName.md diff --git a/src/main/resources/docs/description/Naming_VariableName.md b/docs/description/Naming_VariableName.md similarity index 100% rename from src/main/resources/docs/description/Naming_VariableName.md rename to docs/description/Naming_VariableName.md diff --git a/docs/description/Naming_VariableNumber.md b/docs/description/Naming_VariableNumber.md new file mode 100644 index 00000000..0d70fd33 --- /dev/null +++ b/docs/description/Naming_VariableNumber.md @@ -0,0 +1,77 @@ + +This cop makes sure that all numbered variables use the +configured style, snake_case, normalcase, or non_integer, +for their numbering. + +Additionally, `CheckMethodNames` and `CheckSymbols` configuration options +can be used to specify whether method names and symbols should be checked. +Both are enabled by default. + +# Examples + +```ruby +# bad +:some_sym1 +variable1 = 1 + +def some_method1; end + +def some_method_1(arg1); end + +# good +:some_sym_1 +variable_1 = 1 + +def some_method_1; end + +def some_method_1(arg_1); end# bad +:some_sym_1 +variable_1 = 1 + +def some_method_1; end + +def some_method1(arg_1); end + +# good +:some_sym1 +variable1 = 1 + +def some_method1; end + +def some_method1(arg1); end# bad +:some_sym1 +:some_sym_1 + +variable1 = 1 +variable_1 = 1 + +def some_method1; end + +def some_method_1; end + +def some_methodone(arg1); end +def some_methodone(arg_1); end + +# good +:some_symone +:some_sym_one + +variableone = 1 +variable_one = 1 + +def some_methodone; end + +def some_method_one; end + +def some_methodone(argone); end +def some_methodone(arg_one); end + +# In the following examples, we assume `EnforcedStyle: normalcase` (default).# bad +def some_method_1; end# good +def some_method_1; end# bad +:some_sym_1# good +:some_sym_1# good +expect(Open3).to receive(:capture3) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/VariableNumber) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_AncestorsInclude.md b/docs/description/Performance_AncestorsInclude.md similarity index 100% rename from src/main/resources/docs/description/Performance_AncestorsInclude.md rename to docs/description/Performance_AncestorsInclude.md diff --git a/docs/description/Performance_ArraySemiInfiniteRangeSlice.md b/docs/description/Performance_ArraySemiInfiniteRangeSlice.md new file mode 100644 index 00000000..f9bcd5bc --- /dev/null +++ b/docs/description/Performance_ArraySemiInfiniteRangeSlice.md @@ -0,0 +1,26 @@ + +This cop identifies places where slicing arrays with semi-infinite ranges +can be replaced by `Array#take` and `Array#drop`. +This cop was created due to a mistake in microbenchmark and hence is disabled by default. +Refer /~https://github.com/rubocop-hq/rubocop-performance/pull/175#issuecomment-731892717 +This cop is also unsafe for string slices because strings do not have `#take` and `#drop` methods. + +# Examples + +```ruby +# bad +# array[..2] +# array[...2] +# array[2..] +# array[2...] +# array.slice(..2) + +# good +array.take(3) +array.take(2) +array.drop(2) +array.drop(2) +array.take(3) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/ArraySemiInfiniteRangeSlice) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_BigDecimalWithNumericArgument.md b/docs/description/Performance_BigDecimalWithNumericArgument.md similarity index 100% rename from src/main/resources/docs/description/Performance_BigDecimalWithNumericArgument.md rename to docs/description/Performance_BigDecimalWithNumericArgument.md diff --git a/src/main/resources/docs/description/Performance_BindCall.md b/docs/description/Performance_BindCall.md similarity index 100% rename from src/main/resources/docs/description/Performance_BindCall.md rename to docs/description/Performance_BindCall.md diff --git a/docs/description/Performance_BlockGivenWithExplicitBlock.md b/docs/description/Performance_BlockGivenWithExplicitBlock.md new file mode 100644 index 00000000..9aaf5463 --- /dev/null +++ b/docs/description/Performance_BlockGivenWithExplicitBlock.md @@ -0,0 +1,26 @@ + +This cop identifies unnecessary use of a `block_given?` where explicit check +of block argument would suffice. + +# Examples + +```ruby +# bad +def method(&block) + do_something if block_given? +end + +# good +def method(&block) + do_something if block +end + +# good - block is reassigned +def method(&block) + block ||= -> { do_something } + warn "Using default ..." unless block_given? + # ... +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/BlockGivenWithExplicitBlock) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_Caller.md b/docs/description/Performance_Caller.md similarity index 100% rename from src/main/resources/docs/description/Performance_Caller.md rename to docs/description/Performance_Caller.md diff --git a/src/main/resources/docs/description/Performance_CaseWhenSplat.md b/docs/description/Performance_CaseWhenSplat.md similarity index 100% rename from src/main/resources/docs/description/Performance_CaseWhenSplat.md rename to docs/description/Performance_CaseWhenSplat.md diff --git a/src/main/resources/docs/description/Performance_Casecmp.md b/docs/description/Performance_Casecmp.md similarity index 100% rename from src/main/resources/docs/description/Performance_Casecmp.md rename to docs/description/Performance_Casecmp.md diff --git a/src/main/resources/docs/description/Performance_ChainArrayAllocation.md b/docs/description/Performance_ChainArrayAllocation.md similarity index 100% rename from src/main/resources/docs/description/Performance_ChainArrayAllocation.md rename to docs/description/Performance_ChainArrayAllocation.md diff --git a/docs/description/Performance_CollectionLiteralInLoop.md b/docs/description/Performance_CollectionLiteralInLoop.md new file mode 100644 index 00000000..22898ffc --- /dev/null +++ b/docs/description/Performance_CollectionLiteralInLoop.md @@ -0,0 +1,31 @@ + +This cop identifies places where Array and Hash literals are used +within loops. It is better to extract them into a local variable or constant +to avoid unnecessary allocations on each iteration. + +You can set the minimum number of elements to consider +an offense with `MinSize`. + +# Examples + +```ruby +# bad +users.select do |user| + %i[superadmin admin].include?(user.role) +end + +# good +admin_roles = %i[superadmin admin] +users.select do |user| + admin_roles.include?(user.role) +end + +# good +ADMIN_ROLES = %i[superadmin admin] +... +users.select do |user| + ADMIN_ROLES.include?(user.role) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/CollectionLiteralInLoop) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_CompareWithBlock.md b/docs/description/Performance_CompareWithBlock.md similarity index 100% rename from src/main/resources/docs/description/Performance_CompareWithBlock.md rename to docs/description/Performance_CompareWithBlock.md diff --git a/docs/description/Performance_ConstantRegexp.md b/docs/description/Performance_ConstantRegexp.md new file mode 100644 index 00000000..fea37387 --- /dev/null +++ b/docs/description/Performance_ConstantRegexp.md @@ -0,0 +1,30 @@ + +This cop finds regular expressions with dynamic components that are all constants. + +Ruby allocates a new Regexp object every time it executes a code containing such +a regular expression. It is more efficient to extract it into a constant +or add an `/o` option to perform `#{}` interpolation only once and reuse that +Regexp object. + +# Examples + +```ruby + +# bad +def tokens(pattern) + pattern.scan(TOKEN).reject { |token| token.match?(/\A#{SEPARATORS}\Z/) } +end + +# good +ALL_SEPARATORS = /\A#{SEPARATORS}\Z/ +def tokens(pattern) + pattern.scan(TOKEN).reject { |token| token.match?(ALL_SEPARATORS) } +end + +# good +def tokens(pattern) + pattern.scan(TOKEN).reject { |token| token.match?(/\A#{SEPARATORS}\Z/o) } +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/ConstantRegexp) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_Count.md b/docs/description/Performance_Count.md similarity index 92% rename from src/main/resources/docs/description/Performance_Count.md rename to docs/description/Performance_Count.md index e7e8f1a2..b993389c 100644 --- a/src/main/resources/docs/description/Performance_Count.md +++ b/docs/description/Performance_Count.md @@ -1,6 +1,6 @@ This cop is used to identify usages of `count` on an `Enumerable` that -follow calls to `select` or `reject`. Querying logic can instead be +follow calls to `select`, `find_all`, `filter` or `reject`. Querying logic can instead be passed to the `count` call. `ActiveRecord` compatibility: diff --git a/src/main/resources/docs/description/Performance_DeletePrefix.md b/docs/description/Performance_DeletePrefix.md similarity index 100% rename from src/main/resources/docs/description/Performance_DeletePrefix.md rename to docs/description/Performance_DeletePrefix.md diff --git a/src/main/resources/docs/description/Performance_DeleteSuffix.md b/docs/description/Performance_DeleteSuffix.md similarity index 100% rename from src/main/resources/docs/description/Performance_DeleteSuffix.md rename to docs/description/Performance_DeleteSuffix.md diff --git a/src/main/resources/docs/description/Performance_Detect.md b/docs/description/Performance_Detect.md similarity index 64% rename from src/main/resources/docs/description/Performance_Detect.md rename to docs/description/Performance_Detect.md index 00347bd9..a640f100 100644 --- a/src/main/resources/docs/description/Performance_Detect.md +++ b/docs/description/Performance_Detect.md @@ -1,7 +1,7 @@ -This cop is used to identify usages of -`select.first`, `select.last`, `find_all.first`, and `find_all.last` -and change them to use `detect` instead. +This cop is used to identify usages of `first`, `last`, `[0]` or `[-1]` +chained to `select`, `find_all` or `filter` and change them to use +`detect` instead. `ActiveRecord` compatibility: `ActiveRecord` does not implement a `detect` method and `find` has its @@ -16,6 +16,10 @@ considered unsafe. [].select { |item| true }.last [].find_all { |item| true }.first [].find_all { |item| true }.last +[].filter { |item| true }.first +[].filter { |item| true }.last +[].filter { |item| true }[0] +[].filter { |item| true }[-1] # good [].detect { |item| true } diff --git a/src/main/resources/docs/description/Performance_DoubleStartEndWith.md b/docs/description/Performance_DoubleStartEndWith.md similarity index 100% rename from src/main/resources/docs/description/Performance_DoubleStartEndWith.md rename to docs/description/Performance_DoubleStartEndWith.md diff --git a/src/main/resources/docs/description/Performance_EndWith.md b/docs/description/Performance_EndWith.md similarity index 100% rename from src/main/resources/docs/description/Performance_EndWith.md rename to docs/description/Performance_EndWith.md diff --git a/src/main/resources/docs/description/Performance_FixedSize.md b/docs/description/Performance_FixedSize.md similarity index 100% rename from src/main/resources/docs/description/Performance_FixedSize.md rename to docs/description/Performance_FixedSize.md diff --git a/src/main/resources/docs/description/Performance_FlatMap.md b/docs/description/Performance_FlatMap.md similarity index 100% rename from src/main/resources/docs/description/Performance_FlatMap.md rename to docs/description/Performance_FlatMap.md diff --git a/src/main/resources/docs/description/Performance_InefficientHashSearch.md b/docs/description/Performance_InefficientHashSearch.md similarity index 100% rename from src/main/resources/docs/description/Performance_InefficientHashSearch.md rename to docs/description/Performance_InefficientHashSearch.md diff --git a/src/main/resources/docs/description/Performance_IoReadlines.md b/docs/description/Performance_IoReadlines.md similarity index 100% rename from src/main/resources/docs/description/Performance_IoReadlines.md rename to docs/description/Performance_IoReadlines.md diff --git a/docs/description/Performance_MethodObjectAsBlock.md b/docs/description/Performance_MethodObjectAsBlock.md new file mode 100644 index 00000000..7a834037 --- /dev/null +++ b/docs/description/Performance_MethodObjectAsBlock.md @@ -0,0 +1,18 @@ + +This cop identifies places where methods are converted to blocks, with the +use of `&method`, and passed as arguments to method calls. +It is faster to replace those with explicit blocks, calling those methods inside. + +# Examples + +```ruby +# bad +array.map(&method(:do_something)) +[1, 2, 3].each(&out.method(:puts)) + +# good +array.map { |x| do_something(x) } +[1, 2, 3].each { |x| out.puts(x) } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/MethodObjectAsBlock) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_OpenStruct.md b/docs/description/Performance_OpenStruct.md similarity index 100% rename from src/main/resources/docs/description/Performance_OpenStruct.md rename to docs/description/Performance_OpenStruct.md diff --git a/src/main/resources/docs/description/Performance_RangeInclude.md b/docs/description/Performance_RangeInclude.md similarity index 100% rename from src/main/resources/docs/description/Performance_RangeInclude.md rename to docs/description/Performance_RangeInclude.md diff --git a/src/main/resources/docs/description/Performance_RedundantBlockCall.md b/docs/description/Performance_RedundantBlockCall.md similarity index 100% rename from src/main/resources/docs/description/Performance_RedundantBlockCall.md rename to docs/description/Performance_RedundantBlockCall.md diff --git a/src/main/resources/docs/description/Performance_RedundantMatch.md b/docs/description/Performance_RedundantMatch.md similarity index 100% rename from src/main/resources/docs/description/Performance_RedundantMatch.md rename to docs/description/Performance_RedundantMatch.md diff --git a/src/main/resources/docs/description/Performance_RedundantMerge.md b/docs/description/Performance_RedundantMerge.md similarity index 100% rename from src/main/resources/docs/description/Performance_RedundantMerge.md rename to docs/description/Performance_RedundantMerge.md diff --git a/src/main/resources/docs/description/Performance_RedundantSortBlock.md b/docs/description/Performance_RedundantSortBlock.md similarity index 100% rename from src/main/resources/docs/description/Performance_RedundantSortBlock.md rename to docs/description/Performance_RedundantSortBlock.md diff --git a/src/main/resources/docs/description/Performance_RedundantStringChars.md b/docs/description/Performance_RedundantStringChars.md similarity index 100% rename from src/main/resources/docs/description/Performance_RedundantStringChars.md rename to docs/description/Performance_RedundantStringChars.md diff --git a/src/main/resources/docs/description/Performance_RegexpMatch.md b/docs/description/Performance_RegexpMatch.md similarity index 100% rename from src/main/resources/docs/description/Performance_RegexpMatch.md rename to docs/description/Performance_RegexpMatch.md diff --git a/src/main/resources/docs/description/Performance_ReverseEach.md b/docs/description/Performance_ReverseEach.md similarity index 100% rename from src/main/resources/docs/description/Performance_ReverseEach.md rename to docs/description/Performance_ReverseEach.md diff --git a/src/main/resources/docs/description/Performance_ReverseFirst.md b/docs/description/Performance_ReverseFirst.md similarity index 100% rename from src/main/resources/docs/description/Performance_ReverseFirst.md rename to docs/description/Performance_ReverseFirst.md diff --git a/src/main/resources/docs/description/Performance_Size.md b/docs/description/Performance_Size.md similarity index 100% rename from src/main/resources/docs/description/Performance_Size.md rename to docs/description/Performance_Size.md diff --git a/src/main/resources/docs/description/Performance_SortReverse.md b/docs/description/Performance_SortReverse.md similarity index 100% rename from src/main/resources/docs/description/Performance_SortReverse.md rename to docs/description/Performance_SortReverse.md diff --git a/src/main/resources/docs/description/Performance_Squeeze.md b/docs/description/Performance_Squeeze.md similarity index 100% rename from src/main/resources/docs/description/Performance_Squeeze.md rename to docs/description/Performance_Squeeze.md diff --git a/src/main/resources/docs/description/Performance_StartWith.md b/docs/description/Performance_StartWith.md similarity index 100% rename from src/main/resources/docs/description/Performance_StartWith.md rename to docs/description/Performance_StartWith.md diff --git a/src/main/resources/docs/description/Performance_StringInclude.md b/docs/description/Performance_StringInclude.md similarity index 100% rename from src/main/resources/docs/description/Performance_StringInclude.md rename to docs/description/Performance_StringInclude.md diff --git a/src/main/resources/docs/description/Performance_StringReplacement.md b/docs/description/Performance_StringReplacement.md similarity index 100% rename from src/main/resources/docs/description/Performance_StringReplacement.md rename to docs/description/Performance_StringReplacement.md diff --git a/docs/description/Performance_Sum.md b/docs/description/Performance_Sum.md new file mode 100644 index 00000000..78f66254 --- /dev/null +++ b/docs/description/Performance_Sum.md @@ -0,0 +1,47 @@ + +This cop identifies places where custom code finding the sum of elements +in some Enumerable object can be replaced by `Enumerable#sum` method. + +This cop can change auto-correction scope depending on the value of +`SafeAutoCorrect`. +Its auto-correction is marked as safe by default (`SafeAutoCorrect: true`) +to prevent `TypeError` in auto-correced code when initial value is not +specified as shown below: + +[source,ruby] +---- +['a', 'b'].sum # => (String can't be coerced into Integer) +---- + +Therefore if initial value is not specified, unsafe auto-corrected will not occur. + +If you always want to enable auto-correction, you can set `SafeAutoCorrect: false`. + +[source,yaml] +---- +Performance/Sum: + SafeAutoCorrect: false +---- + +Please note that the auto-correction command line option will be changed from +`rubocop -a` to `rubocop -A`, which includes unsafe auto-correction. + +# Examples + +```ruby +# bad +[1, 2, 3].inject(:+) # These bad cases with no initial value are unsafe and +[1, 2, 3].inject(&:+) # will not be auto-correced by default. If you want to +[1, 2, 3].reduce { |acc, elem| acc + elem } # auto-corrected, you can set `SafeAutoCorrect: false`. +[1, 2, 3].reduce(10, :+) +[1, 2, 3].map { |elem| elem ** 2 }.sum +[1, 2, 3].collect(&:count).sum(10) + +# good +[1, 2, 3].sum +[1, 2, 3].sum(10) +[1, 2, 3].sum { |elem| elem ** 2 } +[1, 2, 3].sum(10, &:count) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Performance/Sum) \ No newline at end of file diff --git a/src/main/resources/docs/description/Performance_TimesMap.md b/docs/description/Performance_TimesMap.md similarity index 100% rename from src/main/resources/docs/description/Performance_TimesMap.md rename to docs/description/Performance_TimesMap.md diff --git a/src/main/resources/docs/description/Performance_UnfreezeString.md b/docs/description/Performance_UnfreezeString.md similarity index 94% rename from src/main/resources/docs/description/Performance_UnfreezeString.md rename to docs/description/Performance_UnfreezeString.md index f14ebb12..127ca8b4 100644 --- a/src/main/resources/docs/description/Performance_UnfreezeString.md +++ b/docs/description/Performance_UnfreezeString.md @@ -6,6 +6,7 @@ Unary plus operator is faster than `String#dup`. NOTE: `String.new` (without operator) is not exactly the same as `+''`. These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`. However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`). +Therefore, auto-correction is unsafe. So, if you expect `ASCII-8BIT` encoding, disable this cop. # Examples diff --git a/src/main/resources/docs/description/Performance_UriDefaultParser.md b/docs/description/Performance_UriDefaultParser.md similarity index 100% rename from src/main/resources/docs/description/Performance_UriDefaultParser.md rename to docs/description/Performance_UriDefaultParser.md diff --git a/src/main/resources/docs/description/Rails_ActionFilter.md b/docs/description/Rails_ActionFilter.md similarity index 100% rename from src/main/resources/docs/description/Rails_ActionFilter.md rename to docs/description/Rails_ActionFilter.md diff --git a/src/main/resources/docs/description/Rails_ActiveRecordAliases.md b/docs/description/Rails_ActiveRecordAliases.md similarity index 100% rename from src/main/resources/docs/description/Rails_ActiveRecordAliases.md rename to docs/description/Rails_ActiveRecordAliases.md diff --git a/docs/description/Rails_ActiveRecordCallbacksOrder.md b/docs/description/Rails_ActiveRecordCallbacksOrder.md new file mode 100644 index 00000000..426fa80b --- /dev/null +++ b/docs/description/Rails_ActiveRecordCallbacksOrder.md @@ -0,0 +1,21 @@ + +This cop checks that Active Record callbacks are declared +in the order in which they will be executed. + +# Examples + +```ruby +# bad +class Person < ApplicationRecord + after_commit :after_commit_callback + before_validation :before_validation_callback +end + +# good +class Person < ApplicationRecord + before_validation :before_validation_callback + after_commit :after_commit_callback +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/ActiveRecordCallbacksOrder) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_ActiveRecordOverride.md b/docs/description/Rails_ActiveRecordOverride.md similarity index 100% rename from src/main/resources/docs/description/Rails_ActiveRecordOverride.md rename to docs/description/Rails_ActiveRecordOverride.md diff --git a/src/main/resources/docs/description/Rails_ActiveSupportAliases.md b/docs/description/Rails_ActiveSupportAliases.md similarity index 100% rename from src/main/resources/docs/description/Rails_ActiveSupportAliases.md rename to docs/description/Rails_ActiveSupportAliases.md diff --git a/docs/description/Rails_AfterCommitOverride.md b/docs/description/Rails_AfterCommitOverride.md new file mode 100644 index 00000000..a622377e --- /dev/null +++ b/docs/description/Rails_AfterCommitOverride.md @@ -0,0 +1,33 @@ + +This cop enforces that there is only one call to `after_commit` +(and its aliases - `after_create_commit`, `after_update_commit`, +and `after_destroy_commit`) with the same callback name per model. + +# Examples + +```ruby +# bad +# This won't be triggered. +after_create_commit :log_action + +# This will override the callback added by +# after_create_commit. +after_update_commit :log_action + +# bad +# This won't be triggered. +after_commit :log_action, on: :create +# This won't be triggered. +after_update_commit :log_action +# This will override both previous callbacks. +after_commit :log_action, on: :destroy + +# good +after_save_commit :log_action + +# good +after_create_commit :log_create_action +after_update_commit :log_update_action +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/AfterCommitOverride) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_ApplicationController.md b/docs/description/Rails_ApplicationController.md similarity index 100% rename from src/main/resources/docs/description/Rails_ApplicationController.md rename to docs/description/Rails_ApplicationController.md diff --git a/src/main/resources/docs/description/Rails_ApplicationJob.md b/docs/description/Rails_ApplicationJob.md similarity index 100% rename from src/main/resources/docs/description/Rails_ApplicationJob.md rename to docs/description/Rails_ApplicationJob.md diff --git a/src/main/resources/docs/description/Rails_ApplicationMailer.md b/docs/description/Rails_ApplicationMailer.md similarity index 100% rename from src/main/resources/docs/description/Rails_ApplicationMailer.md rename to docs/description/Rails_ApplicationMailer.md diff --git a/src/main/resources/docs/description/Rails_ApplicationRecord.md b/docs/description/Rails_ApplicationRecord.md similarity index 100% rename from src/main/resources/docs/description/Rails_ApplicationRecord.md rename to docs/description/Rails_ApplicationRecord.md diff --git a/docs/description/Rails_ArelStar.md b/docs/description/Rails_ArelStar.md new file mode 100644 index 00000000..18cd5afb --- /dev/null +++ b/docs/description/Rails_ArelStar.md @@ -0,0 +1,19 @@ + +This cop prevents usage of `"*"` on an Arel::Table column reference. + +Using `arel_table["*"]` causes the outputted string to be a literal +quoted asterisk (e.g. `my_model`.`*`). This causes the +database to look for a column named `*` (or `"*"`) as opposed +to expanding the column list as one would likely expect. + +# Examples + +```ruby +# bad +MyTable.arel_table["*"] + +# good +MyTable.arel_table[Arel.star] +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/ArelStar) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_AssertNot.md b/docs/description/Rails_AssertNot.md similarity index 100% rename from src/main/resources/docs/description/Rails_AssertNot.md rename to docs/description/Rails_AssertNot.md diff --git a/docs/description/Rails_AttributeDefaultBlockValue.md b/docs/description/Rails_AttributeDefaultBlockValue.md new file mode 100644 index 00000000..3b777bcf --- /dev/null +++ b/docs/description/Rails_AttributeDefaultBlockValue.md @@ -0,0 +1,62 @@ + +This cop looks for `attribute` class methods that specify a `:default` option +which value is an array, string literal or method call without a block. +It will accept all other values, such as string, symbol, integer and float literals +as well as constants. + +# Examples + +```ruby +# bad +class User < ApplicationRecord + attribute :confirmed_at, :datetime, default: Time.zone.now +end + +# good +class User < ApplicationRecord + attribute :confirmed_at, :datetime, default: -> { Time.zone.now } +end + +# bad +class User < ApplicationRecord + attribute :roles, :string, array: true, default: [] +end + +# good +class User < ApplicationRecord + attribute :roles, :string, array: true, default: -> { [] } +end + +# bad +class User < ApplicationRecord + attribute :configuration, default: {} +end + +# good +class User < ApplicationRecord + attribute :configuration, default: -> { {} } +end + +# good +class User < ApplicationRecord + attribute :role, :string, default: :customer +end + +# good +class User < ApplicationRecord + attribute :activated, :boolean, default: false +end + +# good +class User < ApplicationRecord + attribute :login_count, :integer, default: 0 +end + +# good +class User < ApplicationRecord + FOO = 123 + attribute :custom_attribute, :integer, default: FOO +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/AttributeDefaultBlockValue) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_BelongsTo.md b/docs/description/Rails_BelongsTo.md similarity index 100% rename from src/main/resources/docs/description/Rails_BelongsTo.md rename to docs/description/Rails_BelongsTo.md diff --git a/src/main/resources/docs/description/Rails_Blank.md b/docs/description/Rails_Blank.md similarity index 100% rename from src/main/resources/docs/description/Rails_Blank.md rename to docs/description/Rails_Blank.md diff --git a/src/main/resources/docs/description/Rails_BulkChangeTable.md b/docs/description/Rails_BulkChangeTable.md similarity index 100% rename from src/main/resources/docs/description/Rails_BulkChangeTable.md rename to docs/description/Rails_BulkChangeTable.md diff --git a/src/main/resources/docs/description/Rails_ContentTag.md b/docs/description/Rails_ContentTag.md similarity index 100% rename from src/main/resources/docs/description/Rails_ContentTag.md rename to docs/description/Rails_ContentTag.md diff --git a/src/main/resources/docs/description/Rails_CreateTableWithTimestamps.md b/docs/description/Rails_CreateTableWithTimestamps.md similarity index 100% rename from src/main/resources/docs/description/Rails_CreateTableWithTimestamps.md rename to docs/description/Rails_CreateTableWithTimestamps.md diff --git a/src/main/resources/docs/description/Rails_Date.md b/docs/description/Rails_Date.md similarity index 100% rename from src/main/resources/docs/description/Rails_Date.md rename to docs/description/Rails_Date.md diff --git a/docs/description/Rails_DefaultScope.md b/docs/description/Rails_DefaultScope.md new file mode 100644 index 00000000..48196372 --- /dev/null +++ b/docs/description/Rails_DefaultScope.md @@ -0,0 +1,24 @@ + +This cop looks for uses of `default_scope`. + +# Examples + +```ruby +# bad +default_scope -> { where(hidden: false) } + +# good +scope :published, -> { where(hidden: false) } + +# bad +def self.default_scope + where(hidden: false) +end + +# good +def self.published + where(hidden: false) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/DefaultScope) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_Delegate.md b/docs/description/Rails_Delegate.md similarity index 100% rename from src/main/resources/docs/description/Rails_Delegate.md rename to docs/description/Rails_Delegate.md diff --git a/src/main/resources/docs/description/Rails_DelegateAllowBlank.md b/docs/description/Rails_DelegateAllowBlank.md similarity index 100% rename from src/main/resources/docs/description/Rails_DelegateAllowBlank.md rename to docs/description/Rails_DelegateAllowBlank.md diff --git a/src/main/resources/docs/description/Rails_DynamicFindBy.md b/docs/description/Rails_DynamicFindBy.md similarity index 100% rename from src/main/resources/docs/description/Rails_DynamicFindBy.md rename to docs/description/Rails_DynamicFindBy.md diff --git a/src/main/resources/docs/description/Rails_EnumHash.md b/docs/description/Rails_EnumHash.md similarity index 100% rename from src/main/resources/docs/description/Rails_EnumHash.md rename to docs/description/Rails_EnumHash.md diff --git a/src/main/resources/docs/description/Rails_EnumUniqueness.md b/docs/description/Rails_EnumUniqueness.md similarity index 100% rename from src/main/resources/docs/description/Rails_EnumUniqueness.md rename to docs/description/Rails_EnumUniqueness.md diff --git a/src/main/resources/docs/description/Rails_EnvironmentComparison.md b/docs/description/Rails_EnvironmentComparison.md similarity index 100% rename from src/main/resources/docs/description/Rails_EnvironmentComparison.md rename to docs/description/Rails_EnvironmentComparison.md diff --git a/src/main/resources/docs/description/Rails_Exit.md b/docs/description/Rails_Exit.md similarity index 100% rename from src/main/resources/docs/description/Rails_Exit.md rename to docs/description/Rails_Exit.md diff --git a/src/main/resources/docs/description/Rails_FilePath.md b/docs/description/Rails_FilePath.md similarity index 100% rename from src/main/resources/docs/description/Rails_FilePath.md rename to docs/description/Rails_FilePath.md diff --git a/src/main/resources/docs/description/Rails_FindBy.md b/docs/description/Rails_FindBy.md similarity index 100% rename from src/main/resources/docs/description/Rails_FindBy.md rename to docs/description/Rails_FindBy.md diff --git a/docs/description/Rails_FindById.md b/docs/description/Rails_FindById.md new file mode 100644 index 00000000..849af8f0 --- /dev/null +++ b/docs/description/Rails_FindById.md @@ -0,0 +1,18 @@ + +This cop enforces that `ActiveRecord#find` is used instead of +`where.take!`, `find_by!`, and `find_by_id!` to retrieve a single record +by primary key when you expect it to be found. + +# Examples + +```ruby +# bad +User.where(id: id).take! +User.find_by_id!(id) +User.find_by!(id: id) + +# good +User.find(id) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/FindById) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_FindEach.md b/docs/description/Rails_FindEach.md similarity index 82% rename from src/main/resources/docs/description/Rails_FindEach.md rename to docs/description/Rails_FindEach.md index a360f6ce..6699b5cc 100644 --- a/src/main/resources/docs/description/Rails_FindEach.md +++ b/docs/description/Rails_FindEach.md @@ -9,7 +9,8 @@ change them to use `all.find_each` instead. User.all.each # good -User.all.find_each +User.all.find_each# good +User.order(:foo).each ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/FindEach) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_HasAndBelongsToMany.md b/docs/description/Rails_HasAndBelongsToMany.md similarity index 100% rename from src/main/resources/docs/description/Rails_HasAndBelongsToMany.md rename to docs/description/Rails_HasAndBelongsToMany.md diff --git a/src/main/resources/docs/description/Rails_HasManyOrHasOneDependent.md b/docs/description/Rails_HasManyOrHasOneDependent.md similarity index 100% rename from src/main/resources/docs/description/Rails_HasManyOrHasOneDependent.md rename to docs/description/Rails_HasManyOrHasOneDependent.md diff --git a/src/main/resources/docs/description/Rails_HelperInstanceVariable.md b/docs/description/Rails_HelperInstanceVariable.md similarity index 73% rename from src/main/resources/docs/description/Rails_HelperInstanceVariable.md rename to docs/description/Rails_HelperInstanceVariable.md index 0f3bb9a1..fe582889 100644 --- a/src/main/resources/docs/description/Rails_HelperInstanceVariable.md +++ b/docs/description/Rails_HelperInstanceVariable.md @@ -9,6 +9,9 @@ If it seems awkward to explicitly pass in each dependent variable, consider moving the behaviour elsewhere, for example to a model, decorator or presenter. +Provided that a class inherits `ActionView::Helpers::FormBuilder`, +an offense will not be registered. + # Examples ```ruby @@ -21,6 +24,11 @@ end def welcome_message(user) "Hello #{user.name}" end + +# good +class MyFormBuilder < ActionView::Helpers::FormBuilder + @template.do_something +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/HelperInstanceVariable) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_HttpPositionalArguments.md b/docs/description/Rails_HttpPositionalArguments.md similarity index 96% rename from src/main/resources/docs/description/Rails_HttpPositionalArguments.md rename to docs/description/Rails_HttpPositionalArguments.md index fcafa516..197e7b7a 100644 --- a/src/main/resources/docs/description/Rails_HttpPositionalArguments.md +++ b/docs/description/Rails_HttpPositionalArguments.md @@ -14,6 +14,7 @@ get :new, { user_id: 1} # good get :new, params: { user_id: 1 } +get :new, **options ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/HttpPositionalArguments) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_HttpStatus.md b/docs/description/Rails_HttpStatus.md similarity index 100% rename from src/main/resources/docs/description/Rails_HttpStatus.md rename to docs/description/Rails_HttpStatus.md diff --git a/src/main/resources/docs/description/Rails_IgnoredSkipActionFilterOption.md b/docs/description/Rails_IgnoredSkipActionFilterOption.md similarity index 100% rename from src/main/resources/docs/description/Rails_IgnoredSkipActionFilterOption.md rename to docs/description/Rails_IgnoredSkipActionFilterOption.md diff --git a/src/main/resources/docs/description/Rails_IndexBy.md b/docs/description/Rails_IndexBy.md similarity index 93% rename from src/main/resources/docs/description/Rails_IndexBy.md rename to docs/description/Rails_IndexBy.md index 3f3cfb55..5ca34e01 100644 --- a/src/main/resources/docs/description/Rails_IndexBy.md +++ b/docs/description/Rails_IndexBy.md @@ -9,6 +9,7 @@ Rails provides the `index_by` method for this purpose. ```ruby # bad [1, 2, 3].each_with_object({}) { |el, h| h[foo(el)] = el } +[1, 2, 3].to_h { |el| [foo(el), el] } [1, 2, 3].map { |el| [foo(el), el] }.to_h Hash[[1, 2, 3].collect { |el| [foo(el), el] }] diff --git a/src/main/resources/docs/description/Rails_IndexWith.md b/docs/description/Rails_IndexWith.md similarity index 93% rename from src/main/resources/docs/description/Rails_IndexWith.md rename to docs/description/Rails_IndexWith.md index fc563b52..b6ea0b95 100644 --- a/src/main/resources/docs/description/Rails_IndexWith.md +++ b/docs/description/Rails_IndexWith.md @@ -9,6 +9,7 @@ Rails provides the `index_with` method for this purpose. ```ruby # bad [1, 2, 3].each_with_object({}) { |el, h| h[el] = foo(el) } +[1, 2, 3].to_h { |el| [el, foo(el)] } [1, 2, 3].map { |el| [el, foo(el)] }.to_h Hash[[1, 2, 3].collect { |el| [el, foo(el)] }] diff --git a/docs/description/Rails_Inquiry.md b/docs/description/Rails_Inquiry.md new file mode 100644 index 00000000..58c4d028 --- /dev/null +++ b/docs/description/Rails_Inquiry.md @@ -0,0 +1,24 @@ + +This cop checks that Active Support's `inquiry` method is not used. + +# Examples + +```ruby +# bad - String#inquiry +ruby = 'two'.inquiry +ruby.two? + +# good +ruby = 'two' +ruby == 'two' + +# bad - Array#inquiry +pets = %w(cat dog).inquiry +pets.gopher? + +# good +pets = %w(cat dog) +pets.include? 'cat' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/Inquiry) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_InverseOf.md b/docs/description/Rails_InverseOf.md similarity index 100% rename from src/main/resources/docs/description/Rails_InverseOf.md rename to docs/description/Rails_InverseOf.md diff --git a/src/main/resources/docs/description/Rails_LexicallyScopedActionFilter.md b/docs/description/Rails_LexicallyScopedActionFilter.md similarity index 100% rename from src/main/resources/docs/description/Rails_LexicallyScopedActionFilter.md rename to docs/description/Rails_LexicallyScopedActionFilter.md diff --git a/src/main/resources/docs/description/Rails_LinkToBlank.md b/docs/description/Rails_LinkToBlank.md similarity index 100% rename from src/main/resources/docs/description/Rails_LinkToBlank.md rename to docs/description/Rails_LinkToBlank.md diff --git a/docs/description/Rails_MailerName.md b/docs/description/Rails_MailerName.md new file mode 100644 index 00000000..2530b9bf --- /dev/null +++ b/docs/description/Rails_MailerName.md @@ -0,0 +1,25 @@ + +This cop enforces that mailer names end with `Mailer` suffix. + +Without the `Mailer` suffix it isn't immediately apparent what's a mailer +and which views are related to the mailer. + +# Examples + +```ruby +# bad +class User < ActionMailer::Base +end + +class User < ApplicationMailer +end + +# good +class UserMailer < ActionMailer::Base +end + +class UserMailer < ApplicationMailer +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/MailerName) \ No newline at end of file diff --git a/docs/description/Rails_MatchRoute.md b/docs/description/Rails_MatchRoute.md new file mode 100644 index 00000000..c1cd21ae --- /dev/null +++ b/docs/description/Rails_MatchRoute.md @@ -0,0 +1,22 @@ + +This cop identifies places where defining routes with `match` +can be replaced with a specific HTTP method. + +Don't use `match` to define any routes unless there is a need to map multiple request types +among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option. + +# Examples + +```ruby +# bad +match ':controller/:action/:id' +match 'photos/:id', to: 'photos#show', via: :get + +# good +get ':controller/:action/:id' +get 'photos/:id', to: 'photos#show' +match 'photos/:id', to: 'photos#show', via: [:get, :post] +match 'photos/:id', to: 'photos#show', via: :all +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/MatchRoute) \ No newline at end of file diff --git a/docs/description/Rails_NegateInclude.md b/docs/description/Rails_NegateInclude.md new file mode 100644 index 00000000..49719cb1 --- /dev/null +++ b/docs/description/Rails_NegateInclude.md @@ -0,0 +1,20 @@ + +This cop enforces the use of `collection.exclude?(obj)` +over `!collection.include?(obj)`. + +It is marked as unsafe by default because false positive will occur for +a receiver object that do not have `exclude?` method. (e.g. `IPAddr`) + +# Examples + +```ruby +# bad +!array.include?(2) +!hash.include?(:key) + +# good +array.exclude?(2) +hash.exclude?(:key) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/NegateInclude) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_NotNullColumn.md b/docs/description/Rails_NotNullColumn.md similarity index 100% rename from src/main/resources/docs/description/Rails_NotNullColumn.md rename to docs/description/Rails_NotNullColumn.md diff --git a/docs/description/Rails_OrderById.md b/docs/description/Rails_OrderById.md new file mode 100644 index 00000000..72234b95 --- /dev/null +++ b/docs/description/Rails_OrderById.md @@ -0,0 +1,22 @@ + +This cop checks for places where ordering by `id` column is used. + +Don't use the `id` column for ordering. The sequence of ids is not guaranteed +to be in any particular order, despite often (incidentally) being chronological. +Use a timestamp column to order chronologically. As a bonus the intent is clearer. + +NOTE: Make sure the changed order column does not introduce performance +bottlenecks and appropriate database indexes are added. + +# Examples + +```ruby +# bad +scope :chronological, -> { order(id: :asc) } +scope :chronological, -> { order(primary_key => :asc) } + +# good +scope :chronological, -> { order(created_at: :asc) } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/OrderById) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_Output.md b/docs/description/Rails_Output.md similarity index 100% rename from src/main/resources/docs/description/Rails_Output.md rename to docs/description/Rails_Output.md diff --git a/src/main/resources/docs/description/Rails_OutputSafety.md b/docs/description/Rails_OutputSafety.md similarity index 100% rename from src/main/resources/docs/description/Rails_OutputSafety.md rename to docs/description/Rails_OutputSafety.md diff --git a/docs/description/Rails_Pick.md b/docs/description/Rails_Pick.md new file mode 100644 index 00000000..00110d7e --- /dev/null +++ b/docs/description/Rails_Pick.md @@ -0,0 +1,20 @@ + +This cop enforces the use of `pick` over `pluck(...).first`. + +Using `pluck` followed by `first` creates an intermediate array, which +`pick` avoids. When called on an Active Record relation, `pick` adds a +limit to the query so that only one value is fetched from the database. + +# Examples + +```ruby +# bad +Model.pluck(:a).first +[{ a: :b, c: :d }].pluck(:a, :b).first + +# good +Model.pick(:a) +[{ a: :b, c: :d }].pick(:a, :b) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/Pick) \ No newline at end of file diff --git a/docs/description/Rails_Pluck.md b/docs/description/Rails_Pluck.md new file mode 100644 index 00000000..278fa84d --- /dev/null +++ b/docs/description/Rails_Pluck.md @@ -0,0 +1,20 @@ + +This cop enforces the use of `pluck` over `map`. + +`pluck` can be used instead of `map` to extract a single key from each +element in an enumerable. When called on an Active Record relation, it +results in a more efficient query that only selects the necessary key. + +# Examples + +```ruby +# bad +Post.published.map { |post| post[:title] } +[{ a: :b, c: :d }].collect { |el| el[:a] } + +# good +Post.published.pluck(:title) +[{ a: :b, c: :d }].pluck(:a) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/Pluck) \ No newline at end of file diff --git a/docs/description/Rails_PluckId.md b/docs/description/Rails_PluckId.md new file mode 100644 index 00000000..1d1e5e16 --- /dev/null +++ b/docs/description/Rails_PluckId.md @@ -0,0 +1,24 @@ + +This cop enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`. + +# Examples + +```ruby +# bad +User.pluck(:id) +user.posts.pluck(:id) + +def self.user_ids + pluck(primary_key) +end + +# good +User.ids +user.posts.ids + +def self.user_ids + ids +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/PluckId) \ No newline at end of file diff --git a/docs/description/Rails_PluckInWhere.md b/docs/description/Rails_PluckInWhere.md new file mode 100644 index 00000000..0fc25e30 --- /dev/null +++ b/docs/description/Rails_PluckInWhere.md @@ -0,0 +1,30 @@ + +This cop identifies places where `pluck` is used in `where` query methods +and can be replaced with `select`. + +Since `pluck` is an eager method and hits the database immediately, +using `select` helps to avoid additional database queries. + +This cop has two different enforcement modes. When the EnforcedStyle +is conservative (the default) then only calls to `pluck` on a constant +(i.e. a model class) in the `where` is used as offenses. + +When the EnforcedStyle is aggressive then all calls to `pluck` in the +`where` is used as offenses. This may lead to false positives +as the cop cannot replace to `select` between calls to `pluck` on an +`ActiveRecord::Relation` instance vs a call to `pluck` on an `Array` instance. + +# Examples + +```ruby +# bad +Post.where(user_id: User.active.pluck(:id)) + +# good +Post.where(user_id: User.active.select(:id)) +Post.where(user_id: active_users.select(:id))# good +Post.where(user_id: active_users.pluck(:id))# bad +Post.where(user_id: active_users.pluck(:id)) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/PluckInWhere) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_PluralizationGrammar.md b/docs/description/Rails_PluralizationGrammar.md similarity index 100% rename from src/main/resources/docs/description/Rails_PluralizationGrammar.md rename to docs/description/Rails_PluralizationGrammar.md diff --git a/src/main/resources/docs/description/Rails_Presence.md b/docs/description/Rails_Presence.md similarity index 100% rename from src/main/resources/docs/description/Rails_Presence.md rename to docs/description/Rails_Presence.md diff --git a/src/main/resources/docs/description/Rails_Present.md b/docs/description/Rails_Present.md similarity index 100% rename from src/main/resources/docs/description/Rails_Present.md rename to docs/description/Rails_Present.md diff --git a/src/main/resources/docs/description/Rails_RakeEnvironment.md b/docs/description/Rails_RakeEnvironment.md similarity index 100% rename from src/main/resources/docs/description/Rails_RakeEnvironment.md rename to docs/description/Rails_RakeEnvironment.md diff --git a/src/main/resources/docs/description/Rails_ReadWriteAttribute.md b/docs/description/Rails_ReadWriteAttribute.md similarity index 100% rename from src/main/resources/docs/description/Rails_ReadWriteAttribute.md rename to docs/description/Rails_ReadWriteAttribute.md diff --git a/src/main/resources/docs/description/Rails_RedundantAllowNil.md b/docs/description/Rails_RedundantAllowNil.md similarity index 100% rename from src/main/resources/docs/description/Rails_RedundantAllowNil.md rename to docs/description/Rails_RedundantAllowNil.md diff --git a/src/main/resources/docs/description/Rails_RedundantForeignKey.md b/docs/description/Rails_RedundantForeignKey.md similarity index 100% rename from src/main/resources/docs/description/Rails_RedundantForeignKey.md rename to docs/description/Rails_RedundantForeignKey.md diff --git a/src/main/resources/docs/description/Rails_RedundantReceiverInWithOptions.md b/docs/description/Rails_RedundantReceiverInWithOptions.md similarity index 100% rename from src/main/resources/docs/description/Rails_RedundantReceiverInWithOptions.md rename to docs/description/Rails_RedundantReceiverInWithOptions.md diff --git a/src/main/resources/docs/description/Rails_ReflectionClassName.md b/docs/description/Rails_ReflectionClassName.md similarity index 100% rename from src/main/resources/docs/description/Rails_ReflectionClassName.md rename to docs/description/Rails_ReflectionClassName.md diff --git a/src/main/resources/docs/description/Rails_RefuteMethods.md b/docs/description/Rails_RefuteMethods.md similarity index 100% rename from src/main/resources/docs/description/Rails_RefuteMethods.md rename to docs/description/Rails_RefuteMethods.md diff --git a/src/main/resources/docs/description/Rails_RelativeDateConstant.md b/docs/description/Rails_RelativeDateConstant.md similarity index 100% rename from src/main/resources/docs/description/Rails_RelativeDateConstant.md rename to docs/description/Rails_RelativeDateConstant.md diff --git a/docs/description/Rails_RenderInline.md b/docs/description/Rails_RenderInline.md new file mode 100644 index 00000000..d1925c1a --- /dev/null +++ b/docs/description/Rails_RenderInline.md @@ -0,0 +1,26 @@ + +This cop looks for inline rendering within controller actions. + +# Examples + +```ruby +# bad +class ProductsController < ApplicationController + def index + render inline: "<% products.each do |p| %>

<%= p.name %>

<% end %>", type: :erb + end +end + +# good +# app/views/products/index.html.erb +# <% products.each do |p| %> +#

<%= p.name %>

+# <% end %> + +class ProductsController < ApplicationController + def index + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/RenderInline) \ No newline at end of file diff --git a/docs/description/Rails_RenderPlainText.md b/docs/description/Rails_RenderPlainText.md new file mode 100644 index 00000000..62a277bd --- /dev/null +++ b/docs/description/Rails_RenderPlainText.md @@ -0,0 +1,20 @@ + +This cop identifies places where `render text:` can be +replaced with `render plain:`. + +# Examples + +```ruby +# bad - explicit MIME type to `text/plain` +render text: 'Ruby!', content_type: 'text/plain' + +# good - short and precise +render plain: 'Ruby!' + +# good - explicit MIME type not to `text/plain` +render text: 'Ruby!', content_type: 'text/html'# good - sets MIME type to `text/html` +render text: 'Ruby!'# bad - sets MIME type to `text/html` +render text: 'Ruby!' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/RenderPlainText) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_RequestReferer.md b/docs/description/Rails_RequestReferer.md similarity index 100% rename from src/main/resources/docs/description/Rails_RequestReferer.md rename to docs/description/Rails_RequestReferer.md diff --git a/src/main/resources/docs/description/Rails_ReversibleMigration.md b/docs/description/Rails_ReversibleMigration.md similarity index 72% rename from src/main/resources/docs/description/Rails_ReversibleMigration.md rename to docs/description/Rails_ReversibleMigration.md index a7b5f9c7..ab9b8e2b 100644 --- a/src/main/resources/docs/description/Rails_ReversibleMigration.md +++ b/docs/description/Rails_ReversibleMigration.md @@ -110,6 +110,45 @@ def change end end end +end# remove_columns + +# bad +def change + remove_columns :users, :name, :email +end + +# good +def change + reversible do |dir| + dir.up do + remove_columns :users, :name, :email + end + + dir.down do + add_column :users, :name, :string + add_column :users, :email, :string + end + end +end + +# good (Rails >= 6.1, see /~https://github.com/rails/rails/pull/36589) +def change + remove_columns :users, :name, :email, type: :string +end# remove_index + +# bad +def change + remove_index :users, name: :index_users_on_email +end + +# good +def change + remove_index :users, :email +end + +# good +def change + remove_index :users, column: :email end ``` diff --git a/src/main/resources/docs/description/Rails_SafeNavigation.md b/docs/description/Rails_SafeNavigation.md similarity index 100% rename from src/main/resources/docs/description/Rails_SafeNavigation.md rename to docs/description/Rails_SafeNavigation.md diff --git a/src/main/resources/docs/description/Rails_SafeNavigationWithBlank.md b/docs/description/Rails_SafeNavigationWithBlank.md similarity index 100% rename from src/main/resources/docs/description/Rails_SafeNavigationWithBlank.md rename to docs/description/Rails_SafeNavigationWithBlank.md diff --git a/src/main/resources/docs/description/Rails_SaveBang.md b/docs/description/Rails_SaveBang.md similarity index 100% rename from src/main/resources/docs/description/Rails_SaveBang.md rename to docs/description/Rails_SaveBang.md diff --git a/src/main/resources/docs/description/Rails_ScopeArgs.md b/docs/description/Rails_ScopeArgs.md similarity index 100% rename from src/main/resources/docs/description/Rails_ScopeArgs.md rename to docs/description/Rails_ScopeArgs.md diff --git a/docs/description/Rails_ShortI18n.md b/docs/description/Rails_ShortI18n.md new file mode 100644 index 00000000..5ed44257 --- /dev/null +++ b/docs/description/Rails_ShortI18n.md @@ -0,0 +1,34 @@ + +This cop enforces that short forms of `I18n` methods are used: +`t` instead of `translate` and `l` instead of `localize`. + +This cop has two different enforcement modes. When the EnforcedStyle +is conservative (the default) then only `I18n.translate` and `I18n.localize` +calls are added as offenses. + +When the EnforcedStyle is aggressive then all `translate` and `localize` calls +without a receiver are added as offenses. + +# Examples + +```ruby +# bad +I18n.translate :key +I18n.localize Time.now + +# good +I18n.t :key +I18n.l Time.now# good +translate :key +localize Time.now +t :key +l Time.now# bad +translate :key +localize Time.now + +# good +t :key +l Time.now +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/ShortI18n) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_SkipsModelValidations.md b/docs/description/Rails_SkipsModelValidations.md similarity index 92% rename from src/main/resources/docs/description/Rails_SkipsModelValidations.md rename to docs/description/Rails_SkipsModelValidations.md index 911569d0..1f865f2c 100644 --- a/src/main/resources/docs/description/Rails_SkipsModelValidations.md +++ b/docs/description/Rails_SkipsModelValidations.md @@ -3,7 +3,7 @@ This cop checks for the use of methods which skip validations which are listed in https://guides.rubyonrails.org/active_record_validations.html#skipping-validations -Methods may be ignored from this rule by configuring a `Whitelist`. +Methods may be ignored from this rule by configuring a `AllowedMethods`. # Examples diff --git a/docs/description/Rails_SquishedSQLHeredocs.md b/docs/description/Rails_SquishedSQLHeredocs.md new file mode 100644 index 00000000..3dfa4edb --- /dev/null +++ b/docs/description/Rails_SquishedSQLHeredocs.md @@ -0,0 +1,40 @@ + +Checks SQL heredocs to use `.squish`. +Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines +to be preserved in order to work, thus auto-correction for this cop is not safe. + +# Examples + +```ruby +# bad +<<-SQL + SELECT * FROM posts; +SQL + +<<-SQL + SELECT * FROM posts + WHERE id = 1 +SQL + +execute(<<~SQL, "Post Load") + SELECT * FROM posts + WHERE post_id = 1 +SQL + +# good +<<-SQL.squish + SELECT * FROM posts; +SQL + +<<~SQL.squish + SELECT * FROM table + WHERE id = 1 +SQL + +execute(<<~SQL.squish, "Post Load") + SELECT * FROM posts + WHERE post_id = 1 +SQL +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/SquishedSQLHeredocs) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_TimeZone.md b/docs/description/Rails_TimeZone.md similarity index 100% rename from src/main/resources/docs/description/Rails_TimeZone.md rename to docs/description/Rails_TimeZone.md diff --git a/src/main/resources/docs/description/Rails_UniqBeforePluck.md b/docs/description/Rails_UniqBeforePluck.md similarity index 83% rename from src/main/resources/docs/description/Rails_UniqBeforePluck.md rename to docs/description/Rails_UniqBeforePluck.md index eef043be..81a9f0f8 100644 --- a/src/main/resources/docs/description/Rails_UniqBeforePluck.md +++ b/docs/description/Rails_UniqBeforePluck.md @@ -14,6 +14,8 @@ as the cop cannot distinguish between calls to pluck on an ActiveRecord::Relation vs a call to pluck on an ActiveRecord::Associations::CollectionProxy. +This cop is unsafe because the behavior may change depending on the +database collation. Autocorrect is disabled by default for this cop since it may generate false positives. @@ -21,19 +23,19 @@ false positives. ```ruby # bad -Model.pluck(:id).distinct +Model.pluck(:id).uniq # good Model.distinct.pluck(:id)# bad # this will return a Relation that pluck is called on -Model.where(cond: true).pluck(:id).distinct +Model.where(cond: true).pluck(:id).uniq # bad # an association on an instance will return a CollectionProxy -instance.assoc.pluck(:id).distinct +instance.assoc.pluck(:id).uniq # bad -Model.pluck(:id).distinct +Model.pluck(:id).uniq # good Model.distinct.pluck(:id) diff --git a/src/main/resources/docs/description/Rails_UniqueValidationWithoutIndex.md b/docs/description/Rails_UniqueValidationWithoutIndex.md similarity index 100% rename from src/main/resources/docs/description/Rails_UniqueValidationWithoutIndex.md rename to docs/description/Rails_UniqueValidationWithoutIndex.md diff --git a/src/main/resources/docs/description/Rails_UnknownEnv.md b/docs/description/Rails_UnknownEnv.md similarity index 63% rename from src/main/resources/docs/description/Rails_UnknownEnv.md rename to docs/description/Rails_UnknownEnv.md index f05b1d47..8cf02e0e 100644 --- a/src/main/resources/docs/description/Rails_UnknownEnv.md +++ b/docs/description/Rails_UnknownEnv.md @@ -1,6 +1,9 @@ This cop checks that environments called with `Rails.env` predicates exist. +By default the cop allows three environments which Rails ships with: +`development`, `test`, and `production`. +More can be added to the `Environments` config parameter. # Examples diff --git a/src/main/resources/docs/description/Rails_Validation.md b/docs/description/Rails_Validation.md similarity index 100% rename from src/main/resources/docs/description/Rails_Validation.md rename to docs/description/Rails_Validation.md diff --git a/docs/description/Rails_WhereEquals.md b/docs/description/Rails_WhereEquals.md new file mode 100644 index 00000000..8ec7b94c --- /dev/null +++ b/docs/description/Rails_WhereEquals.md @@ -0,0 +1,23 @@ + +This cop identifies places where manually constructed SQL +in `where` can be replaced with `where(attribute: value)`. + +# Examples + +```ruby +# bad +User.where('name = ?', 'Gabe') +User.where('name = :name', name: 'Gabe') +User.where('name IS NULL') +User.where('name IN (?)', ['john', 'jane']) +User.where('name IN (:names)', names: ['john', 'jane']) +User.where('users.name = :name', name: 'Gabe') + +# good +User.where(name: 'Gabe') +User.where(name: nil) +User.where(name: ['john', 'jane']) +User.where(users: { name: 'Gabe' }) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/WhereEquals) \ No newline at end of file diff --git a/docs/description/Rails_WhereExists.md b/docs/description/Rails_WhereExists.md new file mode 100644 index 00000000..63990c99 --- /dev/null +++ b/docs/description/Rails_WhereExists.md @@ -0,0 +1,36 @@ + +This cop enforces consistent style when using `exists?`. + +Two styles are supported for this cop. When EnforcedStyle is 'exists' +then the cop enforces `exists?(...)` over `where(...).exists?`. + +When EnforcedStyle is 'where' then the cop enforces +`where(...).exists?` over `exists?(...)`. + +# Examples + +```ruby +# bad +User.where(name: 'john').exists? +User.where(['name = ?', 'john']).exists? +User.where('name = ?', 'john').exists? +user.posts.where(published: true).exists? + +# good +User.exists?(name: 'john') +User.where('length(name) > 10').exists? +user.posts.exists?(published: true)# bad +User.exists?(name: 'john') +User.exists?(['name = ?', 'john']) +User.exists?('name = ?', 'john') +user.posts.exists?(published: true) + +# good +User.where(name: 'john').exists? +User.where(['name = ?', 'john']).exists? +User.where('name = ?', 'john').exists? +user.posts.where(published: true).exists? +User.where('length(name) > 10').exists? +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/WhereExists) \ No newline at end of file diff --git a/docs/description/Rails_WhereNot.md b/docs/description/Rails_WhereNot.md new file mode 100644 index 00000000..d3135e72 --- /dev/null +++ b/docs/description/Rails_WhereNot.md @@ -0,0 +1,23 @@ + +This cop identifies places where manually constructed SQL +in `where` can be replaced with `where.not(...)`. + +# Examples + +```ruby +# bad +User.where('name != ?', 'Gabe') +User.where('name != :name', name: 'Gabe') +User.where('name <> ?', 'Gabe') +User.where('name <> :name', name: 'Gabe') +User.where('name IS NOT NULL') +User.where('name NOT IN (?)', ['john', 'jane']) +User.where('name NOT IN (:names)', names: ['john', 'jane']) + +# good +User.where.not(name: 'Gabe') +User.where.not(name: nil) +User.where.not(name: ['john', 'jane']) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/WhereNot) \ No newline at end of file diff --git a/src/main/resources/docs/description/Security_Eval.md b/docs/description/Security_Eval.md similarity index 100% rename from src/main/resources/docs/description/Security_Eval.md rename to docs/description/Security_Eval.md diff --git a/src/main/resources/docs/description/Security_JSONLoad.md b/docs/description/Security_JSONLoad.md similarity index 100% rename from src/main/resources/docs/description/Security_JSONLoad.md rename to docs/description/Security_JSONLoad.md diff --git a/src/main/resources/docs/description/Security_MarshalLoad.md b/docs/description/Security_MarshalLoad.md similarity index 100% rename from src/main/resources/docs/description/Security_MarshalLoad.md rename to docs/description/Security_MarshalLoad.md diff --git a/docs/description/Security_Open.md b/docs/description/Security_Open.md new file mode 100644 index 00000000..1c6f459f --- /dev/null +++ b/docs/description/Security_Open.md @@ -0,0 +1,23 @@ + +This cop checks for the use of `Kernel#open` and `URI.open`. + +`Kernel#open` and `URI.open` enable not only file access but also process +invocation by prefixing a pipe symbol (e.g., `open("| ls")`). +So, it may lead to a serious security risk by using variable input to +the argument of `Kernel#open` and `URI.open`. It would be better to use +`File.open`, `IO.popen` or `URI.parse#open` explicitly. + +# Examples + +```ruby +# bad +open(something) +URI.open(something) + +# good +File.open(something) +IO.popen(something) +URI.parse(something).open +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Security/Open) \ No newline at end of file diff --git a/src/main/resources/docs/description/Security_YAMLLoad.md b/docs/description/Security_YAMLLoad.md similarity index 100% rename from src/main/resources/docs/description/Security_YAMLLoad.md rename to docs/description/Security_YAMLLoad.md diff --git a/src/main/resources/docs/description/Style_AccessModifierDeclarations.md b/docs/description/Style_AccessModifierDeclarations.md similarity index 100% rename from src/main/resources/docs/description/Style_AccessModifierDeclarations.md rename to docs/description/Style_AccessModifierDeclarations.md diff --git a/docs/description/Style_AccessorGrouping.md b/docs/description/Style_AccessorGrouping.md new file mode 100644 index 00000000..070930f7 --- /dev/null +++ b/docs/description/Style_AccessorGrouping.md @@ -0,0 +1,33 @@ + +This cop checks for grouping of accessors in `class` and `module` bodies. +By default it enforces accessors to be placed in grouped declarations, +but it can be configured to enforce separating them in multiple declarations. + +NOTE: `Sorbet` is not compatible with "grouped" style. Consider "separated" style +or disabling this cop. + +# Examples + +```ruby +# bad +class Foo + attr_reader :bar + attr_reader :baz +end + +# good +class Foo + attr_reader :bar, :baz +end# bad +class Foo + attr_reader :bar, :baz +end + +# good +class Foo + attr_reader :bar + attr_reader :baz +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/AccessorGrouping) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_Alias.md b/docs/description/Style_Alias.md similarity index 100% rename from src/main/resources/docs/description/Style_Alias.md rename to docs/description/Style_Alias.md diff --git a/src/main/resources/docs/description/Style_AndOr.md b/docs/description/Style_AndOr.md similarity index 100% rename from src/main/resources/docs/description/Style_AndOr.md rename to docs/description/Style_AndOr.md diff --git a/docs/description/Style_ArgumentsForwarding.md b/docs/description/Style_ArgumentsForwarding.md new file mode 100644 index 00000000..d4a173a2 --- /dev/null +++ b/docs/description/Style_ArgumentsForwarding.md @@ -0,0 +1,34 @@ + +In Ruby 2.7, arguments forwarding has been added. + +This cop identifies places where `do_something(*args, &block)` +can be replaced by `do_something(...)`. + +# Examples + +```ruby +# bad +def foo(*args, &block) + bar(*args, &block) +end + +# bad +def foo(*args, **kwargs, &block) + bar(*args, **kwargs, &block) +end + +# good +def foo(...) + bar(...) +end# good +def foo(*args) + bar(*args) +end# bad +# The following code can replace the arguments with `...`, +# but it will change the behavior. Because `...` forwards block also. +def foo(*args) + bar(*args) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ArgumentsForwarding) \ No newline at end of file diff --git a/docs/description/Style_ArrayCoercion.md b/docs/description/Style_ArrayCoercion.md new file mode 100644 index 00000000..475f1154 --- /dev/null +++ b/docs/description/Style_ArrayCoercion.md @@ -0,0 +1,22 @@ + +This cop enforces the use of `Array()` instead of explicit `Array` check or `[*var]`. + +This cop is disabled by default because false positive will occur if +the argument of `Array()` is not an array (e.g. Hash, Set), +an array will be returned as an incompatibility result. + +# Examples + +```ruby +# bad +paths = [paths] unless paths.is_a?(Array) +paths.each { |path| do_something(path) } + +# bad (always creates a new Array instance) +[*paths].each { |path| do_something(path) } + +# good (and a bit more readable) +Array(paths).each { |path| do_something(path) } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ArrayCoercion) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_ArrayJoin.md b/docs/description/Style_ArrayJoin.md similarity index 84% rename from src/main/resources/docs/description/Style_ArrayJoin.md rename to docs/description/Style_ArrayJoin.md index 2423c63d..27c0fbe6 100644 --- a/src/main/resources/docs/description/Style_ArrayJoin.md +++ b/docs/description/Style_ArrayJoin.md @@ -1,5 +1,5 @@ -This cop checks for uses of "\*" as a substitute for *join*. +This cop checks for uses of "*" as a substitute for _join_. Not all cases can reliably checked, due to Ruby's dynamic types, so we consider only cases when the first argument is an diff --git a/src/main/resources/docs/description/Style_AsciiComments.md b/docs/description/Style_AsciiComments.md similarity index 83% rename from src/main/resources/docs/description/Style_AsciiComments.md rename to docs/description/Style_AsciiComments.md index 4f491365..e0528fc9 100644 --- a/src/main/resources/docs/description/Style_AsciiComments.md +++ b/docs/description/Style_AsciiComments.md @@ -1,7 +1,7 @@ This cop checks for non-ascii (non-English) characters in comments. You could set an array of allowed non-ascii chars in -AllowedChars attribute (empty by default). +`AllowedChars` attribute (copyright notice "©" by default). # Examples diff --git a/src/main/resources/docs/description/Style_Attr.md b/docs/description/Style_Attr.md similarity index 100% rename from src/main/resources/docs/description/Style_Attr.md rename to docs/description/Style_Attr.md diff --git a/src/main/resources/docs/description/Style_AutoResourceCleanup.md b/docs/description/Style_AutoResourceCleanup.md similarity index 100% rename from src/main/resources/docs/description/Style_AutoResourceCleanup.md rename to docs/description/Style_AutoResourceCleanup.md diff --git a/src/main/resources/docs/description/Style_BarePercentLiterals.md b/docs/description/Style_BarePercentLiterals.md similarity index 100% rename from src/main/resources/docs/description/Style_BarePercentLiterals.md rename to docs/description/Style_BarePercentLiterals.md diff --git a/src/main/resources/docs/description/Style_BeginBlock.md b/docs/description/Style_BeginBlock.md similarity index 100% rename from src/main/resources/docs/description/Style_BeginBlock.md rename to docs/description/Style_BeginBlock.md diff --git a/docs/description/Style_BisectedAttrAccessor.md b/docs/description/Style_BisectedAttrAccessor.md new file mode 100644 index 00000000..7ac14d1a --- /dev/null +++ b/docs/description/Style_BisectedAttrAccessor.md @@ -0,0 +1,20 @@ + +This cop checks for places where `attr_reader` and `attr_writer` +for the same method can be combined into single `attr_accessor`. + +# Examples + +```ruby +# bad +class Foo + attr_reader :bar + attr_writer :bar +end + +# good +class Foo + attr_accessor :bar +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/BisectedAttrAccessor) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_BlockComments.md b/docs/description/Style_BlockComments.md similarity index 100% rename from src/main/resources/docs/description/Style_BlockComments.md rename to docs/description/Style_BlockComments.md diff --git a/src/main/resources/docs/description/Style_BlockDelimiters.md b/docs/description/Style_BlockDelimiters.md similarity index 100% rename from src/main/resources/docs/description/Style_BlockDelimiters.md rename to docs/description/Style_BlockDelimiters.md diff --git a/src/main/resources/docs/description/Style_CaseEquality.md b/docs/description/Style_CaseEquality.md similarity index 82% rename from src/main/resources/docs/description/Style_CaseEquality.md rename to docs/description/Style_CaseEquality.md index 0e5ae368..17e7b22f 100644 --- a/src/main/resources/docs/description/Style_CaseEquality.md +++ b/docs/description/Style_CaseEquality.md @@ -12,7 +12,7 @@ Array === something # good something.is_a?(Array) (1..100).include?(7) -some_string =~ /something/# Style/CaseEquality: +/something/.match?(some_string)# Style/CaseEquality: # AllowOnConstant: true # bad @@ -22,7 +22,7 @@ some_string =~ /something/# Style/CaseEquality: # good Array === something (1..100).include?(7) -some_string =~ /something/ +/something/.match?(some_string) ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/CaseEquality) \ No newline at end of file diff --git a/docs/description/Style_CaseLikeIf.md b/docs/description/Style_CaseLikeIf.md new file mode 100644 index 00000000..aabc5ff4 --- /dev/null +++ b/docs/description/Style_CaseLikeIf.md @@ -0,0 +1,28 @@ + +This cop identifies places where `if-elsif` constructions +can be replaced with `case-when`. + +# Examples + +```ruby +# bad +if status == :active + perform_action +elsif status == :inactive || status == :hibernating + check_timeout +else + final_action +end + +# good +case status +when :active + perform_action +when :inactive, :hibernating + check_timeout +else + final_action +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/CaseLikeIf) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_CharacterLiteral.md b/docs/description/Style_CharacterLiteral.md similarity index 100% rename from src/main/resources/docs/description/Style_CharacterLiteral.md rename to docs/description/Style_CharacterLiteral.md diff --git a/src/main/resources/docs/description/Style_ClassAndModuleChildren.md b/docs/description/Style_ClassAndModuleChildren.md similarity index 100% rename from src/main/resources/docs/description/Style_ClassAndModuleChildren.md rename to docs/description/Style_ClassAndModuleChildren.md diff --git a/src/main/resources/docs/description/Style_ClassCheck.md b/docs/description/Style_ClassCheck.md similarity index 100% rename from src/main/resources/docs/description/Style_ClassCheck.md rename to docs/description/Style_ClassCheck.md diff --git a/docs/description/Style_ClassEqualityComparison.md b/docs/description/Style_ClassEqualityComparison.md new file mode 100644 index 00000000..149267bd --- /dev/null +++ b/docs/description/Style_ClassEqualityComparison.md @@ -0,0 +1,18 @@ + +This cop enforces the use of `Object#instance_of?` instead of class comparison +for equality. + +# Examples + +```ruby +# bad +var.class == Date +var.class.equal?(Date) +var.class.eql?(Date) +var.class.name == 'Date' + +# good +var.instance_of?(Date) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ClassEqualityComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_ClassMethods.md b/docs/description/Style_ClassMethods.md similarity index 100% rename from src/main/resources/docs/description/Style_ClassMethods.md rename to docs/description/Style_ClassMethods.md diff --git a/docs/description/Style_ClassMethodsDefinitions.md b/docs/description/Style_ClassMethodsDefinitions.md new file mode 100644 index 00000000..fe2db4e7 --- /dev/null +++ b/docs/description/Style_ClassMethodsDefinitions.md @@ -0,0 +1,57 @@ + +This cop enforces using `def self.method_name` or `class << self` to define class methods. + +# Examples + +```ruby +# bad +class SomeClass + class << self + attr_accessor :class_accessor + + def class_method + # ... + end + end +end + +# good +class SomeClass + def self.class_method + # ... + end + + class << self + attr_accessor :class_accessor + end +end + +# good - contains private method +class SomeClass + class << self + attr_accessor :class_accessor + + private + + def private_class_method + # ... + end + end +end# bad +class SomeClass + def self.class_method + # ... + end +end + +# good +class SomeClass + class << self + def class_method + # ... + end + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ClassMethodsDefinitions) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_ClassVars.md b/docs/description/Style_ClassVars.md similarity index 73% rename from src/main/resources/docs/description/Style_ClassVars.md rename to docs/description/Style_ClassVars.md index c409f89f..253d6624 100644 --- a/src/main/resources/docs/description/Style_ClassVars.md +++ b/docs/description/Style_ClassVars.md @@ -17,6 +17,15 @@ class A @@test = 10 end +class A + def self.test(name, value) + class_variable_set("@@#{name}", value) + end +end + +class A; end +A.class_variable_set(:@@test, 10) + # good class A @test = 10 @@ -27,6 +36,12 @@ class A @@test # you can access class variable without offense end end + +class A + def self.test(name) + class_variable_get("@@#{name}") # you can access without offense + end +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ClassVars) \ No newline at end of file diff --git a/docs/description/Style_CollectionCompact.md b/docs/description/Style_CollectionCompact.md new file mode 100644 index 00000000..546b2242 --- /dev/null +++ b/docs/description/Style_CollectionCompact.md @@ -0,0 +1,29 @@ + +This cop checks for places where custom logic on rejection nils from arrays +and hashes can be replaced with `{Array,Hash}#{compact,compact!}`. + +It is marked as unsafe by default because false positives may occur in the +nil check of block arguments to the receiver object. +For example, `[[1, 2], [3, nil]].reject { |first, second| second.nil? }` +and `[[1, 2], [3, nil]].compact` are not compatible. This will work fine +when the receiver is a hash object. + +# Examples + +```ruby +# bad +array.reject { |e| e.nil? } +array.select { |e| !e.nil? } + +# good +array.compact + +# bad +hash.reject! { |k, v| v.nil? } +hash.select! { |k, v| !v.nil? } + +# good +hash.compact! +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/CollectionCompact) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_CollectionMethods.md b/docs/description/Style_CollectionMethods.md similarity index 100% rename from src/main/resources/docs/description/Style_CollectionMethods.md rename to docs/description/Style_CollectionMethods.md diff --git a/src/main/resources/docs/description/Style_ColonMethodCall.md b/docs/description/Style_ColonMethodCall.md similarity index 100% rename from src/main/resources/docs/description/Style_ColonMethodCall.md rename to docs/description/Style_ColonMethodCall.md diff --git a/src/main/resources/docs/description/Style_ColonMethodDefinition.md b/docs/description/Style_ColonMethodDefinition.md similarity index 100% rename from src/main/resources/docs/description/Style_ColonMethodDefinition.md rename to docs/description/Style_ColonMethodDefinition.md diff --git a/docs/description/Style_CombinableLoops.md b/docs/description/Style_CombinableLoops.md new file mode 100644 index 00000000..47c9025b --- /dev/null +++ b/docs/description/Style_CombinableLoops.md @@ -0,0 +1,57 @@ + +This cop checks for places where multiple consecutive loops over the same data +can be combined into a single loop. It is very likely that combining them +will make the code more efficient and more concise. + +It is marked as unsafe, because the first loop might modify +a state that the second loop depends on; these two aren't combinable. + +# Examples + +```ruby +# bad +def method + items.each do |item| + do_something(item) + end + + items.each do |item| + do_something_else(item) + end +end + +# good +def method + items.each do |item| + do_something(item) + do_something_else(item) + end +end + +# bad +def method + for item in items do + do_something(item) + end + + for item in items do + do_something_else(item) + end +end + +# good +def method + for item in items do + do_something(item) + do_something_else(item) + end +end + +# good +def method + each_slice(2) { |slice| do_something(slice) } + each_slice(3) { |slice| do_something(slice) } +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/CombinableLoops) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_CommandLiteral.md b/docs/description/Style_CommandLiteral.md similarity index 100% rename from src/main/resources/docs/description/Style_CommandLiteral.md rename to docs/description/Style_CommandLiteral.md diff --git a/src/main/resources/docs/description/Style_CommentAnnotation.md b/docs/description/Style_CommentAnnotation.md similarity index 59% rename from src/main/resources/docs/description/Style_CommentAnnotation.md rename to docs/description/Style_CommentAnnotation.md index 320fceaa..c85b6ea9 100644 --- a/src/main/resources/docs/description/Style_CommentAnnotation.md +++ b/docs/description/Style_CommentAnnotation.md @@ -2,6 +2,12 @@ This cop checks that comment annotation keywords are written according to guidelines. +NOTE: With a multiline comment block (where each line is only a +comment), only the first line will be able to register an offense, even +if an annotation keyword starts another line. This is done to prevent +incorrect registering of keywords (eg. `review`) inside a paragraph as an +annotation. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_CommentedKeyword.md b/docs/description/Style_CommentedKeyword.md similarity index 70% rename from src/main/resources/docs/description/Style_CommentedKeyword.md rename to docs/description/Style_CommentedKeyword.md index 79abca1b..03fb1c0a 100644 --- a/src/main/resources/docs/description/Style_CommentedKeyword.md +++ b/docs/description/Style_CommentedKeyword.md @@ -1,11 +1,14 @@ This cop checks for comments put on the same line as some keywords. -These keywords are: `begin`, `class`, `def`, `end`, `module`. +These keywords are: `class`, `module`, `def`, `begin`, `end`. Note that some comments (`:nodoc:`, `:yields:`, `rubocop:disable` and `rubocop:todo`) are allowed. +Auto-correction removes comments from `end` keyword and keeps comments +for `class`, `module`, `def` and `begin` above the keyword. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_ConditionalAssignment.md b/docs/description/Style_ConditionalAssignment.md similarity index 100% rename from src/main/resources/docs/description/Style_ConditionalAssignment.md rename to docs/description/Style_ConditionalAssignment.md diff --git a/src/main/resources/docs/description/Style_ConstantVisibility.md b/docs/description/Style_ConstantVisibility.md similarity index 100% rename from src/main/resources/docs/description/Style_ConstantVisibility.md rename to docs/description/Style_ConstantVisibility.md diff --git a/src/main/resources/docs/description/Style_Copyright.md b/docs/description/Style_Copyright.md similarity index 85% rename from src/main/resources/docs/description/Style_Copyright.md rename to docs/description/Style_Copyright.md index 03a550b8..a3b70280 100644 --- a/src/main/resources/docs/description/Style_Copyright.md +++ b/docs/description/Style_Copyright.md @@ -4,8 +4,8 @@ Check that a copyright notice was given in each source file. The default regexp for an acceptable copyright notice can be found in config/default.yml. The default can be changed as follows: - Style/Copyright: - Notice: '^Copyright (\(c\) )?2\d{3} Acme Inc' + Style/Copyright: + Notice: '^Copyright (\(c\) )?2\d{3} Acme Inc' This regex string is treated as an unanchored regex. For each file that RuboCop scans, a comment that matches this regex must be found or diff --git a/src/main/resources/docs/description/Style_DateTime.md b/docs/description/Style_DateTime.md similarity index 100% rename from src/main/resources/docs/description/Style_DateTime.md rename to docs/description/Style_DateTime.md diff --git a/src/main/resources/docs/description/Style_DefWithParentheses.md b/docs/description/Style_DefWithParentheses.md similarity index 100% rename from src/main/resources/docs/description/Style_DefWithParentheses.md rename to docs/description/Style_DefWithParentheses.md diff --git a/src/main/resources/docs/description/Style_Dir.md b/docs/description/Style_Dir.md similarity index 100% rename from src/main/resources/docs/description/Style_Dir.md rename to docs/description/Style_Dir.md diff --git a/src/main/resources/docs/description/Style_DisableCopsWithinSourceCodeDirective.md b/docs/description/Style_DisableCopsWithinSourceCodeDirective.md similarity index 59% rename from src/main/resources/docs/description/Style_DisableCopsWithinSourceCodeDirective.md rename to docs/description/Style_DisableCopsWithinSourceCodeDirective.md index 65e1287f..315b932d 100644 --- a/src/main/resources/docs/description/Style_DisableCopsWithinSourceCodeDirective.md +++ b/docs/description/Style_DisableCopsWithinSourceCodeDirective.md @@ -3,18 +3,25 @@ Detects comments to enable/disable RuboCop. This is useful if want to make sure that every RuboCop error gets fixed and not quickly disabled with a comment. +Specific cops can be allowed with the `AllowedCops` configuration. Note that +if this configuration is set, `rubocop:disable all` is still disallowed. + # Examples ```ruby # bad # rubocop:disable Metrics/AbcSize -def f +def foo end # rubocop:enable Metrics/AbcSize # good -def fixed_method_name_and_no_rubocop_comments +def foo +end# good +# rubocop:disable Metrics/AbcSize +def foo end +# rubocop:enable Metrics/AbcSize ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/DisableCopsWithinSourceCodeDirective) \ No newline at end of file diff --git a/docs/description/Style_DocumentDynamicEvalDefinition.md b/docs/description/Style_DocumentDynamicEvalDefinition.md new file mode 100644 index 00000000..0f119f50 --- /dev/null +++ b/docs/description/Style_DocumentDynamicEvalDefinition.md @@ -0,0 +1,77 @@ + +When using `class_eval` (or other `eval`) with string interpolation, +add a comment block showing its appearance if interpolated (a practice used in Rails code). + +# Examples + +```ruby +# from activesupport/lib/active_support/core_ext/string/output_safety.rb + +# bad +UNSAFE_STRING_METHODS.each do |unsafe_method| + if 'String'.respond_to?(unsafe_method) + class_eval <<-EOT, __FILE__, __LINE__ + 1 + def #{unsafe_method}(*params, &block) + to_str.#{unsafe_method}(*params, &block) + end + + def #{unsafe_method}!(*params) + @dirty = true + super + end + EOT + end +end + +# good, inline comments in heredoc +UNSAFE_STRING_METHODS.each do |unsafe_method| + if 'String'.respond_to?(unsafe_method) + class_eval <<-EOT, __FILE__, __LINE__ + 1 + def #{unsafe_method}(*params, &block) # def capitalize(*params, &block) + to_str.#{unsafe_method}(*params, &block) # to_str.capitalize(*params, &block) + end # end + + def #{unsafe_method}!(*params) # def capitalize!(*params) + @dirty = true # @dirty = true + super # super + end # end + EOT + end +end + +# good, block comments in heredoc +class_eval <<-EOT, __FILE__, __LINE__ + 1 + # def capitalize!(*params) + # @dirty = true + # super + # end + + def #{unsafe_method}!(*params) + @dirty = true + super + end +EOT + +# good, block comments before heredoc +class_eval( + # def capitalize!(*params) + # @dirty = true + # super + # end + + <<-EOT, __FILE__, __LINE__ + 1 + def #{unsafe_method}!(*params) + @dirty = true + super + end + EOT +) + +# bad - interpolated string without comment +class_eval("def #{unsafe_method}!(*params); end") + +# good - with inline comment or replace it with block comment using heredoc +class_eval("def #{unsafe_method}!(*params); end # def capitalize!(*params); end") +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/DocumentDynamicEvalDefinition) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_Documentation.md b/docs/description/Style_Documentation.md similarity index 95% rename from src/main/resources/docs/description/Style_Documentation.md rename to docs/description/Style_Documentation.md index 84788d58..1fa63896 100644 --- a/src/main/resources/docs/description/Style_Documentation.md +++ b/docs/description/Style_Documentation.md @@ -52,6 +52,11 @@ end module Namespace Public = Class.new end + + # Macro calls + module Namespace + extend Foo + end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_DocumentationMethod.md b/docs/description/Style_DocumentationMethod.md similarity index 100% rename from src/main/resources/docs/description/Style_DocumentationMethod.md rename to docs/description/Style_DocumentationMethod.md diff --git a/src/main/resources/docs/description/Style_DoubleCopDisableDirective.md b/docs/description/Style_DoubleCopDisableDirective.md similarity index 100% rename from src/main/resources/docs/description/Style_DoubleCopDisableDirective.md rename to docs/description/Style_DoubleCopDisableDirective.md diff --git a/docs/description/Style_DoubleNegation.md b/docs/description/Style_DoubleNegation.md new file mode 100644 index 00000000..519b76fe --- /dev/null +++ b/docs/description/Style_DoubleNegation.md @@ -0,0 +1,29 @@ + +This cop checks for uses of double negation (`!!`) to convert something to a boolean value. + +When using `EnforcedStyle: allowed_in_returns`, allow double nagation in contexts +that use boolean as a return value. When using `EnforcedStyle: forbidden`, double nagation +should be forbidden always. + +Please, note that when something is a boolean value +!!something and !something.nil? are not the same thing. +As you're unlikely to write code that can accept values of any type +this is rarely a problem in practice. + +# Examples + +```ruby +# bad +!!something + +# good +!something.nil?# good +def foo? + !!return_value +end# bad +def foo? + !!return_value +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/DoubleNegation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_EachForSimpleLoop.md b/docs/description/Style_EachForSimpleLoop.md similarity index 100% rename from src/main/resources/docs/description/Style_EachForSimpleLoop.md rename to docs/description/Style_EachForSimpleLoop.md diff --git a/src/main/resources/docs/description/Style_EachWithObject.md b/docs/description/Style_EachWithObject.md similarity index 100% rename from src/main/resources/docs/description/Style_EachWithObject.md rename to docs/description/Style_EachWithObject.md diff --git a/src/main/resources/docs/description/Style_EmptyBlockParameter.md b/docs/description/Style_EmptyBlockParameter.md similarity index 100% rename from src/main/resources/docs/description/Style_EmptyBlockParameter.md rename to docs/description/Style_EmptyBlockParameter.md diff --git a/src/main/resources/docs/description/Style_EmptyCaseCondition.md b/docs/description/Style_EmptyCaseCondition.md similarity index 100% rename from src/main/resources/docs/description/Style_EmptyCaseCondition.md rename to docs/description/Style_EmptyCaseCondition.md diff --git a/src/main/resources/docs/description/Style_EmptyElse.md b/docs/description/Style_EmptyElse.md similarity index 100% rename from src/main/resources/docs/description/Style_EmptyElse.md rename to docs/description/Style_EmptyElse.md diff --git a/src/main/resources/docs/description/Style_EmptyLambdaParameter.md b/docs/description/Style_EmptyLambdaParameter.md similarity index 100% rename from src/main/resources/docs/description/Style_EmptyLambdaParameter.md rename to docs/description/Style_EmptyLambdaParameter.md diff --git a/src/main/resources/docs/description/Style_EmptyLiteral.md b/docs/description/Style_EmptyLiteral.md similarity index 100% rename from src/main/resources/docs/description/Style_EmptyLiteral.md rename to docs/description/Style_EmptyLiteral.md diff --git a/src/main/resources/docs/description/Style_EmptyMethod.md b/docs/description/Style_EmptyMethod.md similarity index 90% rename from src/main/resources/docs/description/Style_EmptyMethod.md rename to docs/description/Style_EmptyMethod.md index a24d95fa..a9b23fd1 100644 --- a/src/main/resources/docs/description/Style_EmptyMethod.md +++ b/docs/description/Style_EmptyMethod.md @@ -4,7 +4,7 @@ By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the `end` to go on its own line (expanded style). -Note: A method definition is not considered empty if it contains +NOTE: A method definition is not considered empty if it contains comments. # Examples diff --git a/src/main/resources/docs/description/Style_Encoding.md b/docs/description/Style_Encoding.md similarity index 100% rename from src/main/resources/docs/description/Style_Encoding.md rename to docs/description/Style_Encoding.md diff --git a/src/main/resources/docs/description/Style_EndBlock.md b/docs/description/Style_EndBlock.md similarity index 100% rename from src/main/resources/docs/description/Style_EndBlock.md rename to docs/description/Style_EndBlock.md diff --git a/docs/description/Style_EndlessMethod.md b/docs/description/Style_EndlessMethod.md new file mode 100644 index 00000000..59a1e02e --- /dev/null +++ b/docs/description/Style_EndlessMethod.md @@ -0,0 +1,41 @@ + +This cop checks for endless methods. + +It can enforce either the use of endless methods definitions +for single-lined method bodies, or disallow endless methods. + +Other method definition types are not considered by this cop. + +The supported styles are: +* allow_single_line (default) - only single line endless method definitions are allowed. +* allow_always - all endless method definitions are allowed. +* disallow - all endless method definitions are disallowed. + +NOTE: Incorrect endless method definitions will always be +corrected to a multi-line definition. + +# Examples + +```ruby +# good +def my_method() = x + +# bad, multi-line endless method +def my_method() = x.foo + .bar + .baz# good +def my_method() = x + +# good +def my_method() = x.foo + .bar + .baz# bad +def my_method; x end + +# bad +def my_method() = x.foo + .bar + .baz +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/EndlessMethod) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_EvalWithLocation.md b/docs/description/Style_EvalWithLocation.md similarity index 50% rename from src/main/resources/docs/description/Style_EvalWithLocation.md rename to docs/description/Style_EvalWithLocation.md index fa9b7da9..43392f4e 100644 --- a/src/main/resources/docs/description/Style_EvalWithLocation.md +++ b/docs/description/Style_EvalWithLocation.md @@ -1,7 +1,12 @@ -This cop checks `eval` method usage. `eval` can receive source location -metadata, that are filename and line number. The metadata is used by -backtraces. This cop recommends to pass the metadata to `eval` method. +This cop ensures that eval methods (`eval`, `instance_eval`, `class_eval` +and `module_eval`) are given filename and line number values (`__FILE__` +and `__LINE__`). This data is used to ensure that any errors raised +within the evaluated code will be given the correct identification +in a backtrace. + +The cop also checks that the line number given relative to `__LINE__` is +correct. # Examples diff --git a/src/main/resources/docs/description/Style_EvenOdd.md b/docs/description/Style_EvenOdd.md similarity index 100% rename from src/main/resources/docs/description/Style_EvenOdd.md rename to docs/description/Style_EvenOdd.md diff --git a/src/main/resources/docs/description/Style_ExpandPathArguments.md b/docs/description/Style_ExpandPathArguments.md similarity index 100% rename from src/main/resources/docs/description/Style_ExpandPathArguments.md rename to docs/description/Style_ExpandPathArguments.md diff --git a/docs/description/Style_ExplicitBlockArgument.md b/docs/description/Style_ExplicitBlockArgument.md new file mode 100644 index 00000000..236a01e1 --- /dev/null +++ b/docs/description/Style_ExplicitBlockArgument.md @@ -0,0 +1,40 @@ + +This cop enforces the use of explicit block argument to avoid writing +block literal that just passes its arguments to another block. + +NOTE: This cop only registers an offense if the block args match the +yield args exactly. + +# Examples + +```ruby +# bad +def with_tmp_dir + Dir.mktmpdir do |tmp_dir| + Dir.chdir(tmp_dir) { |dir| yield dir } # block just passes arguments + end +end + +# bad +def nine_times + 9.times { yield } +end + +# good +def with_tmp_dir(&block) + Dir.mktmpdir do |tmp_dir| + Dir.chdir(tmp_dir, &block) + end +end + +with_tmp_dir do |dir| + puts "dir is accessible as a parameter and pwd is set: #{dir}" +end + +# good +def nine_times(&block) + 9.times(&block) +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/ExplicitBlockArgument) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_ExponentialNotation.md b/docs/description/Style_ExponentialNotation.md similarity index 81% rename from src/main/resources/docs/description/Style_ExponentialNotation.md rename to docs/description/Style_ExponentialNotation.md index 193f5abb..9e0d61d6 100644 --- a/src/main/resources/docs/description/Style_ExponentialNotation.md +++ b/docs/description/Style_ExponentialNotation.md @@ -1,12 +1,12 @@ This cop enforces consistency when using exponential notation for numbers in the code (eg 1.2e4). Different styles are supported: -- `scientific` which enforces a mantissa between 1 (inclusive) +* `scientific` which enforces a mantissa between 1 (inclusive) and 10 (exclusive). -- `engineering` which enforces the exponent to be a multiple of 3 +* `engineering` which enforces the exponent to be a multiple of 3 and the mantissa to be between 0.1 (inclusive) and 10 (exclusive). -- `integral` which enforces the mantissa to always be a whole number +* `integral` which enforces the mantissa to always be a whole number without trailing zeroes. # Examples diff --git a/src/main/resources/docs/description/Style_FloatDivision.md b/docs/description/Style_FloatDivision.md similarity index 79% rename from src/main/resources/docs/description/Style_FloatDivision.md rename to docs/description/Style_FloatDivision.md index 56a19b0a..dde20b1f 100644 --- a/src/main/resources/docs/description/Style_FloatDivision.md +++ b/docs/description/Style_FloatDivision.md @@ -3,6 +3,9 @@ This cop checks for division with integers coerced to floats. It is recommended to either always use `fdiv` or coerce one side only. This cop also provides other options for code consistency. +This cop is marked as unsafe, because if operand variable is a string object +then `.to_f` will be removed and an error will occur. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_For.md b/docs/description/Style_For.md similarity index 100% rename from src/main/resources/docs/description/Style_For.md rename to docs/description/Style_For.md diff --git a/src/main/resources/docs/description/Style_FormatString.md b/docs/description/Style_FormatString.md similarity index 100% rename from src/main/resources/docs/description/Style_FormatString.md rename to docs/description/Style_FormatString.md diff --git a/src/main/resources/docs/description/Style_FormatStringToken.md b/docs/description/Style_FormatStringToken.md similarity index 52% rename from src/main/resources/docs/description/Style_FormatStringToken.md rename to docs/description/Style_FormatStringToken.md index 7659977a..6ef96375 100644 --- a/src/main/resources/docs/description/Style_FormatStringToken.md +++ b/docs/description/Style_FormatStringToken.md @@ -1,13 +1,18 @@ Use a consistent style for named format string tokens. -**Note:** -`unannotated` style cop only works for strings +NOTE: `unannotated` style cop only works for strings which are passed as arguments to those methods: `printf`, `sprintf`, `format`, `%`. -The reason is that *unannotated* format is very similar +The reason is that _unannotated_ format is very similar to encoded URLs or Date/Time formatting strings. +This cop can be customized ignored methods with `IgnoredMethods`. + +It is allowed to contain unannotated token +if the number of them is less than or equals to +`MaxUnannotatedPlaceholdersAllowed`. + # Examples ```ruby @@ -26,10 +31,23 @@ format('%s', 'Hello') format('%{greeting}', greeting: 'Hello') # bad format('%s', greeting: 'Hello') -format('%{greeting}', 'Hello') +format('%{greeting}', greeting: 'Hello') # good format('%s', 'Hello') +# bad +format('%06d', 10) +format('%s %s.', 'Hello', 'world') + +# good +format('%06d', number: 10) +# bad +format('%s %s.', 'Hello', 'world') + +# good +format('%06d', 10) +# good +redirect('foo/%{bar_id}') ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/FormatStringToken) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_FrozenStringLiteralComment.md b/docs/description/Style_FrozenStringLiteralComment.md similarity index 94% rename from src/main/resources/docs/description/Style_FrozenStringLiteralComment.md rename to docs/description/Style_FrozenStringLiteralComment.md index bc083ecc..9d75073a 100644 --- a/src/main/resources/docs/description/Style_FrozenStringLiteralComment.md +++ b/docs/description/Style_FrozenStringLiteralComment.md @@ -4,8 +4,7 @@ to frozen string literals. It will add the comment `# frozen_string_literal: true` to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and -encoding comment. The frozen string literal comment is only valid in -Ruby 2.3+. +encoding comment. Note that the cop will ignore files where the comment exists but is set to `false` instead of `true`. diff --git a/docs/description/Style_GlobalStdStream.md b/docs/description/Style_GlobalStdStream.md new file mode 100644 index 00000000..f529642b --- /dev/null +++ b/docs/description/Style_GlobalStdStream.md @@ -0,0 +1,29 @@ + +This cop enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`. +`STDOUT/STDERR/STDIN` are constants, and while you can actually +reassign (possibly to redirect some stream) constants in Ruby, you'll get +an interpreter warning if you do so. + +# Examples + +```ruby +# bad +STDOUT.puts('hello') + +hash = { out: STDOUT, key: value } + +def m(out = STDOUT) + out.puts('hello') +end + +# good +$stdout.puts('hello') + +hash = { out: $stdout, key: value } + +def m(out = $stdout) + out.puts('hello') +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/GlobalStdStream) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_GlobalVars.md b/docs/description/Style_GlobalVars.md similarity index 100% rename from src/main/resources/docs/description/Style_GlobalVars.md rename to docs/description/Style_GlobalVars.md diff --git a/src/main/resources/docs/description/Style_GuardClause.md b/docs/description/Style_GuardClause.md similarity index 79% rename from src/main/resources/docs/description/Style_GuardClause.md rename to docs/description/Style_GuardClause.md index 831d3a20..b0ecccdf 100644 --- a/src/main/resources/docs/description/Style_GuardClause.md +++ b/docs/description/Style_GuardClause.md @@ -15,6 +15,7 @@ end # good def test return unless something + work end @@ -33,6 +34,17 @@ end # good raise 'exception' if something ok + +# bad +if something + foo || raise('exception') +else + ok +end + +# good +foo || raise('exception') if something +ok ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/GuardClause) \ No newline at end of file diff --git a/docs/description/Style_HashAsLastArrayItem.md b/docs/description/Style_HashAsLastArrayItem.md new file mode 100644 index 00000000..4b4d03f0 --- /dev/null +++ b/docs/description/Style_HashAsLastArrayItem.md @@ -0,0 +1,28 @@ + +Checks for presence or absence of braces around hash literal as a last +array item depending on configuration. + +NOTE: This cop will ignore arrays where all items are hashes, regardless of +EnforcedStyle. + +# Examples + +```ruby +# bad +[1, 2, one: 1, two: 2] + +# good +[1, 2, { one: 1, two: 2 }] + +# good +[{ one: 1 }, { two: 2 }]# bad +[1, 2, { one: 1, two: 2 }] + +# good +[1, 2, one: 1, two: 2] + +# good +[{ one: 1 }, { two: 2 }] +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashAsLastArrayItem) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_HashEachMethods.md b/docs/description/Style_HashEachMethods.md similarity index 87% rename from src/main/resources/docs/description/Style_HashEachMethods.md rename to docs/description/Style_HashEachMethods.md index 6890663c..a7f95dd8 100644 --- a/src/main/resources/docs/description/Style_HashEachMethods.md +++ b/docs/description/Style_HashEachMethods.md @@ -1,7 +1,7 @@ This cop checks for uses of `each_key` and `each_value` Hash methods. -Note: If you have an array of two-element arrays, you can put +NOTE: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses. diff --git a/docs/description/Style_HashExcept.md b/docs/description/Style_HashExcept.md new file mode 100644 index 00000000..84ffe9d0 --- /dev/null +++ b/docs/description/Style_HashExcept.md @@ -0,0 +1,25 @@ + +This cop checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods +that can be replaced with `Hash#except` method. + +This cop should only be enabled on Ruby version 3.0 or higher. +(`Hash#except` was added in Ruby 3.0.) + +For safe detection, it is limited to commonly used string and symbol comparisons +when used `==`. +And do not check `Hash#delete_if` and `Hash#keep_if` to change receiver object. + +# Examples + +```ruby + +# bad +{foo: 1, bar: 2, baz: 3}.reject {|k, v| k == :bar } +{foo: 1, bar: 2, baz: 3}.select {|k, v| k != :bar } +{foo: 1, bar: 2, baz: 3}.filter {|k, v| k != :bar } + +# good +{foo: 1, bar: 2, baz: 3}.except(:bar) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashExcept) \ No newline at end of file diff --git a/docs/description/Style_HashLikeCase.md b/docs/description/Style_HashLikeCase.md new file mode 100644 index 00000000..4492c250 --- /dev/null +++ b/docs/description/Style_HashLikeCase.md @@ -0,0 +1,35 @@ + +This cop checks for places where `case-when` represents a simple 1:1 +mapping and can be replaced with a hash lookup. + +# Examples + +```ruby +# bad +case country +when 'europe' + 'http://eu.example.com' +when 'america' + 'http://us.example.com' +when 'australia' + 'http://au.example.com' +end + +# good +SITES = { + 'europe' => 'http://eu.example.com', + 'america' => 'http://us.example.com', + 'australia' => 'http://au.example.com' +} +SITES[country]# good +case country +when 'europe' + 'http://eu.example.com' +when 'america' + 'http://us.example.com' +when 'australia' + 'http://au.example.com' +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashLikeCase) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_HashSyntax.md b/docs/description/Style_HashSyntax.md similarity index 96% rename from src/main/resources/docs/description/Style_HashSyntax.md rename to docs/description/Style_HashSyntax.md index 5d04296f..c74ff275 100644 --- a/src/main/resources/docs/description/Style_HashSyntax.md +++ b/docs/description/Style_HashSyntax.md @@ -9,11 +9,11 @@ A separate offense is registered for each problematic pair. The supported styles are: * ruby19 - forces use of the 1.9 syntax (e.g. `{a: 1}`) when hashes have - all symbols for keys +all symbols for keys * hash_rockets - forces use of hash rockets for all hashes * no_mixed_keys - simply checks for hashes with mixed syntaxes * ruby19_no_mixed_keys - forces use of ruby 1.9 syntax and forbids mixed - syntax hashes +syntax hashes # Examples diff --git a/src/main/resources/docs/description/Style_HashTransformKeys.md b/docs/description/Style_HashTransformKeys.md similarity index 84% rename from src/main/resources/docs/description/Style_HashTransformKeys.md rename to docs/description/Style_HashTransformKeys.md index d93aba89..9c6731ed 100644 --- a/src/main/resources/docs/description/Style_HashTransformKeys.md +++ b/docs/description/Style_HashTransformKeys.md @@ -16,7 +16,9 @@ This cop should only be enabled on Ruby version 2.5 or newer ```ruby # bad {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[foo(k)] = v } -{a: 1, b: 2}.map { |k, v| [k.to_s, v] } +Hash[{a: 1, b: 2}.collect { |k, v| [foo(k), v] }] +{a: 1, b: 2}.map { |k, v| [k.to_s, v] }.to_h +{a: 1, b: 2}.to_h { |k, v| [k.to_s, v] } # good {a: 1, b: 2}.transform_keys { |k| foo(k) } diff --git a/src/main/resources/docs/description/Style_HashTransformValues.md b/docs/description/Style_HashTransformValues.md similarity index 85% rename from src/main/resources/docs/description/Style_HashTransformValues.md rename to docs/description/Style_HashTransformValues.md index 9ce6b261..c3a19779 100644 --- a/src/main/resources/docs/description/Style_HashTransformValues.md +++ b/docs/description/Style_HashTransformValues.md @@ -16,7 +16,9 @@ This cop should only be enabled on Ruby version 2.4 or newer ```ruby # bad {a: 1, b: 2}.each_with_object({}) { |(k, v), h| h[k] = foo(v) } -{a: 1, b: 2}.map { |k, v| [k, v * v] } +Hash[{a: 1, b: 2}.collect { |k, v| [k, foo(v)] }] +{a: 1, b: 2}.map { |k, v| [k, v * v] }.to_h +{a: 1, b: 2}.to_h { |k, v| [k, v * v] } # good {a: 1, b: 2}.transform_values { |v| foo(v) } diff --git a/src/main/resources/docs/description/Style_IdenticalConditionalBranches.md b/docs/description/Style_IdenticalConditionalBranches.md similarity index 54% rename from src/main/resources/docs/description/Style_IdenticalConditionalBranches.md rename to docs/description/Style_IdenticalConditionalBranches.md index f0a6ce74..e56aa3e7 100644 --- a/src/main/resources/docs/description/Style_IdenticalConditionalBranches.md +++ b/docs/description/Style_IdenticalConditionalBranches.md @@ -1,6 +1,11 @@ -This cop checks for identical lines at the beginning or end of -each branch of a conditional statement. +This cop checks for identical expressions at the beginning or end of +each branch of a conditional expression. Such expressions should normally +be placed outside the conditional expression - before or after it. + +NOTE: The cop is poorly named and some people might think that it actually +checks for duplicated conditional branches. The name will probably be changed +in a future major RuboCop release. # Examples diff --git a/src/main/resources/docs/description/Style_IfInsideElse.md b/docs/description/Style_IfInsideElse.md similarity index 100% rename from src/main/resources/docs/description/Style_IfInsideElse.md rename to docs/description/Style_IfInsideElse.md diff --git a/src/main/resources/docs/description/Style_IfUnlessModifier.md b/docs/description/Style_IfUnlessModifier.md similarity index 68% rename from src/main/resources/docs/description/Style_IfUnlessModifier.md rename to docs/description/Style_IfUnlessModifier.md index eec99f9c..6eb6f043 100644 --- a/src/main/resources/docs/description/Style_IfUnlessModifier.md +++ b/docs/description/Style_IfUnlessModifier.md @@ -19,14 +19,18 @@ unless qux.empty? Foo.do_something end -do_something_in_a_method_with_a_long_name(arg) if long_condition +do_something_with_a_long_name(arg) if long_condition_that_prevents_code_fit_on_single_line # good do_stuff(bar) if condition Foo.do_something unless qux.empty? -if long_condition - do_something_in_a_method_with_a_long_name(arg) +if long_condition_that_prevents_code_fit_on_single_line + do_something_with_a_long_name(arg) +end + +if short_condition # a long comment that makes it too long if it were just a single line + do_something end ``` diff --git a/src/main/resources/docs/description/Style_IfUnlessModifierOfIfUnless.md b/docs/description/Style_IfUnlessModifierOfIfUnless.md similarity index 100% rename from src/main/resources/docs/description/Style_IfUnlessModifierOfIfUnless.md rename to docs/description/Style_IfUnlessModifierOfIfUnless.md diff --git a/docs/description/Style_IfWithBooleanLiteralBranches.md b/docs/description/Style_IfWithBooleanLiteralBranches.md new file mode 100644 index 00000000..2a1a72bd --- /dev/null +++ b/docs/description/Style_IfWithBooleanLiteralBranches.md @@ -0,0 +1,26 @@ + +This cop checks for redundant `if` with boolean literal branches. +It checks only conditions to return boolean value (`true` or `false`) for safe detection. +The conditions to be checked are comparison methods, predicate methods, and double negative. +However, auto-correction is unsafe because there is no guarantee that all predicate methods +will return boolean value. Those methods can be allowed with `AllowedMethods` config. + +# Examples + +```ruby +# bad +if foo == bar + true +else + false +end + +# bad +foo == bar ? true : false + +# good +foo == bar# good +num.nonzero? ? true : false +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/IfWithBooleanLiteralBranches) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_IfWithSemicolon.md b/docs/description/Style_IfWithSemicolon.md similarity index 100% rename from src/main/resources/docs/description/Style_IfWithSemicolon.md rename to docs/description/Style_IfWithSemicolon.md diff --git a/src/main/resources/docs/description/Style_ImplicitRuntimeError.md b/docs/description/Style_ImplicitRuntimeError.md similarity index 100% rename from src/main/resources/docs/description/Style_ImplicitRuntimeError.md rename to docs/description/Style_ImplicitRuntimeError.md diff --git a/docs/description/Style_InfiniteLoop.md b/docs/description/Style_InfiniteLoop.md new file mode 100644 index 00000000..8a7b76a3 --- /dev/null +++ b/docs/description/Style_InfiniteLoop.md @@ -0,0 +1,22 @@ + +Use `Kernel#loop` for infinite loops. + +This cop is marked as unsafe as the rule does not necessarily +apply if the body might raise a `StopIteration` exception; contrary to +other infinite loops, `Kernel#loop` silently rescues that and returns `nil`. + +# Examples + +```ruby +# bad +while true + work +end + +# good +loop do + work +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/InfiniteLoop) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_InlineComment.md b/docs/description/Style_InlineComment.md similarity index 100% rename from src/main/resources/docs/description/Style_InlineComment.md rename to docs/description/Style_InlineComment.md diff --git a/src/main/resources/docs/description/Style_InverseMethods.md b/docs/description/Style_InverseMethods.md similarity index 100% rename from src/main/resources/docs/description/Style_InverseMethods.md rename to docs/description/Style_InverseMethods.md diff --git a/src/main/resources/docs/description/Style_IpAddresses.md b/docs/description/Style_IpAddresses.md similarity index 100% rename from src/main/resources/docs/description/Style_IpAddresses.md rename to docs/description/Style_IpAddresses.md diff --git a/docs/description/Style_KeywordParametersOrder.md b/docs/description/Style_KeywordParametersOrder.md new file mode 100644 index 00000000..519dd390 --- /dev/null +++ b/docs/description/Style_KeywordParametersOrder.md @@ -0,0 +1,33 @@ + +This cop enforces that optional keyword parameters are placed at the +end of the parameters list. + +This improves readability, because when looking through the source, +it is expected to find required parameters at the beginning of parameters list +and optional parameters at the end. + +# Examples + +```ruby +# bad +def some_method(first: false, second:, third: 10) + # body omitted +end + +# good +def some_method(second:, first: false, third: 10) + # body omitted +end + +# bad +do_something do |first: false, second:, third: 10| + # body omitted +end + +# good +do_something do |second:, first: false, third: 10| + # body omitted +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/KeywordParametersOrder) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_Lambda.md b/docs/description/Style_Lambda.md similarity index 100% rename from src/main/resources/docs/description/Style_Lambda.md rename to docs/description/Style_Lambda.md diff --git a/src/main/resources/docs/description/Style_LambdaCall.md b/docs/description/Style_LambdaCall.md similarity index 100% rename from src/main/resources/docs/description/Style_LambdaCall.md rename to docs/description/Style_LambdaCall.md diff --git a/src/main/resources/docs/description/Style_LineEndConcatenation.md b/docs/description/Style_LineEndConcatenation.md similarity index 100% rename from src/main/resources/docs/description/Style_LineEndConcatenation.md rename to docs/description/Style_LineEndConcatenation.md diff --git a/src/main/resources/docs/description/Style_MethodCallWithArgsParentheses.md b/docs/description/Style_MethodCallWithArgsParentheses.md similarity index 95% rename from src/main/resources/docs/description/Style_MethodCallWithArgsParentheses.md rename to docs/description/Style_MethodCallWithArgsParentheses.md index c608b854..4b083140 100644 --- a/src/main/resources/docs/description/Style_MethodCallWithArgsParentheses.md +++ b/docs/description/Style_MethodCallWithArgsParentheses.md @@ -36,6 +36,9 @@ options. to `true` allows the presence of parentheses in such a method call even with arguments. +NOTE: Parens are required around a method with arguments when inside an +endless method definition (>= Ruby 3.0). + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_MethodCallWithoutArgsParentheses.md b/docs/description/Style_MethodCallWithoutArgsParentheses.md similarity index 100% rename from src/main/resources/docs/description/Style_MethodCallWithoutArgsParentheses.md rename to docs/description/Style_MethodCallWithoutArgsParentheses.md diff --git a/src/main/resources/docs/description/Style_MethodCalledOnDoEndBlock.md b/docs/description/Style_MethodCalledOnDoEndBlock.md similarity index 83% rename from src/main/resources/docs/description/Style_MethodCalledOnDoEndBlock.md rename to docs/description/Style_MethodCalledOnDoEndBlock.md index 0fdf7478..d0b6602f 100644 --- a/src/main/resources/docs/description/Style_MethodCalledOnDoEndBlock.md +++ b/docs/description/Style_MethodCalledOnDoEndBlock.md @@ -6,10 +6,19 @@ when reading code. # Examples ```ruby - +# bad a do b end.c + +# good +a { b }.c + +# good +foo = a do + b +end +foo.c ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MethodCalledOnDoEndBlock) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MethodDefParentheses.md b/docs/description/Style_MethodDefParentheses.md similarity index 94% rename from src/main/resources/docs/description/Style_MethodDefParentheses.md rename to docs/description/Style_MethodDefParentheses.md index 05101ab5..b02c0983 100644 --- a/src/main/resources/docs/description/Style_MethodDefParentheses.md +++ b/docs/description/Style_MethodDefParentheses.md @@ -2,6 +2,9 @@ This cop checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked. +This cop does not consider endless methods, since parentheses are +always required for them. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_MinMax.md b/docs/description/Style_MinMax.md similarity index 100% rename from src/main/resources/docs/description/Style_MinMax.md rename to docs/description/Style_MinMax.md diff --git a/src/main/resources/docs/description/Style_MissingElse.md b/docs/description/Style_MissingElse.md similarity index 100% rename from src/main/resources/docs/description/Style_MissingElse.md rename to docs/description/Style_MissingElse.md diff --git a/src/main/resources/docs/description/Style_MissingRespondToMissing.md b/docs/description/Style_MissingRespondToMissing.md similarity index 100% rename from src/main/resources/docs/description/Style_MissingRespondToMissing.md rename to docs/description/Style_MissingRespondToMissing.md diff --git a/src/main/resources/docs/description/Style_MixinGrouping.md b/docs/description/Style_MixinGrouping.md similarity index 100% rename from src/main/resources/docs/description/Style_MixinGrouping.md rename to docs/description/Style_MixinGrouping.md diff --git a/src/main/resources/docs/description/Style_MixinUsage.md b/docs/description/Style_MixinUsage.md similarity index 100% rename from src/main/resources/docs/description/Style_MixinUsage.md rename to docs/description/Style_MixinUsage.md diff --git a/src/main/resources/docs/description/Style_ModuleFunction.md b/docs/description/Style_ModuleFunction.md similarity index 100% rename from src/main/resources/docs/description/Style_ModuleFunction.md rename to docs/description/Style_ModuleFunction.md diff --git a/src/main/resources/docs/description/Style_MultilineBlockChain.md b/docs/description/Style_MultilineBlockChain.md similarity index 63% rename from src/main/resources/docs/description/Style_MultilineBlockChain.md rename to docs/description/Style_MultilineBlockChain.md index 22908d51..918284a3 100644 --- a/src/main/resources/docs/description/Style_MultilineBlockChain.md +++ b/docs/description/Style_MultilineBlockChain.md @@ -6,11 +6,20 @@ multiple lines. ```ruby -Thread.list.find_all do |t| +# bad +Thread.list.select do |t| t.alive? end.map do |t| t.object_id end + +# good +alive_threads = Thread.list.select do |t| + t.alive? +end +alive_threads.map do |t| + t.object_id +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MultilineBlockChain) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MultilineIfModifier.md b/docs/description/Style_MultilineIfModifier.md similarity index 100% rename from src/main/resources/docs/description/Style_MultilineIfModifier.md rename to docs/description/Style_MultilineIfModifier.md diff --git a/src/main/resources/docs/description/Style_MultilineIfThen.md b/docs/description/Style_MultilineIfThen.md similarity index 100% rename from src/main/resources/docs/description/Style_MultilineIfThen.md rename to docs/description/Style_MultilineIfThen.md diff --git a/src/main/resources/docs/description/Style_MultilineMemoization.md b/docs/description/Style_MultilineMemoization.md similarity index 100% rename from src/main/resources/docs/description/Style_MultilineMemoization.md rename to docs/description/Style_MultilineMemoization.md diff --git a/src/main/resources/docs/description/Style_MultilineMethodSignature.md b/docs/description/Style_MultilineMethodSignature.md similarity index 100% rename from src/main/resources/docs/description/Style_MultilineMethodSignature.md rename to docs/description/Style_MultilineMethodSignature.md diff --git a/src/main/resources/docs/description/Style_MultilineTernaryOperator.md b/docs/description/Style_MultilineTernaryOperator.md similarity index 60% rename from src/main/resources/docs/description/Style_MultilineTernaryOperator.md rename to docs/description/Style_MultilineTernaryOperator.md index 39dcd939..3ac2dc99 100644 --- a/src/main/resources/docs/description/Style_MultilineTernaryOperator.md +++ b/docs/description/Style_MultilineTernaryOperator.md @@ -1,6 +1,9 @@ This cop checks for multi-line ternary op expressions. +NOTE: `return if ... else ... end` is syntax error. If `return` is used before +multiline ternary operator expression, it cannot be auto-corrected. + # Examples ```ruby @@ -15,12 +18,11 @@ a = cond ? # good a = cond ? b : c -a = - if cond - b - else - c - end +a = if cond + b +else + c +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MultilineTernaryOperator) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MultilineWhenThen.md b/docs/description/Style_MultilineWhenThen.md similarity index 77% rename from src/main/resources/docs/description/Style_MultilineWhenThen.md rename to docs/description/Style_MultilineWhenThen.md index f83f9dbe..1ffc354a 100644 --- a/src/main/resources/docs/description/Style_MultilineWhenThen.md +++ b/docs/description/Style_MultilineWhenThen.md @@ -19,6 +19,12 @@ end case foo when bar then do_something end + +# good +case foo +when bar then do_something(arg1, + arg2) +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MultilineWhenThen) \ No newline at end of file diff --git a/docs/description/Style_MultipleComparison.md b/docs/description/Style_MultipleComparison.md new file mode 100644 index 00000000..3ecd19b7 --- /dev/null +++ b/docs/description/Style_MultipleComparison.md @@ -0,0 +1,37 @@ + +This cop checks against comparing a variable with multiple items, where +`Array#include?`, `Set#include?` or a `case` could be used instead +to avoid code repetition. +It accepts comparisons of multiple method calls to avoid unnecessary method calls +by default. It can be configured by `AllowMethodComparison` option. + +# Examples + +```ruby +# bad +a = 'a' +foo if a == 'a' || a == 'b' || a == 'c' + +# good +a = 'a' +foo if ['a', 'b', 'c'].include?(a) + +VALUES = Set['a', 'b', 'c'].freeze +# elsewhere... +foo if VALUES.include?(a) + +case foo +when 'a', 'b', 'c' then foo +# ... +end + +# accepted (but consider `case` as above) +foo if a == b.lightweight || a == b.heavyweight# good +foo if a == b.lightweight || a == b.heavyweight# bad +foo if a == b.lightweight || a == b.heavyweight + +# good +foo if [b.lightweight, b.heavyweight].include?(a) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MultipleComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MutableConstant.md b/docs/description/Style_MutableConstant.md similarity index 92% rename from src/main/resources/docs/description/Style_MutableConstant.md rename to docs/description/Style_MutableConstant.md index 9df7e96f..187aefa5 100644 --- a/src/main/resources/docs/description/Style_MutableConstant.md +++ b/docs/description/Style_MutableConstant.md @@ -10,6 +10,8 @@ frozen objects so there is a decent chance of getting some false positives. Luckily, there is no harm in freezing an already frozen object. +NOTE: Regexp and Range literals are frozen objects since Ruby 3.0. + # Examples ```ruby diff --git a/src/main/resources/docs/description/Style_NegatedIf.md b/docs/description/Style_NegatedIf.md similarity index 95% rename from src/main/resources/docs/description/Style_NegatedIf.md rename to docs/description/Style_NegatedIf.md index 35b79702..0f98ac65 100644 --- a/src/main/resources/docs/description/Style_NegatedIf.md +++ b/docs/description/Style_NegatedIf.md @@ -2,9 +2,9 @@ Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles: - - both - - prefix - - postfix +* both +* prefix +* postfix # Examples diff --git a/docs/description/Style_NegatedIfElseCondition.md b/docs/description/Style_NegatedIfElseCondition.md new file mode 100644 index 00000000..8ec5c68b --- /dev/null +++ b/docs/description/Style_NegatedIfElseCondition.md @@ -0,0 +1,29 @@ + +This cop checks for uses of `if-else` and ternary operators with a negated condition +which can be simplified by inverting condition and swapping branches. + +# Examples + +```ruby +# bad +if !x + do_something +else + do_something_else +end + +# good +if x + do_something_else +else + do_something +end + +# bad +!x ? do_something : do_something_else + +# good +x ? do_something_else : do_something +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/NegatedIfElseCondition) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_NegatedUnless.md b/docs/description/Style_NegatedUnless.md similarity index 95% rename from src/main/resources/docs/description/Style_NegatedUnless.md rename to docs/description/Style_NegatedUnless.md index 64c3ebcc..7619a444 100644 --- a/src/main/resources/docs/description/Style_NegatedUnless.md +++ b/docs/description/Style_NegatedUnless.md @@ -2,9 +2,9 @@ Checks for uses of unless with a negated condition. Only unless without else are considered. There are three different styles: - - both - - prefix - - postfix +* both +* prefix +* postfix # Examples diff --git a/src/main/resources/docs/description/Style_NegatedWhile.md b/docs/description/Style_NegatedWhile.md similarity index 100% rename from src/main/resources/docs/description/Style_NegatedWhile.md rename to docs/description/Style_NegatedWhile.md diff --git a/src/main/resources/docs/description/Style_NestedModifier.md b/docs/description/Style_NestedModifier.md similarity index 100% rename from src/main/resources/docs/description/Style_NestedModifier.md rename to docs/description/Style_NestedModifier.md diff --git a/src/main/resources/docs/description/Style_NestedParenthesizedCalls.md b/docs/description/Style_NestedParenthesizedCalls.md similarity index 100% rename from src/main/resources/docs/description/Style_NestedParenthesizedCalls.md rename to docs/description/Style_NestedParenthesizedCalls.md diff --git a/src/main/resources/docs/description/Style_NestedTernaryOperator.md b/docs/description/Style_NestedTernaryOperator.md similarity index 100% rename from src/main/resources/docs/description/Style_NestedTernaryOperator.md rename to docs/description/Style_NestedTernaryOperator.md diff --git a/src/main/resources/docs/description/Style_Next.md b/docs/description/Style_Next.md similarity index 100% rename from src/main/resources/docs/description/Style_Next.md rename to docs/description/Style_Next.md diff --git a/src/main/resources/docs/description/Style_NilComparison.md b/docs/description/Style_NilComparison.md similarity index 100% rename from src/main/resources/docs/description/Style_NilComparison.md rename to docs/description/Style_NilComparison.md diff --git a/docs/description/Style_NilLambda.md b/docs/description/Style_NilLambda.md new file mode 100644 index 00000000..4535165f --- /dev/null +++ b/docs/description/Style_NilLambda.md @@ -0,0 +1,24 @@ + +This cop checks for lambdas that always return nil, which can be replaced +with an empty lambda instead. + +# Examples + +```ruby +# bad +-> { nil } + +lambda do + next nil +end + +# good +-> {} + +lambda do +end + +-> (x) { nil if x } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/NilLambda) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_NonNilCheck.md b/docs/description/Style_NonNilCheck.md similarity index 73% rename from src/main/resources/docs/description/Style_NonNilCheck.md rename to docs/description/Style_NonNilCheck.md index 5a19b677..c3b6e9a5 100644 --- a/src/main/resources/docs/description/Style_NonNilCheck.md +++ b/docs/description/Style_NonNilCheck.md @@ -4,10 +4,13 @@ This cop checks for non-nil checks, which are usually redundant. With `IncludeSemanticChanges` set to `false` by default, this cop does not report offenses for `!x.nil?` and does no changes that might change behavior. +Also `IncludeSemanticChanges` set to `false` with `EnforcedStyle: comparison` of +`Style/NilComparison` cop, this cop does not report offenses for `x != nil` and +does no changes to `!x.nil?` style. With `IncludeSemanticChanges` set to `true`, this cop reports offenses for `!x.nil?` and autocorrects that and `x != nil` to solely `x`, which -is **usually** OK, but might change behavior. +is *usually* OK, but might change behavior. # Examples diff --git a/src/main/resources/docs/description/Style_Not.md b/docs/description/Style_Not.md similarity index 100% rename from src/main/resources/docs/description/Style_Not.md rename to docs/description/Style_Not.md diff --git a/src/main/resources/docs/description/Style_NumericLiteralPrefix.md b/docs/description/Style_NumericLiteralPrefix.md similarity index 100% rename from src/main/resources/docs/description/Style_NumericLiteralPrefix.md rename to docs/description/Style_NumericLiteralPrefix.md diff --git a/src/main/resources/docs/description/Style_NumericLiterals.md b/docs/description/Style_NumericLiterals.md similarity index 100% rename from src/main/resources/docs/description/Style_NumericLiterals.md rename to docs/description/Style_NumericLiterals.md diff --git a/src/main/resources/docs/description/Style_NumericPredicate.md b/docs/description/Style_NumericPredicate.md similarity index 91% rename from src/main/resources/docs/description/Style_NumericPredicate.md rename to docs/description/Style_NumericPredicate.md index c2365faa..3bdc0d70 100644 --- a/src/main/resources/docs/description/Style_NumericPredicate.md +++ b/docs/description/Style_NumericPredicate.md @@ -4,7 +4,7 @@ This cop checks for usage of comparison operators (`==`, These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse. -The cop disregards `#nonzero?` as it its value is truthy or falsey, +The cop disregards `#nonzero?` as its value is truthy or falsey, but not `true` and `false`, and thus not always interchangeable with `!= 0`. diff --git a/docs/description/Style_OneLineConditional.md b/docs/description/Style_OneLineConditional.md new file mode 100644 index 00000000..42eb8bc5 --- /dev/null +++ b/docs/description/Style_OneLineConditional.md @@ -0,0 +1,33 @@ + +Checks for uses of if/then/else/end constructs on a single line. +AlwaysCorrectToMultiline config option can be set to true to auto-convert all offenses to +multi-line constructs. When AlwaysCorrectToMultiline is false (default case) the +auto-correct will first try converting them to ternary operators. + +# Examples + +```ruby +# bad +if foo then bar else baz end + +# bad +unless foo then baz else bar end + +# good +foo ? bar : baz + +# good +bar if foo + +# good +if foo then bar end + +# good +if foo + bar +else + baz +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/OneLineConditional) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_OptionHash.md b/docs/description/Style_OptionHash.md similarity index 100% rename from src/main/resources/docs/description/Style_OptionHash.md rename to docs/description/Style_OptionHash.md diff --git a/src/main/resources/docs/description/Style_OptionalArguments.md b/docs/description/Style_OptionalArguments.md similarity index 83% rename from src/main/resources/docs/description/Style_OptionalArguments.md rename to docs/description/Style_OptionalArguments.md index a4c8a262..7a9a1ed7 100644 --- a/src/main/resources/docs/description/Style_OptionalArguments.md +++ b/docs/description/Style_OptionalArguments.md @@ -1,6 +1,6 @@ This cop checks for optional arguments to methods -that do not come at the end of the argument list +that do not come at the end of the argument list. # Examples diff --git a/docs/description/Style_OptionalBooleanParameter.md b/docs/description/Style_OptionalBooleanParameter.md new file mode 100644 index 00000000..d45e1339 --- /dev/null +++ b/docs/description/Style_OptionalBooleanParameter.md @@ -0,0 +1,29 @@ + +This cop checks for places where keyword arguments can be used instead of +boolean arguments when defining methods. `respond_to_missing?` method is allowed by default. +These are customizable with `AllowedMethods` option. + +# Examples + +```ruby +# bad +def some_method(bar = false) + puts bar +end + +# bad - common hack before keyword args were introduced +def some_method(options = {}) + bar = options.fetch(:bar, false) + puts bar +end + +# good +def some_method(bar: false) + puts bar +end# good +def some_method(bar = false) + puts bar +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/OptionalBooleanParameter) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_OrAssignment.md b/docs/description/Style_OrAssignment.md similarity index 100% rename from src/main/resources/docs/description/Style_OrAssignment.md rename to docs/description/Style_OrAssignment.md diff --git a/src/main/resources/docs/description/Style_ParallelAssignment.md b/docs/description/Style_ParallelAssignment.md similarity index 100% rename from src/main/resources/docs/description/Style_ParallelAssignment.md rename to docs/description/Style_ParallelAssignment.md diff --git a/src/main/resources/docs/description/Style_ParenthesesAroundCondition.md b/docs/description/Style_ParenthesesAroundCondition.md similarity index 100% rename from src/main/resources/docs/description/Style_ParenthesesAroundCondition.md rename to docs/description/Style_ParenthesesAroundCondition.md diff --git a/src/main/resources/docs/description/Style_PercentLiteralDelimiters.md b/docs/description/Style_PercentLiteralDelimiters.md similarity index 100% rename from src/main/resources/docs/description/Style_PercentLiteralDelimiters.md rename to docs/description/Style_PercentLiteralDelimiters.md diff --git a/src/main/resources/docs/description/Style_PercentQLiterals.md b/docs/description/Style_PercentQLiterals.md similarity index 100% rename from src/main/resources/docs/description/Style_PercentQLiterals.md rename to docs/description/Style_PercentQLiterals.md diff --git a/src/main/resources/docs/description/Style_PerlBackrefs.md b/docs/description/Style_PerlBackrefs.md similarity index 70% rename from src/main/resources/docs/description/Style_PerlBackrefs.md rename to docs/description/Style_PerlBackrefs.md index a9124975..37e4bb55 100644 --- a/src/main/resources/docs/description/Style_PerlBackrefs.md +++ b/docs/description/Style_PerlBackrefs.md @@ -1,6 +1,7 @@ This cop looks for uses of Perl-style regexp match -backreferences like $1, $2, etc. +backreferences and their English versions like +$1, $2, $&, &+, $MATCH, $PREMATCH, etc. # Examples diff --git a/src/main/resources/docs/description/Style_PreferredHashMethods.md b/docs/description/Style_PreferredHashMethods.md similarity index 100% rename from src/main/resources/docs/description/Style_PreferredHashMethods.md rename to docs/description/Style_PreferredHashMethods.md diff --git a/src/main/resources/docs/description/Style_Proc.md b/docs/description/Style_Proc.md similarity index 100% rename from src/main/resources/docs/description/Style_Proc.md rename to docs/description/Style_Proc.md diff --git a/src/main/resources/docs/description/Style_RaiseArgs.md b/docs/description/Style_RaiseArgs.md similarity index 60% rename from src/main/resources/docs/description/Style_RaiseArgs.md rename to docs/description/Style_RaiseArgs.md index 499702f4..6ed5a964 100644 --- a/src/main/resources/docs/description/Style_RaiseArgs.md +++ b/docs/description/Style_RaiseArgs.md @@ -9,24 +9,31 @@ The exploded style works identically, but with the addition that it will also suggest constructing error objects when the exception is passed multiple arguments. +The exploded style has an `AllowedCompactTypes` configuration +option that takes an Array of exception name Strings. + # Examples ```ruby # bad -raise StandardError.new("message") +raise StandardError.new('message') # good -raise StandardError, "message" -fail "message" +raise StandardError, 'message' +fail 'message' raise MyCustomError.new(arg1, arg2, arg3) -raise MyKwArgError.new(key1: val1, key2: val2)# bad -raise StandardError, "message" +raise MyKwArgError.new(key1: val1, key2: val2) + +# With `AllowedCompactTypes` set to ['MyWrappedError'] +raise MyWrappedError.new(obj) +raise MyWrappedError.new(obj), 'message'# bad +raise StandardError, 'message' raise RuntimeError, arg1, arg2, arg3 # good -raise StandardError.new("message") +raise StandardError.new('message') raise MyCustomError.new(arg1, arg2, arg3) -fail "message" +fail 'message' ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RaiseArgs) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_RandomWithOffset.md b/docs/description/Style_RandomWithOffset.md similarity index 100% rename from src/main/resources/docs/description/Style_RandomWithOffset.md rename to docs/description/Style_RandomWithOffset.md diff --git a/docs/description/Style_RedundantArgument.md b/docs/description/Style_RedundantArgument.md new file mode 100644 index 00000000..c65d0612 --- /dev/null +++ b/docs/description/Style_RedundantArgument.md @@ -0,0 +1,43 @@ + +This cop checks for a redundant argument passed to certain methods. + +Limitations: + +1. This cop matches for method names only and hence cannot tell apart + methods with same name in different classes. +2. This cop is limited to methods with single parameter. +3. This cop is unsafe if certain special global variables (e.g. `$;`, `$/`) are set. + That depends on the nature of the target methods, of course. + +Method names and their redundant arguments can be configured like this: + +Methods: + join: '' + split: ' ' + chomp: "\n" + chomp!: "\n" + foo: 2 + +# Examples + +```ruby +# bad +array.join('') +[1, 2, 3].join("") +string.split(" ") +"first\nsecond".split(" ") +string.chomp("\n") +string.chomp!("\n") +A.foo(2) + +# good +array.join +[1, 2, 3].join +string.split +"first second".split +string.chomp +string.chomp! +A.foo +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantArgument) \ No newline at end of file diff --git a/docs/description/Style_RedundantAssignment.md b/docs/description/Style_RedundantAssignment.md new file mode 100644 index 00000000..774e92eb --- /dev/null +++ b/docs/description/Style_RedundantAssignment.md @@ -0,0 +1,39 @@ + +This cop checks for redundant assignment before returning. + +# Examples + +```ruby +# bad +def test + x = foo + x +end + +# bad +def test + if x + z = foo + z + elsif y + z = bar + z + end +end + +# good +def test + foo +end + +# good +def test + if x + foo + elsif y + bar + end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantAssignment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_RedundantBegin.md b/docs/description/Style_RedundantBegin.md similarity index 93% rename from src/main/resources/docs/description/Style_RedundantBegin.md rename to docs/description/Style_RedundantBegin.md index 7d2d4040..8e634a3e 100644 --- a/src/main/resources/docs/description/Style_RedundantBegin.md +++ b/docs/description/Style_RedundantBegin.md @@ -25,6 +25,14 @@ rescue StandardError => e something end +# bad +begin + do_something +end + +# good +do_something + # bad # When using Ruby 2.5 or later. do_something do diff --git a/src/main/resources/docs/description/Style_RedundantCapitalW.md b/docs/description/Style_RedundantCapitalW.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantCapitalW.md rename to docs/description/Style_RedundantCapitalW.md diff --git a/src/main/resources/docs/description/Style_RedundantCondition.md b/docs/description/Style_RedundantCondition.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantCondition.md rename to docs/description/Style_RedundantCondition.md diff --git a/src/main/resources/docs/description/Style_RedundantConditional.md b/docs/description/Style_RedundantConditional.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantConditional.md rename to docs/description/Style_RedundantConditional.md diff --git a/src/main/resources/docs/description/Style_RedundantException.md b/docs/description/Style_RedundantException.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantException.md rename to docs/description/Style_RedundantException.md diff --git a/docs/description/Style_RedundantFetchBlock.md b/docs/description/Style_RedundantFetchBlock.md new file mode 100644 index 00000000..d427782d --- /dev/null +++ b/docs/description/Style_RedundantFetchBlock.md @@ -0,0 +1,30 @@ + +This cop identifies places where `fetch(key) { value }` +can be replaced by `fetch(key, value)`. + +In such cases `fetch(key, value)` method is faster +than `fetch(key) { value }`. + +# Examples + +```ruby +# bad +hash.fetch(:key) { 5 } +hash.fetch(:key) { true } +hash.fetch(:key) { nil } +array.fetch(5) { :value } +ENV.fetch(:key) { 'value' } + +# good +hash.fetch(:key, 5) +hash.fetch(:key, true) +hash.fetch(:key, nil) +array.fetch(5, :value) +ENV.fetch(:key, 'value')# bad +ENV.fetch(:key) { VALUE } + +# good +ENV.fetch(:key, VALUE) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantFetchBlock) \ No newline at end of file diff --git a/docs/description/Style_RedundantFileExtensionInRequire.md b/docs/description/Style_RedundantFileExtensionInRequire.md new file mode 100644 index 00000000..72003cb1 --- /dev/null +++ b/docs/description/Style_RedundantFileExtensionInRequire.md @@ -0,0 +1,26 @@ + +This cop checks for the presence of superfluous `.rb` extension in +the filename provided to `require` and `require_relative`. + +Note: If the extension is omitted, Ruby tries adding '.rb', '.so', + and so on to the name until found. If the file named cannot be found, + a `LoadError` will be raised. + There is an edge case where `foo.so` file is loaded instead of a `LoadError` + if `foo.so` file exists when `require 'foo.rb'` will be changed to `require 'foo'`, + but that seems harmless. + +# Examples + +```ruby +# bad +require 'foo.rb' +require_relative '../foo.rb' + +# good +require 'foo' +require 'foo.so' +require_relative '../foo' +require_relative '../foo.so' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantFileExtensionInRequire) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_RedundantFreeze.md b/docs/description/Style_RedundantFreeze.md similarity index 52% rename from src/main/resources/docs/description/Style_RedundantFreeze.md rename to docs/description/Style_RedundantFreeze.md index 8984441a..3864a1bb 100644 --- a/src/main/resources/docs/description/Style_RedundantFreeze.md +++ b/docs/description/Style_RedundantFreeze.md @@ -1,5 +1,7 @@ -This cop check for uses of Object#freeze on immutable objects. +This cop check for uses of `Object#freeze` on immutable objects. + +NOTE: Regexp and Range literals are frozen objects since Ruby 3.0. # Examples diff --git a/src/main/resources/docs/description/Style_RedundantInterpolation.md b/docs/description/Style_RedundantInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantInterpolation.md rename to docs/description/Style_RedundantInterpolation.md diff --git a/src/main/resources/docs/description/Style_RedundantParentheses.md b/docs/description/Style_RedundantParentheses.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantParentheses.md rename to docs/description/Style_RedundantParentheses.md diff --git a/src/main/resources/docs/description/Style_RedundantPercentQ.md b/docs/description/Style_RedundantPercentQ.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantPercentQ.md rename to docs/description/Style_RedundantPercentQ.md diff --git a/docs/description/Style_RedundantRegexpCharacterClass.md b/docs/description/Style_RedundantRegexpCharacterClass.md new file mode 100644 index 00000000..e896e7a6 --- /dev/null +++ b/docs/description/Style_RedundantRegexpCharacterClass.md @@ -0,0 +1,30 @@ + +This cop checks for unnecessary single-element Regexp character classes. + +# Examples + +```ruby + +# bad +r = /[x]/ + +# good +r = /x/ + +# bad +r = /[\s]/ + +# good +r = /\s/ + +# bad +r = %r{/[b]} + +# good +r = %r{/b} + +# good +r = /[ab]/ +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantRegexpCharacterClass) \ No newline at end of file diff --git a/docs/description/Style_RedundantRegexpEscape.md b/docs/description/Style_RedundantRegexpEscape.md new file mode 100644 index 00000000..32ed139e --- /dev/null +++ b/docs/description/Style_RedundantRegexpEscape.md @@ -0,0 +1,35 @@ + +This cop checks for redundant escapes inside Regexp literals. + +# Examples + +```ruby +# bad +%r{foo\/bar} + +# good +%r{foo/bar} + +# good +/foo\/bar/ + +# good +%r/foo\/bar/ + +# good +%r!foo\!bar! + +# bad +/a\-b/ + +# good +/a-b/ + +# bad +/[\+\-]\d/ + +# good +/[+\-]\d/ +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantRegexpEscape) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_RedundantReturn.md b/docs/description/Style_RedundantReturn.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantReturn.md rename to docs/description/Style_RedundantReturn.md diff --git a/src/main/resources/docs/description/Style_RedundantSelf.md b/docs/description/Style_RedundantSelf.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantSelf.md rename to docs/description/Style_RedundantSelf.md diff --git a/docs/description/Style_RedundantSelfAssignment.md b/docs/description/Style_RedundantSelfAssignment.md new file mode 100644 index 00000000..12e1d86b --- /dev/null +++ b/docs/description/Style_RedundantSelfAssignment.md @@ -0,0 +1,29 @@ + +This cop checks for places where redundant assignments are made for in place +modification methods. + +This cop is marked as unsafe, because it can produce false positives for +user defined methods having one of the expected names, but not modifying +its receiver in place. + +# Examples + +```ruby +# bad +args = args.concat(ary) +hash = hash.merge!(other) + +# good +args.concat(foo) +args += foo +hash.merge!(other) + +# bad +self.foo = foo.concat(ary) + +# good +foo.concat(ary) +self.foo += ary +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantSelfAssignment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_RedundantSort.md b/docs/description/Style_RedundantSort.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantSort.md rename to docs/description/Style_RedundantSort.md diff --git a/src/main/resources/docs/description/Style_RedundantSortBy.md b/docs/description/Style_RedundantSortBy.md similarity index 100% rename from src/main/resources/docs/description/Style_RedundantSortBy.md rename to docs/description/Style_RedundantSortBy.md diff --git a/src/main/resources/docs/description/Style_RegexpLiteral.md b/docs/description/Style_RegexpLiteral.md similarity index 100% rename from src/main/resources/docs/description/Style_RegexpLiteral.md rename to docs/description/Style_RegexpLiteral.md diff --git a/src/main/resources/docs/description/Style_RescueModifier.md b/docs/description/Style_RescueModifier.md similarity index 100% rename from src/main/resources/docs/description/Style_RescueModifier.md rename to docs/description/Style_RescueModifier.md diff --git a/src/main/resources/docs/description/Style_RescueStandardError.md b/docs/description/Style_RescueStandardError.md similarity index 100% rename from src/main/resources/docs/description/Style_RescueStandardError.md rename to docs/description/Style_RescueStandardError.md diff --git a/src/main/resources/docs/description/Style_ReturnNil.md b/docs/description/Style_ReturnNil.md similarity index 100% rename from src/main/resources/docs/description/Style_ReturnNil.md rename to docs/description/Style_ReturnNil.md diff --git a/src/main/resources/docs/description/Style_SafeNavigation.md b/docs/description/Style_SafeNavigation.md similarity index 92% rename from src/main/resources/docs/description/Style_SafeNavigation.md rename to docs/description/Style_SafeNavigation.md index 2f61c561..38ab6cb0 100644 --- a/src/main/resources/docs/description/Style_SafeNavigation.md +++ b/docs/description/Style_SafeNavigation.md @@ -47,6 +47,10 @@ foo && foo.nil? # method that `nil` responds to foo && foo < bar foo < bar if foo +# When checking `foo&.empty?` in a conditional, `foo` being `nil` will actually +# do the opposite of what the author intends. +foo && foo.empty? + # This could start returning `nil` as well as the return of the method foo.nil? || foo.bar !foo || foo.bar diff --git a/src/main/resources/docs/description/Style_Sample.md b/docs/description/Style_Sample.md similarity index 100% rename from src/main/resources/docs/description/Style_Sample.md rename to docs/description/Style_Sample.md diff --git a/src/main/resources/docs/description/Style_SelfAssignment.md b/docs/description/Style_SelfAssignment.md similarity index 100% rename from src/main/resources/docs/description/Style_SelfAssignment.md rename to docs/description/Style_SelfAssignment.md diff --git a/src/main/resources/docs/description/Style_Semicolon.md b/docs/description/Style_Semicolon.md similarity index 100% rename from src/main/resources/docs/description/Style_Semicolon.md rename to docs/description/Style_Semicolon.md diff --git a/src/main/resources/docs/description/Style_Send.md b/docs/description/Style_Send.md similarity index 100% rename from src/main/resources/docs/description/Style_Send.md rename to docs/description/Style_Send.md diff --git a/src/main/resources/docs/description/Style_SignalException.md b/docs/description/Style_SignalException.md similarity index 100% rename from src/main/resources/docs/description/Style_SignalException.md rename to docs/description/Style_SignalException.md diff --git a/docs/description/Style_SingleArgumentDig.md b/docs/description/Style_SingleArgumentDig.md new file mode 100644 index 00000000..c63e013b --- /dev/null +++ b/docs/description/Style_SingleArgumentDig.md @@ -0,0 +1,25 @@ + +Sometimes using dig method ends up with just a single +argument. In such cases, dig should be replaced with []. + +# Examples + +```ruby +# bad +{ key: 'value' }.dig(:key) +[1, 2, 3].dig(0) + +# good +{ key: 'value' }[:key] +[1, 2, 3][0] + +# good +{ key1: { key2: 'value' } }.dig(:key1, :key2) +[1, [2, [3]]].dig(1, 1) + +# good +keys = %i[key1 key2] +{ key1: { key2: 'value' } }.dig(*keys) +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SingleArgumentDig) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_SingleLineBlockParams.md b/docs/description/Style_SingleLineBlockParams.md similarity index 100% rename from src/main/resources/docs/description/Style_SingleLineBlockParams.md rename to docs/description/Style_SingleLineBlockParams.md diff --git a/src/main/resources/docs/description/Style_SingleLineMethods.md b/docs/description/Style_SingleLineMethods.md similarity index 55% rename from src/main/resources/docs/description/Style_SingleLineMethods.md rename to docs/description/Style_SingleLineMethods.md index 19024ee9..5cf48533 100644 --- a/src/main/resources/docs/description/Style_SingleLineMethods.md +++ b/docs/description/Style_SingleLineMethods.md @@ -2,6 +2,12 @@ This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body. +Endless methods added in Ruby 3.0 are also accepted by this cop. + +If `Style/EndlessMethod` is enabled with `EnforcedStyle: allow_single_line` or +`allow_always`, single-line methods will be auto-corrected to endless +methods if there is only one statement in the body. + # Examples ```ruby @@ -12,7 +18,8 @@ def @table.columns; super; end # good def self.resource_class=(klass); end -def @table.columns; end# good +def @table.columns; end +def some_method() = body# good def no_op; end# bad def no_op; end ``` diff --git a/docs/description/Style_SlicingWithRange.md b/docs/description/Style_SlicingWithRange.md new file mode 100644 index 00000000..89cf9a06 --- /dev/null +++ b/docs/description/Style_SlicingWithRange.md @@ -0,0 +1,15 @@ + +This cop checks that arrays are sliced with endless ranges instead of +`ary[start..-1]` on Ruby 2.6+. + +# Examples + +```ruby +# bad +items[1..-1] + +# good +items[1..] +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SlicingWithRange) \ No newline at end of file diff --git a/docs/description/Style_SoleNestedConditional.md b/docs/description/Style_SoleNestedConditional.md new file mode 100644 index 00000000..53609cbb --- /dev/null +++ b/docs/description/Style_SoleNestedConditional.md @@ -0,0 +1,28 @@ + +If the branch of a conditional consists solely of a conditional node, +its conditions can be combined with the conditions of the outer branch. +This helps to keep the nesting level from getting too deep. + +# Examples + +```ruby +# bad +if condition_a + if condition_b + do_something + end +end + +# good +if condition_a && condition_b + do_something +end# bad +if condition_a + do_something if condition_b +end# good +if condition_a + do_something if condition_b +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SoleNestedConditional) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_SpecialGlobalVars.md b/docs/description/Style_SpecialGlobalVars.md similarity index 85% rename from src/main/resources/docs/description/Style_SpecialGlobalVars.md rename to docs/description/Style_SpecialGlobalVars.md index 14db7ed0..f06e9fac 100644 --- a/src/main/resources/docs/description/Style_SpecialGlobalVars.md +++ b/docs/description/Style_SpecialGlobalVars.md @@ -22,11 +22,7 @@ puts $PROCESS_ID # or $PID puts $CHILD_STATUS puts $LAST_MATCH_INFO puts $IGNORECASE -puts $ARGV # or ARGV -puts $MATCH -puts $PREMATCH -puts $POSTMATCH -puts $LAST_PAREN_MATCH# good +puts $ARGV # or ARGV# good puts $: puts $" puts $0 @@ -45,10 +41,6 @@ puts $? puts $~ puts $= puts $* -puts $& -puts $` -puts $' -puts $+ ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SpecialGlobalVars) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_StabbyLambdaParentheses.md b/docs/description/Style_StabbyLambdaParentheses.md similarity index 100% rename from src/main/resources/docs/description/Style_StabbyLambdaParentheses.md rename to docs/description/Style_StabbyLambdaParentheses.md diff --git a/docs/description/Style_StaticClass.md b/docs/description/Style_StaticClass.md new file mode 100644 index 00000000..2b518d7c --- /dev/null +++ b/docs/description/Style_StaticClass.md @@ -0,0 +1,44 @@ + +This cop checks for places where classes with only class methods can be +replaced with a module. Classes should be used only when it makes sense to create +instances out of them. + +This cop is marked as unsafe, because it is possible that this class is a parent +for some other subclass, monkey-patched with instance methods or +a dummy instance is instantiated from it somewhere. + +# Examples + +```ruby +# bad +class SomeClass + def self.some_method + # body omitted + end + + def self.some_other_method + # body omitted + end +end + +# good +module SomeModule + module_function + + def some_method + # body omitted + end + + def some_other_method + # body omitted + end +end + +# good - has instance method +class SomeClass + def instance_method; end + def self.class_method; end +end +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StaticClass) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_StderrPuts.md b/docs/description/Style_StderrPuts.md similarity index 100% rename from src/main/resources/docs/description/Style_StderrPuts.md rename to docs/description/Style_StderrPuts.md diff --git a/docs/description/Style_StringConcatenation.md b/docs/description/Style_StringConcatenation.md new file mode 100644 index 00000000..05455325 --- /dev/null +++ b/docs/description/Style_StringConcatenation.md @@ -0,0 +1,29 @@ + +This cop checks for places where string concatenation +can be replaced with string interpolation. + +The cop can autocorrect simple cases but will skip autocorrecting +more complex cases where the resulting code would be harder to read. +In those cases, it might be useful to extract statements to local +variables or methods which you can then interpolate in a string. + +NOTE: When concatenation between two strings is broken over multiple +lines, this cop does not register an offense; instead, +`Style/LineEndConcatenation` will pick up the offense if enabled. + +# Examples + +```ruby +# bad +email_with_name = user.name + ' <' + user.email + '>' + +# good +email_with_name = "#{user.name} <#{user.email}>" +email_with_name = format('%s <%s>', user.name, user.email) + +# accepted, line-end concatenation +name = 'First' + + 'Last' +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StringConcatenation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_StringHashKeys.md b/docs/description/Style_StringHashKeys.md similarity index 100% rename from src/main/resources/docs/description/Style_StringHashKeys.md rename to docs/description/Style_StringHashKeys.md diff --git a/src/main/resources/docs/description/Style_StringLiterals.md b/docs/description/Style_StringLiterals.md similarity index 100% rename from src/main/resources/docs/description/Style_StringLiterals.md rename to docs/description/Style_StringLiterals.md diff --git a/src/main/resources/docs/description/Style_StringLiteralsInInterpolation.md b/docs/description/Style_StringLiteralsInInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Style_StringLiteralsInInterpolation.md rename to docs/description/Style_StringLiteralsInInterpolation.md diff --git a/src/main/resources/docs/description/Style_StringMethods.md b/docs/description/Style_StringMethods.md similarity index 100% rename from src/main/resources/docs/description/Style_StringMethods.md rename to docs/description/Style_StringMethods.md diff --git a/src/main/resources/docs/description/Style_Strip.md b/docs/description/Style_Strip.md similarity index 100% rename from src/main/resources/docs/description/Style_Strip.md rename to docs/description/Style_Strip.md diff --git a/src/main/resources/docs/description/Style_StructInheritance.md b/docs/description/Style_StructInheritance.md similarity index 100% rename from src/main/resources/docs/description/Style_StructInheritance.md rename to docs/description/Style_StructInheritance.md diff --git a/docs/description/Style_SwapValues.md b/docs/description/Style_SwapValues.md new file mode 100644 index 00000000..2c7cb591 --- /dev/null +++ b/docs/description/Style_SwapValues.md @@ -0,0 +1,18 @@ + +This cop enforces the use of shorthand-style swapping of 2 variables. +Its autocorrection is marked as unsafe, because it can erroneously remove +the temporary variable which is used later. + +# Examples + +```ruby +# bad +tmp = x +x = y +y = tmp + +# good +x, y = y, x +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/SwapValues) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_SymbolArray.md b/docs/description/Style_SymbolArray.md similarity index 100% rename from src/main/resources/docs/description/Style_SymbolArray.md rename to docs/description/Style_SymbolArray.md diff --git a/src/main/resources/docs/description/Style_SymbolLiteral.md b/docs/description/Style_SymbolLiteral.md similarity index 100% rename from src/main/resources/docs/description/Style_SymbolLiteral.md rename to docs/description/Style_SymbolLiteral.md diff --git a/src/main/resources/docs/description/Style_SymbolProc.md b/docs/description/Style_SymbolProc.md similarity index 88% rename from src/main/resources/docs/description/Style_SymbolProc.md rename to docs/description/Style_SymbolProc.md index a7c4ce9e..7c586554 100644 --- a/src/main/resources/docs/description/Style_SymbolProc.md +++ b/docs/description/Style_SymbolProc.md @@ -6,6 +6,7 @@ Use symbols as procs when possible. ```ruby # bad something.map { |s| s.upcase } +something.map { _1.upcase } # good something.map(&:upcase) diff --git a/src/main/resources/docs/description/Style_TernaryParentheses.md b/docs/description/Style_TernaryParentheses.md similarity index 100% rename from src/main/resources/docs/description/Style_TernaryParentheses.md rename to docs/description/Style_TernaryParentheses.md diff --git a/src/main/resources/docs/description/Style_TrailingBodyOnClass.md b/docs/description/Style_TrailingBodyOnClass.md similarity index 100% rename from src/main/resources/docs/description/Style_TrailingBodyOnClass.md rename to docs/description/Style_TrailingBodyOnClass.md diff --git a/src/main/resources/docs/description/Style_TrailingBodyOnMethodDefinition.md b/docs/description/Style_TrailingBodyOnMethodDefinition.md similarity index 100% rename from src/main/resources/docs/description/Style_TrailingBodyOnMethodDefinition.md rename to docs/description/Style_TrailingBodyOnMethodDefinition.md diff --git a/src/main/resources/docs/description/Style_TrailingBodyOnModule.md b/docs/description/Style_TrailingBodyOnModule.md similarity index 100% rename from src/main/resources/docs/description/Style_TrailingBodyOnModule.md rename to docs/description/Style_TrailingBodyOnModule.md diff --git a/src/main/resources/docs/description/Style_TrailingCommaInArguments.md b/docs/description/Style_TrailingCommaInArguments.md similarity index 78% rename from src/main/resources/docs/description/Style_TrailingCommaInArguments.md rename to docs/description/Style_TrailingCommaInArguments.md index aea9204a..655ad83e 100644 --- a/src/main/resources/docs/description/Style_TrailingCommaInArguments.md +++ b/docs/description/Style_TrailingCommaInArguments.md @@ -2,11 +2,11 @@ This cop checks for trailing comma in argument lists. The supported styles are: -- `consistent_comma`: Requires a comma after the last argument, +* `consistent_comma`: Requires a comma after the last argument, for all parenthesized method calls with arguments. -- `comma`: Requires a comma after the last argument, but only for +* `comma`: Requires a comma after the last argument, but only for parenthesized method calls where each argument is on its own line. -- `no_comma`: Requires that there is no comma after the last +* `no_comma`: Requires that there is no comma after the last argument. # Examples diff --git a/src/main/resources/docs/description/Style_TrailingCommaInArrayLiteral.md b/docs/description/Style_TrailingCommaInArrayLiteral.md similarity index 80% rename from src/main/resources/docs/description/Style_TrailingCommaInArrayLiteral.md rename to docs/description/Style_TrailingCommaInArrayLiteral.md index 6f877bb7..cea29575 100644 --- a/src/main/resources/docs/description/Style_TrailingCommaInArrayLiteral.md +++ b/docs/description/Style_TrailingCommaInArrayLiteral.md @@ -2,11 +2,11 @@ This cop checks for trailing comma in array literals. The configuration options are: -- `consistent_comma`: Requires a comma after the +* `consistent_comma`: Requires a comma after the last item of all non-empty, multiline array literals. -- `comma`: Requires a comma after last item in an array, +* `comma`: Requires a comma after last item in an array, but only when each item is on its own line. -- `no_comma`: Does not requires a comma after the +* `no_comma`: Does not requires a comma after the last item in an array # Examples diff --git a/src/main/resources/docs/description/Style_TrailingCommaInBlockArgs.md b/docs/description/Style_TrailingCommaInBlockArgs.md similarity index 73% rename from src/main/resources/docs/description/Style_TrailingCommaInBlockArgs.md rename to docs/description/Style_TrailingCommaInBlockArgs.md index c7032e31..aa6f6ab1 100644 --- a/src/main/resources/docs/description/Style_TrailingCommaInBlockArgs.md +++ b/docs/description/Style_TrailingCommaInBlockArgs.md @@ -4,32 +4,13 @@ required. Blocks with only one argument and a trailing comma require that comma to be present. Blocks with more than one argument never require a trailing comma. - add do |foo, bar,| - foo + bar - end - - # good - add do |foo, bar| - foo + bar - end - - # good - add do |foo,| - foo - end - - # good - add do - foo + bar - end - # Examples ```ruby # bad add { |foo, bar,| foo + bar } - # good +# good add { |foo, bar| foo + bar } # good @@ -39,6 +20,24 @@ add { |foo,| foo } add { foo } # bad +add do |foo, bar,| + foo + bar +end + +# good +add do |foo, bar| + foo + bar +end + +# good +add do |foo,| + foo +end + +# good +add do + foo + bar +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/TrailingCommaInBlockArgs) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_TrailingCommaInHashLiteral.md b/docs/description/Style_TrailingCommaInHashLiteral.md similarity index 84% rename from src/main/resources/docs/description/Style_TrailingCommaInHashLiteral.md rename to docs/description/Style_TrailingCommaInHashLiteral.md index 1b66fd9c..a34e26fe 100644 --- a/src/main/resources/docs/description/Style_TrailingCommaInHashLiteral.md +++ b/docs/description/Style_TrailingCommaInHashLiteral.md @@ -2,11 +2,11 @@ This cop checks for trailing comma in hash literals. The configuration options are: -- `consistent_comma`: Requires a comma after the +* `consistent_comma`: Requires a comma after the last item of all non-empty, multiline hash literals. -- `comma`: Requires a comma after the last item in a hash, +* `comma`: Requires a comma after the last item in a hash, but only when each item is on its own line. -- `no_comma`: Does not requires a comma after the +* `no_comma`: Does not requires a comma after the last item in a hash # Examples diff --git a/src/main/resources/docs/description/Style_TrailingMethodEndStatement.md b/docs/description/Style_TrailingMethodEndStatement.md similarity index 100% rename from src/main/resources/docs/description/Style_TrailingMethodEndStatement.md rename to docs/description/Style_TrailingMethodEndStatement.md diff --git a/src/main/resources/docs/description/Style_TrailingUnderscoreVariable.md b/docs/description/Style_TrailingUnderscoreVariable.md similarity index 100% rename from src/main/resources/docs/description/Style_TrailingUnderscoreVariable.md rename to docs/description/Style_TrailingUnderscoreVariable.md diff --git a/src/main/resources/docs/description/Style_TrivialAccessors.md b/docs/description/Style_TrivialAccessors.md similarity index 100% rename from src/main/resources/docs/description/Style_TrivialAccessors.md rename to docs/description/Style_TrivialAccessors.md diff --git a/src/main/resources/docs/description/Style_UnlessElse.md b/docs/description/Style_UnlessElse.md similarity index 81% rename from src/main/resources/docs/description/Style_UnlessElse.md rename to docs/description/Style_UnlessElse.md index 2217e19c..f3f39eda 100644 --- a/src/main/resources/docs/description/Style_UnlessElse.md +++ b/docs/description/Style_UnlessElse.md @@ -1,5 +1,5 @@ -This cop looks for *unless* expressions with *else* clauses. +This cop looks for `unless` expressions with `else` clauses. # Examples diff --git a/src/main/resources/docs/description/Style_UnpackFirst.md b/docs/description/Style_UnpackFirst.md similarity index 100% rename from src/main/resources/docs/description/Style_UnpackFirst.md rename to docs/description/Style_UnpackFirst.md diff --git a/src/main/resources/docs/description/Style_VariableInterpolation.md b/docs/description/Style_VariableInterpolation.md similarity index 100% rename from src/main/resources/docs/description/Style_VariableInterpolation.md rename to docs/description/Style_VariableInterpolation.md diff --git a/src/main/resources/docs/description/Style_WhenThen.md b/docs/description/Style_WhenThen.md similarity index 78% rename from src/main/resources/docs/description/Style_WhenThen.md rename to docs/description/Style_WhenThen.md index 1abe478f..640a8705 100644 --- a/src/main/resources/docs/description/Style_WhenThen.md +++ b/docs/description/Style_WhenThen.md @@ -1,5 +1,5 @@ -This cop checks for *when;* uses in *case* expressions. +This cop checks for `when;` uses in `case` expressions. # Examples diff --git a/src/main/resources/docs/description/Style_WhileUntilDo.md b/docs/description/Style_WhileUntilDo.md similarity index 100% rename from src/main/resources/docs/description/Style_WhileUntilDo.md rename to docs/description/Style_WhileUntilDo.md diff --git a/src/main/resources/docs/description/Style_WhileUntilModifier.md b/docs/description/Style_WhileUntilModifier.md similarity index 63% rename from src/main/resources/docs/description/Style_WhileUntilModifier.md rename to docs/description/Style_WhileUntilModifier.md index af8ce9c3..5c87c8b7 100644 --- a/src/main/resources/docs/description/Style_WhileUntilModifier.md +++ b/docs/description/Style_WhileUntilModifier.md @@ -18,7 +18,13 @@ until x > 10 end # good -x += 1 until x > 10 +x += 1 until x > 10# bad +x += 100 while x < 500 # a long comment that makes code too long if it were a single line + +# good +while x < 500 # a long comment that makes code too long if it were a single line + x += 100 +end ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/WhileUntilModifier) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_WordArray.md b/docs/description/Style_WordArray.md similarity index 100% rename from src/main/resources/docs/description/Style_WordArray.md rename to docs/description/Style_WordArray.md diff --git a/src/main/resources/docs/description/Style_YodaCondition.md b/docs/description/Style_YodaCondition.md similarity index 89% rename from src/main/resources/docs/description/Style_YodaCondition.md rename to docs/description/Style_YodaCondition.md index df1c777a..e68c3f39 100644 --- a/src/main/resources/docs/description/Style_YodaCondition.md +++ b/docs/description/Style_YodaCondition.md @@ -16,7 +16,9 @@ eg. `5 == x` foo == 99 foo == "bar" foo <= 42 -bar > 10# bad +bar > 10 +"#{interpolation}" == foo +/#{interpolation}/ == foo# bad 99 == foo "bar" != foo diff --git a/src/main/resources/docs/description/Style_ZeroLengthPredicate.md b/docs/description/Style_ZeroLengthPredicate.md similarity index 100% rename from src/main/resources/docs/description/Style_ZeroLengthPredicate.md rename to docs/description/Style_ZeroLengthPredicate.md diff --git a/src/main/resources/docs/description/description.json b/docs/description/description.json similarity index 79% rename from src/main/resources/docs/description/description.json rename to docs/description/description.json index f5d242a9..7f8b7337 100644 --- a/src/main/resources/docs/description/description.json +++ b/docs/description/description.json @@ -30,6 +30,10 @@ { "name": "IgnoredGems", "description": "IgnoredGems" + }, + { + "name": "OnlyFor", + "description": "OnlyFor" } ] }, @@ -55,6 +59,10 @@ "name": "TreatCommentsAsGroupSeparators", "description": "TreatCommentsAsGroupSeparators" }, + { + "name": "ConsiderPunctuation", + "description": "ConsiderPunctuation" + }, { "name": "Include", "description": "Include" @@ -83,6 +91,10 @@ "name": "TreatCommentsAsGroupSeparators", "description": "TreatCommentsAsGroupSeparators" }, + { + "name": "ConsiderPunctuation", + "description": "ConsiderPunctuation" + }, { "name": "Include", "description": "Include" @@ -91,8 +103,8 @@ }, { "patternId": "Gemspec_RequiredRubyVersion", - "title": "Checks that `required_ruby_version` of gemspec and `TargetRubyVersion` of .rubocop.yml are equal.", - "description": "Checks that `required_ruby_version` of gemspec and `TargetRubyVersion` of .rubocop.yml are equal.", + "title": "Checks that `required_ruby_version` of gemspec is specified and equal to `TargetRubyVersion` of .rubocop.yml.", + "description": "Checks that `required_ruby_version` of gemspec is specified and equal to `TargetRubyVersion` of .rubocop.yml.", "timeToFix": 5, "parameters": [ { @@ -185,6 +197,26 @@ } ] }, + { + "patternId": "Layout_BeginEndAlignment", + "title": "Align ends corresponding to begins correctly.", + "description": "Align ends corresponding to begins correctly.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyleAlignWith", + "description": "EnforcedStyleAlignWith" + }, + { + "name": "SupportedStylesAlignWith", + "description": "SupportedStylesAlignWith" + }, + { + "name": "Severity", + "description": "Severity" + } + ] + }, { "patternId": "Layout_BlockAlignment", "title": "Align block ends correctly.", @@ -285,10 +317,6 @@ "name": "SupportedStylesAlignWith", "description": "SupportedStylesAlignWith" }, - { - "name": "AutoCorrect", - "description": "AutoCorrect" - }, { "name": "Severity", "description": "Severity" @@ -345,12 +373,30 @@ "description": "Add an empty line after magic comments to separate them from code.", "timeToFix": 5 }, + { + "patternId": "Layout_EmptyLineAfterMultilineCondition", + "title": "Enforces empty line after multiline condition.", + "description": "Enforces empty line after multiline condition.", + "timeToFix": 5 + }, { "patternId": "Layout_EmptyLineBetweenDefs", - "title": "Use empty lines between defs.", - "description": "Use empty lines between defs.", + "title": "Use empty lines between class/module/method defs.", + "description": "Use empty lines between class/module/method defs.", "timeToFix": 5, "parameters": [ + { + "name": "EmptyLineBetweenMethodDefs", + "description": "EmptyLineBetweenMethodDefs" + }, + { + "name": "EmptyLineBetweenClassDefs", + "description": "EmptyLineBetweenClassDefs" + }, + { + "name": "EmptyLineBetweenModuleDefs", + "description": "EmptyLineBetweenModuleDefs" + }, { "name": "AllowAdjacentOneLineDefs", "description": "AllowAdjacentOneLineDefs" @@ -383,6 +429,22 @@ "description": "Keeps track of empty lines around method arguments.", "timeToFix": 5 }, + { + "patternId": "Layout_EmptyLinesAroundAttributeAccessor", + "title": "Keep blank lines around attribute accessors.", + "description": "Keep blank lines around attribute accessors.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowAliasSyntax", + "description": "AllowAliasSyntax" + }, + { + "name": "AllowedMethods", + "description": "AllowedMethods" + } + ] + }, { "patternId": "Layout_EmptyLinesAroundBeginBody", "title": "Keeps track of empty lines around begin-end bodies.", @@ -469,10 +531,6 @@ "name": "SupportedStylesAlignWith", "description": "SupportedStylesAlignWith" }, - { - "name": "AutoCorrect", - "description": "AutoCorrect" - }, { "name": "Severity", "description": "Severity" @@ -665,17 +723,7 @@ "patternId": "Layout_HeredocIndentation", "title": "This cop checks the indentation of the here document bodies.", "description": "This cop checks the indentation of the here document bodies.", - "timeToFix": 5, - "parameters": [ - { - "name": "EnforcedStyle", - "description": "EnforcedStyle" - }, - { - "name": "SupportedStyles", - "description": "SupportedStyles" - } - ] + "timeToFix": 5 }, { "patternId": "Layout_IndentationConsistency", @@ -759,8 +807,8 @@ }, { "patternId": "Layout_LineLength", - "title": "Limit lines to 80 characters.", - "description": "Limit lines to 80 characters.", + "title": "Checks that line length does not exceed the configured limit.", + "description": "Checks that line length does not exceed the configured limit.", "timeToFix": 5, "parameters": [ { @@ -1085,6 +1133,12 @@ } ] }, + { + "patternId": "Layout_SpaceBeforeBrackets", + "title": "Checks for receiver with a space before the opening brackets.", + "description": "Checks for receiver with a space before the opening brackets.", + "timeToFix": 5 + }, { "patternId": "Layout_SpaceBeforeComma", "title": "No spaces before commas.", @@ -1309,6 +1363,12 @@ } ] }, + { + "patternId": "Lint_AmbiguousAssignment", + "title": "Checks for mistyped shorthand assignments.", + "description": "Checks for mistyped shorthand assignments.", + "timeToFix": 5 + }, { "patternId": "Lint_AmbiguousBlockAssociation", "title": "Checks for ambiguous block association with method when param passed without parentheses.", @@ -1345,11 +1405,29 @@ "description": "`BigDecimal.new()` is deprecated. Use `BigDecimal()` instead.", "timeToFix": 5 }, + { + "patternId": "Lint_BinaryOperatorWithIdenticalOperands", + "title": "This cop checks for places where binary operator has identical operands.", + "description": "This cop checks for places where binary operator has identical operands.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Lint_BooleanSymbol", "title": "Check for `:true` and `:false` symbols.", "description": "Check for `:true` and `:false` symbols.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] }, { "patternId": "Lint_CircularArgumentReference", @@ -1357,11 +1435,49 @@ "description": "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument.", "timeToFix": 5 }, + { + "patternId": "Lint_ConstantDefinitionInBlock", + "title": "Do not define constants within a block.", + "description": "Do not define constants within a block.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowedMethods", + "description": "AllowedMethods" + } + ] + }, + { + "patternId": "Lint_ConstantResolution", + "title": "Check that constants are fully qualified with `::`.", + "description": "Check that constants are fully qualified with `::`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Only", + "description": "Only" + }, + { + "name": "Ignore", + "description": "Ignore" + } + ] + }, { "patternId": "Lint_Debugger", "title": "Check for debugger calls.", "description": "Check for debugger calls.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "DebuggerReceivers", + "description": "DebuggerReceivers" + }, + { + "name": "DebuggerMethods", + "description": "DebuggerMethods" + } + ] }, { "patternId": "Lint_DeprecatedClassMethods", @@ -1369,6 +1485,24 @@ "description": "Check for deprecated class method calls.", "timeToFix": 5 }, + { + "patternId": "Lint_DeprecatedConstants", + "title": "Checks for deprecated constants.", + "description": "Checks for deprecated constants.", + "timeToFix": 5, + "parameters": [ + { + "name": "DeprecatedConstants", + "description": "DeprecatedConstants" + } + ] + }, + { + "patternId": "Lint_DeprecatedOpenSSLConstant", + "title": "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`.", + "description": "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`.", + "timeToFix": 5 + }, { "patternId": "Lint_DisjunctiveAssignmentInConstructor", "title": "In constructor, plain assignment is preferred over disjunctive.", @@ -1381,12 +1515,34 @@ } ] }, + { + "patternId": "Lint_DuplicateBranch", + "title": "Checks that there are no repeated bodies within `if/unless`, `case-when` and `rescue` constructs.", + "description": "Checks that there are no repeated bodies within `if/unless`, `case-when` and `rescue` constructs.", + "timeToFix": 5, + "parameters": [ + { + "name": "IgnoreLiteralBranches", + "description": "IgnoreLiteralBranches" + }, + { + "name": "IgnoreConstantBranches", + "description": "IgnoreConstantBranches" + } + ] + }, { "patternId": "Lint_DuplicateCaseCondition", "title": "Do not repeat values in case conditionals.", "description": "Do not repeat values in case conditionals.", "timeToFix": 5 }, + { + "patternId": "Lint_DuplicateElsifCondition", + "title": "Do not repeat conditions used in if `elsif`.", + "description": "Do not repeat conditions used in if `elsif`.", + "timeToFix": 5 + }, { "patternId": "Lint_DuplicateHashKey", "title": "Check for duplicate keys in hash literals.", @@ -1399,6 +1555,24 @@ "description": "Check for duplicate method definitions.", "timeToFix": 5 }, + { + "patternId": "Lint_DuplicateRegexpCharacterClassElement", + "title": "Checks for duplicate elements in Regexp character classes.", + "description": "Checks for duplicate elements in Regexp character classes.", + "timeToFix": 5 + }, + { + "patternId": "Lint_DuplicateRequire", + "title": "Check for duplicate `require`s and `require_relative`s.", + "description": "Check for duplicate `require`s and `require_relative`s.", + "timeToFix": 5 + }, + { + "patternId": "Lint_DuplicateRescueException", + "title": "Checks that there are no repeated exceptions used in `rescue` expressions.", + "description": "Checks that there are no repeated exceptions used in `rescue` expressions.", + "timeToFix": 5 + }, { "patternId": "Lint_EachWithObjectArgument", "title": "Check for immutable argument given to each_with_object.", @@ -1412,23 +1586,69 @@ "timeToFix": 5 }, { - "patternId": "Lint_EmptyEnsure", - "title": "Checks for empty ensure block.", - "description": "Checks for empty ensure block.", + "patternId": "Lint_EmptyBlock", + "title": "This cop checks for blocks without a body.", + "description": "This cop checks for blocks without a body.", "timeToFix": 5, "parameters": [ { - "name": "AutoCorrect", - "description": "AutoCorrect" + "name": "AllowComments", + "description": "AllowComments" + }, + { + "name": "AllowEmptyLambdas", + "description": "AllowEmptyLambdas" + } + ] + }, + { + "patternId": "Lint_EmptyClass", + "title": "Checks for classes and metaclasses without a body.", + "description": "Checks for classes and metaclasses without a body.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowComments", + "description": "AllowComments" + } + ] + }, + { + "patternId": "Lint_EmptyConditionalBody", + "title": "This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.", + "description": "This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowComments", + "description": "AllowComments" } ] }, + { + "patternId": "Lint_EmptyEnsure", + "title": "Checks for empty ensure block.", + "description": "Checks for empty ensure block.", + "timeToFix": 5 + }, { "patternId": "Lint_EmptyExpression", "title": "Checks for empty expressions.", "description": "Checks for empty expressions.", "timeToFix": 5 }, + { + "patternId": "Lint_EmptyFile", + "title": "Enforces that Ruby source files are not empty.", + "description": "Enforces that Ruby source files are not empty.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowComments", + "description": "AllowComments" + } + ] + }, { "patternId": "Lint_EmptyInterpolation", "title": "Checks for empty string interpolation.", @@ -1439,7 +1659,13 @@ "patternId": "Lint_EmptyWhen", "title": "Checks for `when` branches with empty bodies.", "description": "Checks for `when` branches with empty bodies.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "AllowComments", + "description": "AllowComments" + } + ] }, { "patternId": "Lint_EnsureReturn", @@ -1459,6 +1685,12 @@ "description": "Checks for flip-flops.", "timeToFix": 5 }, + { + "patternId": "Lint_FloatComparison", + "title": "Checks for the presence of precise comparison of floating point numbers.", + "description": "Checks for the presence of precise comparison of floating point numbers.", + "timeToFix": 5 + }, { "patternId": "Lint_FloatOutOfRange", "title": "Catches floating-point literals too large or small for Ruby to represent.", @@ -1471,12 +1703,30 @@ "description": "The number of parameters to format/sprint must match the fields.", "timeToFix": 5 }, + { + "patternId": "Lint_HashCompareByIdentity", + "title": "Prefer using `Hash#compare_by_identity` than using `object_id` for keys.", + "description": "Prefer using `Hash#compare_by_identity` than using `object_id` for keys.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Lint_HeredocMethodCallPosition", "title": "Checks for the ordering of a method call where the receiver of the call is a HEREDOC.", "description": "Checks for the ordering of a method call where the receiver of the call is a HEREDOC.", "timeToFix": 5 }, + { + "patternId": "Lint_IdentityComparison", + "title": "Prefer `equal?` over `==` when comparing `object_id`.", + "description": "Prefer `equal?` over `==` when comparing `object_id`.", + "timeToFix": 5 + }, { "patternId": "Lint_ImplicitStringConcatenation", "title": "Checks for adjacent string literals on the same line, which could better be represented as a single string literal.", @@ -1509,6 +1759,18 @@ "patternId": "Lint_InterpolationCheck", "title": "Raise warning for interpolation in single q strs.", "description": "Raise warning for interpolation in single q strs.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Lint_LambdaWithoutLiteralBlock", + "title": "Checks uses of lambda without a literal block.", + "description": "Checks uses of lambda without a literal block.", "timeToFix": 5 }, { @@ -1527,7 +1789,13 @@ "patternId": "Lint_Loop", "title": "Use Kernel#loop with break rather than begin/end/until or begin/end/while for post-loop tests.", "description": "Use Kernel#loop with break rather than begin/end/until or begin/end/while for post-loop tests.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] }, { "patternId": "Lint_MissingCopEnableDirective", @@ -1541,11 +1809,29 @@ } ] }, + { + "patternId": "Lint_MissingSuper", + "title": "This cop checks for the presence of constructors and lifecycle callbacks without calls to `super`'.", + "description": "This cop checks for the presence of constructors and lifecycle callbacks without calls to `super`'.", + "timeToFix": 5 + }, + { + "patternId": "Lint_MixedRegexpCaptureTypes", + "title": "Do not mix named captures and numbered captures in a Regexp literal.", + "description": "Do not mix named captures and numbered captures in a Regexp literal.", + "timeToFix": 5 + }, { "patternId": "Lint_MultipleComparison", "title": "Use `&&` operator to compare multiple values.", "description": "Use `&&` operator to compare multiple values.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "AllowMethodComparison", + "description": "AllowMethodComparison" + } + ] }, { "patternId": "Lint_NestedMethodDefinition", @@ -1565,6 +1851,12 @@ "description": "Do not omit the accumulator when calling `next` in a `reduce`/`inject` block.", "timeToFix": 5 }, + { + "patternId": "Lint_NoReturnInBeginEndBlocks", + "title": "Do not `return` inside `begin..end` blocks in assignment contexts.", + "description": "Do not `return` inside `begin..end` blocks in assignment contexts.", + "timeToFix": 5 + }, { "patternId": "Lint_NonDeterministicRequireOrder", "title": "Always sort arrays returned by Dir.glob when requiring files.", @@ -1592,23 +1884,61 @@ { "name": "SafeAutoCorrect", "description": "SafeAutoCorrect" + }, + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" + }, + { + "name": "IgnoredClasses", + "description": "IgnoredClasses" } ] }, { - "patternId": "Lint_OrderedMagicComments", - "title": "Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.", - "description": "Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.", - "timeToFix": 5 - }, - { - "patternId": "Lint_ParenthesesAsGroupedExpression", - "title": "Checks for method calls with a space before the opening parenthesis.", - "description": "Checks for method calls with a space before the opening parenthesis.", + "patternId": "Lint_NumberedParameterAssignment", + "title": "Checks for uses of numbered parameter assignment.", + "description": "Checks for uses of numbered parameter assignment.", "timeToFix": 5 }, { - "patternId": "Lint_PercentStringArray", + "patternId": "Lint_OrAssignmentToConstant", + "title": "Checks unintended or-assignment to constant.", + "description": "Checks unintended or-assignment to constant.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Lint_OrderedMagicComments", + "title": "Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.", + "description": "Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.", + "timeToFix": 5 + }, + { + "patternId": "Lint_OutOfRangeRegexpRef", + "title": "Checks for out of range reference for Regexp because it always returns nil.", + "description": "Checks for out of range reference for Regexp because it always returns nil.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Lint_ParenthesesAsGroupedExpression", + "title": "Checks for method calls with a space before the opening parenthesis.", + "description": "Checks for method calls with a space before the opening parenthesis.", + "timeToFix": 5 + }, + { + "patternId": "Lint_PercentStringArray", "title": "Checks for unwanted commas and quotes in %w/%W literals.", "description": "Checks for unwanted commas and quotes in %w/%W literals.", "timeToFix": 5, @@ -1631,6 +1961,10 @@ "description": "Checks for `raise` or `fail` statements which are raising `Exception` class.", "timeToFix": 5, "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, { "name": "AllowedImplicitNamespaces", "description": "AllowedImplicitNamespaces" @@ -1649,17 +1983,45 @@ "description": "Checks for rubocop:enable comments that can be removed.", "timeToFix": 5 }, + { + "patternId": "Lint_RedundantDirGlobSort", + "title": "Checks for redundant `sort` method to `Dir.glob` and `Dir[]`.", + "description": "Checks for redundant `sort` method to `Dir.glob` and `Dir[]`.", + "timeToFix": 5 + }, { "patternId": "Lint_RedundantRequireStatement", "title": "Checks for unnecessary `require` statement.", "description": "Checks for unnecessary `require` statement.", "timeToFix": 5 }, + { + "patternId": "Lint_RedundantSafeNavigation", + "title": "Checks for redundant safe navigation calls.", + "description": "Checks for redundant safe navigation calls.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowedMethods", + "description": "AllowedMethods" + }, + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Lint_RedundantSplatExpansion", "title": "Checks for splat unnecessarily being called on literals.", "description": "Checks for splat unnecessarily being called on literals.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "AllowPercentLiteralArrayArgument", + "description": "AllowPercentLiteralArrayArgument" + } + ] }, { "patternId": "Lint_RedundantStringCoercion", @@ -1745,6 +2107,12 @@ "description": "Grant script file execute permission.", "timeToFix": 5 }, + { + "patternId": "Lint_SelfAssignment", + "title": "Checks for self-assignments.", + "description": "Checks for self-assignments.", + "timeToFix": 5 + }, { "patternId": "Lint_SendWithMixinArgument", "title": "Checks for `send` method when using mixin.", @@ -1793,10 +2161,22 @@ } ] }, + { + "patternId": "Lint_SymbolConversion", + "title": "Checks for unnecessary symbol conversions.", + "description": "Checks for unnecessary symbol conversions.", + "timeToFix": 5 + }, { "patternId": "Lint_Syntax", - "title": "Checks syntax error.", - "description": "Checks syntax error.", + "title": "Checks for syntax errors.", + "description": "Checks for syntax errors.", + "timeToFix": 5 + }, + { + "patternId": "Lint_ToEnumArguments", + "title": "This cop ensures that `to_enum`/`enum_for`, called for the current method, has correct arguments.", + "description": "This cop ensures that `to_enum`/`enum_for`, called for the current method, has correct arguments.", "timeToFix": 5 }, { @@ -1805,6 +2185,24 @@ "description": "Ensure #to_json includes an optional argument.", "timeToFix": 5 }, + { + "patternId": "Lint_TopLevelReturnWithArgument", + "title": "This cop detects top level return statements with argument.", + "description": "This cop detects top level return statements with argument.", + "timeToFix": 5 + }, + { + "patternId": "Lint_TrailingCommaInAttributeDeclaration", + "title": "This cop checks for trailing commas in attribute declarations.", + "description": "This cop checks for trailing commas in attribute declarations.", + "timeToFix": 5 + }, + { + "patternId": "Lint_TripleQuotes", + "title": "Checks for useless triple quote constructs.", + "description": "Checks for useless triple quote constructs.", + "timeToFix": 5 + }, { "patternId": "Lint_UnderscorePrefixedVariableName", "title": "Do not use prefix `_` for a variable that is used.", @@ -1817,18 +2215,52 @@ } ] }, + { + "patternId": "Lint_UnexpectedBlockArity", + "title": "Looks for blocks that have fewer arguments that the calling method expects.", + "description": "Looks for blocks that have fewer arguments that the calling method expects.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "Methods", + "description": "Methods" + } + ] + }, { "patternId": "Lint_UnifiedInteger", "title": "Use Integer instead of Fixnum or Bignum.", "description": "Use Integer instead of Fixnum or Bignum.", "timeToFix": 5 }, + { + "patternId": "Lint_UnmodifiedReduceAccumulator", + "title": "Checks for `reduce` or `inject` blocks that do not update the accumulator each iteration.", + "description": "Checks for `reduce` or `inject` blocks that do not update the accumulator each iteration.", + "timeToFix": 5 + }, { "patternId": "Lint_UnreachableCode", "title": "Unreachable code.", "description": "Unreachable code.", "timeToFix": 5 }, + { + "patternId": "Lint_UnreachableLoop", + "title": "This cop checks for loops that will have at most one iteration.", + "description": "This cop checks for loops that will have at most one iteration.", + "timeToFix": 5, + "parameters": [ + { + "name": "IgnoredPatterns", + "description": "IgnoredPatterns" + } + ] + }, { "patternId": "Lint_UnusedBlockArgument", "title": "Checks for unused block arguments.", @@ -1899,23 +2331,49 @@ "description": "Checks for useless assignment to a local variable.", "timeToFix": 5 }, - { - "patternId": "Lint_UselessComparison", - "title": "Checks for comparison of something with itself.", - "description": "Checks for comparison of something with itself.", - "timeToFix": 5 - }, { "patternId": "Lint_UselessElseWithoutRescue", "title": "Checks for useless `else` in `begin..end` without `rescue`.", "description": "Checks for useless `else` in `begin..end` without `rescue`.", "timeToFix": 5 }, + { + "patternId": "Lint_UselessMethodDefinition", + "title": "Checks for useless method definitions.", + "description": "Checks for useless method definitions.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "AllowComments", + "description": "AllowComments" + } + ] + }, { "patternId": "Lint_UselessSetterCall", "title": "Checks for useless setter call to a local variable.", "description": "Checks for useless setter call to a local variable.", "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Lint_UselessTimes", + "title": "Checks for useless `Integer#times` calls.", + "description": "Checks for useless `Integer#times` calls.", + "timeToFix": 5, "parameters": [ { "name": "Safe", @@ -1961,6 +2419,10 @@ "name": "IgnoredMethods", "description": "IgnoredMethods" }, + { + "name": "CountRepeatedAttributes", + "description": "CountRepeatedAttributes" + }, { "name": "Max", "description": "Max" @@ -1981,10 +2443,18 @@ "name": "Max", "description": "Max" }, + { + "name": "CountAsOne", + "description": "CountAsOne" + }, { "name": "ExcludedMethods", "description": "ExcludedMethods" }, + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" + }, { "name": "Exclude", "description": "Exclude" @@ -2020,6 +2490,10 @@ { "name": "Max", "description": "Max" + }, + { + "name": "CountAsOne", + "description": "CountAsOne" } ] }, @@ -2037,9 +2511,17 @@ "name": "Max", "description": "Max" }, + { + "name": "CountAsOne", + "description": "CountAsOne" + }, { "name": "ExcludedMethods", "description": "ExcludedMethods" + }, + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" } ] }, @@ -2056,6 +2538,10 @@ { "name": "Max", "description": "Max" + }, + { + "name": "CountAsOne", + "description": "CountAsOne" } ] }, @@ -2072,6 +2558,10 @@ { "name": "CountKeywordArgs", "description": "CountKeywordArgs" + }, + { + "name": "MaxOptionalParameters", + "description": "MaxOptionalParameters" } ] }, @@ -2099,9 +2589,15 @@ }, { "patternId": "Naming_AsciiIdentifiers", - "title": "Use only ascii symbols in identifiers.", - "description": "Use only ascii symbols in identifiers.", - "timeToFix": 5 + "title": "Use only ascii symbols in identifiers and constants.", + "description": "Use only ascii symbols in identifiers and constants.", + "timeToFix": 5, + "parameters": [ + { + "name": "AsciiConstants", + "description": "AsciiConstants" + } + ] }, { "patternId": "Naming_BlockParameterName", @@ -2131,7 +2627,13 @@ "patternId": "Naming_ClassAndModuleCamelCase", "title": "Use CamelCase for classes and modules.", "description": "Use CamelCase for classes and modules.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "AllowedNames", + "description": "AllowedNames" + } + ] }, { "patternId": "Naming_ConstantName", @@ -2153,6 +2655,10 @@ "name": "ExpectMatchingDefinition", "description": "ExpectMatchingDefinition" }, + { + "name": "CheckDefinitionPathHierarchy", + "description": "CheckDefinitionPathHierarchy" + }, { "name": "Regex", "description": "Regex" @@ -2314,13 +2820,17 @@ { "name": "SupportedStyles", "description": "SupportedStyles" + }, + { + "name": "AllowedIdentifiers", + "description": "AllowedIdentifiers" } ] }, { "patternId": "Naming_VariableNumber", - "title": "Use the configured style when numbering variables.", - "description": "Use the configured style when numbering variables.", + "title": "Use the configured style when numbering symbols, methods and variables.", + "description": "Use the configured style when numbering symbols, methods and variables.", "timeToFix": 5, "parameters": [ { @@ -2330,6 +2840,18 @@ { "name": "SupportedStyles", "description": "SupportedStyles" + }, + { + "name": "CheckMethodNames", + "description": "CheckMethodNames" + }, + { + "name": "CheckSymbols", + "description": "CheckSymbols" + }, + { + "name": "AllowedIdentifiers", + "description": "AllowedIdentifiers" } ] }, @@ -2353,6 +2875,22 @@ } ] }, + { + "patternId": "Style_AccessorGrouping", + "title": "Checks for grouping of accessors in `class` and `module` bodies.", + "description": "Checks for grouping of accessors in `class` and `module` bodies.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Style_Alias", "title": "Use alias instead of alias_method.", @@ -2385,6 +2923,30 @@ } ] }, + { + "patternId": "Style_ArgumentsForwarding", + "title": "Use arguments forwarding.", + "description": "Use arguments forwarding.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowOnlyRestArgument", + "description": "AllowOnlyRestArgument" + } + ] + }, + { + "patternId": "Style_ArrayCoercion", + "title": "Use Array() instead of explicit Array check or [*var], when dealing with a variable you want to treat as an Array, but you're not certain it's an array.", + "description": "Use Array() instead of explicit Array check or [*var], when dealing with a variable you want to treat as an Array, but you're not certain it's an array.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_ArrayJoin", "title": "Use Array#join instead of Array#*.", @@ -2437,6 +2999,12 @@ "description": "Avoid the use of BEGIN blocks.", "timeToFix": 5 }, + { + "patternId": "Style_BisectedAttrAccessor", + "title": "Checks for places where `attr_reader` and `attr_writer` for the same method can be combined into single `attr_accessor`.", + "description": "Checks for places where `attr_reader` and `attr_writer` for the same method can be combined into single `attr_accessor`.", + "timeToFix": 5 + }, { "patternId": "Style_BlockComments", "title": "Do not use block comments.", @@ -2491,6 +3059,18 @@ } ] }, + { + "patternId": "Style_CaseLikeIf", + "title": "This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.", + "description": "This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_CharacterLiteral", "title": "Checks for uses of character literals.", @@ -2507,10 +3087,6 @@ "name": "SafeAutoCorrect", "description": "SafeAutoCorrect" }, - { - "name": "AutoCorrect", - "description": "AutoCorrect" - }, { "name": "EnforcedStyle", "description": "EnforcedStyle" @@ -2537,18 +3113,58 @@ } ] }, + { + "patternId": "Style_ClassEqualityComparison", + "title": "Enforces the use of `Object#instance_of?` instead of class comparison for equality.", + "description": "Enforces the use of `Object#instance_of?` instead of class comparison for equality.", + "timeToFix": 5, + "parameters": [ + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" + } + ] + }, { "patternId": "Style_ClassMethods", "title": "Use self when defining module/class methods.", "description": "Use self when defining module/class methods.", "timeToFix": 5 }, + { + "patternId": "Style_ClassMethodsDefinitions", + "title": "Enforces using `def self.method_name` or `class << self` to define class methods.", + "description": "Enforces using `def self.method_name` or `class << self` to define class methods.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Style_ClassVars", "title": "Avoid the use of class variables.", "description": "Avoid the use of class variables.", "timeToFix": 5 }, + { + "patternId": "Style_CollectionCompact", + "title": "Use `{Array,Hash}#{compact,compact!}` instead of custom logic to reject nils.", + "description": "Use `{Array,Hash}#{compact,compact!}` instead of custom logic to reject nils.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_CollectionMethods", "title": "Preferred collection methods.", @@ -2562,6 +3178,10 @@ { "name": "PreferredMethods", "description": "PreferredMethods" + }, + { + "name": "MethodsAcceptingSymbol", + "description": "MethodsAcceptingSymbol" } ] }, @@ -2577,6 +3197,18 @@ "description": "Do not use :: for defining class methods.", "timeToFix": 5 }, + { + "patternId": "Style_CombinableLoops", + "title": "Checks for places where multiple consecutive loops over the same data can be combined into a single loop.", + "description": "Checks for places where multiple consecutive loops over the same data can be combined into a single loop.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_CommandLiteral", "title": "Use `` or %x around command literals.", @@ -2599,8 +3231,8 @@ }, { "patternId": "Style_CommentAnnotation", - "title": "Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW).", - "description": "Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW).", + "title": "Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE).", + "description": "Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE).", "timeToFix": 5, "parameters": [ { @@ -2667,6 +3299,10 @@ "description": "Use Time over DateTime.", "timeToFix": 5, "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, { "name": "AllowCoercion", "description": "AllowCoercion" @@ -2689,7 +3325,13 @@ "patternId": "Style_DisableCopsWithinSourceCodeDirective", "title": "Forbids disabling/enabling cops within source code.", "description": "Forbids disabling/enabling cops within source code.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "AllowedCops", + "description": "AllowedCops" + } + ] }, { "patternId": "Style_DocumentationMethod", @@ -2719,6 +3361,12 @@ } ] }, + { + "patternId": "Style_DocumentDynamicEvalDefinition", + "title": "When using `class_eval` (or other `eval`) with string interpolation, add a comment block showing its appearance if interpolated.", + "description": "When using `class_eval` (or other `eval`) with string interpolation, add a comment block showing its appearance if interpolated.", + "timeToFix": 5 + }, { "patternId": "Style_DoubleCopDisableDirective", "title": "Checks for double rubocop:disable comments on a single line.", @@ -2729,7 +3377,21 @@ "patternId": "Style_DoubleNegation", "title": "Checks for uses of double negation (!!).", "description": "Checks for uses of double negation (!!).", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] }, { "patternId": "Style_EachForSimpleLoop", @@ -2799,6 +3461,22 @@ } ] }, + { + "patternId": "Style_EndlessMethod", + "title": "Avoid the use of multi-lined endless method definitions.", + "description": "Avoid the use of multi-lined endless method definitions.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Style_Encoding", "title": "Use UTF-8 as the source file encoding.", @@ -2829,6 +3507,12 @@ "description": "Use `expand_path(__dir__)` instead of `expand_path('..', __FILE__)`.", "timeToFix": 5 }, + { + "patternId": "Style_ExplicitBlockArgument", + "title": "Consider using explicit block argument to avoid writing block literal that just passes its arguments to another block.", + "description": "Consider using explicit block argument to avoid writing block literal that just passes its arguments to another block.", + "timeToFix": 5 + }, { "patternId": "Style_ExponentialNotation", "title": "When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).", @@ -2851,6 +3535,10 @@ "description": "For performing float division, coerce one side only.", "timeToFix": 5, "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, { "name": "EnforcedStyle", "description": "EnforcedStyle" @@ -2906,6 +3594,14 @@ { "name": "SupportedStyles", "description": "SupportedStyles" + }, + { + "name": "MaxUnannotatedPlaceholdersAllowed", + "description": "MaxUnannotatedPlaceholdersAllowed" + }, + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" } ] }, @@ -2924,8 +3620,20 @@ "description": "SupportedStyles" }, { - "name": "Safe", - "description": "Safe" + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + } + ] + }, + { + "patternId": "Style_GlobalStdStream", + "title": "Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.", + "description": "Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" } ] }, @@ -2953,6 +3661,22 @@ } ] }, + { + "patternId": "Style_HashAsLastArrayItem", + "title": "Checks for presence or absence of braces around hash literal as a last array item depending on configuration.", + "description": "Checks for presence or absence of braces around hash literal as a last array item depending on configuration.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Style_HashEachMethods", "title": "Use Hash#each_key and Hash#each_value.", @@ -2965,6 +3689,24 @@ } ] }, + { + "patternId": "Style_HashExcept", + "title": "Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods that can be replaced with `Hash#except` method.", + "description": "Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods that can be replaced with `Hash#except` method.", + "timeToFix": 5 + }, + { + "patternId": "Style_HashLikeCase", + "title": "Checks for places where `case-when` represents a simple 1:1 mapping and can be replaced with a hash lookup.", + "description": "Checks for places where `case-when` represents a simple 1:1 mapping and can be replaced with a hash lookup.", + "timeToFix": 5, + "parameters": [ + { + "name": "MinBranchesCount", + "description": "MinBranchesCount" + } + ] + }, { "patternId": "Style_HashSyntax", "title": "Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }.", @@ -2991,8 +3733,8 @@ }, { "patternId": "Style_HashTransformKeys", - "title": "Prefer `transform_keys` over `each_with_object` and `map`.", - "description": "Prefer `transform_keys` over `each_with_object` and `map`.", + "title": "Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.", + "description": "Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.", "timeToFix": 5, "parameters": [ { @@ -3003,8 +3745,8 @@ }, { "patternId": "Style_HashTransformValues", - "title": "Prefer `transform_values` over `each_with_object` and `map`.", - "description": "Prefer `transform_values` over `each_with_object` and `map`.", + "title": "Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.", + "description": "Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.", "timeToFix": 5, "parameters": [ { @@ -3043,6 +3785,22 @@ "description": "Avoid modifier if/unless usage on conditionals.", "timeToFix": 5 }, + { + "patternId": "Style_IfWithBooleanLiteralBranches", + "title": "Checks for redundant `if` with boolean literal branches.", + "description": "Checks for redundant `if` with boolean literal branches.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, + { + "name": "AllowedMethods", + "description": "AllowedMethods" + } + ] + }, { "patternId": "Style_IfWithSemicolon", "title": "Do not use if x; .... Use the ternary operator instead.", @@ -3057,13 +3815,13 @@ }, { "patternId": "Style_InfiniteLoop", - "title": "Use Kernel#loop for infinite loops.", - "description": "Use Kernel#loop for infinite loops.", + "title": "Use Kernel#loop for infinite loops. This cop is unsafe in the body may raise a `StopIteration` exception.", + "description": "Use Kernel#loop for infinite loops. This cop is unsafe in the body may raise a `StopIteration` exception.", "timeToFix": 5, "parameters": [ { - "name": "SafeAutoCorrect", - "description": "SafeAutoCorrect" + "name": "Safe", + "description": "Safe" } ] }, @@ -3102,9 +3860,19 @@ { "name": "AllowedAddresses", "description": "AllowedAddresses" + }, + { + "name": "Exclude", + "description": "Exclude" } ] }, + { + "patternId": "Style_KeywordParametersOrder", + "title": "Enforces that optional keyword parameters are placed at the end of the parameters list.", + "description": "Enforces that optional keyword parameters are placed at the end of the parameters list.", + "timeToFix": 5 + }, { "patternId": "Style_Lambda", "title": "Use the new lambda literal syntax for single-line blocks.", @@ -3205,6 +3973,70 @@ } ] }, + { + "patternId": "Style_RedundantAssignment", + "title": "Checks for redundant assignment before returning.", + "description": "Checks for redundant assignment before returning.", + "timeToFix": 5 + }, + { + "patternId": "Style_RedundantFetchBlock", + "title": "Use `fetch(key, value)` instead of `fetch(key) { value }` when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.", + "description": "Use `fetch(key, value)` instead of `fetch(key) { value }` when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "SafeForConstants", + "description": "SafeForConstants" + } + ] + }, + { + "patternId": "Style_RedundantFileExtensionInRequire", + "title": "Checks for the presence of superfluous `.rb` extension in the filename provided to `require` and `require_relative`.", + "description": "Checks for the presence of superfluous `.rb` extension in the filename provided to `require` and `require_relative`.", + "timeToFix": 5 + }, + { + "patternId": "Style_RedundantSelfAssignment", + "title": "Checks for places where redundant assignments are made for in place modification methods.", + "description": "Checks for places where redundant assignments are made for in place modification methods.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Style_SoleNestedConditional", + "title": "Finds sole nested conditional nodes which can be merged into outer conditional node.", + "description": "Finds sole nested conditional nodes which can be merged into outer conditional node.", + "timeToFix": 5, + "parameters": [ + { + "name": "AllowModifier", + "description": "AllowModifier" + } + ] + }, + { + "patternId": "Style_StaticClass", + "title": "Prefer modules to classes with only class methods.", + "description": "Prefer modules to classes with only class methods.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_MethodCalledOnDoEndBlock", "title": "Avoid chaining a method call on a do...end block.", @@ -3227,12 +4059,6 @@ } ] }, - { - "patternId": "Style_MethodMissingSuper", - "title": "Checks for `method_missing` to call `super`.", - "description": "Checks for `method_missing` to call `super`.", - "timeToFix": 5 - }, { "patternId": "Style_MinMax", "title": "Use `Enumerable#minmax` instead of `Enumerable#min` and `Enumerable#max` in conjunction.", @@ -3371,6 +4197,10 @@ "description": "Do not assign mutable objects to constants.", "timeToFix": 5, "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, { "name": "EnforcedStyle", "description": "EnforcedStyle" @@ -3397,6 +4227,12 @@ } ] }, + { + "patternId": "Style_NegatedIfElseCondition", + "title": "This cop checks for uses of `if-else` and ternary operators with a negated condition which can be simplified by inverting condition and swapping branches.", + "description": "This cop checks for uses of `if-else` and ternary operators with a negated condition which can be simplified by inverting condition and swapping branches.", + "timeToFix": 5 + }, { "patternId": "Style_NegatedUnless", "title": "Favor if over unless for negative conditions.", @@ -3479,6 +4315,12 @@ } ] }, + { + "patternId": "Style_NilLambda", + "title": "Prefer `-> {}` to `-> { nil }`.", + "description": "Prefer `-> {}` to `-> { nil }`.", + "timeToFix": 5 + }, { "patternId": "Style_NonNilCheck", "title": "Checks for redundant nil checks.", @@ -3543,10 +4385,6 @@ "name": "SafeAutoCorrect", "description": "SafeAutoCorrect" }, - { - "name": "AutoCorrect", - "description": "AutoCorrect" - }, { "name": "EnforcedStyle", "description": "EnforcedStyle" @@ -3567,9 +4405,15 @@ }, { "patternId": "Style_OneLineConditional", - "title": "Favor the ternary operator(?:) over if/then/else/end constructs.", - "description": "Favor the ternary operator(?:) over if/then/else/end constructs.", - "timeToFix": 5 + "title": "Favor the ternary operator (?:) or multi-line constructs over single-line if/then/else/end constructs.", + "description": "Favor the ternary operator (?:) or multi-line constructs over single-line if/then/else/end constructs.", + "timeToFix": 5, + "parameters": [ + { + "name": "AlwaysCorrectToMultiline", + "description": "AlwaysCorrectToMultiline" + } + ] }, { "patternId": "Style_OrAssignment", @@ -3593,7 +4437,29 @@ "patternId": "Style_OptionalArguments", "title": "Checks for optional arguments that do not appear at the end of the argument list.", "description": "Checks for optional arguments that do not appear at the end of the argument list.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Style_OptionalBooleanParameter", + "title": "Use keyword arguments when defining method with boolean argument.", + "description": "Use keyword arguments when defining method with boolean argument.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "AllowedMethods", + "description": "AllowedMethods" + } + ] }, { "patternId": "Style_ParallelAssignment", @@ -3690,6 +4556,10 @@ { "name": "SupportedStyles", "description": "SupportedStyles" + }, + { + "name": "AllowedCompactTypes", + "description": "AllowedCompactTypes" } ] }, @@ -3699,6 +4569,22 @@ "description": "Prefer to use ranges when generating random numbers instead of integers with offsets.", "timeToFix": 5 }, + { + "patternId": "Style_RedundantArgument", + "title": "Check for a redundant argument passed to certain methods.", + "description": "Check for a redundant argument passed to certain methods.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "Methods", + "description": "Methods" + } + ] + }, { "patternId": "Style_RedundantBegin", "title": "Don't use begin blocks when they are not needed.", @@ -3753,6 +4639,18 @@ "description": "Checks for %q/%Q when single quotes or double quotes would do.", "timeToFix": 5 }, + { + "patternId": "Style_RedundantRegexpCharacterClass", + "title": "Checks for unnecessary single-element Regexp character classes.", + "description": "Checks for unnecessary single-element Regexp character classes.", + "timeToFix": 5 + }, + { + "patternId": "Style_RedundantRegexpEscape", + "title": "Checks for redundant escapes in Regexps.", + "description": "Checks for redundant escapes in Regexps.", + "timeToFix": 5 + }, { "patternId": "Style_RedundantReturn", "title": "Don't use return where it's not required.", @@ -3843,8 +4741,8 @@ }, { "patternId": "Style_SafeNavigation", - "title": "This cop transforms usages of a method call safeguarded by a check for the existence of the object to safe navigation (`&.`).", - "description": "This cop transforms usages of a method call safeguarded by a check for the existence of the object to safe navigation (`&.`).", + "title": "This cop transforms usages of a method call safeguarded by a check for the existence of the object to safe navigation (`&.`). Auto-correction is unsafe as it assumes the object will be `nil` or truthy, but never `false`.", + "description": "This cop transforms usages of a method call safeguarded by a check for the existence of the object to safe navigation (`&.`). Auto-correction is unsafe as it assumes the object will be `nil` or truthy, but never `false`.", "timeToFix": 5, "parameters": [ { @@ -3854,6 +4752,10 @@ { "name": "AllowedMethods", "description": "AllowedMethods" + }, + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" } ] }, @@ -3903,6 +4805,18 @@ } ] }, + { + "patternId": "Style_SingleArgumentDig", + "title": "Avoid using single argument dig method.", + "description": "Avoid using single argument dig method.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_SingleLineBlockParams", "title": "Enforces the names of some block params.", @@ -3927,6 +4841,18 @@ } ] }, + { + "patternId": "Style_SlicingWithRange", + "title": "Checks array slicing is done with endless ranges when suitable.", + "description": "Checks array slicing is done with endless ranges when suitable.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_SpecialGlobalVars", "title": "Avoid Perl-style global variables.", @@ -3969,6 +4895,18 @@ "description": "Use `warn` instead of `$stderr.puts`.", "timeToFix": 5 }, + { + "patternId": "Style_StringConcatenation", + "title": "Checks for places where string concatenation can be replaced with string interpolation.", + "description": "Checks for places where string concatenation can be replaced with string interpolation.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Style_StringHashKeys", "title": "Prefer symbols instead of strings as hash keys.", @@ -4041,6 +4979,18 @@ "description": "Checks for inheritance from Struct.new.", "timeToFix": 5 }, + { + "patternId": "Style_SwapValues", + "title": "This cop enforces the use of shorthand-style swapping of 2 variables.", + "description": "This cop enforces the use of shorthand-style swapping of 2 variables.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + } + ] + }, { "patternId": "Style_SymbolArray", "title": "Use %i or %I for arrays of symbols.", @@ -4074,8 +5024,8 @@ "timeToFix": 5, "parameters": [ { - "name": "SafeAutoCorrect", - "description": "SafeAutoCorrect" + "name": "Safe", + "description": "Safe" }, { "name": "IgnoredMethods", @@ -4349,8 +5299,8 @@ }, { "patternId": "Security_Open", - "title": "The use of Kernel#open represents a serious security risk.", - "description": "The use of Kernel#open represents a serious security risk.", + "title": "The use of `Kernel#open` and `URI.open` represent a serious security risk.", + "description": "The use of `Kernel#open` and `URI.open` represent a serious security risk.", "timeToFix": 5, "parameters": [ { @@ -4383,6 +5333,18 @@ } ] }, + { + "patternId": "Performance_ArraySemiInfiniteRangeSlice", + "title": "Identifies places where slicing arrays with semi-infinite ranges can be replaced by `Array#take` and `Array#drop`.", + "description": "Identifies places where slicing arrays with semi-infinite ranges can be replaced by `Array#take` and `Array#drop`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Performance_BigDecimalWithNumericArgument", "title": "Convert numeric argument to string before passing to BigDecimal.", @@ -4395,6 +5357,12 @@ "description": "Use `bind_call(obj, args, ...)` instead of `bind(obj).call(args, ...)`.", "timeToFix": 5 }, + { + "patternId": "Performance_BlockGivenWithExplicitBlock", + "title": "Check block argument explicitly instead of using `block_given?`.", + "description": "Check block argument explicitly instead of using `block_given?`.", + "timeToFix": 5 + }, { "patternId": "Performance_Caller", "title": "Use `caller(n..n)` instead of `caller`.", @@ -4429,16 +5397,34 @@ } ] }, + { + "patternId": "Performance_CollectionLiteralInLoop", + "title": "Extract Array and Hash literals outside of loops into local variables or constants.", + "description": "Extract Array and Hash literals outside of loops into local variables or constants.", + "timeToFix": 5, + "parameters": [ + { + "name": "MinSize", + "description": "MinSize" + } + ] + }, { "patternId": "Performance_CompareWithBlock", "title": "Use `sort_by(&:foo)` instead of `sort { |a, b| a.foo <=> b.foo }`.", "description": "Use `sort_by(&:foo)` instead of `sort { |a, b| a.foo <=> b.foo }`.", "timeToFix": 5 }, + { + "patternId": "Performance_ConstantRegexp", + "title": "Finds regular expressions with dynamic components that are all constants.", + "description": "Finds regular expressions with dynamic components that are all constants.", + "timeToFix": 5 + }, { "patternId": "Performance_Count", - "title": "Use `count` instead of `select...size`, `reject...size`, `select...count`, `reject...count`, `select...length`, and `reject...length`.", - "description": "Use `count` instead of `select...size`, `reject...size`, `select...count`, `reject...count`, `select...length`, and `reject...length`.", + "title": "Use `count` instead of `{select,find_all,filter,reject}...{size,count,length}`.", + "description": "Use `count` instead of `{select,find_all,filter,reject}...{size,count,length}`.", "timeToFix": 5, "parameters": [ { @@ -4473,8 +5459,8 @@ }, { "patternId": "Performance_Detect", - "title": "Use `detect` instead of `select.first`, `find_all.first`, `select.last`, and `find_all.last`.", - "description": "Use `detect` instead of `select.first`, `find_all.first`, `select.last`, and `find_all.last`.", + "title": "Use `detect` instead of `select.first`, `find_all.first`, `filter.first`, `select.last`, `find_all.last`, and `filter.last`.", + "description": "Use `detect` instead of `select.first`, `find_all.first`, `filter.first`, `select.last`, `find_all.last`, and `filter.last`.", "timeToFix": 5, "parameters": [ { @@ -4545,6 +5531,12 @@ } ] }, + { + "patternId": "Performance_MethodObjectAsBlock", + "title": "Use block explicitly instead of block-passing a method object.", + "description": "Use block explicitly instead of block-passing a method object.", + "timeToFix": 5 + }, { "patternId": "Performance_OpenStruct", "title": "Use `Struct` instead of `OpenStruct`.", @@ -4689,6 +5681,12 @@ "description": "Use `tr` instead of `gsub` when you are replacing the same number of characters. Use `delete` instead of `gsub` when you are deleting characters.", "timeToFix": 5 }, + { + "patternId": "Performance_Sum", + "title": "Use `sum` instead of a custom array summation.", + "description": "Use `sum` instead of a custom array summation.", + "timeToFix": 5 + }, { "patternId": "Performance_TimesMap", "title": "Checks for .times.map calls.", @@ -4709,7 +5707,13 @@ "patternId": "Performance_UnfreezeString", "title": "Use unary plus to get an unfrozen string literal.", "description": "Use unary plus to get an unfrozen string literal.", - "timeToFix": 5 + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + } + ] }, { "patternId": "Performance_UriDefaultParser", @@ -4755,6 +5759,18 @@ } ] }, + { + "patternId": "Rails_ActiveRecordCallbacksOrder", + "title": "Order callback declarations in the order in which they will be executed.", + "description": "Order callback declarations in the order in which they will be executed.", + "timeToFix": 5, + "parameters": [ + { + "name": "Include", + "description": "Include" + } + ] + }, { "patternId": "Rails_ActiveRecordOverride", "title": "Check for overriding Active Record methods instead of using callbacks.", @@ -4773,6 +5789,12 @@ "description": "Avoid ActiveSupport aliases of standard ruby methods: `String#starts_with?`, `String#ends_with?`, `Array#append`, `Array#prepend`.", "timeToFix": 5 }, + { + "patternId": "Rails_AfterCommitOverride", + "title": "This cop enforces that there is only one call to `after_commit` (and its aliases - `after_create_commit`, `after_update_commit`, and `after_destroy_commit`) with the same callback name per model.", + "description": "This cop enforces that there is only one call to `after_commit` (and its aliases - `after_create_commit`, `after_update_commit`, and `after_destroy_commit`) with the same callback name per model.", + "timeToFix": 5 + }, { "patternId": "Rails_ApplicationController", "title": "Check that controllers subclass ApplicationController.", @@ -4821,6 +5843,18 @@ } ] }, + { + "patternId": "Rails_ArelStar", + "title": "Enforces `Arel.star` instead of `\"*\"` for expanded columns.", + "description": "Enforces `Arel.star` instead of `\"*\"` for expanded columns.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + } + ] + }, { "patternId": "Rails_AssertNot", "title": "Use `assert_not` instead of `assert !`.", @@ -4833,6 +5867,18 @@ } ] }, + { + "patternId": "Rails_AttributeDefaultBlockValue", + "title": "Pass method call in block for attribute option `default`.", + "description": "Pass method call in block for attribute option `default`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Include", + "description": "Include" + } + ] + }, { "patternId": "Rails_BelongsTo", "title": "Use `optional: true` instead of `required: false` for `belongs_to` relations.", @@ -4913,6 +5959,12 @@ } ] }, + { + "patternId": "Rails_DefaultScope", + "title": "Avoid use of `default_scope`.", + "description": "Avoid use of `default_scope`.", + "timeToFix": 5 + }, { "patternId": "Rails_Delegate", "title": "Prefer delegate method for delegations.", @@ -5025,6 +6077,12 @@ } ] }, + { + "patternId": "Rails_FindById", + "title": "Favor the use of `find` over `where.take!`, `find_by!`, and `find_by_id!` when you need to retrieve a single record by primary key when you expect it to be found.", + "description": "Favor the use of `find` over `where.take!`, `find_by!`, and `find_by_id!` when you need to retrieve a single record by primary key when you expect it to be found.", + "timeToFix": 5 + }, { "patternId": "Rails_FindEach", "title": "Prefer all.find_each over all.find.", @@ -5034,6 +6092,10 @@ { "name": "Include", "description": "Include" + }, + { + "name": "IgnoredMethods", + "description": "IgnoredMethods" } ] }, @@ -5115,14 +6177,20 @@ }, { "patternId": "Rails_IndexBy", - "title": "Prefer `index_by` over `each_with_object` or `map`.", - "description": "Prefer `index_by` over `each_with_object` or `map`.", + "title": "Prefer `index_by` over `each_with_object`, `to_h`, or `map`.", + "description": "Prefer `index_by` over `each_with_object`, `to_h`, or `map`.", "timeToFix": 5 }, { "patternId": "Rails_IndexWith", - "title": "Prefer `index_with` over `each_with_object` or `map`.", - "description": "Prefer `index_with` over `each_with_object` or `map`.", + "title": "Prefer `index_with` over `each_with_object`, `to_h`, or `map`.", + "description": "Prefer `index_with` over `each_with_object`, `to_h`, or `map`.", + "timeToFix": 5 + }, + { + "patternId": "Rails_Inquiry", + "title": "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`.", + "description": "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`.", "timeToFix": 5 }, { @@ -5159,6 +6227,46 @@ "description": "Checks that `link_to` with a `target: \"_blank\"` have a `rel: \"noopener\"` option passed to them.", "timeToFix": 5 }, + { + "patternId": "Rails_MailerName", + "title": "Mailer should end with `Mailer` suffix.", + "description": "Mailer should end with `Mailer` suffix.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, + { + "name": "Include", + "description": "Include" + } + ] + }, + { + "patternId": "Rails_MatchRoute", + "title": "Don't use `match` to define any routes unless there is a need to map multiple request types among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option.", + "description": "Don't use `match` to define any routes unless there is a need to map multiple request types among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option.", + "timeToFix": 5, + "parameters": [ + { + "name": "Include", + "description": "Include" + } + ] + }, + { + "patternId": "Rails_NegateInclude", + "title": "Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.", + "description": "Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, { "patternId": "Rails_NotNullColumn", "title": "Do not add a NOT NULL column without a default value.", @@ -5171,6 +6279,12 @@ } ] }, + { + "patternId": "Rails_OrderById", + "title": "Do not use the `id` column for ordering. Use a timestamp column to order chronologically.", + "description": "Do not use the `id` column for ordering. Use a timestamp column to order chronologically.", + "timeToFix": 5 + }, { "patternId": "Rails_Output", "title": "Checks for calls to puts, print, etc.", @@ -5201,6 +6315,44 @@ } ] }, + { + "patternId": "Rails_Pluck", + "title": "Prefer `pluck` over `map { ... }`.", + "description": "Prefer `pluck` over `map { ... }`.", + "timeToFix": 5 + }, + { + "patternId": "Rails_PluckId", + "title": "Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.", + "description": "Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + } + ] + }, + { + "patternId": "Rails_PluckInWhere", + "title": "Use `select` instead of `pluck` in `where` query methods.", + "description": "Use `select` instead of `pluck` in `where` query methods.", + "timeToFix": 5, + "parameters": [ + { + "name": "Safe", + "description": "Safe" + }, + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Rails_PluralizationGrammar", "title": "Checks for incorrect grammar when using methods like `3.day.ago`.", @@ -5327,6 +6479,24 @@ } ] }, + { + "patternId": "Rails_RenderInline", + "title": "Prefer using a template over inline rendering.", + "description": "Prefer using a template over inline rendering.", + "timeToFix": 5 + }, + { + "patternId": "Rails_RenderPlainText", + "title": "Prefer `render plain:` over `render text:`.", + "description": "Prefer `render plain:` over `render text:`.", + "timeToFix": 5, + "parameters": [ + { + "name": "ContentTypeCompatibility", + "description": "ContentTypeCompatibility" + } + ] + }, { "patternId": "Rails_RequestReferer", "title": "Use consistent syntax for request.referer.", @@ -5411,6 +6581,22 @@ } ] }, + { + "patternId": "Rails_ShortI18n", + "title": "Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.", + "description": "Use the short form of the I18n methods: `t` instead of `translate` and `l` instead of `localize`.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, { "patternId": "Rails_SkipsModelValidations", "title": "Use methods that skips model validations with caution. See reference for more information.", @@ -5418,12 +6604,24 @@ "timeToFix": 5, "parameters": [ { - "name": "Blacklist", - "description": "Blacklist" + "name": "ForbiddenMethods", + "description": "ForbiddenMethods" }, { - "name": "Whitelist", - "description": "Whitelist" + "name": "AllowedMethods", + "description": "AllowedMethods" + } + ] + }, + { + "patternId": "Rails_SquishedSQLHeredocs", + "title": "Checks SQL heredocs to use `.squish`.", + "description": "Checks SQL heredocs to use `.squish`.", + "timeToFix": 5, + "parameters": [ + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" } ] }, @@ -5461,6 +6659,10 @@ "name": "SupportedStyles", "description": "SupportedStyles" }, + { + "name": "SafeAutoCorrect", + "description": "SafeAutoCorrect" + }, { "name": "AutoCorrect", "description": "AutoCorrect" @@ -5502,5 +6704,33 @@ "description": "Include" } ] + }, + { + "patternId": "Rails_WhereEquals", + "title": "Pass conditions to `where` as a hash instead of manually constructing SQL.", + "description": "Pass conditions to `where` as a hash instead of manually constructing SQL.", + "timeToFix": 5 + }, + { + "patternId": "Rails_WhereExists", + "title": "Prefer `exists?(...)` over `where(...).exists?`.", + "description": "Prefer `exists?(...)` over `where(...).exists?`.", + "timeToFix": 5, + "parameters": [ + { + "name": "EnforcedStyle", + "description": "EnforcedStyle" + }, + { + "name": "SupportedStyles", + "description": "SupportedStyles" + } + ] + }, + { + "patternId": "Rails_WhereNot", + "title": "Use `where.not(...)` instead of manually constructing negated SQL in `where`.", + "description": "Use `where.not(...)` instead of manually constructing negated SQL in `where`.", + "timeToFix": 5 } ] \ No newline at end of file diff --git a/src/main/resources/docs/multiple-tests/line-length/patterns.xml b/docs/multiple-tests/line-length/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/line-length/patterns.xml rename to docs/multiple-tests/line-length/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/line-length/results.xml b/docs/multiple-tests/line-length/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/line-length/results.xml rename to docs/multiple-tests/line-length/results.xml diff --git a/src/main/resources/docs/multiple-tests/line-length/src/.rubocop.yml b/docs/multiple-tests/line-length/src/.rubocop.yml similarity index 99% rename from src/main/resources/docs/multiple-tests/line-length/src/.rubocop.yml rename to docs/multiple-tests/line-length/src/.rubocop.yml index 475cecfb..1592111b 100644 --- a/src/main/resources/docs/multiple-tests/line-length/src/.rubocop.yml +++ b/docs/multiple-tests/line-length/src/.rubocop.yml @@ -7,6 +7,7 @@ AllCops: Exclude: - 'db/**/*' - 'client/node_modules/**/*' + NewCops: enable #################### Lint ################################ @@ -189,10 +190,6 @@ Lint/UselessAssignment: StyleGuide: '/~https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' Enabled: true -Lint/UselessComparison: - Description: 'Checks for comparison of something with itself.' - Enabled: true - Lint/UselessElseWithoutRescue: Description: 'Checks for useless `else` in `begin..end` without `rescue`.' Enabled: true diff --git a/src/main/resources/docs/tests/Layout_LineLength.rb b/docs/multiple-tests/line-length/src/Layout_LineLength.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_LineLength.rb rename to docs/multiple-tests/line-length/src/Layout_LineLength.rb diff --git a/src/main/resources/docs/multiple-tests/rake-plugin/patterns.xml b/docs/multiple-tests/rake-plugin/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rake-plugin/patterns.xml rename to docs/multiple-tests/rake-plugin/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/rake-plugin/results.xml b/docs/multiple-tests/rake-plugin/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rake-plugin/results.xml rename to docs/multiple-tests/rake-plugin/results.xml diff --git a/src/main/resources/docs/multiple-tests/rake-plugin/src/.rubocop.yml b/docs/multiple-tests/rake-plugin/src/.rubocop.yml similarity index 100% rename from src/main/resources/docs/multiple-tests/rake-plugin/src/.rubocop.yml rename to docs/multiple-tests/rake-plugin/src/.rubocop.yml diff --git a/src/main/resources/docs/multiple-tests/rake-plugin/src/Rakefile b/docs/multiple-tests/rake-plugin/src/Rakefile similarity index 100% rename from src/main/resources/docs/multiple-tests/rake-plugin/src/Rakefile rename to docs/multiple-tests/rake-plugin/src/Rakefile diff --git a/src/main/resources/docs/multiple-tests/rspec-config-file/patterns.xml b/docs/multiple-tests/rspec-config-file/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-config-file/patterns.xml rename to docs/multiple-tests/rspec-config-file/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/rspec-config-file/results.xml b/docs/multiple-tests/rspec-config-file/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-config-file/results.xml rename to docs/multiple-tests/rspec-config-file/results.xml diff --git a/src/main/resources/docs/multiple-tests/rspec-config-file/src/.rubocop.yml b/docs/multiple-tests/rspec-config-file/src/.rubocop.yml similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-config-file/src/.rubocop.yml rename to docs/multiple-tests/rspec-config-file/src/.rubocop.yml diff --git a/src/main/resources/docs/multiple-tests/rspec-config-file/src/sample_code_spec.rb b/docs/multiple-tests/rspec-config-file/src/sample_code_spec.rb similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-config-file/src/sample_code_spec.rb rename to docs/multiple-tests/rspec-config-file/src/sample_code_spec.rb diff --git a/src/main/resources/docs/multiple-tests/rspec-without-config-file/patterns.xml b/docs/multiple-tests/rspec-without-config-file/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-without-config-file/patterns.xml rename to docs/multiple-tests/rspec-without-config-file/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/rspec-without-config-file/results.xml b/docs/multiple-tests/rspec-without-config-file/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-without-config-file/results.xml rename to docs/multiple-tests/rspec-without-config-file/results.xml diff --git a/src/main/resources/docs/multiple-tests/rspec-without-config-file/src/sample_code_spec.rb b/docs/multiple-tests/rspec-without-config-file/src/sample_code_spec.rb similarity index 100% rename from src/main/resources/docs/multiple-tests/rspec-without-config-file/src/sample_code_spec.rb rename to docs/multiple-tests/rspec-without-config-file/src/sample_code_spec.rb diff --git a/src/main/resources/docs/multiple-tests/with-config-file/patterns.xml b/docs/multiple-tests/with-config-file/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/with-config-file/patterns.xml rename to docs/multiple-tests/with-config-file/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/with-config-file/results.xml b/docs/multiple-tests/with-config-file/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/with-config-file/results.xml rename to docs/multiple-tests/with-config-file/results.xml diff --git a/src/main/resources/docs/multiple-tests/with-config-file/src/.rubocop.yml b/docs/multiple-tests/with-config-file/src/.rubocop.yml similarity index 99% rename from src/main/resources/docs/multiple-tests/with-config-file/src/.rubocop.yml rename to docs/multiple-tests/with-config-file/src/.rubocop.yml index 14425686..ed815eaa 100644 --- a/src/main/resources/docs/multiple-tests/with-config-file/src/.rubocop.yml +++ b/docs/multiple-tests/with-config-file/src/.rubocop.yml @@ -5,6 +5,7 @@ require: AllCops: Exclude: - 'db/**/*' + NewCops: enable #################### Lint ################################ @@ -182,10 +183,6 @@ Lint/UselessAssignment: StyleGuide: '/~https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' Enabled: true -Lint/UselessComparison: - Description: 'Checks for comparison of something with itself.' - Enabled: true - Lint/UselessElseWithoutRescue: Description: 'Checks for useless `else` in `begin..end` without `rescue`.' Enabled: true diff --git a/src/main/resources/docs/multiple-tests/with-config-file/src/Gemfile.lock b/docs/multiple-tests/with-config-file/src/Gemfile.lock similarity index 100% rename from src/main/resources/docs/multiple-tests/with-config-file/src/Gemfile.lock rename to docs/multiple-tests/with-config-file/src/Gemfile.lock diff --git a/src/main/resources/docs/multiple-tests/with-config-file/src/Lint_AssignmentInCondition.rb b/docs/multiple-tests/with-config-file/src/Lint_AssignmentInCondition.rb similarity index 100% rename from src/main/resources/docs/multiple-tests/with-config-file/src/Lint_AssignmentInCondition.rb rename to docs/multiple-tests/with-config-file/src/Lint_AssignmentInCondition.rb diff --git a/src/main/resources/docs/multiple-tests/without-config-file/patterns.xml b/docs/multiple-tests/without-config-file/patterns.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/without-config-file/patterns.xml rename to docs/multiple-tests/without-config-file/patterns.xml diff --git a/src/main/resources/docs/multiple-tests/without-config-file/results.xml b/docs/multiple-tests/without-config-file/results.xml similarity index 100% rename from src/main/resources/docs/multiple-tests/without-config-file/results.xml rename to docs/multiple-tests/without-config-file/results.xml diff --git a/src/main/resources/docs/multiple-tests/without-config-file/src/sample_code_spec.rb b/docs/multiple-tests/without-config-file/src/sample_code_spec.rb similarity index 100% rename from src/main/resources/docs/multiple-tests/without-config-file/src/sample_code_spec.rb rename to docs/multiple-tests/without-config-file/src/sample_code_spec.rb diff --git a/src/main/resources/docs/multiple-tests/without-config-file/src/test.rb b/docs/multiple-tests/without-config-file/src/test.rb similarity index 100% rename from src/main/resources/docs/multiple-tests/without-config-file/src/test.rb rename to docs/multiple-tests/without-config-file/src/test.rb diff --git a/src/main/resources/docs/patterns.json b/docs/patterns.json similarity index 81% rename from src/main/resources/docs/patterns.json rename to docs/patterns.json index 22a4528e..e6e94ff9 100644 --- a/src/main/resources/docs/patterns.json +++ b/docs/patterns.json @@ -1,6 +1,6 @@ { "name": "rubocop", - "version": "0.82.0", + "version": "1.9.1", "patterns": [ { "patternId": "Migration_DepartmentName", @@ -41,6 +41,12 @@ "name": "IgnoredGems", "default": [ + ] + }, + { + "name": "OnlyFor", + "default": [ + ] } ], @@ -71,6 +77,10 @@ "name": "TreatCommentsAsGroupSeparators", "default": "true" }, + { + "name": "ConsiderPunctuation", + "default": "false" + }, { "name": "Include", "default": [ @@ -105,6 +115,10 @@ "name": "TreatCommentsAsGroupSeparators", "default": "true" }, + { + "name": "ConsiderPunctuation", + "default": "false" + }, { "name": "Include", "default": [ @@ -223,6 +237,29 @@ ], "enabled": false }, + { + "patternId": "Layout_BeginEndAlignment", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "EnforcedStyleAlignWith", + "default": "start_of_line" + }, + { + "name": "SupportedStylesAlignWith", + "default": [ + "start_of_line", + "begin" + ] + }, + { + "name": "Severity", + "default": "warning" + } + ], + "enabled": false + }, { "patternId": "Layout_BlockAlignment", "level": "Info", @@ -340,10 +377,6 @@ "def" ] }, - { - "name": "AutoCorrect", - "default": "false" - }, { "name": "Severity", "default": "warning" @@ -404,11 +437,29 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Layout_EmptyLineAfterMultilineCondition", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Layout_EmptyLineBetweenDefs", "level": "Info", "category": "CodeStyle", "parameters": [ + { + "name": "EmptyLineBetweenMethodDefs", + "default": "true" + }, + { + "name": "EmptyLineBetweenClassDefs", + "default": "true" + }, + { + "name": "EmptyLineBetweenModuleDefs", + "default": "true" + }, { "name": "AllowAdjacentOneLineDefs", "default": "false" @@ -445,6 +496,27 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Layout_EmptyLinesAroundAttributeAccessor", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "AllowAliasSyntax", + "default": "true" + }, + { + "name": "AllowedMethods", + "default": [ + "alias_method", + "public", + "protected", + "private" + ] + } + ], + "enabled": false + }, { "patternId": "Layout_EmptyLinesAroundBeginBody", "level": "Info", @@ -549,10 +621,6 @@ "start_of_line" ] }, - { - "name": "AutoCorrect", - "default": "false" - }, { "name": "Severity", "default": "warning" @@ -779,21 +847,6 @@ "patternId": "Layout_HeredocIndentation", "level": "Info", "category": "CodeStyle", - "parameters": [ - { - "name": "EnforcedStyle", - "default": "squiggly" - }, - { - "name": "SupportedStyles", - "default": [ - "squiggly", - "active_support", - "powerpack", - "unindent" - ] - } - ], "enabled": false }, { @@ -891,11 +944,11 @@ "parameters": [ { "name": "AutoCorrect", - "default": "false" + "default": "true" }, { "name": "Max", - "default": "80" + "default": "120" }, { "name": "AllowHeredoc", @@ -1268,6 +1321,12 @@ ], "enabled": false }, + { + "patternId": "Layout_SpaceBeforeBrackets", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Layout_SpaceBeforeComma", "level": "Info", @@ -1530,6 +1589,12 @@ ], "enabled": false }, + { + "patternId": "Lint_AmbiguousAssignment", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_AmbiguousBlockAssociation", "level": "Warning", @@ -1567,230 +1632,484 @@ "enabled": false }, { - "patternId": "Lint_BooleanSymbol", + "patternId": "Lint_BinaryOperatorWithIdenticalOperands", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], "enabled": false }, { - "patternId": "Lint_CircularArgumentReference", + "patternId": "Lint_BooleanSymbol", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], "enabled": false }, { - "patternId": "Lint_Debugger", + "patternId": "Lint_CircularArgumentReference", "level": "Warning", "category": "ErrorProne", - "enabled": true + "enabled": false }, { - "patternId": "Lint_DeprecatedClassMethods", + "patternId": "Lint_ConstantDefinitionInBlock", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "AllowedMethods", + "default": [ + "enums" + ] + } + ], "enabled": false }, { - "patternId": "Lint_DisjunctiveAssignmentInConstructor", + "patternId": "Lint_ConstantResolution", "level": "Warning", "category": "ErrorProne", "parameters": [ { - "name": "Safe", - "default": "false" + "name": "Only", + "default": [ + + ] + }, + { + "name": "Ignore", + "default": [ + + ] } ], "enabled": false }, { - "patternId": "Lint_DuplicateCaseCondition", + "patternId": "Lint_Debugger", "level": "Warning", "category": "ErrorProne", - "enabled": false + "parameters": [ + { + "name": "DebuggerReceivers", + "default": [ + "binding", + "Kernel", + "Pry" + ] + }, + { + "name": "DebuggerMethods", + "default": [ + "debugger", + "byebug", + "remote_byebug", + "pry", + "remote_pry", + "pry_remote", + "console", + "rescue", + "save_and_open_page", + "save_and_open_screenshot", + "irb" + ] + } + ], + "enabled": true }, { - "patternId": "Lint_DuplicateHashKey", + "patternId": "Lint_DeprecatedClassMethods", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_DuplicateMethods", + "patternId": "Lint_DeprecatedConstants", "level": "Warning", "category": "ErrorProne", - "enabled": true + "parameters": [ + { + "name": "DeprecatedConstants", + "default": "{\"NIL\"=>{\"Alternative\"=>\"nil\", \"DeprecatedVersion\"=>\"2.4\"}, \"TRUE\"=>{\"Alternative\"=>\"true\", \"DeprecatedVersion\"=>\"2.4\"}, \"FALSE\"=>{\"Alternative\"=>\"false\", \"DeprecatedVersion\"=>\"2.4\"}, \"Random::DEFAULT\"=>{\"Alternative\"=>\"Random.new\", \"DeprecatedVersion\"=>\"3.0\"}}" + } + ], + "enabled": false }, { - "patternId": "Lint_EachWithObjectArgument", + "patternId": "Lint_DeprecatedOpenSSLConstant", "level": "Warning", "category": "ErrorProne", - "enabled": true + "enabled": false }, { - "patternId": "Lint_ElseLayout", + "patternId": "Lint_DisjunctiveAssignmentInConstructor", "level": "Warning", "category": "ErrorProne", - "enabled": true + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false }, { - "patternId": "Lint_EmptyEnsure", + "patternId": "Lint_DuplicateBranch", "level": "Warning", "category": "ErrorProne", "parameters": [ { - "name": "AutoCorrect", + "name": "IgnoreLiteralBranches", + "default": "false" + }, + { + "name": "IgnoreConstantBranches", "default": "false" } ], - "enabled": true + "enabled": false }, { - "patternId": "Lint_EmptyExpression", + "patternId": "Lint_DuplicateCaseCondition", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_EmptyInterpolation", + "patternId": "Lint_DuplicateElsifCondition", "level": "Warning", "category": "ErrorProne", - "enabled": true + "enabled": false }, { - "patternId": "Lint_EmptyWhen", + "patternId": "Lint_DuplicateHashKey", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_EnsureReturn", + "patternId": "Lint_DuplicateMethods", "level": "Warning", "category": "ErrorProne", "enabled": true }, { - "patternId": "Lint_ErbNewArguments", + "patternId": "Lint_DuplicateRegexpCharacterClassElement", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_FlipFlop", + "patternId": "Lint_DuplicateRequire", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_FloatOutOfRange", + "patternId": "Lint_DuplicateRescueException", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_FormatParameterMismatch", + "patternId": "Lint_EachWithObjectArgument", "level": "Warning", "category": "ErrorProne", - "enabled": false + "enabled": true }, { - "patternId": "Lint_HeredocMethodCallPosition", + "patternId": "Lint_ElseLayout", "level": "Warning", "category": "ErrorProne", - "enabled": false + "enabled": true }, { - "patternId": "Lint_ImplicitStringConcatenation", + "patternId": "Lint_EmptyBlock", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "AllowComments", + "default": "true" + }, + { + "name": "AllowEmptyLambdas", + "default": "true" + } + ], "enabled": false }, { - "patternId": "Lint_InheritException", + "patternId": "Lint_EmptyClass", "level": "Warning", "category": "ErrorProne", "parameters": [ { - "name": "EnforcedStyle", - "default": "runtime_error" - }, - { - "name": "SupportedStyles", - "default": [ - "runtime_error", - "standard_error" - ] + "name": "AllowComments", + "default": "false" } ], "enabled": false }, { - "patternId": "Lint_IneffectiveAccessModifier", + "patternId": "Lint_EmptyConditionalBody", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "AllowComments", + "default": "true" + } + ], "enabled": false }, { - "patternId": "Lint_InterpolationCheck", + "patternId": "Lint_EmptyEnsure", "level": "Warning", "category": "ErrorProne", - "enabled": false + "enabled": true }, { - "patternId": "Lint_LiteralAsCondition", + "patternId": "Lint_EmptyExpression", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_LiteralInInterpolation", + "patternId": "Lint_EmptyFile", "level": "Warning", "category": "ErrorProne", - "enabled": true + "parameters": [ + { + "name": "AllowComments", + "default": "true" + } + ], + "enabled": false }, { - "patternId": "Lint_Loop", + "patternId": "Lint_EmptyInterpolation", "level": "Warning", "category": "ErrorProne", "enabled": true }, { - "patternId": "Lint_MissingCopEnableDirective", + "patternId": "Lint_EmptyWhen", "level": "Warning", "category": "ErrorProne", "parameters": [ { - "name": "MaximumRangeSize", - "default": "Infinity" + "name": "AllowComments", + "default": "true" } ], "enabled": false }, { - "patternId": "Lint_MultipleComparison", + "patternId": "Lint_EnsureReturn", "level": "Warning", "category": "ErrorProne", - "enabled": false + "enabled": true }, { - "patternId": "Lint_NestedMethodDefinition", + "patternId": "Lint_ErbNewArguments", "level": "Warning", "category": "ErrorProne", - "enabled": true + "enabled": false }, { - "patternId": "Lint_NestedPercentLiteral", + "patternId": "Lint_FlipFlop", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_NextWithoutAccumulator", + "patternId": "Lint_FloatComparison", "level": "Warning", "category": "ErrorProne", "enabled": false }, { - "patternId": "Lint_NonDeterministicRequireOrder", + "patternId": "Lint_FloatOutOfRange", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_FormatParameterMismatch", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_HashCompareByIdentity", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Lint_HeredocMethodCallPosition", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_IdentityComparison", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_ImplicitStringConcatenation", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_InheritException", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "runtime_error" + }, + { + "name": "SupportedStyles", + "default": [ + "runtime_error", + "standard_error" + ] + } + ], + "enabled": false + }, + { + "patternId": "Lint_IneffectiveAccessModifier", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_InterpolationCheck", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Lint_LambdaWithoutLiteralBlock", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_LiteralAsCondition", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_LiteralInInterpolation", + "level": "Warning", + "category": "ErrorProne", + "enabled": true + }, + { + "patternId": "Lint_Loop", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": true + }, + { + "patternId": "Lint_MissingCopEnableDirective", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "MaximumRangeSize", + "default": "Infinity" + } + ], + "enabled": false + }, + { + "patternId": "Lint_MissingSuper", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_MixedRegexpCaptureTypes", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_MultipleComparison", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "AllowMethodComparison", + "default": "true" + } + ], + "enabled": false + }, + { + "patternId": "Lint_NestedMethodDefinition", + "level": "Warning", + "category": "ErrorProne", + "enabled": true + }, + { + "patternId": "Lint_NestedPercentLiteral", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_NextWithoutAccumulator", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_NoReturnInBeginEndBlocks", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_NonDeterministicRequireOrder", "level": "Warning", "category": "ErrorProne", "parameters": [ @@ -1815,6 +2134,37 @@ { "name": "SafeAutoCorrect", "default": "false" + }, + { + "name": "IgnoredMethods", + "default": [ + + ] + }, + { + "name": "IgnoredClasses", + "default": [ + "Time", + "DateTime" + ] + } + ], + "enabled": false + }, + { + "patternId": "Lint_NumberedParameterAssignment", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_OrAssignmentToConstant", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" } ], "enabled": false @@ -1825,6 +2175,18 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_OutOfRangeRegexpRef", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Lint_ParenthesesAsGroupedExpression", "level": "Warning", @@ -1854,6 +2216,10 @@ "level": "Warning", "category": "ErrorProne", "parameters": [ + { + "name": "Safe", + "default": "false" + }, { "name": "AllowedImplicitNamespaces", "default": [ @@ -1875,16 +2241,51 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_RedundantDirGlobSort", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_RedundantRequireStatement", "level": "Warning", "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_RedundantSafeNavigation", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "AllowedMethods", + "default": [ + "instance_of?", + "kind_of?", + "is_a?", + "eql?", + "respond_to?", + "equal?" + ] + }, + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Lint_RedundantSplatExpansion", "level": "Warning", "category": "ErrorProne", + "parameters": [ + { + "name": "AllowPercentLiteralArrayArgument", + "default": "true" + } + ], "enabled": false }, { @@ -1965,7 +2366,8 @@ "blank?", "presence", "try", - "try!" + "try!", + "in?" ] } ], @@ -1983,6 +2385,12 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_SelfAssignment", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_SendWithMixinArgument", "level": "Warning", @@ -2031,18 +2439,48 @@ ], "enabled": false }, + { + "patternId": "Lint_SymbolConversion", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_Syntax", "level": "Warning", "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_ToEnumArguments", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_ToJSON", "level": "Warning", "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_TopLevelReturnWithArgument", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_TrailingCommaInAttributeDeclaration", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Lint_TripleQuotes", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_UnderscorePrefixedVariableName", "level": "Warning", @@ -2055,18 +2493,54 @@ ], "enabled": false }, + { + "patternId": "Lint_UnexpectedBlockArity", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "Methods", + "default": "{\"chunk_while\"=>2, \"each_with_index\"=>2, \"each_with_object\"=>2, \"inject\"=>2, \"max\"=>2, \"min\"=>2, \"minmax\"=>2, \"reduce\"=>2, \"slice_when\"=>2, \"sort\"=>2}" + } + ], + "enabled": false + }, { "patternId": "Lint_UnifiedInteger", "level": "Warning", "category": "ErrorProne", "enabled": false }, + { + "patternId": "Lint_UnmodifiedReduceAccumulator", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Lint_UnreachableCode", "level": "Warning", "category": "ErrorProne", "enabled": true }, + { + "patternId": "Lint_UnreachableLoop", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "IgnoredPatterns", + "default": [ + "(?-mix:(exactly|at_least|at_most)\\(\\d+\\)\\.times)" + ] + } + ], + "enabled": false + }, { "patternId": "Lint_UnusedBlockArgument", "level": "Warning", @@ -2142,22 +2616,36 @@ "enabled": true }, { - "patternId": "Lint_UselessComparison", + "patternId": "Lint_UselessElseWithoutRescue", "level": "Warning", "category": "ErrorProne", "enabled": true }, { - "patternId": "Lint_UselessElseWithoutRescue", + "patternId": "Lint_UselessMethodDefinition", "level": "Warning", "category": "ErrorProne", - "enabled": true + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "AllowComments", + "default": "true" + } + ], + "enabled": false }, { "patternId": "Lint_UselessSetterCall", "level": "Warning", "category": "ErrorProne", "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + }, { "name": "Safe", "default": "false" @@ -2165,6 +2653,18 @@ ], "enabled": true }, + { + "patternId": "Lint_UselessTimes", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Lint_Void", "level": "Warning", @@ -2190,7 +2690,7 @@ }, { "name": "Max", - "default": "6" + "default": "7" } ], "enabled": true @@ -2206,9 +2706,13 @@ ] }, + { + "name": "CountRepeatedAttributes", + "default": "true" + }, { "name": "Max", - "default": "15" + "default": "17" } ], "enabled": false @@ -2226,8 +2730,20 @@ "name": "Max", "default": "25" }, + { + "name": "CountAsOne", + "default": [ + + ] + }, { "name": "ExcludedMethods", + "default": [ + + ] + }, + { + "name": "IgnoredMethods", "default": [ "refine" ] @@ -2269,6 +2785,12 @@ { "name": "Max", "default": "100" + }, + { + "name": "CountAsOne", + "default": [ + + ] } ], "enabled": false @@ -2286,10 +2808,22 @@ "name": "Max", "default": "10" }, + { + "name": "CountAsOne", + "default": [ + + ] + }, { "name": "ExcludedMethods", "default": [ + ] + }, + { + "name": "IgnoredMethods", + "default": [ + ] } ], @@ -2307,6 +2841,12 @@ { "name": "Max", "default": "100" + }, + { + "name": "CountAsOne", + "default": [ + + ] } ], "enabled": false @@ -2323,6 +2863,10 @@ { "name": "CountKeywordArgs", "default": "true" + }, + { + "name": "MaxOptionalParameters", + "default": "3" } ], "enabled": false @@ -2340,7 +2884,7 @@ }, { "name": "Max", - "default": "7" + "default": "8" } ], "enabled": false @@ -2355,6 +2899,12 @@ "patternId": "Naming_AsciiIdentifiers", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "AsciiConstants", + "default": "true" + } + ], "enabled": false }, { @@ -2389,6 +2939,14 @@ "patternId": "Naming_ClassAndModuleCamelCase", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "AllowedNames", + "default": [ + "module_parent" + ] + } + ], "enabled": false }, { @@ -2412,6 +2970,10 @@ "name": "ExpectMatchingDefinition", "default": "false" }, + { + "name": "CheckDefinitionPathHierarchy", + "default": "true" + }, { "name": "Regex", "default": "" @@ -2562,17 +3124,18 @@ { "name": "AllowedNames", "default": [ - "io", - "id", - "to", + "at", "by", - "on", + "db", + "id", "in", - "at", + "io", "ip", - "db", + "of", + "on", "os", - "pp" + "pp", + "to" ] }, { @@ -2660,6 +3223,12 @@ "snake_case", "camelCase" ] + }, + { + "name": "AllowedIdentifiers", + "default": [ + + ] } ], "enabled": false @@ -2680,6 +3249,25 @@ "normalcase", "non_integer" ] + }, + { + "name": "CheckMethodNames", + "default": "true" + }, + { + "name": "CheckSymbols", + "default": "true" + }, + { + "name": "AllowedIdentifiers", + "default": [ + "capture3", + "iso8601", + "rfc1123_date", + "rfc822", + "rfc2822", + "rfc3339" + ] } ], "enabled": false @@ -2707,6 +3295,25 @@ ], "enabled": false }, + { + "patternId": "Style_AccessorGrouping", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "grouped" + }, + { + "name": "SupportedStyles", + "default": [ + "separated", + "grouped" + ] + } + ], + "enabled": false + }, { "patternId": "Style_Alias", "level": "Info", @@ -2745,6 +3352,30 @@ ], "enabled": false }, + { + "patternId": "Style_ArgumentsForwarding", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "AllowOnlyRestArgument", + "default": "true" + } + ], + "enabled": false + }, + { + "patternId": "Style_ArrayCoercion", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_ArrayJoin", "level": "Info", @@ -2759,7 +3390,7 @@ { "name": "AllowedChars", "default": [ - + "©" ] } ], @@ -2802,6 +3433,12 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_BisectedAttrAccessor", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_BlockComments", "level": "Info", @@ -2883,6 +3520,18 @@ ], "enabled": true }, + { + "patternId": "Style_CaseLikeIf", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_CharacterLiteral", "level": "Info", @@ -2898,10 +3547,6 @@ "name": "SafeAutoCorrect", "default": "false" }, - { - "name": "AutoCorrect", - "default": "false" - }, { "name": "EnforcedStyle", "default": "nested" @@ -2935,18 +3580,65 @@ ], "enabled": false }, + { + "patternId": "Style_ClassEqualityComparison", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "IgnoredMethods", + "default": [ + "==", + "equal?", + "eql?" + ] + } + ], + "enabled": false + }, { "patternId": "Style_ClassMethods", "level": "Info", "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_ClassMethodsDefinitions", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "def_self" + }, + { + "name": "SupportedStyles", + "default": [ + "def_self", + "self_class" + ] + } + ], + "enabled": false + }, { "patternId": "Style_ClassVars", "level": "Info", "category": "CodeStyle", "enabled": true }, + { + "patternId": "Style_CollectionCompact", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_CollectionMethods", "level": "Info", @@ -2959,6 +3651,13 @@ { "name": "PreferredMethods", "default": "{\"collect\"=>\"map\", \"collect!\"=>\"map!\", \"inject\"=>\"reduce\", \"detect\"=>\"find\", \"find_all\"=>\"select\", \"member?\"=>\"include?\"}" + }, + { + "name": "MethodsAcceptingSymbol", + "default": [ + "inject", + "reduce" + ] } ], "enabled": false @@ -2975,6 +3674,18 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_CombinableLoops", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_CommandLiteral", "level": "Info", @@ -3011,7 +3722,8 @@ "FIXME", "OPTIMIZE", "HACK", - "REVIEW" + "REVIEW", + "NOTE" ] } ], @@ -3077,6 +3789,10 @@ "level": "Info", "category": "CodeStyle", "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + }, { "name": "AllowCoercion", "default": "false" @@ -3100,6 +3816,14 @@ "patternId": "Style_DisableCopsWithinSourceCodeDirective", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "AllowedCops", + "default": [ + + ] + } + ], "enabled": false }, { @@ -3136,6 +3860,12 @@ ], "enabled": false }, + { + "patternId": "Style_DocumentDynamicEvalDefinition", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_DoubleCopDisableDirective", "level": "Info", @@ -3146,6 +3876,23 @@ "patternId": "Style_DoubleNegation", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "allowed_in_returns" + }, + { + "name": "SafeAutoCorrect", + "default": "false" + }, + { + "name": "SupportedStyles", + "default": [ + "allowed_in_returns", + "forbidden" + ] + } + ], "enabled": true }, { @@ -3223,6 +3970,26 @@ ], "enabled": false }, + { + "patternId": "Style_EndlessMethod", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "allow_single_line" + }, + { + "name": "SupportedStyles", + "default": [ + "allow_single_line", + "allow_always", + "disallow" + ] + } + ], + "enabled": false + }, { "patternId": "Style_Encoding", "level": "Info", @@ -3253,6 +4020,12 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_ExplicitBlockArgument", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_ExponentialNotation", "level": "Info", @@ -3278,6 +4051,10 @@ "level": "Info", "category": "CodeStyle", "parameters": [ + { + "name": "Safe", + "default": "false" + }, { "name": "EnforcedStyle", "default": "single_coerce" @@ -3349,6 +4126,16 @@ "template", "unannotated" ] + }, + { + "name": "MaxUnannotatedPlaceholdersAllowed", + "default": "1" + }, + { + "name": "IgnoredMethods", + "default": [ + + ] } ], "enabled": false @@ -3371,46 +4158,95 @@ ] }, { - "name": "Safe", - "default": "false" + "name": "SafeAutoCorrect", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_GlobalStdStream", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_GlobalVars", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "AllowedVariables", + "default": [ + + ] + } + ], + "enabled": false + }, + { + "patternId": "Style_GuardClause", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "MinBodyLength", + "default": "1" } ], "enabled": false }, { - "patternId": "Style_GlobalVars", + "patternId": "Style_HashAsLastArrayItem", "level": "Info", "category": "CodeStyle", "parameters": [ { - "name": "AllowedVariables", + "name": "EnforcedStyle", + "default": "braces" + }, + { + "name": "SupportedStyles", "default": [ - + "braces", + "no_braces" ] } ], "enabled": false }, { - "patternId": "Style_GuardClause", + "patternId": "Style_HashEachMethods", "level": "Info", "category": "CodeStyle", "parameters": [ { - "name": "MinBodyLength", - "default": "1" + "name": "Safe", + "default": "false" } ], "enabled": false }, { - "patternId": "Style_HashEachMethods", + "patternId": "Style_HashExcept", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, + { + "patternId": "Style_HashLikeCase", "level": "Info", "category": "CodeStyle", "parameters": [ { - "name": "Safe", - "default": "false" + "name": "MinBranchesCount", + "default": "3" } ], "enabled": false @@ -3498,6 +4334,24 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_IfWithBooleanLiteralBranches", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + }, + { + "name": "AllowedMethods", + "default": [ + "nonzero?" + ] + } + ], + "enabled": false + }, { "patternId": "Style_IfWithSemicolon", "level": "Info", @@ -3516,8 +4370,8 @@ "category": "CodeStyle", "parameters": [ { - "name": "SafeAutoCorrect", - "default": "true" + "name": "Safe", + "default": "false" } ], "enabled": true @@ -3558,10 +4412,25 @@ "default": [ "::" ] + }, + { + "name": "Exclude", + "default": [ + "**/*.gemfile", + "**/Gemfile", + "**/gems.rb", + "**/*.gemspec" + ] } ], "enabled": false }, + { + "patternId": "Style_KeywordParametersOrder", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_Lambda", "level": "Info", @@ -3680,6 +4549,70 @@ ], "enabled": false }, + { + "patternId": "Style_RedundantAssignment", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, + { + "patternId": "Style_RedundantFetchBlock", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "SafeForConstants", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_RedundantFileExtensionInRequire", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, + { + "patternId": "Style_RedundantSelfAssignment", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_SoleNestedConditional", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "AllowModifier", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_StaticClass", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_MethodCalledOnDoEndBlock", "level": "Info", @@ -3706,12 +4639,6 @@ ], "enabled": false }, - { - "patternId": "Style_MethodMissingSuper", - "level": "Info", - "category": "CodeStyle", - "enabled": false - }, { "patternId": "Style_MinMax", "level": "Info", @@ -3863,6 +4790,10 @@ "level": "Info", "category": "CodeStyle", "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + }, { "name": "EnforcedStyle", "default": "literals" @@ -3897,6 +4828,12 @@ ], "enabled": true }, + { + "patternId": "Style_NegatedIfElseCondition", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_NegatedUnless", "level": "Info", @@ -4007,6 +4944,12 @@ ], "enabled": true }, + { + "patternId": "Style_NilLambda", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_NonNilCheck", "level": "Info", @@ -4073,10 +5016,6 @@ "name": "SafeAutoCorrect", "default": "false" }, - { - "name": "AutoCorrect", - "default": "false" - }, { "name": "EnforcedStyle", "default": "predicate" @@ -4107,6 +5046,12 @@ "patternId": "Style_OneLineConditional", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "AlwaysCorrectToMultiline", + "default": "false" + } + ], "enabled": true }, { @@ -4137,6 +5082,30 @@ "patternId": "Style_OptionalArguments", "level": "Info", "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Style_OptionalBooleanParameter", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "AllowedMethods", + "default": [ + "respond_to_missing?" + ] + } + ], "enabled": false }, { @@ -4242,6 +5211,12 @@ "compact", "exploded" ] + }, + { + "name": "AllowedCompactTypes", + "default": [ + + ] } ], "enabled": false @@ -4252,6 +5227,22 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_RedundantArgument", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "Methods", + "default": "{\"join\"=>\"\", \"split\"=>\" \", \"chomp\"=>\"\\n\", \"chomp!\"=>\"\\n\"}" + } + ], + "enabled": false + }, { "patternId": "Style_RedundantBegin", "level": "Info", @@ -4306,6 +5297,18 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_RedundantRegexpCharacterClass", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, + { + "patternId": "Style_RedundantRegexpEscape", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Style_RedundantReturn", "level": "Info", @@ -4422,6 +5425,10 @@ "try", "try!" ] + }, + { + "name": "SafeAutoCorrect", + "default": "false" } ], "enabled": false @@ -4476,6 +5483,18 @@ ], "enabled": false }, + { + "patternId": "Style_SingleArgumentDig", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_SingleLineBlockParams", "level": "Info", @@ -4513,6 +5532,18 @@ ], "enabled": false }, + { + "patternId": "Style_SlicingWithRange", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_SpecialGlobalVars", "level": "Info", @@ -4561,6 +5592,18 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_StringConcatenation", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_StringHashKeys", "level": "Info", @@ -4639,6 +5682,18 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Style_SwapValues", + "level": "Info", + "category": "CodeStyle", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Style_SymbolArray", "level": "Info", @@ -4674,7 +5729,7 @@ "category": "CodeStyle", "parameters": [ { - "name": "SafeAutoCorrect", + "name": "Safe", "default": "false" }, { @@ -5023,7 +6078,19 @@ "enabled": false }, { - "patternId": "Performance_AncestorsInclude", + "patternId": "Performance_AncestorsInclude", + "level": "Warning", + "category": "Performance", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Performance_ArraySemiInfiniteRangeSlice", "level": "Warning", "category": "Performance", "parameters": [ @@ -5046,6 +6113,12 @@ "category": "Performance", "enabled": false }, + { + "patternId": "Performance_BlockGivenWithExplicitBlock", + "level": "Warning", + "category": "Performance", + "enabled": false + }, { "patternId": "Performance_Caller", "level": "Warning", @@ -5080,12 +6153,30 @@ ], "enabled": false }, + { + "patternId": "Performance_CollectionLiteralInLoop", + "level": "Warning", + "category": "Performance", + "parameters": [ + { + "name": "MinSize", + "default": "1" + } + ], + "enabled": false + }, { "patternId": "Performance_CompareWithBlock", "level": "Warning", "category": "Performance", "enabled": false }, + { + "patternId": "Performance_ConstantRegexp", + "level": "Warning", + "category": "Performance", + "enabled": false + }, { "patternId": "Performance_Count", "level": "Warning", @@ -5196,6 +6287,12 @@ ], "enabled": false }, + { + "patternId": "Performance_MethodObjectAsBlock", + "level": "Warning", + "category": "Performance", + "enabled": false + }, { "patternId": "Performance_OpenStruct", "level": "Warning", @@ -5340,6 +6437,12 @@ "category": "Performance", "enabled": false }, + { + "patternId": "Performance_Sum", + "level": "Warning", + "category": "Performance", + "enabled": false + }, { "patternId": "Performance_TimesMap", "level": "Warning", @@ -5360,6 +6463,12 @@ "patternId": "Performance_UnfreezeString", "level": "Warning", "category": "Performance", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + } + ], "enabled": false }, { @@ -5411,6 +6520,20 @@ ], "enabled": false }, + { + "patternId": "Rails_ActiveRecordCallbacksOrder", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Include", + "default": [ + "app/models/**/*.rb" + ] + } + ], + "enabled": false + }, { "patternId": "Rails_ActiveRecordOverride", "level": "Warning", @@ -5431,6 +6554,12 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Rails_AfterCommitOverride", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Rails_ApplicationController", "level": "Warning", @@ -5479,6 +6608,18 @@ ], "enabled": false }, + { + "patternId": "Rails_ArelStar", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Rails_AssertNot", "level": "Warning", @@ -5493,6 +6634,20 @@ ], "enabled": false }, + { + "patternId": "Rails_AttributeDefaultBlockValue", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Include", + "default": [ + "models/**/*" + ] + } + ], + "enabled": false + }, { "patternId": "Rails_BelongsTo", "level": "Warning", @@ -5583,6 +6738,12 @@ ], "enabled": true }, + { + "patternId": "Rails_DefaultScope", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Rails_Delegate", "level": "Warning", @@ -5716,6 +6877,12 @@ ], "enabled": false }, + { + "patternId": "Rails_FindById", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Rails_FindEach", "level": "Warning", @@ -5726,6 +6893,15 @@ "default": [ "app/models/**/*.rb" ] + }, + { + "name": "IgnoredMethods", + "default": [ + "order", + "limit", + "select", + "lock" + ] } ], "enabled": false @@ -5832,6 +7008,12 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Rails_Inquiry", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Rails_InverseOf", "level": "Warning", @@ -5870,6 +7052,51 @@ "category": "ErrorProne", "enabled": false }, + { + "patternId": "Rails_MailerName", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + }, + { + "name": "Include", + "default": [ + "app/mailers/**/*.rb" + ] + } + ], + "enabled": false + }, + { + "patternId": "Rails_MatchRoute", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Include", + "default": [ + "config/routes.rb", + "config/routes/**/*.rb" + ] + } + ], + "enabled": false + }, + { + "patternId": "Rails_NegateInclude", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Rails_NotNullColumn", "level": "Warning", @@ -5884,6 +7111,12 @@ ], "enabled": false }, + { + "patternId": "Rails_OrderById", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, { "patternId": "Rails_Output", "level": "Warning", @@ -5919,6 +7152,47 @@ ], "enabled": false }, + { + "patternId": "Rails_Pluck", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Rails_PluckId", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + } + ], + "enabled": false + }, + { + "patternId": "Rails_PluckInWhere", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "Safe", + "default": "false" + }, + { + "name": "EnforcedStyle", + "default": "conservative" + }, + { + "name": "SupportedStyles", + "default": [ + "conservative", + "aggressive" + ] + } + ], + "enabled": false + }, { "patternId": "Rails_PluralizationGrammar", "level": "Warning", @@ -6059,6 +7333,24 @@ ], "enabled": false }, + { + "patternId": "Rails_RenderInline", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Rails_RenderPlainText", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "ContentTypeCompatibility", + "default": "true" + } + ], + "enabled": false + }, { "patternId": "Rails_RequestReferer", "level": "Warning", @@ -6152,29 +7444,55 @@ ], "enabled": false }, + { + "patternId": "Rails_ShortI18n", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "conservative" + }, + { + "name": "SupportedStyles", + "default": [ + "conservative", + "aggressive" + ] + } + ], + "enabled": false + }, { "patternId": "Rails_SkipsModelValidations", "level": "Warning", "category": "ErrorProne", "parameters": [ { - "name": "Blacklist", + "name": "ForbiddenMethods", "default": [ "decrement!", "decrement_counter", "increment!", "increment_counter", + "insert", + "insert!", + "insert_all", + "insert_all!", "toggle!", "touch", + "touch_all", "update_all", "update_attribute", "update_column", "update_columns", - "update_counters" + "update_counters", + "upsert", + "upsert_all" ] }, { - "name": "Whitelist", + "name": "AllowedMethods", "default": [ ] @@ -6182,6 +7500,18 @@ ], "enabled": false }, + { + "patternId": "Rails_SquishedSQLHeredocs", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "SafeAutoCorrect", + "default": "false" + } + ], + "enabled": false + }, { "patternId": "Rails_TimeZone", "level": "Warning", @@ -6221,6 +7551,10 @@ "aggressive" ] }, + { + "name": "SafeAutoCorrect", + "default": "false" + }, { "name": "AutoCorrect", "default": "false" @@ -6271,6 +7605,37 @@ } ], "enabled": false + }, + { + "patternId": "Rails_WhereEquals", + "level": "Warning", + "category": "ErrorProne", + "enabled": false + }, + { + "patternId": "Rails_WhereExists", + "level": "Warning", + "category": "ErrorProne", + "parameters": [ + { + "name": "EnforcedStyle", + "default": "exists" + }, + { + "name": "SupportedStyles", + "default": [ + "exists", + "where" + ] + } + ], + "enabled": false + }, + { + "patternId": "Rails_WhereNot", + "level": "Warning", + "category": "ErrorProne", + "enabled": false } ] } \ No newline at end of file diff --git a/src/main/resources/docs/tests/Layout_AccessModifierIndentation.rb b/docs/tests/Layout_AccessModifierIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_AccessModifierIndentation.rb rename to docs/tests/Layout_AccessModifierIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_ArgumentAlignment.rb b/docs/tests/Layout_ArgumentAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ArgumentAlignment.rb rename to docs/tests/Layout_ArgumentAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_ArrayAlignment.rb b/docs/tests/Layout_ArrayAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ArrayAlignment.rb rename to docs/tests/Layout_ArrayAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_BlockAlignment.rb b/docs/tests/Layout_BlockAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_BlockAlignment.rb rename to docs/tests/Layout_BlockAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_BlockEndNewline.rb b/docs/tests/Layout_BlockEndNewline.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_BlockEndNewline.rb rename to docs/tests/Layout_BlockEndNewline.rb diff --git a/src/main/resources/docs/tests/Layout_CaseIndentation.rb b/docs/tests/Layout_CaseIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_CaseIndentation.rb rename to docs/tests/Layout_CaseIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_ClosingParenthesisIndentation.rb b/docs/tests/Layout_ClosingParenthesisIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ClosingParenthesisIndentation.rb rename to docs/tests/Layout_ClosingParenthesisIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_ConditionPosition.rb b/docs/tests/Layout_ConditionPosition.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ConditionPosition.rb rename to docs/tests/Layout_ConditionPosition.rb diff --git a/src/main/resources/docs/tests/Layout_DefEndAlignment.rb b/docs/tests/Layout_DefEndAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_DefEndAlignment.rb rename to docs/tests/Layout_DefEndAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_DotPosition.rb b/docs/tests/Layout_DotPosition.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_DotPosition.rb rename to docs/tests/Layout_DotPosition.rb diff --git a/src/main/resources/docs/tests/Layout_ElseAlignment.rb b/docs/tests/Layout_ElseAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ElseAlignment.rb rename to docs/tests/Layout_ElseAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLineBetweenDefs.rb b/docs/tests/Layout_EmptyLineBetweenDefs.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLineBetweenDefs.rb rename to docs/tests/Layout_EmptyLineBetweenDefs.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLines.rb b/docs/tests/Layout_EmptyLines.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLines.rb rename to docs/tests/Layout_EmptyLines.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLinesAroundAccessModifier.rb b/docs/tests/Layout_EmptyLinesAroundAccessModifier.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLinesAroundAccessModifier.rb rename to docs/tests/Layout_EmptyLinesAroundAccessModifier.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLinesAroundBlockBody.rb b/docs/tests/Layout_EmptyLinesAroundBlockBody.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLinesAroundBlockBody.rb rename to docs/tests/Layout_EmptyLinesAroundBlockBody.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLinesAroundClassBody.rb b/docs/tests/Layout_EmptyLinesAroundClassBody.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLinesAroundClassBody.rb rename to docs/tests/Layout_EmptyLinesAroundClassBody.rb diff --git a/src/main/resources/docs/tests/Layout_EmptyLinesAroundModuleBody.rb b/docs/tests/Layout_EmptyLinesAroundModuleBody.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EmptyLinesAroundModuleBody.rb rename to docs/tests/Layout_EmptyLinesAroundModuleBody.rb diff --git a/src/main/resources/docs/tests/Layout_EndAlignment.rb b/docs/tests/Layout_EndAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EndAlignment.rb rename to docs/tests/Layout_EndAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_EndOfLine.rb b/docs/tests/Layout_EndOfLine.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_EndOfLine.rb rename to docs/tests/Layout_EndOfLine.rb diff --git a/src/main/resources/docs/tests/Layout_ExtraSpacing.rb b/docs/tests/Layout_ExtraSpacing.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_ExtraSpacing.rb rename to docs/tests/Layout_ExtraSpacing.rb diff --git a/src/main/resources/docs/tests/Layout_FirstArgumentIndentation.rb b/docs/tests/Layout_FirstArgumentIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_FirstArgumentIndentation.rb rename to docs/tests/Layout_FirstArgumentIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_FirstArrayElementIndentation.rb b/docs/tests/Layout_FirstArrayElementIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_FirstArrayElementIndentation.rb rename to docs/tests/Layout_FirstArrayElementIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_FirstHashElementIndentation.rb b/docs/tests/Layout_FirstHashElementIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_FirstHashElementIndentation.rb rename to docs/tests/Layout_FirstHashElementIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_HashAlignment.rb b/docs/tests/Layout_HashAlignment.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_HashAlignment.rb rename to docs/tests/Layout_HashAlignment.rb diff --git a/src/main/resources/docs/tests/Layout_IndentationConsistency.rb b/docs/tests/Layout_IndentationConsistency.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_IndentationConsistency.rb rename to docs/tests/Layout_IndentationConsistency.rb diff --git a/src/main/resources/docs/tests/Layout_IndentationWidth.rb b/docs/tests/Layout_IndentationWidth.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_IndentationWidth.rb rename to docs/tests/Layout_IndentationWidth.rb diff --git a/docs/tests/Layout_LineLength.rb b/docs/tests/Layout_LineLength.rb new file mode 100644 index 00000000..5254b7b1 --- /dev/null +++ b/docs/tests/Layout_LineLength.rb @@ -0,0 +1,4 @@ +##Patterns: Layout_LineLength + +##Info: Layout_LineLength +puts 'HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello' diff --git a/src/main/resources/docs/tests/Layout_MultilineBlockLayout.rb b/docs/tests/Layout_MultilineBlockLayout.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_MultilineBlockLayout.rb rename to docs/tests/Layout_MultilineBlockLayout.rb diff --git a/src/main/resources/docs/tests/Layout_MultilineOperationIndentation.rb b/docs/tests/Layout_MultilineOperationIndentation.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_MultilineOperationIndentation.rb rename to docs/tests/Layout_MultilineOperationIndentation.rb diff --git a/src/main/resources/docs/tests/Layout_SpaceBeforeFirstArg.rb b/docs/tests/Layout_SpaceBeforeFirstArg.rb similarity index 100% rename from src/main/resources/docs/tests/Layout_SpaceBeforeFirstArg.rb rename to docs/tests/Layout_SpaceBeforeFirstArg.rb diff --git a/src/main/resources/docs/tests/Lint_AmbiguousOperator.rb b/docs/tests/Lint_AmbiguousOperator.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_AmbiguousOperator.rb rename to docs/tests/Lint_AmbiguousOperator.rb diff --git a/src/main/resources/docs/tests/Lint_AmbiguousRegexpLiteral.rb b/docs/tests/Lint_AmbiguousRegexpLiteral.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_AmbiguousRegexpLiteral.rb rename to docs/tests/Lint_AmbiguousRegexpLiteral.rb diff --git a/src/main/resources/docs/tests/Lint_AssignmentInCondition.rb b/docs/tests/Lint_AssignmentInCondition.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_AssignmentInCondition.rb rename to docs/tests/Lint_AssignmentInCondition.rb diff --git a/src/main/resources/docs/tests/Lint_Debugger.rb b/docs/tests/Lint_Debugger.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_Debugger.rb rename to docs/tests/Lint_Debugger.rb diff --git a/src/main/resources/docs/tests/Lint_DeprecatedClassMethods.rb b/docs/tests/Lint_DeprecatedClassMethods.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_DeprecatedClassMethods.rb rename to docs/tests/Lint_DeprecatedClassMethods.rb diff --git a/src/main/resources/docs/tests/Lint_DuplicateMethods.rb b/docs/tests/Lint_DuplicateMethods.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_DuplicateMethods.rb rename to docs/tests/Lint_DuplicateMethods.rb diff --git a/src/main/resources/docs/tests/Lint_EachWithObjectArgument.rb b/docs/tests/Lint_EachWithObjectArgument.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_EachWithObjectArgument.rb rename to docs/tests/Lint_EachWithObjectArgument.rb diff --git a/src/main/resources/docs/tests/Lint_ElseLayout.rb b/docs/tests/Lint_ElseLayout.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_ElseLayout.rb rename to docs/tests/Lint_ElseLayout.rb diff --git a/src/main/resources/docs/tests/Lint_EmptyEnsure.rb b/docs/tests/Lint_EmptyEnsure.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_EmptyEnsure.rb rename to docs/tests/Lint_EmptyEnsure.rb diff --git a/src/main/resources/docs/tests/Lint_EmptyInterpolation.rb b/docs/tests/Lint_EmptyInterpolation.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_EmptyInterpolation.rb rename to docs/tests/Lint_EmptyInterpolation.rb diff --git a/src/main/resources/docs/tests/Lint_EnsureReturn.rb b/docs/tests/Lint_EnsureReturn.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_EnsureReturn.rb rename to docs/tests/Lint_EnsureReturn.rb diff --git a/src/main/resources/docs/tests/Lint_FlipFlop.rb b/docs/tests/Lint_FlipFlop.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_FlipFlop.rb rename to docs/tests/Lint_FlipFlop.rb diff --git a/src/main/resources/docs/tests/Lint_LiteralInInterpolation.rb b/docs/tests/Lint_LiteralInInterpolation.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_LiteralInInterpolation.rb rename to docs/tests/Lint_LiteralInInterpolation.rb diff --git a/src/main/resources/docs/tests/Lint_Loop.rb b/docs/tests/Lint_Loop.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_Loop.rb rename to docs/tests/Lint_Loop.rb diff --git a/src/main/resources/docs/tests/Lint_NestedMethodDefinition.rb b/docs/tests/Lint_NestedMethodDefinition.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_NestedMethodDefinition.rb rename to docs/tests/Lint_NestedMethodDefinition.rb diff --git a/src/main/resources/docs/tests/Lint_NonLocalExitFromIterator.rb b/docs/tests/Lint_NonLocalExitFromIterator.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_NonLocalExitFromIterator.rb rename to docs/tests/Lint_NonLocalExitFromIterator.rb diff --git a/src/main/resources/docs/tests/Lint_ParenthesesAsGroupedExpression.rb b/docs/tests/Lint_ParenthesesAsGroupedExpression.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_ParenthesesAsGroupedExpression.rb rename to docs/tests/Lint_ParenthesesAsGroupedExpression.rb diff --git a/src/main/resources/docs/tests/Lint_RedundantStringCoercion.rb b/docs/tests/Lint_RedundantStringCoercion.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_RedundantStringCoercion.rb rename to docs/tests/Lint_RedundantStringCoercion.rb diff --git a/src/main/resources/docs/tests/Lint_RequireParentheses.rb b/docs/tests/Lint_RequireParentheses.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_RequireParentheses.rb rename to docs/tests/Lint_RequireParentheses.rb diff --git a/src/main/resources/docs/tests/Lint_RescueException.rb b/docs/tests/Lint_RescueException.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_RescueException.rb rename to docs/tests/Lint_RescueException.rb diff --git a/src/main/resources/docs/tests/Lint_ShadowingOuterLocalVariable.rb b/docs/tests/Lint_ShadowingOuterLocalVariable.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_ShadowingOuterLocalVariable.rb rename to docs/tests/Lint_ShadowingOuterLocalVariable.rb diff --git a/src/main/resources/docs/tests/Lint_SuppressedException.rb b/docs/tests/Lint_SuppressedException.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_SuppressedException.rb rename to docs/tests/Lint_SuppressedException.rb diff --git a/src/main/resources/docs/tests/Lint_UnderscorePrefixedVariableName.rb b/docs/tests/Lint_UnderscorePrefixedVariableName.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UnderscorePrefixedVariableName.rb rename to docs/tests/Lint_UnderscorePrefixedVariableName.rb diff --git a/src/main/resources/docs/tests/Lint_UnreachableCode.rb b/docs/tests/Lint_UnreachableCode.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UnreachableCode.rb rename to docs/tests/Lint_UnreachableCode.rb diff --git a/src/main/resources/docs/tests/Lint_UnusedBlockArgument.rb b/docs/tests/Lint_UnusedBlockArgument.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UnusedBlockArgument.rb rename to docs/tests/Lint_UnusedBlockArgument.rb diff --git a/src/main/resources/docs/tests/Lint_UnusedMethodArgument.rb b/docs/tests/Lint_UnusedMethodArgument.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UnusedMethodArgument.rb rename to docs/tests/Lint_UnusedMethodArgument.rb diff --git a/src/main/resources/docs/tests/Lint_UselessAccessModifier.rb b/docs/tests/Lint_UselessAccessModifier.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UselessAccessModifier.rb rename to docs/tests/Lint_UselessAccessModifier.rb diff --git a/src/main/resources/docs/tests/Lint_UselessAssignment.rb b/docs/tests/Lint_UselessAssignment.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UselessAssignment.rb rename to docs/tests/Lint_UselessAssignment.rb diff --git a/src/main/resources/docs/tests/Lint_UselessElseWithoutRescue.rb b/docs/tests/Lint_UselessElseWithoutRescue.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UselessElseWithoutRescue.rb rename to docs/tests/Lint_UselessElseWithoutRescue.rb diff --git a/src/main/resources/docs/tests/Lint_UselessSetterCall.rb b/docs/tests/Lint_UselessSetterCall.rb similarity index 100% rename from src/main/resources/docs/tests/Lint_UselessSetterCall.rb rename to docs/tests/Lint_UselessSetterCall.rb diff --git a/src/main/resources/docs/tests/Metrics_AbcSize.rb b/docs/tests/Metrics_AbcSize.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_AbcSize.rb rename to docs/tests/Metrics_AbcSize.rb diff --git a/src/main/resources/docs/tests/Metrics_BlockNesting.rb b/docs/tests/Metrics_BlockNesting.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_BlockNesting.rb rename to docs/tests/Metrics_BlockNesting.rb diff --git a/src/main/resources/docs/tests/Metrics_ClassLength.rb b/docs/tests/Metrics_ClassLength.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_ClassLength.rb rename to docs/tests/Metrics_ClassLength.rb diff --git a/src/main/resources/docs/tests/Metrics_CyclomaticComplexity.rb b/docs/tests/Metrics_CyclomaticComplexity.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_CyclomaticComplexity.rb rename to docs/tests/Metrics_CyclomaticComplexity.rb diff --git a/src/main/resources/docs/tests/Metrics_MethodLength.rb b/docs/tests/Metrics_MethodLength.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_MethodLength.rb rename to docs/tests/Metrics_MethodLength.rb diff --git a/src/main/resources/docs/tests/Metrics_ModuleLength.rb b/docs/tests/Metrics_ModuleLength.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_ModuleLength.rb rename to docs/tests/Metrics_ModuleLength.rb diff --git a/src/main/resources/docs/tests/Metrics_ParameterLists.rb b/docs/tests/Metrics_ParameterLists.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_ParameterLists.rb rename to docs/tests/Metrics_ParameterLists.rb diff --git a/src/main/resources/docs/tests/Metrics_PerceivedComplexity.rb b/docs/tests/Metrics_PerceivedComplexity.rb similarity index 100% rename from src/main/resources/docs/tests/Metrics_PerceivedComplexity.rb rename to docs/tests/Metrics_PerceivedComplexity.rb diff --git a/src/main/resources/docs/tests/Naming_BinaryOperatorParameterName.rb b/docs/tests/Naming_BinaryOperatorParameterName.rb similarity index 100% rename from src/main/resources/docs/tests/Naming_BinaryOperatorParameterName.rb rename to docs/tests/Naming_BinaryOperatorParameterName.rb diff --git a/src/main/resources/docs/tests/Performance_Count.rb b/docs/tests/Performance_Count.rb similarity index 100% rename from src/main/resources/docs/tests/Performance_Count.rb rename to docs/tests/Performance_Count.rb diff --git a/src/main/resources/docs/tests/Performance_Detect.rb b/docs/tests/Performance_Detect.rb similarity index 100% rename from src/main/resources/docs/tests/Performance_Detect.rb rename to docs/tests/Performance_Detect.rb diff --git a/src/main/resources/docs/tests/Performance_FlatMap.rb b/docs/tests/Performance_FlatMap.rb similarity index 100% rename from src/main/resources/docs/tests/Performance_FlatMap.rb rename to docs/tests/Performance_FlatMap.rb diff --git a/src/main/resources/docs/tests/Performance_ReverseEach.rb b/docs/tests/Performance_ReverseEach.rb similarity index 100% rename from src/main/resources/docs/tests/Performance_ReverseEach.rb rename to docs/tests/Performance_ReverseEach.rb diff --git a/src/main/resources/docs/tests/Performance_Size.rb b/docs/tests/Performance_Size.rb similarity index 100% rename from src/main/resources/docs/tests/Performance_Size.rb rename to docs/tests/Performance_Size.rb diff --git a/src/main/resources/docs/tests/Rails_Date.rb b/docs/tests/Rails_Date.rb similarity index 100% rename from src/main/resources/docs/tests/Rails_Date.rb rename to docs/tests/Rails_Date.rb diff --git a/src/main/resources/docs/tests/Rails_Delegate.rb b/docs/tests/Rails_Delegate.rb similarity index 100% rename from src/main/resources/docs/tests/Rails_Delegate.rb rename to docs/tests/Rails_Delegate.rb diff --git a/src/main/resources/docs/tests/Security_Eval.rb b/docs/tests/Security_Eval.rb similarity index 100% rename from src/main/resources/docs/tests/Security_Eval.rb rename to docs/tests/Security_Eval.rb diff --git a/src/main/resources/docs/tests/Style_AccessorMethodName.rb b/docs/tests/Style_AccessorMethodName.rb similarity index 100% rename from src/main/resources/docs/tests/Style_AccessorMethodName.rb rename to docs/tests/Style_AccessorMethodName.rb diff --git a/src/main/resources/docs/tests/Style_Alias.rb b/docs/tests/Style_Alias.rb similarity index 100% rename from src/main/resources/docs/tests/Style_Alias.rb rename to docs/tests/Style_Alias.rb diff --git a/src/main/resources/docs/tests/Style_AndOr.rb b/docs/tests/Style_AndOr.rb similarity index 100% rename from src/main/resources/docs/tests/Style_AndOr.rb rename to docs/tests/Style_AndOr.rb diff --git a/src/main/resources/docs/tests/Style_ArrayJoin.rb b/docs/tests/Style_ArrayJoin.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ArrayJoin.rb rename to docs/tests/Style_ArrayJoin.rb diff --git a/src/main/resources/docs/tests/Style_AsciiComments.rb b/docs/tests/Style_AsciiComments.rb similarity index 100% rename from src/main/resources/docs/tests/Style_AsciiComments.rb rename to docs/tests/Style_AsciiComments.rb diff --git a/src/main/resources/docs/tests/Style_AutoResourceCleanup.rb b/docs/tests/Style_AutoResourceCleanup.rb similarity index 100% rename from src/main/resources/docs/tests/Style_AutoResourceCleanup.rb rename to docs/tests/Style_AutoResourceCleanup.rb diff --git a/src/main/resources/docs/tests/Style_BarePercentLiterals.rb b/docs/tests/Style_BarePercentLiterals.rb similarity index 100% rename from src/main/resources/docs/tests/Style_BarePercentLiterals.rb rename to docs/tests/Style_BarePercentLiterals.rb diff --git a/src/main/resources/docs/tests/Style_BeginBlock.rb b/docs/tests/Style_BeginBlock.rb similarity index 100% rename from src/main/resources/docs/tests/Style_BeginBlock.rb rename to docs/tests/Style_BeginBlock.rb diff --git a/src/main/resources/docs/tests/Style_BlockComments.rb b/docs/tests/Style_BlockComments.rb similarity index 100% rename from src/main/resources/docs/tests/Style_BlockComments.rb rename to docs/tests/Style_BlockComments.rb diff --git a/src/main/resources/docs/tests/Style_CaseEquality.rb b/docs/tests/Style_CaseEquality.rb similarity index 100% rename from src/main/resources/docs/tests/Style_CaseEquality.rb rename to docs/tests/Style_CaseEquality.rb diff --git a/src/main/resources/docs/tests/Style_CharacterLiteral.rb b/docs/tests/Style_CharacterLiteral.rb similarity index 100% rename from src/main/resources/docs/tests/Style_CharacterLiteral.rb rename to docs/tests/Style_CharacterLiteral.rb diff --git a/src/main/resources/docs/tests/Style_ClassAndModuleCamelCase.rb b/docs/tests/Style_ClassAndModuleCamelCase.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ClassAndModuleCamelCase.rb rename to docs/tests/Style_ClassAndModuleCamelCase.rb diff --git a/src/main/resources/docs/tests/Style_ClassAndModuleChildren.rb b/docs/tests/Style_ClassAndModuleChildren.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ClassAndModuleChildren.rb rename to docs/tests/Style_ClassAndModuleChildren.rb diff --git a/src/main/resources/docs/tests/Style_ClassCheck.rb b/docs/tests/Style_ClassCheck.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ClassCheck.rb rename to docs/tests/Style_ClassCheck.rb diff --git a/src/main/resources/docs/tests/Style_ClassMethods.rb b/docs/tests/Style_ClassMethods.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ClassMethods.rb rename to docs/tests/Style_ClassMethods.rb diff --git a/src/main/resources/docs/tests/Style_ClassVars.rb b/docs/tests/Style_ClassVars.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ClassVars.rb rename to docs/tests/Style_ClassVars.rb diff --git a/src/main/resources/docs/tests/Style_ColonMethodCall.rb b/docs/tests/Style_ColonMethodCall.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ColonMethodCall.rb rename to docs/tests/Style_ColonMethodCall.rb diff --git a/src/main/resources/docs/tests/Style_CommandLiteral.rb b/docs/tests/Style_CommandLiteral.rb similarity index 100% rename from src/main/resources/docs/tests/Style_CommandLiteral.rb rename to docs/tests/Style_CommandLiteral.rb diff --git a/src/main/resources/docs/tests/Style_CommentAnnotation.rb b/docs/tests/Style_CommentAnnotation.rb similarity index 100% rename from src/main/resources/docs/tests/Style_CommentAnnotation.rb rename to docs/tests/Style_CommentAnnotation.rb diff --git a/src/main/resources/docs/tests/Style_ConstantName.rb b/docs/tests/Style_ConstantName.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ConstantName.rb rename to docs/tests/Style_ConstantName.rb diff --git a/src/main/resources/docs/tests/Style_DefWithParentheses.rb b/docs/tests/Style_DefWithParentheses.rb similarity index 100% rename from src/main/resources/docs/tests/Style_DefWithParentheses.rb rename to docs/tests/Style_DefWithParentheses.rb diff --git a/src/main/resources/docs/tests/Style_DotPosition_leading.rb b/docs/tests/Style_DotPosition_leading.rb similarity index 100% rename from src/main/resources/docs/tests/Style_DotPosition_leading.rb rename to docs/tests/Style_DotPosition_leading.rb diff --git a/src/main/resources/docs/tests/Style_DotPosition_trailing.rb b/docs/tests/Style_DotPosition_trailing.rb similarity index 100% rename from src/main/resources/docs/tests/Style_DotPosition_trailing.rb rename to docs/tests/Style_DotPosition_trailing.rb diff --git a/src/main/resources/docs/tests/Style_DoubleNegation.rb b/docs/tests/Style_DoubleNegation.rb similarity index 100% rename from src/main/resources/docs/tests/Style_DoubleNegation.rb rename to docs/tests/Style_DoubleNegation.rb diff --git a/src/main/resources/docs/tests/Style_EachWithObject.rb b/docs/tests/Style_EachWithObject.rb similarity index 100% rename from src/main/resources/docs/tests/Style_EachWithObject.rb rename to docs/tests/Style_EachWithObject.rb diff --git a/src/main/resources/docs/tests/Style_EmptyElse.rb b/docs/tests/Style_EmptyElse.rb similarity index 100% rename from src/main/resources/docs/tests/Style_EmptyElse.rb rename to docs/tests/Style_EmptyElse.rb diff --git a/src/main/resources/docs/tests/Style_EmptyLiteral.rb b/docs/tests/Style_EmptyLiteral.rb similarity index 100% rename from src/main/resources/docs/tests/Style_EmptyLiteral.rb rename to docs/tests/Style_EmptyLiteral.rb diff --git a/src/main/resources/docs/tests/Style_Encoding.rb b/docs/tests/Style_Encoding.rb similarity index 100% rename from src/main/resources/docs/tests/Style_Encoding.rb rename to docs/tests/Style_Encoding.rb diff --git a/src/main/resources/docs/tests/Style_EndBlock.rb b/docs/tests/Style_EndBlock.rb similarity index 100% rename from src/main/resources/docs/tests/Style_EndBlock.rb rename to docs/tests/Style_EndBlock.rb diff --git a/src/main/resources/docs/tests/Style_EvenOdd.rb b/docs/tests/Style_EvenOdd.rb similarity index 100% rename from src/main/resources/docs/tests/Style_EvenOdd.rb rename to docs/tests/Style_EvenOdd.rb diff --git a/src/main/resources/docs/tests/Style_For.rb b/docs/tests/Style_For.rb similarity index 100% rename from src/main/resources/docs/tests/Style_For.rb rename to docs/tests/Style_For.rb diff --git a/src/main/resources/docs/tests/Style_FormatString.rb b/docs/tests/Style_FormatString.rb similarity index 100% rename from src/main/resources/docs/tests/Style_FormatString.rb rename to docs/tests/Style_FormatString.rb diff --git a/src/main/resources/docs/tests/Style_GlobalVars.rb b/docs/tests/Style_GlobalVars.rb similarity index 100% rename from src/main/resources/docs/tests/Style_GlobalVars.rb rename to docs/tests/Style_GlobalVars.rb diff --git a/src/main/resources/docs/tests/Style_GlobalVars2.rb b/docs/tests/Style_GlobalVars2.rb similarity index 100% rename from src/main/resources/docs/tests/Style_GlobalVars2.rb rename to docs/tests/Style_GlobalVars2.rb diff --git a/src/main/resources/docs/tests/Style_GuardClause.rb b/docs/tests/Style_GuardClause.rb similarity index 100% rename from src/main/resources/docs/tests/Style_GuardClause.rb rename to docs/tests/Style_GuardClause.rb diff --git a/src/main/resources/docs/tests/Style_HashSyntax.rb b/docs/tests/Style_HashSyntax.rb similarity index 100% rename from src/main/resources/docs/tests/Style_HashSyntax.rb rename to docs/tests/Style_HashSyntax.rb diff --git a/src/main/resources/docs/tests/Style_IfUnlessModifier.rb b/docs/tests/Style_IfUnlessModifier.rb similarity index 100% rename from src/main/resources/docs/tests/Style_IfUnlessModifier.rb rename to docs/tests/Style_IfUnlessModifier.rb diff --git a/src/main/resources/docs/tests/Style_IfWithSemicolon.rb b/docs/tests/Style_IfWithSemicolon.rb similarity index 100% rename from src/main/resources/docs/tests/Style_IfWithSemicolon.rb rename to docs/tests/Style_IfWithSemicolon.rb diff --git a/src/main/resources/docs/tests/Style_InfiniteLoop.rb b/docs/tests/Style_InfiniteLoop.rb similarity index 100% rename from src/main/resources/docs/tests/Style_InfiniteLoop.rb rename to docs/tests/Style_InfiniteLoop.rb diff --git a/src/main/resources/docs/tests/Style_Lambda.rb b/docs/tests/Style_Lambda.rb similarity index 100% rename from src/main/resources/docs/tests/Style_Lambda.rb rename to docs/tests/Style_Lambda.rb diff --git a/src/main/resources/docs/tests/Style_LambdaCall.rb b/docs/tests/Style_LambdaCall.rb similarity index 100% rename from src/main/resources/docs/tests/Style_LambdaCall.rb rename to docs/tests/Style_LambdaCall.rb diff --git a/src/main/resources/docs/tests/Style_LineEndConcatenation.rb b/docs/tests/Style_LineEndConcatenation.rb similarity index 100% rename from src/main/resources/docs/tests/Style_LineEndConcatenation.rb rename to docs/tests/Style_LineEndConcatenation.rb diff --git a/src/main/resources/docs/tests/Style_MethodCallWithArgsParentheses.rb b/docs/tests/Style_MethodCallWithArgsParentheses.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MethodCallWithArgsParentheses.rb rename to docs/tests/Style_MethodCallWithArgsParentheses.rb diff --git a/src/main/resources/docs/tests/Style_MethodCallWithoutArgsParentheses.rb b/docs/tests/Style_MethodCallWithoutArgsParentheses.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MethodCallWithoutArgsParentheses.rb rename to docs/tests/Style_MethodCallWithoutArgsParentheses.rb diff --git a/src/main/resources/docs/tests/Style_MethodCalledOnDoEndBlock.rb b/docs/tests/Style_MethodCalledOnDoEndBlock.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MethodCalledOnDoEndBlock.rb rename to docs/tests/Style_MethodCalledOnDoEndBlock.rb diff --git a/src/main/resources/docs/tests/Style_MethodDefParentheses.rb b/docs/tests/Style_MethodDefParentheses.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MethodDefParentheses.rb rename to docs/tests/Style_MethodDefParentheses.rb diff --git a/src/main/resources/docs/tests/Style_MethodName.rb b/docs/tests/Style_MethodName.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MethodName.rb rename to docs/tests/Style_MethodName.rb diff --git a/src/main/resources/docs/tests/Style_ModuleFunction.rb b/docs/tests/Style_ModuleFunction.rb similarity index 100% rename from src/main/resources/docs/tests/Style_ModuleFunction.rb rename to docs/tests/Style_ModuleFunction.rb diff --git a/src/main/resources/docs/tests/Style_MultilineBlockChain.rb b/docs/tests/Style_MultilineBlockChain.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MultilineBlockChain.rb rename to docs/tests/Style_MultilineBlockChain.rb diff --git a/src/main/resources/docs/tests/Style_MultilineIfThen.rb b/docs/tests/Style_MultilineIfThen.rb similarity index 100% rename from src/main/resources/docs/tests/Style_MultilineIfThen.rb rename to docs/tests/Style_MultilineIfThen.rb diff --git a/src/main/resources/docs/tests/Style_NegatedIf.rb b/docs/tests/Style_NegatedIf.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NegatedIf.rb rename to docs/tests/Style_NegatedIf.rb diff --git a/src/main/resources/docs/tests/Style_NegatedWhile.rb b/docs/tests/Style_NegatedWhile.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NegatedWhile.rb rename to docs/tests/Style_NegatedWhile.rb diff --git a/src/main/resources/docs/tests/Style_NestedTernaryOperator.rb b/docs/tests/Style_NestedTernaryOperator.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NestedTernaryOperator.rb rename to docs/tests/Style_NestedTernaryOperator.rb diff --git a/src/main/resources/docs/tests/Style_NilComparison.rb b/docs/tests/Style_NilComparison.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NilComparison.rb rename to docs/tests/Style_NilComparison.rb diff --git a/src/main/resources/docs/tests/Style_NonNilCheck.rb b/docs/tests/Style_NonNilCheck.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NonNilCheck.rb rename to docs/tests/Style_NonNilCheck.rb diff --git a/src/main/resources/docs/tests/Style_Not.rb b/docs/tests/Style_Not.rb similarity index 100% rename from src/main/resources/docs/tests/Style_Not.rb rename to docs/tests/Style_Not.rb diff --git a/src/main/resources/docs/tests/Style_NumericLiterals.rb b/docs/tests/Style_NumericLiterals.rb similarity index 100% rename from src/main/resources/docs/tests/Style_NumericLiterals.rb rename to docs/tests/Style_NumericLiterals.rb diff --git a/src/main/resources/docs/tests/Style_OneLineConditional.rb b/docs/tests/Style_OneLineConditional.rb similarity index 100% rename from src/main/resources/docs/tests/Style_OneLineConditional.rb rename to docs/tests/Style_OneLineConditional.rb diff --git a/src/main/resources/docs/tests/Style_PreferredHashMethods.rb b/docs/tests/Style_PreferredHashMethods.rb similarity index 100% rename from src/main/resources/docs/tests/Style_PreferredHashMethods.rb rename to docs/tests/Style_PreferredHashMethods.rb diff --git a/src/main/resources/docs/tests/Style_Sample.rb b/docs/tests/Style_Sample.rb similarity index 100% rename from src/main/resources/docs/tests/Style_Sample.rb rename to docs/tests/Style_Sample.rb diff --git a/src/main/resources/docs/tests/VariableName.rb b/docs/tests/VariableName.rb similarity index 100% rename from src/main/resources/docs/tests/VariableName.rb rename to docs/tests/VariableName.rb diff --git a/src/main/resources/docs/tool-description.md b/docs/tool-description.md similarity index 100% rename from src/main/resources/docs/tool-description.md rename to docs/tool-description.md diff --git a/scripts/doc_generate.sh b/scripts/doc_generate.sh index 5ed8e003..af797293 100755 --- a/scripts/doc_generate.sh +++ b/scripts/doc_generate.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + DOCS_PATH=$1 rm -rf $DOCS_PATH/docs/description/* mkdir -p "$DOCS_PATH/docs/description" diff --git a/src/main/resources/docs/description/Bundler_GemComment.md b/src/main/resources/docs/description/Bundler_GemComment.md deleted file mode 100644 index 367fd469..00000000 --- a/src/main/resources/docs/description/Bundler_GemComment.md +++ /dev/null @@ -1,17 +0,0 @@ - -Add a comment describing each gem in your Gemfile. - -# Examples - -```ruby -# bad - -gem 'foo' - -# good - -# Helpers for the foo things. -gem 'foo' -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Bundler/GemComment) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_EmptyLineBetweenDefs.md b/src/main/resources/docs/description/Layout_EmptyLineBetweenDefs.md deleted file mode 100644 index 3368b740..00000000 --- a/src/main/resources/docs/description/Layout_EmptyLineBetweenDefs.md +++ /dev/null @@ -1,29 +0,0 @@ - -This cop checks whether method definitions are -separated by one empty line. - -`NumberOfEmptyLines` can be an integer (default is 1) or -an array (e.g. [1, 2]) to specify a minimum and maximum -number of empty lines permitted. - -`AllowAdjacentOneLineDefs` configures whether adjacent -one-line method definitions are considered an offense. - -# Examples - -```ruby - -# bad -def a -end -def b -end -# good -def a -end - -def b -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EmptyLineBetweenDefs) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_HeredocIndentation.md b/src/main/resources/docs/description/Layout_HeredocIndentation.md deleted file mode 100644 index dca21876..00000000 --- a/src/main/resources/docs/description/Layout_HeredocIndentation.md +++ /dev/null @@ -1,42 +0,0 @@ - -This cop checks the indentation of the here document bodies. The bodies -are indented one step. -In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you -use the older rubies, you should introduce some library to your project -(e.g. ActiveSupport, Powerpack or Unindent). -Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default), - this cop does not add any offenses for long here documents to - avoid `Layout/LineLength`'s offenses. - -# Examples - -```ruby -# bad -<<-RUBY -something -RUBY - -# good -# When EnforcedStyle is squiggly, bad code is auto-corrected to the -# following code. -<<~RUBY - something -RUBY# good -# When EnforcedStyle is active_support, bad code is auto-corrected to -# the following code. -<<-RUBY.strip_heredoc - something -RUBY# good -# When EnforcedStyle is powerpack, bad code is auto-corrected to -# the following code. -<<-RUBY.strip_indent - something -RUBY# good -# When EnforcedStyle is unindent, bad code is auto-corrected to -# the following code. -<<-RUBY.unindent - something -RUBY -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/HeredocIndentation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Layout_MultilineOperationIndentation.md b/src/main/resources/docs/description/Layout_MultilineOperationIndentation.md deleted file mode 100644 index edcd72cf..00000000 --- a/src/main/resources/docs/description/Layout_MultilineOperationIndentation.md +++ /dev/null @@ -1,31 +0,0 @@ - -This cop checks the indentation of the right hand side operand in -binary operations that span more than one line. - -# Examples - -```ruby -# bad -if a + - b - something -end - -# good -if a + - b - something -end# bad -if a + - b - something -end - -# good -if a + - b - something -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/MultilineOperationIndentation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ElseLayout.md b/src/main/resources/docs/description/Lint_ElseLayout.md deleted file mode 100644 index 8eb6ffd4..00000000 --- a/src/main/resources/docs/description/Lint_ElseLayout.md +++ /dev/null @@ -1,27 +0,0 @@ - -This cop checks for odd else block layout - like -having an expression on the same line as the else keyword, -which is usually a mistake. - -# Examples - -```ruby - -# bad - -if something - # ... -else do_this - do_that -end -# good - -if something - # ... -else - do_this - do_that -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ElseLayout) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_EmptyWhen.md b/src/main/resources/docs/description/Lint_EmptyWhen.md deleted file mode 100644 index 0158e8b1..00000000 --- a/src/main/resources/docs/description/Lint_EmptyWhen.md +++ /dev/null @@ -1,22 +0,0 @@ - -This cop checks for the presence of `when` branches without a body. - -# Examples - -```ruby - -# bad - -case foo -when bar then 1 -when baz then # nothing -end -# good - -case foo -when bar then 1 -when baz then 2 -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EmptyWhen) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_EnsureReturn.md b/src/main/resources/docs/description/Lint_EnsureReturn.md deleted file mode 100644 index faf9c472..00000000 --- a/src/main/resources/docs/description/Lint_EnsureReturn.md +++ /dev/null @@ -1,28 +0,0 @@ - -This cop checks for *return* from an *ensure* block. -Explicit return from an ensure block alters the control flow -as the return will take precedence over any exception being raised, -and the exception will be silently thrown away as if it were rescued. - -# Examples - -```ruby - -# bad - -begin - do_something -ensure - do_something_else - return -end -# good - -begin - do_something -ensure - do_something_else -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/EnsureReturn) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_FlipFlop.md b/src/main/resources/docs/description/Lint_FlipFlop.md deleted file mode 100644 index 9bc1441c..00000000 --- a/src/main/resources/docs/description/Lint_FlipFlop.md +++ /dev/null @@ -1,19 +0,0 @@ - -This cop looks for uses of flip-flop operator. -flip-flop operator is deprecated since Ruby 2.6.0. - -# Examples - -```ruby -# bad -(1..20).each do |x| - puts x if (x == 5) .. (x == 10) -end - -# good -(1..20).each do |x| - puts x if (x >= 5) && (x <= 10) -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/FlipFlop) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_NumberConversion.md b/src/main/resources/docs/description/Lint_NumberConversion.md deleted file mode 100644 index f7125752..00000000 --- a/src/main/resources/docs/description/Lint_NumberConversion.md +++ /dev/null @@ -1,23 +0,0 @@ - -This cop warns the usage of unsafe number conversions. Unsafe -number conversion can cause unexpected error if auto type conversion -fails. Cop prefer parsing with number class instead. - -# Examples - -```ruby - -# bad - -'10'.to_i -'10.2'.to_f -'10'.to_c - -# good - -Integer('10', 10) -Float('10.2') -Complex('10') -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/NumberConversion) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_ShadowingOuterLocalVariable.md b/src/main/resources/docs/description/Lint_ShadowingOuterLocalVariable.md deleted file mode 100644 index 5ebc66aa..00000000 --- a/src/main/resources/docs/description/Lint_ShadowingOuterLocalVariable.md +++ /dev/null @@ -1,31 +0,0 @@ - -This cop looks for use of the same name as outer local variables -for block arguments or block local variables. -This is a mimic of the warning -"shadowing outer local variable - foo" from `ruby -cw`. - -# Examples - -```ruby - -# bad - -def some_method - foo = 1 - - 2.times do |foo| # shadowing outer `foo` - do_something(foo) - end -end -# good - -def some_method - foo = 1 - - 2.times do |bar| - do_something(bar) - end -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ShadowingOuterLocalVariable) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_Syntax.md b/src/main/resources/docs/description/Lint_Syntax.md deleted file mode 100644 index 0be0869e..00000000 --- a/src/main/resources/docs/description/Lint_Syntax.md +++ /dev/null @@ -1,9 +0,0 @@ - -This is not actually a cop. It does not inspect anything. It just -provides methods to repack Parser's diagnostics/errors -into RuboCop's offenses. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/Syntax) \ No newline at end of file diff --git a/src/main/resources/docs/description/Lint_UselessComparison.md b/src/main/resources/docs/description/Lint_UselessComparison.md deleted file mode 100644 index ebaadb7f..00000000 --- a/src/main/resources/docs/description/Lint_UselessComparison.md +++ /dev/null @@ -1,13 +0,0 @@ - -This cop checks for comparison of something with itself. - -# Examples - -```ruby - -# bad - -x.top >= x.top -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/UselessComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_AbcSize.md b/src/main/resources/docs/description/Metrics_AbcSize.md deleted file mode 100644 index 76ef60f4..00000000 --- a/src/main/resources/docs/description/Metrics_AbcSize.md +++ /dev/null @@ -1,10 +0,0 @@ - -This cop checks that the ABC size of methods is not higher than the -configured maximum. The ABC size is based on assignments, branches -(method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric -and https://en.wikipedia.org/wiki/ABC_Software_Metric. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/AbcSize) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_BlockLength.md b/src/main/resources/docs/description/Metrics_BlockLength.md deleted file mode 100644 index 8bed1cd7..00000000 --- a/src/main/resources/docs/description/Metrics_BlockLength.md +++ /dev/null @@ -1,10 +0,0 @@ - -This cop checks if the length of a block exceeds some maximum value. -Comment lines can optionally be ignored. -The maximum allowed length is configurable. -The cop can be configured to ignore blocks passed to certain methods. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/BlockLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_ClassLength.md b/src/main/resources/docs/description/Metrics_ClassLength.md deleted file mode 100644 index fb0b6635..00000000 --- a/src/main/resources/docs/description/Metrics_ClassLength.md +++ /dev/null @@ -1,9 +0,0 @@ - -This cop checks if the length a class exceeds some maximum value. -Comment lines can optionally be ignored. -The maximum allowed length is configurable. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ClassLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_MethodLength.md b/src/main/resources/docs/description/Metrics_MethodLength.md deleted file mode 100644 index 0ca6ae6e..00000000 --- a/src/main/resources/docs/description/Metrics_MethodLength.md +++ /dev/null @@ -1,9 +0,0 @@ - -This cop checks if the length of a method exceeds some maximum value. -Comment lines can optionally be ignored. -The maximum allowed length is configurable. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/MethodLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_ModuleLength.md b/src/main/resources/docs/description/Metrics_ModuleLength.md deleted file mode 100644 index 7f4c8ea0..00000000 --- a/src/main/resources/docs/description/Metrics_ModuleLength.md +++ /dev/null @@ -1,9 +0,0 @@ - -This cop checks if the length a module exceeds some maximum value. -Comment lines can optionally be ignored. -The maximum allowed length is configurable. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ModuleLength) \ No newline at end of file diff --git a/src/main/resources/docs/description/Metrics_ParameterLists.md b/src/main/resources/docs/description/Metrics_ParameterLists.md deleted file mode 100644 index 5473a062..00000000 --- a/src/main/resources/docs/description/Metrics_ParameterLists.md +++ /dev/null @@ -1,9 +0,0 @@ - -This cop checks for methods with too many parameters. -The maximum number of parameters is configurable. -Keyword arguments can optionally be excluded from the total count. - -# Examples - - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/ParameterLists) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_AccessorMethodName.md b/src/main/resources/docs/description/Naming_AccessorMethodName.md deleted file mode 100644 index 1ee3e010..00000000 --- a/src/main/resources/docs/description/Naming_AccessorMethodName.md +++ /dev/null @@ -1,24 +0,0 @@ - -This cop makes sure that accessor methods are named properly. - -# Examples - -```ruby -# bad -def set_attribute(value) -end - -# good -def attribute=(value) -end - -# bad -def get_attribute -end - -# good -def attribute -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/AccessorMethodName) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_ClassAndModuleCamelCase.md b/src/main/resources/docs/description/Naming_ClassAndModuleCamelCase.md deleted file mode 100644 index 447a0776..00000000 --- a/src/main/resources/docs/description/Naming_ClassAndModuleCamelCase.md +++ /dev/null @@ -1,21 +0,0 @@ - -This cop checks for class and module names with -an underscore in them. - -# Examples - -```ruby -# bad -class My_Class -end -module My_Module -end - -# good -class MyClass -end -module MyModule -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/ClassAndModuleCamelCase) \ No newline at end of file diff --git a/src/main/resources/docs/description/Naming_VariableNumber.md b/src/main/resources/docs/description/Naming_VariableNumber.md deleted file mode 100644 index 02589a21..00000000 --- a/src/main/resources/docs/description/Naming_VariableNumber.md +++ /dev/null @@ -1,34 +0,0 @@ - -This cop makes sure that all numbered variables use the -configured style, snake_case, normalcase, or non_integer, -for their numbering. - -# Examples - -```ruby -# bad - -variable1 = 1 - -# good - -variable_1 = 1# bad - -variable_1 = 1 - -# good - -variable1 = 1# bad - -variable1 = 1 - -variable_1 = 1 - -# good - -variableone = 1 - -variable_one = 1 -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/VariableNumber) \ No newline at end of file diff --git a/src/main/resources/docs/description/Rails_Pick.md b/src/main/resources/docs/description/Rails_Pick.md deleted file mode 100644 index 992d98d2..00000000 --- a/src/main/resources/docs/description/Rails_Pick.md +++ /dev/null @@ -1,16 +0,0 @@ - -This cop enforces the use `pick` over `pluck(...).first`. - -# Examples - -```ruby -# bad -Model.pluck(:a).first -Model.pluck(:a, :b).first - -# good -Model.pick(:a) -Model.pick(:a, :b) -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/Pick) \ No newline at end of file diff --git a/src/main/resources/docs/description/Security_Open.md b/src/main/resources/docs/description/Security_Open.md deleted file mode 100644 index 79e76e31..00000000 --- a/src/main/resources/docs/description/Security_Open.md +++ /dev/null @@ -1,22 +0,0 @@ - -This cop checks for the use of `Kernel#open`. - -`Kernel#open` enables not only file access but also process invocation -by prefixing a pipe symbol (e.g., `open("| ls")`). So, it may lead to -a serious security risk by using variable input to the argument of -`Kernel#open`. It would be better to use `File.open`, `IO.popen` or -`URI#open` explicitly. - -# Examples - -```ruby -# bad -open(something) - -# good -File.open(something) -IO.popen(something) -URI.parse(something).open -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Security/Open) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_DoubleNegation.md b/src/main/resources/docs/description/Style_DoubleNegation.md deleted file mode 100644 index 165dc5d6..00000000 --- a/src/main/resources/docs/description/Style_DoubleNegation.md +++ /dev/null @@ -1,22 +0,0 @@ - -This cop checks for uses of double negation (!!) to convert something -to a boolean value. As this is both cryptic and usually redundant, it -should be avoided. - -Please, note that when something is a boolean value -!!something and !something.nil? are not the same thing. -As you're unlikely to write code that can accept values of any type -this is rarely a problem in practice. - -# Examples - -```ruby - -# bad -!!something - -# good -!something.nil? -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/DoubleNegation) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_InfiniteLoop.md b/src/main/resources/docs/description/Style_InfiniteLoop.md deleted file mode 100644 index e959486e..00000000 --- a/src/main/resources/docs/description/Style_InfiniteLoop.md +++ /dev/null @@ -1,18 +0,0 @@ - -Use `Kernel#loop` for infinite loops. - -# Examples - -```ruby -# bad -while true - work -end - -# good -loop do - work -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/InfiniteLoop) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MethodMissingSuper.md b/src/main/resources/docs/description/Style_MethodMissingSuper.md deleted file mode 100644 index 14d31ed8..00000000 --- a/src/main/resources/docs/description/Style_MethodMissingSuper.md +++ /dev/null @@ -1,21 +0,0 @@ - -This cop checks for the presence of `method_missing` without -falling back on `super`. - -# Examples - -```ruby -#bad -def method_missing(name, *args) - # ... -end - -#good - -def method_missing(name, *args) - # ... - super -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MethodMissingSuper) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_MultipleComparison.md b/src/main/resources/docs/description/Style_MultipleComparison.md deleted file mode 100644 index d4fd9ae5..00000000 --- a/src/main/resources/docs/description/Style_MultipleComparison.md +++ /dev/null @@ -1,17 +0,0 @@ - -This cop checks against comparing a variable with multiple items, where -`Array#include?` could be used instead to avoid code repetition. - -# Examples - -```ruby -# bad -a = 'a' -foo if a == 'a' || a == 'b' || a == 'c' - -# good -a = 'a' -foo if ['a', 'b', 'c'].include?(a) -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MultipleComparison) \ No newline at end of file diff --git a/src/main/resources/docs/description/Style_OneLineConditional.md b/src/main/resources/docs/description/Style_OneLineConditional.md deleted file mode 100644 index 7d51c0bc..00000000 --- a/src/main/resources/docs/description/Style_OneLineConditional.md +++ /dev/null @@ -1,25 +0,0 @@ - -TODO: Make configurable. -Checks for uses of if/then/else/end on a single line. - -# Examples - -```ruby -# bad -if foo then boo else doo end -unless foo then boo else goo end - -# good -foo ? boo : doo -boo if foo -if foo then boo end - -# good -if foo - boo -else - doo -end -``` - -[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/OneLineConditional) \ No newline at end of file diff --git a/src/main/resources/docs/multiple-tests/line-length/src/Layout_LineLength.rb b/src/main/resources/docs/multiple-tests/line-length/src/Layout_LineLength.rb deleted file mode 120000 index 1d715af1..00000000 --- a/src/main/resources/docs/multiple-tests/line-length/src/Layout_LineLength.rb +++ /dev/null @@ -1 +0,0 @@ -../../../tests/Layout_LineLength.rb \ No newline at end of file diff --git a/src/main/resources/docs/tests/Lint_UselessComparison.rb b/src/main/resources/docs/tests/Lint_UselessComparison.rb deleted file mode 100644 index dce5c06f..00000000 --- a/src/main/resources/docs/tests/Lint_UselessComparison.rb +++ /dev/null @@ -1,4 +0,0 @@ -##Patterns: Lint_UselessComparison - -##Warn: Lint_UselessComparison -x.top >= x.top diff --git a/src/main/resources/docs/tests/Style_MultilineTernaryOperator.rb b/src/main/resources/docs/tests/Style_MultilineTernaryOperator.rb deleted file mode 100644 index 3f59c819..00000000 --- a/src/main/resources/docs/tests/Style_MultilineTernaryOperator.rb +++ /dev/null @@ -1,5 +0,0 @@ -##Patterns: Style_MultilineTernaryOperator - -##Info: Style_MultilineTernaryOperator -if_this_is_a_true_value ? - then_the_result_is_this : else_it_is_this