RuboCop是一个基于社区驱动的Ruby样式指南的Ruby代码样式检查器(linter)和格式化程序。
RuboCop非常灵活,其行为的大多数方面都可以通过各种配置选项进行调整。在实践中,RuboCop几乎支持你能想到的每一种(相当流行的)编码风格。
除了报告代码中的问题外,RuboCop还可以自动为您修复一些问题。
RuboCop提供Bundler,Gemspec,Layout,Lint,Metrics,Migration,Naming,Security,Style这几类的规则配置,一共531条规则。
使用gui配置工具
使用gui配置工具,可以让配置RoboCop参数更简单。
在凌鲨(linksaas)的微应用里面可以找到RoboCop配置助手,快速配置自定义规则。
凌鲨(linksaas)是以开源方式运作的,您可以从jihulab.com/linksaas 访问源代码。也可以从 linksaas.pro 下载预编译的版本。
附录
可配置规则
- Bundler/DuplicatedGem
- Bundler/GemComment
- Bundler/GemFilename
- Bundler/GemVersion
- Bundler/InsecureProtocolSource
- Bundler/OrderedGems
- Gemspec/DependencyVersion
- Gemspec/DeprecatedAttributeAssignment
- Gemspec/DevelopmentDependencies
- Gemspec/DuplicatedAssignment
- Gemspec/OrderedDependencies
- Gemspec/RequireMFA
- Gemspec/RequiredRubyVersion
- Gemspec/RubyVersionGlobalsUsage
- Layout/AccessModifierIndentation
- Layout/ArgumentAlignment
- Layout/ArrayAlignment
- Layout/AssignmentIndentation
- Layout/BeginEndAlignment
- Layout/BlockAlignment
- Layout/BlockEndNewline
- Layout/CaseIndentation
- Layout/ClassStructure
- Layout/ClosingHeredocIndentation
- Layout/ClosingParenthesisIndentation
- Layout/CommentIndentation
- Layout/ConditionPosition
- Layout/DefEndAlignment
- Layout/DotPosition
- Layout/ElseAlignment
- Layout/EmptyComment
- Layout/EmptyLineAfterGuardClause
- Layout/EmptyLineAfterMagicComment
- Layout/EmptyLineAfterMultilineCondition
- Layout/EmptyLineBetweenDefs
- Layout/EmptyLines
- Layout/EmptyLinesAroundAccessModifier
- Layout/EmptyLinesAroundArguments
- Layout/EmptyLinesAroundAttributeAccessor
- Layout/EmptyLinesAroundBeginBody
- Layout/EmptyLinesAroundBlockBody
- Layout/EmptyLinesAroundClassBody
- Layout/EmptyLinesAroundExceptionHandlingKeywords
- Layout/EmptyLinesAroundMethodBody
- Layout/EmptyLinesAroundModuleBody
- Layout/EndAlignment
- Layout/EndOfLine
- Layout/ExtraSpacing
- Layout/FirstArgumentIndentation
- Layout/FirstArrayElementIndentation
- Layout/FirstArrayElementLineBreak
- Layout/FirstHashElementIndentation
- Layout/FirstHashElementLineBreak
- Layout/FirstMethodArgumentLineBreak
- Layout/FirstMethodParameterLineBreak
- Layout/FirstParameterIndentation
- Layout/HashAlignment
- Layout/HeredocArgumentClosingParenthesis
- Layout/HeredocIndentation
- Layout/IndentationConsistency
- Layout/IndentationStyle
- Layout/IndentationWidth
- Layout/InitialIndentation
- Layout/LeadingCommentSpace
- Layout/LeadingEmptyLines
- Layout/LineContinuationLeadingSpace
- Layout/LineContinuationSpacing
- Layout/LineEndStringConcatenationIndentation
- Layout/LineLength
- Layout/MultilineArrayBraceLayout
- Layout/MultilineArrayLineBreaks
- Layout/MultilineAssignmentLayout
- Layout/MultilineBlockLayout
- Layout/MultilineHashBraceLayout
- Layout/MultilineHashKeyLineBreaks
- Layout/MultilineMethodArgumentLineBreaks
- Layout/MultilineMethodCallBraceLayout
- Layout/MultilineMethodCallIndentation
- Layout/MultilineMethodDefinitionBraceLayout
- Layout/MultilineMethodParameterLineBreaks
- Layout/MultilineOperationIndentation
- Layout/ParameterAlignment
- Layout/RedundantLineBreak
- Layout/RescueEnsureAlignment
- Layout/SingleLineBlockChain
- Layout/SpaceAfterColon
- Layout/SpaceAfterComma
- Layout/SpaceAfterMethodName
- Layout/SpaceAfterNot
- Layout/SpaceAfterSemicolon
- Layout/SpaceAroundBlockParameters
- Layout/SpaceAroundEqualsInParameterDefault
- Layout/SpaceAroundKeyword
- Layout/SpaceAroundMethodCallOperator
- Layout/SpaceAroundOperators
- Layout/SpaceBeforeBlockBraces
- Layout/SpaceBeforeBrackets
- Layout/SpaceBeforeComma
- Layout/SpaceBeforeComment
- Layout/SpaceBeforeFirstArg
- Layout/SpaceBeforeSemicolon
- Layout/SpaceInLambdaLiteral
- Layout/SpaceInsideArrayLiteralBrackets
- Layout/SpaceInsideArrayPercentLiteral
- Layout/SpaceInsideBlockBraces
- Layout/SpaceInsideHashLiteralBraces
- Layout/SpaceInsideParens
- Layout/SpaceInsidePercentLiteralDelimiters
- Layout/SpaceInsideRangeLiteral
- Layout/SpaceInsideReferenceBrackets
- Layout/SpaceInsideStringInterpolation
- Layout/TrailingEmptyLines
- Layout/TrailingWhitespace
- Lint/AmbiguousAssignment
- Lint/AmbiguousBlockAssociation
- Lint/AmbiguousOperator
- Lint/AmbiguousOperatorPrecedence
- Lint/AmbiguousRange
- Lint/AmbiguousRegexpLiteral
- Lint/AssignmentInCondition
- Lint/BigDecimalNew
- Lint/BinaryOperatorWithIdenticalOperands
- Lint/BooleanSymbol
- Lint/CircularArgumentReference
- Lint/ConstantDefinitionInBlock
- Lint/ConstantOverwrittenInRescue
- Lint/ConstantResolution
- Lint/Debugger
- Lint/DeprecatedClassMethods
- Lint/DeprecatedConstants
- Lint/DeprecatedOpenSSLConstant
- Lint/DisjunctiveAssignmentInConstructor
- Lint/DuplicateBranch
- Lint/DuplicateCaseCondition
- Lint/DuplicateElsifCondition
- Lint/DuplicateHashKey
- Lint/DuplicateMagicComment
- Lint/DuplicateMatchPattern
- Lint/DuplicateMethods
- Lint/DuplicateRegexpCharacterClassElement
- Lint/DuplicateRequire
- Lint/DuplicateRescueException
- Lint/EachWithObjectArgument
- Lint/ElseLayout
- Lint/EmptyBlock
- Lint/EmptyClass
- Lint/EmptyConditionalBody
- Lint/EmptyEnsure
- Lint/EmptyExpression
- Lint/EmptyFile
- Lint/EmptyInPattern
- Lint/EmptyInterpolation
- Lint/EmptyWhen
- Lint/EnsureReturn
- Lint/ErbNewArguments
- Lint/FlipFlop
- Lint/FloatComparison
- Lint/FloatOutOfRange
- Lint/FormatParameterMismatch
- Lint/HashCompareByIdentity
- Lint/HeredocMethodCallPosition
- Lint/IdentityComparison
- Lint/ImplicitStringConcatenation
- Lint/IncompatibleIoSelectWithFiberScheduler
- Lint/IneffectiveAccessModifier
- Lint/InheritException
- Lint/InterpolationCheck
- Lint/LambdaWithoutLiteralBlock
- Lint/LiteralAsCondition
- Lint/LiteralInInterpolation
- Lint/Loop
- Lint/MissingCopEnableDirective
- Lint/MissingSuper
- Lint/MixedRegexpCaptureTypes
- Lint/MultipleComparison
- Lint/NestedMethodDefinition
- Lint/NestedPercentLiteral
- Lint/NextWithoutAccumulator
- Lint/NoReturnInBeginEndBlocks
- Lint/NonAtomicFileOperation
- Lint/NonDeterministicRequireOrder
- Lint/NonLocalExitFromIterator
- Lint/NumberConversion
- Lint/NumberedParameterAssignment
- Lint/OrAssignmentToConstant
- Lint/OrderedMagicComments
- Lint/OutOfRangeRegexpRef
- Lint/ParenthesesAsGroupedExpression
- Lint/PercentStringArray
- Lint/PercentSymbolArray
- Lint/RaiseException
- Lint/RandOne
- Lint/RedundantCopDisableDirective
- Lint/RedundantCopEnableDirective
- Lint/RedundantDirGlobSort
- Lint/RedundantRequireStatement
- Lint/RedundantSafeNavigation
- Lint/RedundantSplatExpansion
- Lint/RedundantStringCoercion
- Lint/RedundantWithIndex
- Lint/RedundantWithObject
- Lint/RefinementImportMethods
- Lint/RegexpAsCondition
- Lint/RequireParentheses
- Lint/RequireRangeParentheses
- Lint/RequireRelativeSelfPath
- Lint/RescueException
- Lint/RescueType
- Lint/ReturnInVoidContext
- Lint/SafeNavigationChain
- Lint/SafeNavigationConsistency
- Lint/SafeNavigationWithEmpty
- Lint/ScriptPermission
- Lint/SelfAssignment
- Lint/SendWithMixinArgument
- Lint/ShadowedArgument
- Lint/ShadowedException
- Lint/ShadowingOuterLocalVariable
- Lint/StructNewOverride
- Lint/SuppressedException
- Lint/SymbolConversion
- Lint/Syntax
- Lint/ToEnumArguments
- Lint/ToJSON
- Lint/TopLevelReturnWithArgument
- Lint/TrailingCommaInAttributeDeclaration
- Lint/TripleQuotes
- Lint/UnderscorePrefixedVariableName
- Lint/UnexpectedBlockArity
- Lint/UnifiedInteger
- Lint/UnmodifiedReduceAccumulator
- Lint/UnreachableCode
- Lint/UnreachableLoop
- Lint/UnusedBlockArgument
- Lint/UnusedMethodArgument
- Lint/UriEscapeUnescape
- Lint/UriRegexp
- Lint/UselessAccessModifier
- Lint/UselessAssignment
- Lint/UselessElseWithoutRescue
- Lint/UselessMethodDefinition
- Lint/UselessRescue
- Lint/UselessRuby2Keywords
- Lint/UselessSetterCall
- Lint/UselessTimes
- Lint/Void
- Metrics/AbcSize
- Metrics/BlockLength
- Metrics/BlockNesting
- Metrics/ClassLength
- Metrics/CollectionLiteralLength
- Metrics/CyclomaticComplexity
- Metrics/MethodLength
- Metrics/ModuleLength
- Metrics/ParameterLists
- Metrics/PerceivedComplexity
- Migration/DepartmentName
- Naming/AccessorMethodName
- Naming/AsciiIdentifiers
- Naming/BinaryOperatorParameterName
- Naming/BlockForwarding
- Naming/BlockParameterName
- Naming/ClassAndModuleCamelCase
- Naming/ConstantName
- Naming/FileName
- Naming/HeredocDelimiterCase
- Naming/HeredocDelimiterNaming
- Naming/InclusiveLanguage
- Naming/MemoizedInstanceVariableName
- Naming/MethodName
- Naming/MethodParameterName
- Naming/PredicateName
- Naming/RescuedExceptionsVariableName
- Naming/VariableName
- Naming/VariableNumber
- Security/CompoundHash
- Security/Eval
- Security/IoMethods
- Security/JSONLoad
- Security/MarshalLoad
- Security/Open
- Security/YAMLLoad
- Style/AccessModifierDeclarations
- Style/AccessorGrouping
- Style/Alias
- Style/AndOr
- Style/ArgumentsForwarding
- Style/ArrayCoercion
- Style/ArrayIntersect
- Style/ArrayJoin
- Style/AsciiComments
- Style/Attr
- Style/AutoResourceCleanup
- Style/BarePercentLiterals
- Style/BeginBlock
- Style/BisectedAttrAccessor
- Style/BlockComments
- Style/BlockDelimiters
- Style/CaseEquality
- Style/CaseLikeIf
- Style/CharacterLiteral
- Style/ClassAndModuleChildren
- Style/ClassCheck
- Style/ClassEqualityComparison
- Style/ClassMethods
- Style/ClassMethodsDefinitions
- Style/ClassVars
- Style/CollectionCompact
- Style/CollectionMethods
- Style/ColonMethodCall
- Style/ColonMethodDefinition
- Style/CombinableLoops
- Style/CommandLiteral
- Style/CommentAnnotation
- Style/CommentedKeyword
- Style/ComparableClamp
- Style/ConcatArrayLiterals
- Style/ConditionalAssignment
- Style/ConstantVisibility
- Style/Copyright
- Style/DataInheritance
- Style/DateTime
- Style/DefWithParentheses
- Style/Dir
- Style/DirEmpty
- Style/DisableCopsWithinSourceCodeDirective
- Style/DocumentDynamicEvalDefinition
- Style/Documentation
- Style/DocumentationMethod
- Style/DoubleCopDisableDirective
- Style/DoubleNegation
- Style/EachForSimpleLoop
- Style/EachWithObject
- Style/EmptyBlockParameter
- Style/EmptyCaseCondition
- Style/EmptyElse
- Style/EmptyHeredoc
- Style/EmptyLambdaParameter
- Style/EmptyLiteral
- Style/EmptyMethod
- Style/Encoding
- Style/EndBlock
- Style/EndlessMethod
- Style/EnvHome
- Style/EvalWithLocation
- Style/EvenOdd
- Style/ExpandPathArguments
- Style/ExplicitBlockArgument
- Style/ExponentialNotation
- Style/FetchEnvVar
- Style/FileEmpty
- Style/FileRead
- Style/FileWrite
- Style/FloatDivision
- Style/For
- Style/FormatString
- Style/FormatStringToken
- Style/FrozenStringLiteralComment
- Style/GlobalStdStream
- Style/GlobalVars
- Style/GuardClause
- Style/HashAsLastArrayItem
- Style/HashConversion
- Style/HashEachMethods
- Style/HashExcept
- Style/HashLikeCase
- Style/HashSyntax
- Style/HashTransformKeys
- Style/HashTransformValues
- Style/IdenticalConditionalBranches
- Style/IfInsideElse
- Style/IfUnlessModifier
- Style/IfUnlessModifierOfIfUnless
- Style/IfWithBooleanLiteralBranches
- Style/IfWithSemicolon
- Style/ImplicitRuntimeError
- Style/InPatternThen
- Style/InfiniteLoop
- Style/InlineComment
- Style/InverseMethods
- Style/InvertibleUnlessCondition
- Style/IpAddresses
- Style/KeywordParametersOrder
- Style/Lambda
- Style/LambdaCall
- Style/LineEndConcatenation
- Style/MagicCommentFormat
- Style/MapCompactWithConditionalBlock
- Style/MapToHash
- Style/MapToSet
- Style/MethodCallWithArgsParentheses
- Style/MethodCallWithoutArgsParentheses
- Style/MethodCalledOnDoEndBlock
- Style/MethodDefParentheses
- Style/MinMax
- Style/MinMaxComparison
- Style/MissingElse
- Style/MissingRespondToMissing
- Style/MixinGrouping
- Style/MixinUsage
- Style/ModuleFunction
- Style/MultilineBlockChain
- Style/MultilineIfModifier
- Style/MultilineIfThen
- Style/MultilineInPatternThen
- Style/MultilineMemoization
- Style/MultilineMethodSignature
- Style/MultilineTernaryOperator
- Style/MultilineWhenThen
- Style/MultipleComparison
- Style/MutableConstant
- Style/NegatedIf
- Style/NegatedIfElseCondition
- Style/NegatedUnless
- Style/NegatedWhile
- Style/NestedFileDirname
- Style/NestedModifier
- Style/NestedParenthesizedCalls
- Style/NestedTernaryOperator
- Style/Next
- Style/NilComparison
- Style/NilLambda
- Style/NonNilCheck
- Style/Not
- Style/NumberedParameters
- Style/NumberedParametersLimit
- Style/NumericLiteralPrefix
- Style/NumericLiterals
- Style/NumericPredicate
- Style/ObjectThen
- Style/OneLineConditional
- Style/OpenStructUse
- Style/OperatorMethodCall
- Style/OptionHash
- Style/OptionalArguments
- Style/OptionalBooleanParameter
- Style/OrAssignment
- Style/ParallelAssignment
- Style/ParenthesesAroundCondition
- Style/PercentLiteralDelimiters
- Style/PercentQLiterals
- Style/PerlBackrefs
- Style/PreferredHashMethods
- Style/Proc
- Style/QuotedSymbols
- Style/RaiseArgs
- Style/RandomWithOffset
- Style/RedundantArgument
- Style/RedundantAssignment
- Style/RedundantBegin
- Style/RedundantCapitalW
- Style/RedundantCondition
- Style/RedundantConditional
- Style/RedundantConstantBase
- Style/RedundantDoubleSplatHashBraces
- Style/RedundantEach
- Style/RedundantException
- Style/RedundantFetchBlock
- Style/RedundantFileExtensionInRequire
- Style/RedundantFreeze
- Style/RedundantHeredocDelimiterQuotes
- Style/RedundantInitialize
- Style/RedundantInterpolation
- Style/RedundantLineContinuation
- Style/RedundantParentheses
- Style/RedundantPercentQ
- Style/RedundantRegexpCharacterClass
- Style/RedundantRegexpEscape
- Style/RedundantReturn
- Style/RedundantSelf
- Style/RedundantSelfAssignment
- Style/RedundantSelfAssignmentBranch
- Style/RedundantSort
- Style/RedundantSortBy
- Style/RedundantStringEscape
- Style/RegexpLiteral
- Style/RequireOrder
- Style/RescueModifier
- Style/RescueStandardError
- Style/ReturnNil
- Style/SafeNavigation
- Style/Sample
- Style/SelectByRegexp
- Style/SelfAssignment
- Style/Semicolon
- Style/Send
- Style/SignalException
- Style/SingleArgumentDig
- Style/SingleLineBlockParams
- Style/SingleLineMethods
- Style/SlicingWithRange
- Style/SoleNestedConditional
- Style/SpecialGlobalVars
- Style/StabbyLambdaParentheses
- Style/StaticClass
- Style/StderrPuts
- Style/StringChars
- Style/StringConcatenation
- Style/StringHashKeys
- Style/StringLiterals
- Style/StringLiteralsInInterpolation
- Style/StringMethods
- Style/Strip
- Style/StructInheritance
- Style/SwapValues
- Style/SymbolArray
- Style/SymbolLiteral
- Style/SymbolProc
- Style/TernaryParentheses
- Style/TopLevelMethodDefinition
- Style/TrailingBodyOnClass
- Style/TrailingBodyOnMethodDefinition
- Style/TrailingBodyOnModule
- Style/TrailingCommaInArguments
- Style/TrailingCommaInArrayLiteral
- Style/TrailingCommaInBlockArgs
- Style/TrailingCommaInHashLiteral
- Style/TrailingMethodEndStatement
- Style/TrailingUnderscoreVariable
- Style/TrivialAccessors
- Style/UnlessElse
- Style/UnlessLogicalOperators
- Style/UnpackFirst
- Style/VariableInterpolation
- Style/WhenThen
- Style/WhileUntilDo
- Style/WhileUntilModifier
- Style/WordArray
- Style/YodaCondition
- Style/YodaExpression
- Style/ZeroLengthPredicate