lint_roller-1.1.0/0000755000004100000410000000000015144420047014067 5ustar www-datawww-datalint_roller-1.1.0/Gemfile.lock0000644000004100000410000000226715144420046016317 0ustar www-datawww-dataPATH remote: . specs: lint_roller (1.1.0) GEM remote: https://rubygems.org/ specs: ast (2.4.2) json (2.6.3) language_server-protocol (3.17.0.3) m (1.6.1) method_source (>= 0.6.7) rake (>= 0.9.2.2) method_source (1.0.0) minitest (5.18.0) parallel (1.22.1) parser (3.2.2.0) ast (~> 2.4.1) rainbow (3.1.1) rake (13.0.6) regexp_parser (2.7.0) rexml (3.2.5) rubocop (1.48.1) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.26.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.28.0) parser (>= 3.2.1.0) rubocop-performance (1.16.0) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) ruby-progressbar (1.13.0) standard (1.26.0) language_server-protocol (~> 3.17.0.2) rubocop (~> 1.48.1) rubocop-performance (~> 1.16.0) unicode-display_width (2.4.2) PLATFORMS arm64-darwin-22 x86_64-linux DEPENDENCIES lint_roller! m minitest rake standard BUNDLED WITH 2.4.10 lint_roller-1.1.0/.standard.yml0000644000004100000410000000015115144420046016464 0ustar www-datawww-data# For available configuration options, see: # https://github.com/testdouble/standard ruby_version: 2.6 lint_roller-1.1.0/lib/0000755000004100000410000000000015144420046014634 5ustar www-datawww-datalint_roller-1.1.0/lib/lint_roller/0000755000004100000410000000000015144420046017161 5ustar www-datawww-datalint_roller-1.1.0/lib/lint_roller/error.rb0000644000004100000410000000007215144420046020636 0ustar www-datawww-datamodule LintRoller class Error < StandardError end end lint_roller-1.1.0/lib/lint_roller/rules.rb0000644000004100000410000000125315144420046020641 0ustar www-datawww-datamodule LintRoller Rules = Struct.new( # Valid values: :path, :object, :error :type, # Only known value right now is :rubocop but nothing would stop rufo or # rubyfmt or prettier from adding support without a change to the gem :config_format, # If type is :path, String or Pathname. Otherwise, whatever :object type # makes sense given :config_format (e.g. for RuboCop, a Hash loaded from a # YAML file; note that providing a hash will prevent the use of RuboCop features # like `inherit_from' and `require'!) :value, # If something went wrong an Error for the runner to deal with appropriately :error, keyword_init: true ) end lint_roller-1.1.0/lib/lint_roller/about.rb0000644000004100000410000000044315144420046020621 0ustar www-datawww-datamodule LintRoller About = Struct.new( :name, # "standard-performance" :version, # "1.2.3" :homepage, # "https://github.com/testdouble/standard-performance" :description, # "A configuration of rubocop-performance rules to make Ruby go faster" keyword_init: true ) end lint_roller-1.1.0/lib/lint_roller/plugin.rb0000644000004100000410000000116515144420046021007 0ustar www-datawww-datamodule LintRoller class Plugin # `config' is a Hash of options passed to the plugin by the user def initialize(config = {}) @config = config end def about raise Error.new("Please implement `about` and return an instance of LintRoller::About") end # `context' is an instance of LintRoller::Context provided by the runner def supported?(context) true end # `context' is an instance of LintRoller::Context provided by the runner def rules(context) raise Error.new("Please implement `rules(context)` and return an instance of LintRoller::Rules") end end end lint_roller-1.1.0/lib/lint_roller/context.rb0000644000004100000410000000042615144420046021174 0ustar www-datawww-datamodule LintRoller Context = Struct.new( :runner, # :standard, :rubocop :runner_version, # "1.2.3" :engine, # :rubocop :engine_version, # "2.3.4", :rule_format, # :rubocop :target_ruby_version, # Gem::Version.new("2.7.0") keyword_init: true ) end lint_roller-1.1.0/lib/lint_roller/version.rb0000644000004100000410000000005215144420046021170 0ustar www-datawww-datamodule LintRoller VERSION = "1.1.0" end lint_roller-1.1.0/lib/lint_roller/support/0000755000004100000410000000000015144420046020675 5ustar www-datawww-datalint_roller-1.1.0/lib/lint_roller/support/merges_upstream_metadata.rb0000644000004100000410000000130315144420046026261 0ustar www-datawww-datamodule LintRoller module Support class MergesUpstreamMetadata def merge(plugin_yaml, upstream_yaml) common_upstream_values = upstream_yaml.select { |key| plugin_yaml.key?(key) } plugin_yaml.merge(common_upstream_values) { |key, plugin_value, upstream_value| if plugin_value.is_a?(Hash) && upstream_value.is_a?(Hash) plugin_value.merge(upstream_value) { |sub_key, plugin_sub_value, upstream_sub_value| if plugin_value.key?(sub_key) plugin_sub_value else upstream_sub_value end } else plugin_value end } end end end end lint_roller-1.1.0/lib/lint_roller.rb0000644000004100000410000000047515144420046017514 0ustar www-datawww-datarequire_relative "lint_roller/version" require_relative "lint_roller/about" require_relative "lint_roller/context" require_relative "lint_roller/rules" require_relative "lint_roller/plugin" require_relative "lint_roller/error" require_relative "lint_roller/support/merges_upstream_metadata" module LintRoller end lint_roller-1.1.0/LICENSE.txt0000644000004100000410000000207415144420046015714 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2023 Test Double, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. lint_roller-1.1.0/Rakefile0000644000004100000410000000035415144420046015535 0ustar www-datawww-datarequire "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new(:test) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList["test/**/*_test.rb"] end require "standard/rake" task default: %i[test standard:fix] lint_roller-1.1.0/Gemfile0000644000004100000410000000022215144420046015355 0ustar www-datawww-datasource "https://rubygems.org" # Specify your gem's dependencies in lint_roller.gemspec gemspec gem "rake" gem "minitest" gem "standard" gem "m" lint_roller-1.1.0/lint_roller.gemspec0000644000004100000410000000312615144420047017763 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: lint_roller 1.1.0 ruby lib Gem::Specification.new do |s| s.name = "lint_roller".freeze s.version = "1.1.0".freeze s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "changelog_uri" => "https://github.com/standardrb/lint_roller/blob/main/CHANGELOG.md", "homepage_uri" => "https://github.com/standardrb/lint_roller", "source_code_uri" => "https://github.com/standardrb/lint_roller" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Justin Searls".freeze] s.bindir = "exe".freeze s.date = "2023-07-07" s.email = ["searls@gmail.com".freeze] s.files = [".standard.yml".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "lib/lint_roller.rb".freeze, "lib/lint_roller/about.rb".freeze, "lib/lint_roller/context.rb".freeze, "lib/lint_roller/error.rb".freeze, "lib/lint_roller/plugin.rb".freeze, "lib/lint_roller/rules.rb".freeze, "lib/lint_roller/support/merges_upstream_metadata.rb".freeze, "lib/lint_roller/version.rb".freeze] s.homepage = "https://github.com/standardrb/lint_roller".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.6.0".freeze) s.rubygems_version = "3.4.14".freeze s.summary = "A plugin specification for linter and formatter rulesets".freeze end lint_roller-1.1.0/README.md0000644000004100000410000001367315144420046015357 0ustar www-datawww-data# lint_roller - A plugin specification for linters `lint_roller` is an itty-bitty plugin API for code analysis tools like linters and formatters. It provides plugins for those tools to load extensions and specify custom rulesets. (As of this release, only [Standard Ruby](https://github.com/standardrb/standard) supports `lint_roller` plugins, but we think [RuboCop](https://github.com/rubocop/rubocop) could add support and most plugins would be compatible with both `rubocop` and `standardrb`. Additionally, there's nothing that would prevent other tools like [rufo](https://github.com/ruby-formatter/rufo) from adopting it.) ## How to make a plugin If you want to make a plugin, the first thing you should do is extend [LintRoller::Plugin](/lib/lint_roller/plugin.rb) with a custom class. Let's take this example plugin for banana-related static analysis: ```ruby module BananaRoller class Plugin < LintRoller::Plugin # `config' is a Hash of options passed to the plugin by the user def initialize(config = {}) @alternative = config["alternative"] ||= "chocolate" end def about LintRoller::About.new( name: "banana_roller", version: "1.0", # or, in a gem, probably BananaRoller::VERSION homepage: "https://github.com/example/banana_roller", description: "Configuration of banana-related code" ) end # `context' is an instance of LintRoller::Context provided by the runner def supported?(context) context.engine == :rubocop end # `context' is an instance of LintRoller::Context provided by the runner def rules(context) LintRoller::Rules.new( type: :path, config_format: :rubocop, value: Pathname.new(__dir__).join("../../config/default.yml") ) end end end ``` And that's pretty much it. Just a declarative way to identify your plugin, detect whether it supports the given [LintRoller::Context](/lib/lint_roller_context.rb) (e.g. the current `runner` and `engine` and their respective `_version`s), for which the plugin will ultimately its configuration as a [LintRoller::Rules](/lib/lint_roller/rules.rb) object. ## Packaging a plugin in a gem In order for a formatter to use your plugin, it needs to know what path to require as well as the name of the plugin class to instantiate and invoke. To make this work seamlessly for your users without additional configuration of their own, all you need to do is specify a metadata attribute called `default_lint_roller_plugin` in your gemspec. Taking [standard-custom](https://github.com/standardrb/standard-custom) as an example, its gemspec contains: ```ruby Gem::Specification.new do |spec| # … spec.metadata["default_lint_roller_plugin"] = "Standard::Custom::Plugin" # … end ``` Because gem specs are loaded by RubyGems and Bundler very early, remember to specify the plugin as a string representation of the constant, as load order usually matters, and most tools will need to be loaded before any custom extensions. Hence, `"Standard::Custom::Plugin"` instead of `Standard::Custom::Plugin`. ## Using your plugin Once you've made your plugin, here's how it's configured from a Standard Ruby `.standard.yml` file. ### If your plugin is packaged as a gem Packaging your plugin in a gem is the golden path, both because distributing code via [RubyGems.org](https://rubygems.org) is very neat, but also because it makes the least work for your users. If your gem name is `banana_roller` and you've set `spec.metadata["default_lint_roller_plugin"]` to `"BananaRoller::Plugin"`, then your users could just add this to their `.standard.yml` file: ```yaml plugins: - banana_roller ``` And that's it! During initialization, `standardrb` will `require "banana_roller"` and know to call `BananaRoller::Plugin.new(config)` to instantiate it. ### If your plugin ISN'T in a gem If you're developing a plugin for internal use or in conjunction with a single project, you may want it to live in the same repo as opposed to packaging it in a gem. To do this, then—in lieu of a gem name—provide the path you want to be required as its name, and (since there is no `spec.metadata` to learn of your plugin's class name), specify it as an option on the plugin: ```yaml plugins: - lib/banana_roller/plugin: plugin_class_name: BananaRoller::Plugin ``` (Be careful with the indentation here! Any configuration under a plugin must be indented in order for it to be parsed as a hash under the `"lib/banana_roller/plugin"` key.) Additionally, if you want the plugin's name to make more sense, you can give it whatever name you like in the configuration and specify the `require_path` explicitly: ```yaml plugins: - banana_roller: require_path: lib/banana_roller/plugin plugin_class_name: BananaRoller::Plugin ``` ### Passing user configuration to the plugin When a `LintRoller::Plugin` is instantiated, users can pass a configuration hash that tells your plugin how to behave. To illustrate how this works in Standard Ruby, anything passed as a hash beneath a plugin will be passed to the class's `initialize` method: ```yaml plugins: - apple_roller - banana_roller: require_path: lib/banana_roller/plugin plugin_class_name: BananaRoller::Plugin alternative: "apples" - orange_roller: rind: false ``` In the above case, `apple_roller`'s plugin class will be instantiated with `new({})`, `banana_roller` will get all 3 of those parameters passed `BananaRoller::Plugin.new({require_path…})`, and `orange_roller`'s class will be called with `new({rind: false})`. ## Code of Conduct This project follows Test Double's [code of conduct](https://testdouble.com/code-of-conduct) for all community interactions, including (but not limited to) one-on-one communications, public posts/comments, code reviews, pull requests, and GitHub issues. If violations occur, Test Double will take any action they deem appropriate for the infraction, up to and including blocking a user from the organization's repositories. lint_roller-1.1.0/CHANGELOG.md0000644000004100000410000000105615144420046015701 0ustar www-datawww-data## [Unreleased] ## [1.1.0] - Add `LintRoller::Support` module of classes designed to make it a little easier to author plugins. `MergesUpstreamMetadata#merge` will allow a minimal YAML config (say, `standard-sorbet`'s, which only contains `Enabled` values for each rule) to merge in any other defaults from a source YAML (e.g. `rubocop-sorbet`'s which includes `Description`, `VersionAdded`, and so on). This way that metadata is neither absent at runtime nor duplicated in a standard plugin that mirrors a rubocop extension ## [1.0.0] - Initial release