Class: JsDuck::Warning::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/warning/basic.rb

Overview

A basic warning type.

Instance Method Summary collapse

Constructor Details

#initialize(type, msg) ⇒ Basic

Creates a simple warning with a message text. The warning is disabled by default.



11
12
13
14
15
16
# File 'lib/jsduck/warning/basic.rb', line 11

def initialize(type, msg)
  @type = type
  @msg = msg
  @enabled = false
  @patterns = []
end

Instance Method Details

#docObject

Documentation for the warning.



44
45
46
# File 'lib/jsduck/warning/basic.rb', line 44

def doc
  " #{@enabled ? '+' : '-'}#{@type} - #{@msg}"
end

#enabled?(filename = "", params = []) ⇒ Boolean

True when warning is enabled for the given filename. (The params parameter is ignored).

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/jsduck/warning/basic.rb', line 35

def enabled?(filename="", params=[])
  if @patterns.any? {|re| filename =~ re }
    !@enabled
  else
    @enabled
  end
end

#set(enabled, path_pattern = nil, params = []) ⇒ Object

Enables or disables the warning. Optionally enables/disables it for files matching a path_pattern.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jsduck/warning/basic.rb', line 20

def set(enabled, path_pattern=nil, params=[])
  if path_pattern
    if @enabled == enabled
      raise WarnException, "Warning rule '#{enabled ? '+' : '-'}#{@type}:#{path_pattern}' has no effect"
    else
      @patterns << Regexp.new(Regexp.escape(path_pattern))
    end
  else
    @enabled = enabled
    @patterns = []
  end
end