class Overcommit::Hook::PreCommit::W3cCss

Runs `w3c_validators` against any modified CSS files.

@see github.com/alexdunae/w3c_validators

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 8
def run
  collect_messages
rescue W3CValidators::ParsingError,
       W3CValidators::ValidatorUnavailable => e
  [:fail, e.message]
end

Private Instance Methods

collect_messages() click to toggle source
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 17
def collect_messages
  applicable_files.collect do |path|
    results = validator.validate_file(path)
    messages = results.errors + results.warnings
    messages.collect do |msg|
      # Some warnings are not per-line, so use 0 as a default
      line = Integer(msg.line || 0)

      # Build message by hand to reduce noise from the validator response
      text = "#{msg.type.to_s.upcase}; URI: #{path}; line #{line}: #{msg.message.strip}"
      Overcommit::Hook::Message.new(msg.type, path, line, text)
    end
  end.flatten
end
language() click to toggle source
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 52
def language
  @language ||= config['language']
end
opts() click to toggle source
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 42
def opts
  @opts ||= {
    validator_uri: config['validator_uri'],
    proxy_server:  config['proxy_server'],
    proxy_port:    config['proxy_port'],
    proxy_user:    config['proxy_user'],
    proxy_pass:    config['proxy_pass']
  }
end
profile() click to toggle source

Values specified at

http://www.rubydoc.info/gems/w3c_validators/1.2/W3CValidators#CSS_PROFILES
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 58
def profile
  @profile ||= config['profile']
end
validator() click to toggle source
# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 32
def validator
  unless @validator
    @validator = W3CValidators::CSSValidator.new(opts)
    @validator.set_language!(language) unless language.nil?
    @validator.set_profile!(profile) unless profile.nil?
    @validator.set_warn_level!(warn_level) unless warn_level.nil?
  end
  @validator
end
warn_level() click to toggle source

One of 0, 1, 2, 'no'

# File lib/overcommit/hook/pre_commit/w3c_css.rb, line 63
def warn_level
  @warn_level ||= config['warn_level']
end