relnotes/v0.36.0.md
An epic release - the one which contains the most new features and bugfixes since the inception of the project! A huge thanks to the amazing contributors who helped make it a reality!
Notably, this release adds support for Ruby 2.3 and introduces the
important concept of a target Ruby version - meaning RuboCop will no
longer try to parse the code with a parser matching the interpreter
you're using, but a parser matching the target Ruby version you
specified in .rubocop.yml. This way you won't introduce accidentally
syntax from a newer Ruby when you want to maintain
compatibility with certain older Rubies.
Enjoy!
Lint/RandOne checks for rand(1), Kernel.rand(1.0) and similar calls. Such call are most likely a mistake because they always return 0. (@DNNX)Performance/DoubleStartEndWith checks for two start_with? (or end_with?) calls joined by || with the same receiver, like str.start_with?('x') || str.start_with?('y') and suggests using one call instead: str.start_with?('x', 'y'). (@DNNX)Performance/TimesMap checks for x.times.map{} and suggests replacing them with Array.new(x){}. (@DNNX)Lint/NextWithoutAccumulator finds bare next in reduce/inject blocks which assigns nil to the accumulator. (@mvidner)AllowHeredoc to Metrics/LineLength. (@fphilipe)Style/ConditionalAssignment checks for assignment of the same variable in all branches of conditionals and replaces them with a single assignment to the return of the conditional. (@rrosenblum)Style/IndentAssignment checks the indentation of the first line of the right-hand-side of a multi-line assignment. (@panthomakos)IgnoreExecutableScripts option to Style/FileName. (@sometimesfood)Style/UnneededInterpolation checks for strings that are just an interpolated expression. (@cgriego)Style/MultilineAssignmentLayout cop checks for a newline after the assignment operator in a multi-line assignment. (@panthomakos)Lint/UselessAccessModifier can catch more types of useless access modifiers. (@alexdowad)Performance/Casecmp cop. (@alexdowad)Performance/RangeInclude cop. (@alexdowad)Performance/RedundantSortBy cop. (@alexdowad)Performance/LstripRstrip cop. (@alexdowad)Performance/StartWith cop. (@alexdowad)Performance/EndWith cop. (@alexdowad)Performance/RedundantMerge cop. (@alexdowad)Lint/Debugger cop can now auto-correct offenses. (@alexdowad)Performance/RedundantMatch cop. (@alexdowad)Performance/RedundantBlockCall cop. (@alexdowad)Lint/UnneededDisable can now autocorrect. (@alexdowad)Lint/ImplicitStringConcatenation cop. (@alexdowad)Style/RedundantParentheses cop. (@lumeet)Style/SpecialGlobalVars can be configured to use either use_english_names or use_perl_names styles. (@alexdowad)Style/NestedParenthesizedCalls cop checks for non-parenthesized method calls nested inside a parenthesized call, like method1(method2 arg). (@alexdowad)--stdin and --auto-correct CLI options can be combined, and if you do so, corrected code is printed to stdout. (@alexdowad)Style/ConditionalAssignment works on conditionals with a common aref assignment (like array[index] = val) or attribute assignment (like self.attribute = val). (@alexdowad)Style/GuardClause catches if..else nodes with one branch which terminates the execution of the current scope. (@alexdowad)Style/IdenticalConditionalBranches flags if..else and case..when..else constructs with an identical line at the end of each branch. (@alexdowad)Lint/FloatOutOfRange cop which catches floating-point literals which are too large or too small for Ruby to represent. (@alexdowad)Style/GuardClause doesn't report offenses in places where correction would make a line too long. (@alexdowad)Lint/DuplicateMethods can find duplicate method definitions in many more circumstances, even across multiple files; however, it ignores definitions inside if or something which could be a DSL method. (@alexdowad)EnforcedStyle is configured. (@alexdowad)Lint/IneffectiveAccessModifier checks for access modifiers which are erroneously applied to a singleton method, where they have no effect. (@alexdowad)Lint/BlockAlignment aligns block end with splat operator when applied to a splatted method call. (@alexdowad)task.options = %w(--format ...) is used when configuring RuboCop::RakeTask; this should be task.formatters = ... instead. (@alexdowad)--no-offense-counts CLI option suppresses the inclusion of offense count lines in auto-generated config. (@alexdowad)AllowForAlignment config parameter for Style/SingleSpaceBeforeFirstArg allows the insertion of extra spaces before the first argument if it aligns it with something on the preceding or following line. (@alexdowad)Style/ExtraSpacing has new ForceEqualSignAlignment config parameter which forces = signs on consecutive lines to be aligned, and it can auto-correct. (@alexdowad)Lint/BlockAlignment aligns block end with unary operators like ~, -, or ! when such operators are applied to the method call taking the block. (@alexdowad)Style/Alias supports both prefer_alias and prefer_alias_method styles. (@alexdowad)ExpectMatchingDefinition config parameter for Style/FileName makes it check for a class or module definition in each file which corresponds to the file name and path. (@alexdowad)Style/ConditionalAssignment to check and correct conditionals that contain multiple assignments. (@rrosenblum)Style/ConditionalAssignment to correct assignment in ternary operations. (@rrosenblum)Style/ConditionalAssignment to correct comparable methods. (@rrosenblum)Style/MultilineMethodCallIndentation takes over the responsibility for checking alignment of methods from the Style/MultilineOperationIndentation cop. (@jonas054)Style/MultilineArrayBraceLayout checks that the closing brace in an array literal is symmetrical with respect to the opening brace and the array elements. (@panthomakos)Style/WordArray has both percent and brackets (which enforces the use of bracketed arrays for strings) styles. (@alexdowad)Style/SpaceAroundOperators has AllowForAlignment config parameter which allows extra spaces on the left if they serve to align the operator with another. (@alexdowad)Style/SymbolArray has both percent and brackets (which enforces the user of bracketed arrays for symbols) styles. (@alexdowad)Style: Enabled: false. (@alexdowad)start_of_line style for Lint/EndAlignment aligns a closing end keyword with the start of the line where the opening keyword appears. (@alexdowad)Regex config parameter for Style/FileName allows user to provide their own regex for validating file names. (@alexdowad)DefaultFormatter config parameter can be used to set formatter from within .rubocop.yml. (@alexdowad)WorstOffendersFormatter prints a list of files with offenses (and offense counts), showing the files with the most offenses first. (@alexdowad)IfInsideElse cop catches if..end nodes which can be converted into an elsif instead, reducing the nesting level. (@alexdowad)ConsistentQuotesInMultiline config param for Style/StringLiterals forces all literals which are concatenated using \ to use the same quote style. (@alexdowad)Style/AccessModifierIndentation, Style/CaseIndentation, Style/FirstParameterIndentation, Style/IndentArray, Style/IndentAssignment, Style/IndentHash, Style/MultilineMethodCallIndentation, and Style/MultilineOperationIndentation all have a new IndentationWidth parameter which can be used to override the indentation width from Style/IndentationWidth. (@alexdowad)Performance/HashEachMethods cop. (@ojab)Style/FrozenStringLiteralComment will check for and add the comment # frozen_string_literal: true to the top of files. This will help with upgrading to Ruby 3.0. (@rrosenblum)Style/EmptyLiteral autocorrector respects Style/StringLiterals:EnforcedStyle config. (@DNNX)%Q for dynamic strings with double quotes inside them. (@jonas054)Style/Next does not remove comments when auto-correcting. (@lumeet)Style/Next handles auto-correction of nested offenses. (@lumeet)Style/VariableInterpolation now detects non-numeric regex back references. (@cgriego)ProgressFormatter fully respects the --no-color switch. (@savef)Time.zone.current with Time.current on Rails::TimeZone cop message. (@volmer)Style/StabbyLambdaParentheses does not treat method calls named lambda as lambdas. (@domcleal)Style/MethodName doesn't choke on methods which are defined inside methods. (@alexdowad)Style/StabbyLambdaParentheses only checks lambdas in the arrow form. (@lumeet)Lint/NestedMethodDefinition doesn't register offenses for method definitions inside an eval block (either instance_eval, class_eval, or module_eval). (@alexdowad)Style/ParallelAssignment understands aref and attribute assignments, and doesn't warn if they can't be correctly rearranged into a series of single assignments. (@alexdowad)Style/AndOr doesn't raise an exception when trying to autocorrect !variable or .... (@alexdowad)Style/Tab doesn't register errors for leading tabs which occur inside a string literal (including heredoc). (@alexdowad)Style/TrailingComma incorrectly categorizes single-line hashes in methods calls. (@panthomakos)Style/AlignParameters doesn't crash if it finds nested offenses. (@alexdowad)Style/SpaceInsideHashLiteralBraces doesn't mangle a hash literal which is not surrounded by curly braces, but has another hash literal which does as its first key. (@alexdowad)Style/Attr differentiate between attr_accessor and attr_reader. (@weh)Style/ConditionalAssignment doesn't crash if it finds a case with an empty branch. (@lumeet)Lint/FormatParameterMismatch understands %{} and %<> interpolations. (@alexdowad)Lint/ParenthesesAsGroupedExpression ignores calls with multiple arguments, since they are not ambiguous. (@alexdowad)Lint/UselessAccessModifier doesn't think that an access modifier applied to attr_writer is useless. (@alexdowad)Style/ConditionalAssignment doesn't think that branches using << and []= should be combined. (@alexdowad)CharacterLiteral auto-corrector now properly corrects ?'. (@bfontaine)Rails/FindEach doesn't break code which uses order(...).each, limit(...).each, and so on. (@alexdowad)Rails/FindBy doesn't autocorrect where(...).first to find_by, since the returned record is often different. (@alexdowad)EmacsFormatter strips newlines out of error messages, if there are any. (@alexdowad)Style/RescueEnsureAlignment works on rescue nested inside a class or module block. (@alexdowad)Lint/BlockAlignment does not refer to a block terminator as end when it is actually }. (@alexdowad)Lint/FormatParameterMismatch understands format specifiers with multiple flags. (@alexdowad)Style/SpaceAroundOperators doesn't eat newlines. (@alexdowad)Style/AndOr autocorrects in cases where parentheses must be added, even inside a nested begin node. (@alexdowad)Style/Next adjusts indentation when auto-correcting, to avoid introducing new offenses. (@alexdowad)Style/TrivialAccessors doesn't flag what appear to be trivial accessor method definitions, if they are nested inside a call to instance_eval. (@alexdowad)Style/SymbolArray doesn't flag arrays of symbols if a symbol contains a space character. (@alexdowad)Style/SymbolArray can auto-correct offenses. (@alexdowad)rubocop:disable comments (not the single line kind) for a given cop appear in a file with no rubocop:enable in between. (@jonas054)Style/Encoding can auto-correct files with a blank first line. (@alexdowad)Style/SpecialGlobalVariables generates auto-config correctly. (@alexdowad)Style/SpaceAroundOperators leave spacing around => to Style/AlignHash. (@jonas054)Style/MethodCallParentheses doesn't register warnings for object.() syntax, since it is handled by Style/LambdaCall. (@alexdowad)Performance/RedundantMerge doesn't break code with a modifier if when autocorrecting. (@alexdowad)Performance/RedundantMerge doesn't break code with a modifier while or until when autocorrecting. (@alexdowad)variable style for Lint/EndAlignment is working again. (@alexdowad)Lint/EndAlignment can autocorrect offenses on the RHS of an assignment to an instance variable, class variable, constant, and so on; previously, it only worked if the LHS was a local variable. (@alexdowad)Style/StringReplacement doesn't break code when autocorrection involves a regex with embedded escapes (like /\n/). (@alexdowad)Style/AlignHash doesn't move a key so far left that it goes onto the previous line (in an attempt to align). (@alexdowad)Style/SymbolProc doesn't break code when autocorrecting a method call with a trailing comma in the argument list. (@alexdowad)Style/TrailingCommaInArguments and Style/TrailingCommaInLiteral don't special-case single-item lists in a way which contradicts the documentation. (@alexdowad)Style/FileName doesn't fail on empty files when ExpectMatchingDefinition is true. (@alexdowad)Style/RedundantFreeze registers offences for frozen dynamic symbols. (@segiddins)AutocorrectUnlessChangingAST module can now autocorrect files which contain __FILE__. (@alexdowad)Style/ConditionalAssignment can autocorrect =~ within a ternary expression. (@alexdowad)some-random-script) for Ruby scripts that have a shebang. (@sometimesfood)Lint/UnneededDisable now adds "unknown cop" to messages if cop names in rubocop:disable comments are unrecognized, or "did you mean ..." if they are misspelled names of existing cops. (@jonas054)Style/Documentation considers classes and modules which only define constants to be "namespaces", and doesn't flag them for lack of a documentation comment. (@alexdowad)rake repl task can be used for experimentation when working on RuboCop. (@alexdowad)Lint/SpaceBeforeFirstArg cop has been removed, since it just duplicates Style/SingleSpaceBeforeFirstArg. (@alexdowad)Style/SingleSpaceBeforeFirstArg cop has been renamed to Style/SpaceBeforeFirstArg, which more accurately reflects what it now does. (@alexdowad)Style/UnneededPercentQ reports %q() strings with what only appears to be an escape, but is not really (there are no escapes in %q() strings). (@alexdowad)Performance/StringReplacement, Performance\StartWith, and Performance\EndWith more accurately identify code which can be improved. (@alexdowad)MultiSpaceAllowedForOperators config parameter for Style/SpaceAroundOperators has been removed, as it is made redundant by AllowForAlignment. If someone attempts to use it, config validation will fail with a helpful message. (@alexdowad)RunRailsCops config parameter in .rubocop.yml is now obsolete. If someone attempts to use it, config validation will fail with a helpful message. (@alexdowad)Exclude config parameters in .rubocop.yml will be merged into the generated .rubocop_todo.yml. (@alexdowad)Rails/DefaultScope cop. (@alexdowad)TargetRubyVersion configuration parameter can be used to specify which version of the Ruby interpreter the inspected code is intended to run on. (@alexdowad)Style/GuardClause does not warn about if nodes whose condition spans multiple lines. (@alexdowad)Style/EmptyLinesAroundClassBody, Style/EmptyLinesAroundModuleBody, and Style/EmptyLinesAroundBlockBody accept an empty body with no blank line, even if configured to empty_lines style. This is because the empty lines only serve to provide a break between the header, body, and footer, and are redundant if there is no body. (@alexdowad)Style/FirstMethodArgumentLineBreak handles implicit hash arguments without braces; Style/FirstHashElementLineBreak still handles those with braces. (@alexdowad)Style/TrailingComma has been split into Style/TrailingCommaInArguments and Style/TrailingCommaInLiteral. (@alexdowad)