Class: Browsable::Analyzers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/browsable/analyzers/base.rb

Overview

Base class for analyzers. An analyzer turns a list of files into Findings.

browsable owns no parsing or compat-data logic of its own: analyzers are thin adapters over Herb (in-process) or stylelint/eslint (shelled out).

Direct Known Subclasses

CSS, ERB, Javascript

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target:, config:) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/browsable/analyzers/base.rb', line 15

def initialize(target:, config:)
  @target = target
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/browsable/analyzers/base.rb', line 13

def config
  @config
end

#targetObject (readonly)

Returns the value of attribute target.



13
14
15
# File 'lib/browsable/analyzers/base.rb', line 13

def target
  @target
end

Class Method Details

.compat_dataObject

The bundled MDN browser-compat-data subset, parsed once and shared.



30
31
32
33
34
# File 'lib/browsable/analyzers/base.rb', line 30

def self.compat_data
  @compat_data ||= JSON.parse(
    File.read(File.join(Browsable.data_dir, "bcd-snapshot.json"))
  )
end

Instance Method Details

#analyze(_files) ⇒ Array<Finding>

Parameters:

  • files (Array<String>)

    absolute paths to analyze

Returns:

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/browsable/analyzers/base.rb', line 22

def analyze(_files)
  raise NotImplementedError, "#{self.class} must implement #analyze"
end

#required_toolsObject

External binaries this analyzer needs on PATH. Empty for in-process ones.



27
# File 'lib/browsable/analyzers/base.rb', line 27

def required_tools = []