Sha256: d1285dada3f61853d15ba2362df9457de033a15e27dd9acbf109a0229848a254

Contents?: true

Size: 1.34 KB

Versions: 23

Compression:

Stored size: 1.34 KB

Contents

module SCSSLint
  class Plugins
    # Load linter plugin gems
    class LinterGem
      attr_reader :config

      def initialize(name)
        @name = name
      end

      def load
        require @name
        @config = plugin_config
        self
      rescue Gem::LoadError, LoadError
        raise SCSSLint::Exceptions::PluginGemLoadError,
              "Unable to load linter plugin gem '#{@name}'. Try running " \
              "`gem install #{@name}`, or adding it to your Gemfile and " \
              'running `bundle install`. See the `plugin_gems` section of ' \
              'your .scss-lint.yml file to add/remove gem plugins.'
      end

    private

      # Returns the {SCSSLint::Config} for this plugin.
      #
      # This is intended to be merged with the configuration that loaded this
      # plugin.
      #
      # @return [SCSSLint::Config]
      def plugin_config
        file = plugin_config_file

        if File.exist?(file)
          Config.load(file, merge_with_default: false)
        else
          Config.new({})
        end
      end

      # Path of the configuration file to attempt to load for this plugin.
      #
      # @return [String]
      def plugin_config_file
        gem_specification = Gem::Specification.find_by_name(@name)

        File.join(gem_specification.gem_dir, Config::FILE_NAME)
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
scss_lint-0.41.0 lib/scss_lint/plugins/linter_gem.rb
scss_lint-0.40.1 lib/scss_lint/plugins/linter_gem.rb
scss_lint-0.40.0 lib/scss_lint/plugins/linter_gem.rb