Class: SCSSLint::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/scss_lint/engine.rb

Overview

Contains all information for a parsed SCSS file, including its name, contents, and parse tree.

Constant Summary collapse

ENGINE_OPTIONS =
{ cache: false, syntax: :scss }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Engine

Creates a parsed representation of an SCSS document from the given string or file.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :file (String)

    The file to load

  • :code (String)

    The code to parse



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scss_lint/engine.rb', line 19

def initialize(options = {})
  if options[:path]
    build_from_file(options)
  elsif options[:code]
    build_from_string(options[:code])
  end

  # Need to force encoding to avoid Windows-related bugs.
  # Need to encode with universal newline to avoid other Windows-related bugs.
  # Need `to_a` for Ruby 1.9.3.
  encoding = 'UTF-8'
  @lines = @contents.force_encoding(encoding)
                    .encode(encoding, universal_newline: true)
                    .lines.to_a
  @tree = @engine.to_tree
  find_any_control_commands
rescue Encoding::UndefinedConversionError, Sass::SyntaxError, ArgumentError => error
  if error.is_a?(Encoding::UndefinedConversionError) ||
     error.message.match(/invalid.*(byte sequence|character)/i)
    raise FileEncodingError,
          "Unable to parse SCSS file: #{error}",
          error.backtrace
  else
    raise
  end
end

Instance Attribute Details

#any_control_commandsObject (readonly)

Returns the value of attribute any_control_commands.



11
12
13
# File 'lib/scss_lint/engine.rb', line 11

def any_control_commands
  @any_control_commands
end

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/scss_lint/engine.rb', line 11

def contents
  @contents
end

#filenameObject (readonly)

Returns the value of attribute filename.



11
12
13
# File 'lib/scss_lint/engine.rb', line 11

def filename
  @filename
end

#linesObject (readonly)

Returns the value of attribute lines.



11
12
13
# File 'lib/scss_lint/engine.rb', line 11

def lines
  @lines
end

#treeObject (readonly)

Returns the value of attribute tree.



11
12
13
# File 'lib/scss_lint/engine.rb', line 11

def tree
  @tree
end