require 'sass'

module SCSSLint
  class FileEncodingError < StandardError; end

  # Contains all information for a parsed SCSS file, including its name,
  # contents, and parse tree.
  class Engine
    ENGINE_OPTIONS = { cache: false, syntax: :scss }

    attr_reader :contents, :filename, :lines, :tree

    def initialize(scss_or_filename)
      if File.exists?(scss_or_filename)
        @filename = scss_or_filename
        @engine = Sass::Engine.for_file(scss_or_filename, ENGINE_OPTIONS)
        @contents = File.open(scss_or_filename, 'r').read
      else
        @engine = Sass::Engine.new(scss_or_filename, ENGINE_OPTIONS)
        @contents = scss_or_filename
      end

      @lines = @contents.split("\n")
      @tree = @engine.to_tree
    rescue Encoding::UndefinedConversionError, ArgumentError => error
      if error.is_a?(Encoding::UndefinedConversionError) ||
         error.message.include?('invalid byte sequence')
        raise FileEncodingError,
              "Unable to parse SCSS file: #{error.to_s}",
              error.backtrace
      else
        raise
      end
    end
  end
end

require 'sass'

module SCSSLint
  class FileEncodingError < StandardError; end

  # Contains all information for a parsed SCSS file, including its name,
  # contents, and parse tree.
  class Engine
    ENGINE_OPTIONS = { cache: false, syntax: :scss }

    attr_reader :contents, :filename, :lines, :tree

    def initialize(scss_or_filename)
      if File.exist?(scss_or_filename)
        @filename = scss_or_filename
        @engine = Sass::Engine.for_file(scss_or_filename, ENGINE_OPTIONS)
        @contents = File.open(scss_or_filename, 'r').read
      else
        @engine = Sass::Engine.new(scss_or_filename, ENGINE_OPTIONS)
        @contents = scss_or_filename
      end

      @lines = @contents.split("\n")
      @tree = @engine.to_tree
    rescue Encoding::UndefinedConversionError, ArgumentError => error
      if error.is_a?(Encoding::UndefinedConversionError) ||
         error.message.include?('invalid byte sequence')
        raise FileEncodingError,
              "Unable to parse SCSS file: #{error}",
              error.backtrace
      else
        raise
      end
    end
  end
end

Fix Rubocop lints in Engine class
Fix Rubocop lints in Engine class

Change-Id: Ib6135d18727a078277810f78ecfc516085e1362d
Reviewed-on: http://gerrit.causes.com/36708
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
