Class: Rubocop::Cop::Cop
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- Rubocop::Cop::Cop
- Extended by:
- AST::Sexp
- Defined in:
- lib/rubocop/cop/cop.rb
Direct Known Subclasses
AccessControl, Alias, AlignParameters, AndOr, AsciiComments, AsciiIdentifiers, AvoidClassVars, AvoidFor, AvoidGlobalVars, AvoidPerlBackrefs, AvoidPerlisms, BlockComments, Blocks, CaseIndentation, ClassAndModuleCamelCase, ClassMethods, CollectionMethods, ColonMethodCall, ConstantName, DefWithParentheses, DefWithoutParentheses, EmptyLineBetweenDefs, EmptyLines, EmptyLiteral, Encoding, EndOfLine, EnsureReturn, Eval, FavorJoin, FavorPercentR, FavorSprintf, FavorUnlessOverNegatedIf, FavorUntilOverNegatedWhile, HandleExceptions, HashSyntax, IfUnlessModifier, IfWithSemicolon, LeadingCommentSpace, LineContinuation, LineLength, Loop, MethodAndVariableSnakeCase, MethodLength, MultilineIfThen, MultilineTernaryOperator, NestedTernaryOperator, NewLambdaLiteral, Not, NumericLiterals, OneLineConditional, OpMethod, ParameterLists, ParenthesesAroundCondition, PercentR, ReduceArguments, RescueException, RescueModifier, Semicolon, SingleLineMethods, SpaceAfterColon, SpaceAfterComma, SpaceAfterControlKeyword, SpaceAfterSemicolon, SpaceAroundBraces, SpaceAroundEqualsInParameterDefault, SpaceAroundOperators, SpaceInsideBrackets, SpaceInsideHashLiteralBraces, SpaceInsideParens, StringLiterals, SymbolArray, SymbolName, Syntax, Tab, TrailingWhitespace, TrivialAccessors, UnlessElse, VariableInterpolation, WhenThen, WhileUntilModifier, WordArray
Class Attribute Summary collapse
-
.all ⇒ Object
Returns the value of attribute all.
-
.config ⇒ Object
Returns the value of attribute config.
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#disabled_lines ⇒ Object
writeonly
Sets the attribute disabled_lines.
-
#offences ⇒ Object
Returns the value of attribute offences.
Class Method Summary collapse
Instance Method Summary collapse
- #add_offence(severity, line_number, message) ⇒ Object
- #has_report? ⇒ Boolean
-
#initialize ⇒ Cop
constructor
A new instance of Cop.
- #inspect(source, tokens, ast, comments) ⇒ Object
- #name ⇒ Object
- #on_comment(comment) ⇒ Object
Constructor Details
#initialize ⇒ Cop
Returns a new instance of Cop.
40 41 42 43 |
# File 'lib/rubocop/cop/cop.rb', line 40 def initialize @offences = [] @debug = false end |
Class Attribute Details
.all ⇒ Object
Returns the value of attribute all.
28 29 30 |
# File 'lib/rubocop/cop/cop.rb', line 28 def all @all end |
.config ⇒ Object
Returns the value of attribute config.
29 30 31 |
# File 'lib/rubocop/cop/cop.rb', line 29 def config @config end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
21 22 23 |
# File 'lib/rubocop/cop/cop.rb', line 21 def debug @debug end |
#disabled_lines=(value) ⇒ Object (writeonly)
Sets the attribute disabled_lines
22 23 24 |
# File 'lib/rubocop/cop/cop.rb', line 22 def disabled_lines=(value) @disabled_lines = value end |
#offences ⇒ Object
Returns the value of attribute offences.
20 21 22 |
# File 'lib/rubocop/cop/cop.rb', line 20 def offences @offences end |
Class Method Details
.cop_name ⇒ Object
36 37 38 |
# File 'lib/rubocop/cop/cop.rb', line 36 def self.cop_name name.to_s.split('::').last end |
.inherited(subclass) ⇒ Object
32 33 34 |
# File 'lib/rubocop/cop/cop.rb', line 32 def self.inherited(subclass) all << subclass end |
Instance Method Details
#add_offence(severity, line_number, message) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/rubocop/cop/cop.rb', line 57 def add_offence(severity, line_number, ) unless @disabled_lines && @disabled_lines.include?(line_number) = debug ? "#{name}: #{}" : @offences << Offence.new(severity, line_number, ) end end |
#has_report? ⇒ Boolean
45 46 47 |
# File 'lib/rubocop/cop/cop.rb', line 45 def has_report? !@offences.empty? end |
#inspect(source, tokens, ast, comments) ⇒ Object
49 50 51 52 |
# File 'lib/rubocop/cop/cop.rb', line 49 def inspect(source, tokens, ast, comments) process(ast) comments.each { |c| on_comment(c) } end |
#name ⇒ Object
64 65 66 |
# File 'lib/rubocop/cop/cop.rb', line 64 def name self.class.cop_name end |
#on_comment(comment) ⇒ Object
54 55 |
# File 'lib/rubocop/cop/cop.rb', line 54 def on_comment(comment) end |