standard 1.22.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +48 -11
- data/config/base.yml +1 -0
- data/lib/standard/creates_config_store/merges_user_config_extensions.rb +29 -12
- data/lib/standard/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f79913870ce4e07e94a76c49bfdb2bdf671b72cfe28b9c8d23d3dcfe723b9093
         | 
| 4 | 
            +
              data.tar.gz: 1fbbe5ecbb1b9b093997cf96f4102c089305ef35f5bf0523406924120cb5906e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 19e734ff2ab15102430f2cd927ef9beed5c403b6e7b30804bb8baf23d83978ffdfeec3324482d957daae0bd7efbbc7ebcd9bce9bc9f9a84e81c85839c2f30eb0
         | 
| 7 | 
            +
              data.tar.gz: a3135a540a166b292633aa3e2adb11854f09b67fa07dccbc5199de73efa5d289b4612b10917481791563105bdc815a89e7912e054a737428fb55c25c32cfe0bb
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,12 @@ | |
| 1 1 | 
             
            # Changelog
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 1.22.1
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            * Improve the behavior of `extend_config` to more accurately reflect how Rubocop
         | 
| 6 | 
            +
            extensions would behave when loaded via the `rubocop` CLI (by capturing any
         | 
| 7 | 
            +
            mutations to RuboCop's default configuration)
         | 
| 8 | 
            +
            [#512](https://github.com/testdouble/standard/pull/512)
         | 
| 9 | 
            +
             | 
| 3 10 | 
             
            ## 1.22.0
         | 
| 4 11 |  | 
| 5 12 | 
             
            * Add `extend_config` option [#506](https://github.com/testdouble/standard/pull/506)
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -219,6 +219,7 @@ Here are a few examples of Ruby Standard-compliant teams & projects: | |
| 219 219 |  | 
| 220 220 | 
             
            * [Test Double](https://testdouble.com/agency)
         | 
| 221 221 | 
             
            * [Amazon Web Services](https://aws.amazon.com/)
         | 
| 222 | 
            +
            * [Arrows](https://arrows.to/)
         | 
| 222 223 | 
             
            * [Babylist](https://www.babylist.com/)
         | 
| 223 224 | 
             
            * [Brand New Box](https://brandnewbox.com)
         | 
| 224 225 | 
             
            * [Brave Software](https://github.com/brave-intl/publishers)
         | 
| @@ -402,18 +403,49 @@ work for older Rubies. | |
| 402 403 | 
             
            If you want to use Standard in conjunction with RuboCop extensions or custom
         | 
| 403 404 | 
             
            cops, you can specify them in your own [RuboCop configuration
         | 
| 404 405 | 
             
            YAML](https://docs.rubocop.org/rubocop/configuration.html) files and
         | 
| 405 | 
            -
            `.standard.yml` using the "extend_config | 
| 406 | 
            +
            `.standard.yml` using the "extend_config` setting.
         | 
| 407 | 
            +
             | 
| 408 | 
            +
            For a simple example, you could include [rubocop-rails](https://github.com/rubocop/rubocop-rails)
         | 
| 409 | 
            +
            when Standard runs by first specifying a file in `.standard.yml`:
         | 
| 410 | 
            +
             | 
| 411 | 
            +
            ```yaml
         | 
| 412 | 
            +
            # .standard.yml
         | 
| 413 | 
            +
             | 
| 414 | 
            +
            extend_config:
         | 
| 415 | 
            +
              - .standard_rubocop_extensions.yml
         | 
| 416 | 
            +
            ```
         | 
| 417 | 
            +
             | 
| 418 | 
            +
            And a minimal RuboCop configuration file:
         | 
| 419 | 
            +
             | 
| 420 | 
            +
            ```yaml
         | 
| 421 | 
            +
            # .standard_rubocop_extensions.yml
         | 
| 422 | 
            +
             | 
| 423 | 
            +
            require:
         | 
| 424 | 
            +
              - rubocop-rails
         | 
| 425 | 
            +
            ```
         | 
| 426 | 
            +
             | 
| 427 | 
            +
            That's it! Now, in addition to all of Standard's built-in rules, `standardrb`
         | 
| 428 | 
            +
            and `rake standard` will also execute the default configuration of the
         | 
| 429 | 
            +
            `rubocop-rails` gem without needing to invoke `rubocop` separately.
         | 
| 430 | 
            +
             | 
| 431 | 
            +
            For a slightly more complex example, we could add the
         | 
| 432 | 
            +
            [https://github.com/Betterment/betterlint] gem from our friends at
         | 
| 433 | 
            +
            [Betterment](https://www.betterment.com), first by telling Standard where our
         | 
| 434 | 
            +
            configuration file is:
         | 
| 406 435 |  | 
| 407 436 | 
             
            ```yml
         | 
| 408 437 | 
             
            # .standard.yml
         | 
| 438 | 
            +
             | 
| 409 439 | 
             
            extend_config:
         | 
| 410 440 | 
             
              - .betterlint.yml
         | 
| 411 441 | 
             
            ```
         | 
| 412 442 |  | 
| 413 | 
            -
             | 
| 443 | 
            +
            But if we only wanted to enable a particular rule, we could configure it more
         | 
| 444 | 
            +
            narrowly, like this:
         | 
| 414 445 |  | 
| 415 446 | 
             
            ```yml
         | 
| 416 447 | 
             
            # .betterlint.yml
         | 
| 448 | 
            +
             | 
| 417 449 | 
             
            require:
         | 
| 418 450 | 
             
              - rubocop/cop/betterment.rb
         | 
| 419 451 |  | 
| @@ -427,15 +459,20 @@ Betterment/UnscopedFind: | |
| 427 459 | 
             
                - SystemConfiguration
         | 
| 428 460 | 
             
            ```
         | 
| 429 461 |  | 
| 430 | 
            -
             | 
| 431 | 
            -
             | 
| 432 | 
            -
             | 
| 433 | 
            -
             | 
| 434 | 
            -
             | 
| 435 | 
            -
             | 
| 436 | 
            -
             | 
| 437 | 
            -
             | 
| 438 | 
            -
             | 
| 462 | 
            +
            This same approach works for more than just gems! Just require a Ruby file that
         | 
| 463 | 
            +
            defines or loads your [custom RuboCop
         | 
| 464 | 
            +
            implementation](https://docs.rubocop.org/rubocop/development.html) and configure
         | 
| 465 | 
            +
            it using `extend_config`.
         | 
| 466 | 
            +
             | 
| 467 | 
            +
            When Standard encounters an `extend_config` property, it will merge your
         | 
| 468 | 
            +
            configuration files with Standard's base ruleset. To prevent Standard's built-in
         | 
| 469 | 
            +
            rules from being modified, any configuration of rules includued in the `rubocop`
         | 
| 470 | 
            +
            or `rubocop-performance` gems will be ignored. Most settings under `AllCops:`
         | 
| 471 | 
            +
            can be configured, however, unless they'd conflict with a setting used by
         | 
| 472 | 
            +
            Standard (like `TargetRubyVersion`) or prevent Standard's own rules from running
         | 
| 473 | 
            +
            (like `StyleGuideCopsOnly`). If you specify multiple YAML files under
         | 
| 474 | 
            +
            `extend_config`, note that their resulting RuboCop configurations will be merged
         | 
| 475 | 
            +
            in order (i.e.  last-in-wins).
         | 
| 439 476 |  | 
| 440 477 | 
             
            If you find that Standard's `extend_config` feature doesn't meet your needs,
         | 
| 441 478 | 
             
            Evil Martians also maintains [a regularly updated
         | 
    
        data/config/base.yml
    CHANGED
    
    
| @@ -6,27 +6,31 @@ class Standard::CreatesConfigStore | |
| 6 6 | 
             
                  "Include",
         | 
| 7 7 | 
             
                  "Exclude",
         | 
| 8 8 | 
             
                  "StyleGuideCopsOnly",
         | 
| 9 | 
            -
                  "TargetRubyVersion"
         | 
| 9 | 
            +
                  "TargetRubyVersion",
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  # The AllCops[Enabled] key is an unused artifact of #merge_with_default.
         | 
| 12 | 
            +
                  # See: https://github.com/rubocop/rubocop/blob/master/lib/rubocop/config_loader_resolver.rb#L81-L85
         | 
| 13 | 
            +
                  "Enabled"
         | 
| 10 14 | 
             
                ].freeze
         | 
| 11 15 |  | 
| 12 16 | 
             
                def call(options_config, standard_config)
         | 
| 13 17 | 
             
                  return unless standard_config[:extend_config]&.any?
         | 
| 14 18 |  | 
| 15 | 
            -
                  extended_config = load_and_merge_extended_rubocop_configs(standard_config)
         | 
| 19 | 
            +
                  extended_config = load_and_merge_extended_rubocop_configs(options_config, standard_config).to_h
         | 
| 16 20 | 
             
                  merge_standard_and_user_all_cops!(options_config, extended_config)
         | 
| 17 21 | 
             
                  merge_extended_rules_into_standard!(options_config, extended_config)
         | 
| 18 22 | 
             
                end
         | 
| 19 23 |  | 
| 20 24 | 
             
                private
         | 
| 21 25 |  | 
| 22 | 
            -
                def load_and_merge_extended_rubocop_configs(standard_config)
         | 
| 23 | 
            -
                   | 
| 24 | 
            -
                     | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
                       | 
| 28 | 
            -
                       | 
| 29 | 
            -
                       | 
| 26 | 
            +
                def load_and_merge_extended_rubocop_configs(options_config, standard_config)
         | 
| 27 | 
            +
                  fake_out_rubocop_default_configuration(options_config) do |fake_config|
         | 
| 28 | 
            +
                    standard_config[:extend_config].reduce(fake_config) do |config, path|
         | 
| 29 | 
            +
                      RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      user_rubocop_yaml_path = Standard::FileFinder.new.call(path, Dir.pwd)
         | 
| 32 | 
            +
                      extension = RuboCop::ConfigLoader.load_file(user_rubocop_yaml_path)
         | 
| 33 | 
            +
                      RuboCop::ConfigLoader.merge_with_default(extension, path)
         | 
| 30 34 | 
             
                    end
         | 
| 31 35 | 
             
                  end
         | 
| 32 36 | 
             
                end
         | 
| @@ -43,8 +47,21 @@ class Standard::CreatesConfigStore | |
| 43 47 | 
             
                  end
         | 
| 44 48 | 
             
                end
         | 
| 45 49 |  | 
| 46 | 
            -
                def  | 
| 47 | 
            -
                   | 
| 50 | 
            +
                def fake_out_rubocop_default_configuration(options_config)
         | 
| 51 | 
            +
                  og_default_config = RuboCop::ConfigLoader.instance_variable_get(:@default_configuration)
         | 
| 52 | 
            +
                  result = yield blank_rubocop_config(options_config)
         | 
| 53 | 
            +
                  RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, og_default_config)
         | 
| 54 | 
            +
                  result
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                # Blank configuration object to merge extensions into, with all known
         | 
| 58 | 
            +
                # AllCops keys set to avoid warnings about unknown properties
         | 
| 59 | 
            +
                def blank_rubocop_config(example_config)
         | 
| 60 | 
            +
                  RuboCop::Config.new(example_config.to_h.slice("AllCops"), "")
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def except(hash_or_config, keys)
         | 
| 64 | 
            +
                  hash_or_config.to_h.reject { |key, _| keys.include?(key) }.to_h
         | 
| 48 65 | 
             
                end
         | 
| 49 66 | 
             
              end
         | 
| 50 67 | 
             
            end
         | 
    
        data/lib/standard/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: standard
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.22. | 
| 4 | 
            +
              version: 1.22.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Justin Searls
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-01- | 
| 11 | 
            +
            date: 2023-01-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rubocop
         | 
| @@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 135 135 | 
             
                - !ruby/object:Gem::Version
         | 
| 136 136 | 
             
                  version: '0'
         | 
| 137 137 | 
             
            requirements: []
         | 
| 138 | 
            -
            rubygems_version: 3.3. | 
| 138 | 
            +
            rubygems_version: 3.3.7
         | 
| 139 139 | 
             
            signing_key:
         | 
| 140 140 | 
             
            specification_version: 4
         | 
| 141 141 | 
             
            summary: Ruby Style Guide, with linter & automatic code fixer
         |