class Policial::StyleGuides::Scss

Public: Determine SCSS style guide violations per-line.

Constants

KEY

Public Instance Methods

default_config_file() click to toggle source
# File lib/policial/style_guides/scss.rb, line 29
def default_config_file
  require 'scss_lint'
  SCSSLint::Config::FILE_NAME
end
exclude_file?(filename) click to toggle source
# File lib/policial/style_guides/scss.rb, line 21
def exclude_file?(filename)
  config.excluded_file?(File.expand_path(filename))
end
filename_pattern() click to toggle source
# File lib/policial/style_guides/scss.rb, line 25
def filename_pattern
  /.+\.scss\z/
end
violations_in_file(file) click to toggle source
# File lib/policial/style_guides/scss.rb, line 9
def violations_in_file(file)
  absolute_path = File.expand_path(file.filename)

  runner = new_runner

  tempfile_from(file.filename, file.content) do |tempfile|
    runner.run([{ file: tempfile, path: absolute_path }])
  end

  violations(runner, file)
end

Private Instance Methods

config() click to toggle source
# File lib/policial/style_guides/scss.rb, line 36
def config
  require 'scss_lint'
  @config ||= begin
    content = @config_loader.raw(config_file)
    tempfile_from(config_file, content) do |temp|
      SCSSLint::Config.load(temp, merge_with_default: true)
    end
  end
end
new_runner() click to toggle source
# File lib/policial/style_guides/scss.rb, line 54
def new_runner
  require 'scss_lint'
  SCSSLint::Runner.new(config)
end
tempfile_from(filename, content) { |tempfile| ... } click to toggle source
# File lib/policial/style_guides/scss.rb, line 59
def tempfile_from(filename, content)
  Tempfile.create(File.basename(filename), Dir.pwd) do |tempfile|
    tempfile.write(content)
    tempfile.rewind

    yield(tempfile)
  end
end
violations(runner, file) click to toggle source
# File lib/policial/style_guides/scss.rb, line 46
def violations(runner, file)
  runner.lints.map do |lint|
    linter_name = lint.linter ? lint.linter.name : 'undefined'
    Violation.new(
      file, lint.location.line, lint.description, linter_name)
  end
end