New features
- #15492: Add AllCops/ProjectIndexIncludesGems for bundle-wide indexing. (@bbatsov)
- #15498: Add
DelegatingMethodsoption toLint/DuplicateMethodsto register customdelegate-shaped methods. (@bbatsov) - #15042: Add
DisallowedCopsconfiguration option toStyle/DisableCopsWithinSourceCodeDirective. (@hammadxcm) - #15441: Add new
AllowYARDCommentBlockSeparatoroption toLayout/LeadingCommentSpace. (@koic) - #15466: Add new
Lint/DeprecatedReferencecop to detect references to methods and constants documented as@deprecated, powered by the project index. (@bbatsov) - #15491: Add new
Lint/NameTypocop. (@bbatsov) - #15468: Add new
Lint/UnusedPrivateMethodcop for project-wide dead-code detection via the project index (disabled by default). (@bbatsov) - #14598: Make
Style/DisableCopsWithinSourceCodeDirectiveimpossible to disable via directive comments when explicitly enabled withEnabled: true. (@rafaelfranca) - #15511: Support
textDocument/codeActionrequests in the built-in language server, so LSP clients that request code actions (Eglot, Helix, Flycheck, ...) can apply RuboCop's autocorrects, not only clients that read them off the published diagnostic. (@bbatsov) - #8565: Support
NewCopsin department configuration to enable pending cops per department, including cops added up to a specific version (e.g.Style: NewCops: '1.19'). (@koic) - #9373: Support autocorrection for tab indentation in
Layout/IndentationWidthandStyle/ClassAndModuleChildren. (@ioquatix, @koic)
Bug fixes
- #15257: Fix a false negative for
Lint/ToEnumArgumentswhen explicit extra keyword arguments are passed (e.g.def m(x:); to_enum(:m, x: x, y: 1); end), which raisesArgumentErrorwhen the enumerator is used. (@RedZapdos123) - #15452: Fix a false positive for
Layout/HashAlignmentwhen usingEnforcedHashRocketStyle: tableand a hash key spans multiple lines. (@dduugg) - #12269: Fix a false positive for
Lint/UselessAssignmentwith modifier conditions. (@bbatsov) - #13786: Fix a false positive for
Lint/Voidwith setter methods. (@bbatsov) - #15507: Fix a false positive for
Naming/VariableNumberwhen using an empty symbol hash key. (@koic) - #15284: Fix a false positive for
Style/MutableConstantwithData.define. (@bbatsov) - #15483: Fix a false positive for
Style/MissingRespondToMissingwhenrespond_to_missing?is defined in a reopening of the class andUseProjectIndexis enabled. (@bbatsov) - #15500: Fix an error for
Lint/LiteralAsConditionwhen a literal condition has an empty branch. (@koic) - #15499: Fix an error for
Lint/UselessRuby2Keywordswhenruby2_keywordsis used with a symbol but no method definition is found. (@koic) - #15453: Fix an error for
Metrics/MethodLengthwhen a method contains a heredoc and__ENCODING__. (@koic) - #15442: Fix an error for
Style/ArrayIntersectcop when the block-based check callsmember?/include?without an explicit receiver. (@dduugg) - #15434: Fix an error for
Style/NegativeArrayIndexcop. (@viralpraxis) - #15469: Fix an error for
Style/RedundantFormatwhen a format string uses a positional argument number beyond the 64-bit range. (@koic) - #15454: Fix an error for
Style/RedundantFormatwhen the argument for a positional variable width is missing. (@koic) - #15298: Fix an incorrect autocorrect for
Lint/LiteralInInterpolation. (@bbatsov) - #15515: Fix an incorrect autocorrect for
Style/ArrayIntersectwhen using safe navigationnone?with a block. (@koic) - #15364: Fix an incorrect autocorrect for
Style/MultipleComparisonthat dropped an allowed method comparison appearing between the compared values. (@bbatsov) - #15367: Fix an incorrect autocorrect for
Style/RedundantFileExtensionInRequirethat produced invalid Ruby when a backslash preceded the.rbextension. (@bbatsov) - #12017: Fix
Lint/Voidto no longer autocorrect a constant used in a void context, since removing it can change behavior through constant autoloading side effects. (@bbatsov) - #14797: Avoid cache writes during server checks. (@sjh9714)
- #15484: Fix false negatives for
Lint/InheritExceptionwhenExceptionis inherited indirectly through a project class (UseProjectIndex). (@bbatsov) - #15357: Fix a false negative for
Lint/AmbiguousAssignmentwhen using attribute or index assignment. (@sngsmz) - #9571: Fix false negatives in
Layout/ClassStructurewhen class body elements are wrapped inbeginblocks. (@koic) - #9570: Fix false negatives in
Layout/ClassStructurewhen usingprivate_class_methodorpublic_class_methoddef modifiers. (@koic) - #15438: Fix false positives in
Style/ArrayIntersectwhen the receiver ofinclude?in a block is not an array literal. (@koic) - #15445: Fix false positives in
Style/MultilineIfThenwhen using the Prism parser engine and anelsifwithoutthenfollows a branch usingthenwith a body on the same line. (@koic) - #15058: Fix false positives in
Lint/DuplicateMethodsfor anonymous classes (Class.new) passed as arguments to the same named-receiver method call (e.g.T.cast). EachClass.newblock is an independent class, so methods defined in different blocks should not be treated as duplicates. (@rafaelfranca) - #15486: Fix false negatives for
Style/RedundantConstantBaseinside namespaces when the constant provably resolves identically without::(UseProjectIndex). (@bbatsov) - #15505: Fix incompatible autocorrect between
Style/LambdaandStyle/SymbolProcproducing a syntax error like->(x)(&:method)when both cops run onlambda { |x| x.method }. (@koic) - #15481: Fix cross-file offenses depending on which files are inspected: the project index now always covers the whole project (
UseProjectIndex). (@bbatsov) - #13794: Fix
Layout/LineLengthautocorrection for endless methods with block bodies. (@hervetatche) - #15462: Fix an error for
Lint/ConstantReassignmentwhen a built-in constant name is assigned andUseProjectIndexis enabled. (@bbatsov) - #15321: Fix
Style/ClassAndModuleChildrenignoringEnforcedStyleForClassesandEnforcedStyleForModules, and skip autocorrection when mixed per-type styles make the result ambiguous. (@bbatsov) - #15122: Fix false positive in
Layout/MultilineMethodCallIndentationwhen a line has multiple chained calls before a single-line block. (@hammadxcm) - #15471: Fix false negatives for
Style/RedundantLineContinuationby verifying backslash removal against a reparse of the source instead of hand-written grammar rules. (@bbatsov) - #15522: Fix Ruby version detection from mise.toml with single quotes. (@joklek-vinted)
- #15488: Fix false positives for
Naming/PredicatePrefixandNaming/AccessorMethodNamewhen the method overrides an ancestor method defined in the project (UseProjectIndex). (@bbatsov) - #15485: Fix a false positive for
Style/StaticClasswhen the class is subclassed elsewhere in the project (UseProjectIndex). (@bbatsov) - #15477: Fix false positives for
Style/MethodCallWithArgsParenthesesomit_parenthesesstyle by verifying each omission by reparsing before registering an offense. (@bbatsov)
Changes
- #15482: Change
Style/Documentationto accept a reopened class or module documented at another definition site whenUseProjectIndexis enabled. (@bbatsov) - #15355: Add
rubocop-i18nto suggested extensions. (@tejasbubane) - #15521: Advertise
executeCommandProviderand the supported code action kinds in the language server's capabilities, so clients can discover therubocop.formatAutocorrectsandrubocop.formatAutocorrectsAllcommands. (@bbatsov) - #15521: Improve language server performance by caching the project index across requests instead of rebuilding it on every keystroke when
AllCops/UseProjectIndexis enabled. (@bbatsov) - #14835: Extend
Lint/AmbiguousBlockAssociationto detectdo...endblocks likely intended for enumerable methods in arguments. (@hammadxcm) - #15458: Improve
Layout/LineLengthperformance on files with large collection literals. (@koic) - #15497: Make
Style/ConditionalAssignmentskip cases it cannot safely rewrite instead of emitting invalid code or erroring on unusual branch shapes. (@bbatsov) - #15261: Mention the required parentheses in the
Style/IfUnlessModifieroffense message when the condition is part of a larger expression. (@rafa-el-souza) - #15513: Improve
Style/DisableCopsWithinSourceCodeDirectiveperformance on largeAllowedCopsandDisallowedCopslists by matching directives against memoized sets instead of rebuilding an array lookup per comment. (@corsonknowles) - #15501: Improve performance for large literal files. (@koic)
- #15519: Improve
Style/RedundantLineContinuationperformance on files with many adjacent string literals joined by line continuations. (@koic) - #15462: Change
Lint/DuplicateMethodsto detect duplicates across files whenUseProjectIndexis enabled. (@bbatsov) - #14983: Load cops lazily to speed up loading RuboCop; only the cops needed for a run are loaded. (@lovro-bikic, @koic)
- #15493: Make
Style/IfUnlessModifier,Style/WhileUntilModifier,Style/GuardClause, and other modifier cops respectLayout/LineLengthexemptions (allowed patterns, cop directives, allowed URIs) when checking whether the modifier form fits on one line. (@bbatsov) - #15433: Mark
Lint/SafeNavigationChainautocorrection as unsafe. (@koic) - #15487: Change
Lint/ConstantResolutionto report only genuinely ambiguous constants whenUseProjectIndexis enabled. (@bbatsov) - #14809: Do not autocorrect
Style/RedundantAssignmentoffenses when there are comments between assignment and reference. (@lovro-bikic) - #15463: Change
Style/ClassAndModuleChildrenautocorrection to consult the project index for the namespace kind and definition sites whenUseProjectIndexis enabled. (@bbatsov) - #15464: Change
Lint/MissingSuperto skip the constructor offense when the project index shows no ancestor definesinitialize(UseProjectIndex). (@bbatsov) - #15490: Change
Style/Copyrightto validateAutocorrectNoticeonly when autocorrection is requested (-a/-A), so plain inspection no longer raises a warning. (@koic) - #15476: Change
Layout/RedundantLineBreakto verify each correction by reparsing before registering an offense. (@bbatsov) - #15472: Change
Style/RedundantParenthesesto verify each correction by reparsing before registering an offense. (@bbatsov) - #15478: Change
Style/SoleNestedConditionalto only register an offense when its correction is verified to parse. (@bbatsov)