Class: Browsable::Analyzers::CSS

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

Overview

Audits CSS by shelling out to stylelint with the ‘stylelint-no-unsupported-browser-features` plugin configured for the project’s target. browsable supplies the config; stylelint (and its bundled caniuse data) does the actual compatibility reasoning.

Constant Summary collapse

SCSS_EXTENSIONS =

Extensions that stylelint cannot parse with its default PostCSS syntax. We route them through postcss-scss when any are present.

%w[.scss .sass].freeze

Instance Attribute Summary

Attributes inherited from Base

#config, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

compat_data, #initialize

Constructor Details

This class inherits a constructor from Browsable::Analyzers::Base

Class Method Details

.scss_like?(file) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/browsable/analyzers/css.rb', line 17

def self.scss_like?(file)
  SCSS_EXTENSIONS.include?(File.extname(file).downcase)
end

Instance Method Details

#analyze(files) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/browsable/analyzers/css.rb', line 23

def analyze(files)
  return [] if files.empty?

  argv = ["stylelint", "--config", write_stylelintrc,
          "--formatter", "json"]
  # SCSS is a strict superset of CSS for the constructs we audit; running
  # plain .css through postcss-scss is safe, so one invocation covers
  # mixed inputs as long as any SCSS-like file is present.
  argv.push("--customSyntax", "postcss-scss") if files.any? { |f| self.class.scss_like?(f) }
  argv.concat(files)
  parse(shell_out(argv, dry_run_key: "BROWSABLE_DRY_RUN_CSS"))
end

#required_toolsObject



21
# File 'lib/browsable/analyzers/css.rb', line 21

def required_tools = ["stylelint"]