Class: CC::Engine::Categories

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/engine/categories.rb

Overview

Generates categories for a given linter

Constant Summary collapse

CATEGORIES =

Maps the linters to their categories

{
  'AlignmentTabs' => 'Style',
  'AltText' => 'Compatibility',
  'ClassAttributeWithStaticValue' => 'Style',
  'ClassesBeforeIds' => 'Style',
  'ConsecutiveComments' => 'Complexity',
  'ConsecutiveSilentScripts' => 'Complexity',
  'EmptyObjectReference' => 'Clarity',
  'EmptyScript' => 'Clarity',
  'FinalNewline' => 'Style',
  'HtmlAttributes' => 'Complexity',
  'IdNames' => 'Style',
  'ImplicitDiv' => 'Style',
  'Indentation' => 'Style',
  'InlineStyles' => 'Style',
  'InstanceVariables' => 'Style',
  'LeadingCommentSpace' => 'Style',
  'LineLength' => 'Style',
  'MultilinePipe' => 'Complexity',
  'MultilineScript' => 'Complexity',
  'ObjectReferenceAttributes' => 'Clarity',
  'RepeatedId' => 'Bug Risk',
  'RuboCop' => 'Style',
  'RubyComments' => 'Bug Risk',
  'SpaceBeforeScript' => 'Style',
  'SpaceInsideHashAttributes' => 'Style',
  'Syntax' => 'Bug Risk',
  'TagName' => 'Compatibility',
  'TrailingWhitespace' => 'Style',
  'UnnecessaryInterpolation' => 'Clarity',
  'UnnecessaryStringOutput' => 'Clarity',
  'ViewLength' => 'Complexity'
}.freeze
POSSIBLE =

Lists the possible categories

[
  'Bug Risk',
  'Clarity',
  'Compatibility',
  'Complexity',
  'Duplication',
  'Performance',
  'Security',
  'Style'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(linter) ⇒ Categories

Instantiates a set of categories for a linter

Examples:

CC::Engine::Categories.new("AltText")

Parameters:

  • linter (String)

    the name of the linter to categorize


65
66
67
# File 'lib/cc/engine/categories.rb', line 65

def initialize(linter)
  @linter = linter
end

Instance Attribute Details

#linterString (readonly)

The name of the linter to categorize

Examples:

CC::Engine::Categories.new("AltText").linter  #=> "AltText"

Returns:

  • (String)

76
77
78
# File 'lib/cc/engine/categories.rb', line 76

def linter
  @linter
end

Instance Method Details

#empty?Boolean

Checks whether the category is empty

Examples:

CC::Engine::Categories.new("AltText").empty?  #=> false

Returns:

  • (Boolean)

85
86
87
# File 'lib/cc/engine/categories.rb', line 85

def empty?
  !category
end

#to_json(*args) ⇒ String

Converts the categories into a JSON format

Examples:

CC::Engine::Categories.new("AltText").to_json  #=> ["Compatibility"]

Returns:

  • (String)

    a JSON document of the compatibilities


96
97
98
99
100
# File 'lib/cc/engine/categories.rb', line 96

def to_json(*args)
  return unless category

  [category].to_json(*args)
end