RuboCop
RuboCop, the Ruby linter and formatter.
- Formats
- Ruby
- In
ur.toml [format.ruby] style = "rubocop"- Its options
- https://docs.rubocop.org/rubocop/configuration.html
Formatted
cart.rb, as written# What a cart costs.
def subtotal(items)
items.sum { |item| item.price*item.quantity }
end
def label(item) = item.name+" x"+item.quantity.to_s
ur format --style rubocop cart.rb# What a cart costs.
def subtotal(items)
items.sum { |item| item.price * item.quantity }
end
def label(item) = item.name + " x" + item.quantity.to_s
Defaults
The shared options, as RuboCop sets them when nothing configures it. Its own names for them are read from its configuration files, but ur.toml sets them by the shared name only.
| Option | Default | RuboCop calls it |
|---|---|---|
width | 120 | Layout/LineLength.Max |
indent.width | 2 | Layout/IndentationWidth.Width |
indent.style | Layout/IndentationStyle.EnforcedStyle | |
line-ending | "auto" | |
trailing-comma.add | "preserve" | |
trailing-comma.forces-break | false | |
quotes | "preserve" | |
target | AllCops.TargetRubyVersion |
Its own options
Set in a table named for it, such as [format.rubocop], or in a language's table, as rubocop = { ... }.
| Option | Default | Values |
|---|---|---|
AllCops.EnabledByDefault | false | true or false |
AllCops.DisabledByDefault | false | true or false |
AllCops.NewCops | "pending" | a string |
AllCops.ParserEngine | "default" | a string |
AllCops.ActiveSupportExtensionsEnabled | false | true or false |
AllCops.StringLiteralsFrozenByDefault | | any value |
Layout/AccessModifierIndentation.Enabled | true | any value |
Layout/AccessModifierIndentation.EnforcedStyle | "indent" | a string |
Layout/AccessModifierIndentation.IndentationWidth | | any value |
Layout/ArgumentAlignment.Enabled | true | any value |
Layout/ArgumentAlignment.EnforcedStyle | "with_first_argument" | a string |
Layout/ArgumentAlignment.IndentationWidth | | any value |
Layout/ArrayAlignment.Enabled | true | any value |
Layout/ArrayAlignment.EnforcedStyle | "with_first_element" | a string |
Layout/ArrayAlignment.IndentationWidth | | any value |
Layout/AssignmentIndentation.Enabled | true | any value |
Layout/AssignmentIndentation.IndentationWidth | | any value |
Layout/BeginEndAlignment.Enabled | true | any value |
Layout/BeginEndAlignment.EnforcedStyleAlignWith | "start_of_line" | a string |
Layout/BlockAlignment.Enabled | true | any value |
Layout/BlockAlignment.EnforcedStyleAlignWith | "either" | a string |
Layout/BlockEndNewline.Enabled | true | any value |
Layout/CaseIndentation.Enabled | true | any value |
Layout/CaseIndentation.EnforcedStyle | "case" | a string |
Layout/CaseIndentation.IndentOneStep | false | true or false |
Layout/CaseIndentation.IndentationWidth | | any value |
Layout/ClassStructure.Enabled | false | any value |
Layout/ClassStructure.Categories | {"module_inclusion":["include","prepend","extend"]} | any value |
Layout/ClassStructure.ExpectedOrder | ["module_inclusion","constants","public_class_methods","initializer","public_methods","protected_methods","private_class_methods","private_methods"] | any value |
Layout/ClosingHeredocIndentation.Enabled | true | any value |
Layout/ClosingParenthesisIndentation.Enabled | true | any value |
Layout/ClosingParenthesisIndentation.IndentationWidth | | any value |
Layout/CommentIndentation.Enabled | true | any value |
Layout/CommentIndentation.AllowForAlignment | false | true or false |
Layout/CommentIndentation.IndentationWidth | | any value |
Layout/ConditionPosition.Enabled | true | any value |
Layout/DefEndAlignment.Enabled | true | any value |
Layout/DefEndAlignment.EnforcedStyleAlignWith | "start_of_line" | a string |
Layout/DotPosition.Enabled | true | any value |
Layout/DotPosition.EnforcedStyle | "leading" | a string |
Layout/ElseAlignment.Enabled | true | any value |
Layout/EmptyComment.Enabled | true | any value |
Layout/EmptyComment.AutoCorrect | "contextual" | a string |
Layout/EmptyComment.AllowBorderComment | true | true or false |
Layout/EmptyComment.AllowMarginComment | true | true or false |
Layout/EmptyLineAfterGuardClause.Enabled | true | any value |
Layout/EmptyLineAfterMagicComment.Enabled | true | any value |
Layout/EmptyLineAfterMagicComment.NumberOfEmptyLines | 1 | a number |
Layout/EmptyLineAfterMultilineCondition.Enabled | false | any value |
Layout/EmptyLineBetweenDefs.Enabled | true | any value |
Layout/EmptyLineBetweenDefs.EmptyLineBetweenMethodDefs | true | true or false |
Layout/EmptyLineBetweenDefs.EmptyLineBetweenClassDefs | true | true or false |
Layout/EmptyLineBetweenDefs.EmptyLineBetweenModuleDefs | true | true or false |
Layout/EmptyLineBetweenDefs.DefLikeMacros | [] | any value |
Layout/EmptyLineBetweenDefs.AllowAdjacentOneLineDefs | true | true or false |
Layout/EmptyLineBetweenDefs.NumberOfEmptyLines | 1 | a number |
Layout/EmptyLines.Enabled | true | any value |
Layout/EmptyLinesAfterModuleInclusion.Enabled | "pending" | any value |
Layout/EmptyLinesAroundAccessModifier.Enabled | true | any value |
Layout/EmptyLinesAroundAccessModifier.EnforcedStyle | "around" | a string |
Layout/EmptyLinesAroundArguments.Enabled | true | any value |
Layout/EmptyLinesAroundAttributeAccessor.Enabled | true | any value |
Layout/EmptyLinesAroundAttributeAccessor.AllowAliasSyntax | true | true or false |
Layout/EmptyLinesAroundAttributeAccessor.AllowedMethods | ["alias_method","public","protected","private"] | any value |
Layout/EmptyLinesAroundBeginBody.Enabled | true | any value |
Layout/EmptyLinesAroundBlockBody.Enabled | true | any value |
Layout/EmptyLinesAroundBlockBody.EnforcedStyle | "no_empty_lines" | a string |
Layout/EmptyLinesAroundClassBody.Enabled | true | any value |
Layout/EmptyLinesAroundClassBody.EnforcedStyle | "no_empty_lines" | a string |
Layout/EmptyLinesAroundExceptionHandlingKeywords.Enabled | true | any value |
Layout/EmptyLinesAroundMethodBody.Enabled | true | any value |
Layout/EmptyLinesAroundModuleBody.Enabled | true | any value |
Layout/EmptyLinesAroundModuleBody.EnforcedStyle | "no_empty_lines" | a string |
Layout/EndAlignment.Enabled | true | any value |
Layout/EndAlignment.EnforcedStyleAlignWith | "keyword" | a string |
Layout/EndOfLine.Enabled | true | any value |
Layout/EndOfLine.EnforcedStyle | "native" | a string |
Layout/ExtraSpacing.Enabled | true | any value |
Layout/ExtraSpacing.AllowForAlignment | true | true or false |
Layout/ExtraSpacing.AllowBeforeTrailingComments | false | true or false |
Layout/ExtraSpacing.ForceEqualSignAlignment | false | true or false |
Layout/FirstArgumentIndentation.Enabled | true | any value |
Layout/FirstArgumentIndentation.EnforcedStyle | "special_for_inner_method_call_in_parentheses" | a string |
Layout/FirstArgumentIndentation.IndentationWidth | | any value |
Layout/FirstArrayElementIndentation.Enabled | true | any value |
Layout/FirstArrayElementIndentation.EnforcedStyle | "special_inside_parentheses" | a string |
Layout/FirstArrayElementIndentation.IndentationWidth | | any value |
Layout/FirstArrayElementLineBreak.Enabled | false | any value |
Layout/FirstArrayElementLineBreak.AllowImplicitArrayLiterals | false | true or false |
Layout/FirstArrayElementLineBreak.AllowMultilineFinalElement | false | true or false |
Layout/FirstHashElementIndentation.Enabled | true | any value |
Layout/FirstHashElementIndentation.EnforcedStyle | "special_inside_parentheses" | a string |
Layout/FirstHashElementIndentation.IndentationWidth | | any value |
Layout/FirstHashElementLineBreak.Enabled | false | any value |
Layout/FirstHashElementLineBreak.AllowMultilineFinalElement | false | true or false |
Layout/FirstMethodArgumentLineBreak.Enabled | false | any value |
Layout/FirstMethodArgumentLineBreak.AllowMultilineFinalElement | false | true or false |
Layout/FirstMethodArgumentLineBreak.AllowedMethods | [] | any value |
Layout/FirstMethodParameterLineBreak.Enabled | false | any value |
Layout/FirstMethodParameterLineBreak.AllowMultilineFinalElement | false | true or false |
Layout/FirstParameterIndentation.Enabled | true | any value |
Layout/FirstParameterIndentation.EnforcedStyle | "consistent" | a string |
Layout/FirstParameterIndentation.IndentationWidth | | any value |
Layout/HashAlignment.Enabled | true | any value |
Layout/HashAlignment.AllowMultipleStyles | true | true or false |
Layout/HashAlignment.EnforcedHashRocketStyle | "key" | a string |
Layout/HashAlignment.EnforcedColonStyle | "key" | a string |
Layout/HashAlignment.EnforcedLastArgumentHashStyle | "always_inspect" | a string |
Layout/HeredocArgumentClosingParenthesis.Enabled | false | any value |
Layout/HeredocIndentation.Enabled | true | any value |
Layout/IndentationConsistency.Enabled | true | any value |
Layout/IndentationConsistency.EnforcedStyle | "normal" | a string |
Layout/IndentationStyle.Enabled | true | any value |
Layout/IndentationStyle.IndentationWidth | | any value |
Layout/IndentationStyle.EnforcedStyle | "spaces" | a string |
Layout/IndentationWidth.Enabled | true | any value |
Layout/IndentationWidth.Width | 2 | a number |
Layout/IndentationWidth.EnforcedStyleAlignWith | "start_of_line" | a string |
Layout/IndentationWidth.AllowedPatterns | [] | any value |
Layout/InitialIndentation.Enabled | true | any value |
Layout/LeadingCommentSpace.Enabled | true | any value |
Layout/LeadingCommentSpace.AllowDoxygenCommentStyle | false | true or false |
Layout/LeadingCommentSpace.AllowGemfileRubyComment | false | true or false |
Layout/LeadingCommentSpace.AllowRBSInlineAnnotation | false | true or false |
Layout/LeadingCommentSpace.AllowSteepAnnotation | false | true or false |
Layout/LeadingCommentSpace.AllowYARDCommentBlockSeparator | false | true or false |
Layout/LeadingEmptyLines.Enabled | true | any value |
Layout/LineContinuationLeadingSpace.Enabled | "pending" | any value |
Layout/LineContinuationLeadingSpace.EnforcedStyle | "trailing" | a string |
Layout/LineContinuationSpacing.Enabled | "pending" | any value |
Layout/LineContinuationSpacing.EnforcedStyle | "space" | a string |
Layout/LineEndStringConcatenationIndentation.Enabled | "pending" | any value |
Layout/LineEndStringConcatenationIndentation.EnforcedStyle | "aligned" | a string |
Layout/LineEndStringConcatenationIndentation.IndentationWidth | | any value |
Layout/LineLength.Enabled | true | any value |
Layout/LineLength.Max | 120 | a number |
Layout/LineLength.AllowHeredoc | true | true or false |
Layout/LineLength.AllowURI | true | true or false |
Layout/LineLength.AllowQualifiedName | true | true or false |
Layout/LineLength.URISchemes | ["http","https"] | any value |
Layout/LineLength.AllowRBSInlineAnnotation | false | true or false |
Layout/LineLength.AllowCopDirectives | true | true or false |
Layout/LineLength.AllowedPatterns | [] | any value |
Layout/LineLength.SplitStrings | false | true or false |
Layout/MultilineArrayBraceLayout.Enabled | true | any value |
Layout/MultilineArrayBraceLayout.EnforcedStyle | "symmetrical" | a string |
Layout/MultilineArrayLineBreaks.Enabled | false | any value |
Layout/MultilineArrayLineBreaks.AllowMultilineFinalElement | false | true or false |
Layout/MultilineAssignmentLayout.Enabled | false | any value |
Layout/MultilineAssignmentLayout.EnforcedStyle | "new_line" | a string |
Layout/MultilineBlockLayout.Enabled | true | any value |
Layout/MultilineHashBraceLayout.Enabled | true | any value |
Layout/MultilineHashBraceLayout.EnforcedStyle | "symmetrical" | a string |
Layout/MultilineHashKeyLineBreaks.Enabled | false | any value |
Layout/MultilineHashKeyLineBreaks.AllowMultilineFinalElement | false | true or false |
Layout/MultilineMethodArgumentLineBreaks.Enabled | false | any value |
Layout/MultilineMethodArgumentLineBreaks.AllowMultilineFinalElement | false | true or false |
Layout/MultilineMethodCallBraceLayout.Enabled | true | any value |
Layout/MultilineMethodCallBraceLayout.EnforcedStyle | "symmetrical" | a string |
Layout/MultilineMethodCallIndentation.Enabled | true | any value |
Layout/MultilineMethodCallIndentation.EnforcedStyle | "aligned" | a string |
Layout/MultilineMethodCallIndentation.IndentationWidth | | any value |
Layout/MultilineMethodDefinitionBraceLayout.Enabled | true | any value |
Layout/MultilineMethodDefinitionBraceLayout.EnforcedStyle | "symmetrical" | a string |
Layout/MultilineMethodParameterLineBreaks.Enabled | false | any value |
Layout/MultilineMethodParameterLineBreaks.AllowMultilineFinalElement | false | true or false |
Layout/MultilineOperationIndentation.Enabled | true | any value |
Layout/MultilineOperationIndentation.EnforcedStyle | "aligned" | a string |
Layout/MultilineOperationIndentation.IndentationWidth | | any value |
Layout/ParameterAlignment.Enabled | true | any value |
Layout/ParameterAlignment.EnforcedStyle | "with_first_parameter" | a string |
Layout/ParameterAlignment.IndentationWidth | | any value |
Layout/RedundantLineBreak.Enabled | false | any value |
Layout/RedundantLineBreak.InspectBlocks | false | true or false |
Layout/RescueEnsureAlignment.Enabled | true | any value |
Layout/SingleLineBlockChain.Enabled | false | any value |
Layout/SpaceAfterColon.Enabled | true | any value |
Layout/SpaceAfterComma.Enabled | true | any value |
Layout/SpaceAfterMethodName.Enabled | true | any value |
Layout/SpaceAfterNot.Enabled | true | any value |
Layout/SpaceAfterSemicolon.Enabled | true | any value |
Layout/SpaceAroundBlockParameters.Enabled | true | any value |
Layout/SpaceAroundBlockParameters.EnforcedStyleInsidePipes | "no_space" | a string |
Layout/SpaceAroundEqualsInParameterDefault.Enabled | true | any value |
Layout/SpaceAroundEqualsInParameterDefault.EnforcedStyle | "space" | a string |
Layout/SpaceAroundKeyword.Enabled | true | any value |
Layout/SpaceAroundMethodCallOperator.Enabled | true | any value |
Layout/SpaceAroundOperators.Enabled | true | any value |
Layout/SpaceAroundOperators.AllowForAlignment | true | true or false |
Layout/SpaceAroundOperators.EnforcedStyleForExponentOperator | "no_space" | a string |
Layout/SpaceAroundOperators.EnforcedStyleForRationalLiterals | "no_space" | a string |
Layout/SpaceBeforeBlockBraces.Enabled | true | any value |
Layout/SpaceBeforeBlockBraces.EnforcedStyle | "space" | a string |
Layout/SpaceBeforeBlockBraces.EnforcedStyleForEmptyBraces | "space" | a string |
Layout/SpaceBeforeBrackets.Enabled | "pending" | any value |
Layout/SpaceBeforeComma.Enabled | true | any value |
Layout/SpaceBeforeComment.Enabled | true | any value |
Layout/SpaceBeforeFirstArg.Enabled | true | any value |
Layout/SpaceBeforeFirstArg.AllowForAlignment | true | true or false |
Layout/SpaceBeforeSemicolon.Enabled | true | any value |
Layout/SpaceInLambdaLiteral.Enabled | true | any value |
Layout/SpaceInLambdaLiteral.EnforcedStyle | "require_no_space" | a string |
Layout/SpaceInsideArrayLiteralBrackets.Enabled | true | any value |
Layout/SpaceInsideArrayLiteralBrackets.EnforcedStyle | "no_space" | a string |
Layout/SpaceInsideArrayLiteralBrackets.EnforcedStyleForEmptyBrackets | "no_space" | a string |
Layout/SpaceInsideArrayPercentLiteral.Enabled | true | any value |
Layout/SpaceInsideBlockBraces.Enabled | true | any value |
Layout/SpaceInsideBlockBraces.EnforcedStyle | "space" | a string |
Layout/SpaceInsideBlockBraces.EnforcedStyleForEmptyBraces | "no_space" | a string |
Layout/SpaceInsideBlockBraces.SpaceBeforeBlockParameters | true | true or false |
Layout/SpaceInsideHashLiteralBraces.Enabled | true | any value |
Layout/SpaceInsideHashLiteralBraces.EnforcedStyle | "space" | a string |
Layout/SpaceInsideHashLiteralBraces.EnforcedStyleForEmptyBraces | "no_space" | a string |
Layout/SpaceInsideParens.Enabled | true | any value |
Layout/SpaceInsideParens.EnforcedStyle | "no_space" | a string |
Layout/SpaceInsidePercentLiteralDelimiters.Enabled | true | any value |
Layout/SpaceInsideRangeLiteral.Enabled | true | any value |
Layout/SpaceInsideReferenceBrackets.Enabled | true | any value |
Layout/SpaceInsideReferenceBrackets.EnforcedStyle | "no_space" | a string |
Layout/SpaceInsideReferenceBrackets.EnforcedStyleForEmptyBrackets | "no_space" | a string |
Layout/SpaceInsideStringInterpolation.Enabled | true | any value |
Layout/SpaceInsideStringInterpolation.EnforcedStyle | "no_space" | a string |
Layout/TrailingEmptyLines.Enabled | true | any value |
Layout/TrailingEmptyLines.EnforcedStyle | "final_newline" | a string |
Layout/TrailingWhitespace.Enabled | true | any value |
Layout/TrailingWhitespace.AllowInHeredoc | false | true or false |