Sha256: 64d3ab408619632dfbd0265d8034c52fc65ecbd2c57c521f807822f70f689f3a

Contents?: true

Size: 1.77 KB

Versions: 80

Compression:

Stored size: 1.77 KB

Contents

require_relative "builds_ruleset"

module Standard::Performance
  class Plugin < LintRoller::Plugin
    def initialize(config)
      @config = config
      @builds_ruleset = BuildsRuleset.new
    end

    def about
      LintRoller::About.new(
        name: "standard-performance",
        version: VERSION,
        homepage: "https://github.com/testdouble/standard-performance",
        description: "Configuration for rubocop-performance's rules"
      )
    end

    def supported?(context)
      true
    end

    def rules(context)
      trick_rubocop_into_thinking_we_required_rubocop_performance!

      LintRoller::Rules.new(
        type: :object,
        config_format: :rubocop,
        value: @builds_ruleset.build(context.target_ruby_version)
      )
    end

    private

    # This is not fantastic.
    #
    # When you `require "rubocop-performance"`, it will not only load the cops,
    # but it will also monkey-patch RuboCop's default_configuration, which is
    # something that can't be undone for the lifetime of the process.
    #
    # See: https://github.com/rubocop/rubocop-performance/commit/587050a8c0ec6d2fa64f5be970425a7f4c5d779b
    #
    # As an alternative, standard-performance loads the cops directly, and then
    # simply tells the RuboCop config loader that it's been loaded. This is
    # taking advantage of a private API of an `attr_reader` that probably wasn't
    # meant to be mutated externally, but it's better than the `Inject` monkey
    # patching that rubocop-performance does (and many other RuboCop plugins do)
    def trick_rubocop_into_thinking_we_required_rubocop_performance!
      require "rubocop"
      require "rubocop/cop/performance_cops"
      RuboCop::ConfigLoader.default_configuration.loaded_features.add("rubocop-performance")
    end
  end
end

Version data entries

80 entries across 80 versions & 3 rubygems

Version Path
standard-performance-1.6.0 lib/standard/performance/plugin.rb
standard-performance-1.5.0 lib/standard/performance/plugin.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
standard-performance-1.3.1 lib/standard/performance/plugin.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/plugin.rb