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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0be084d42bce81134fcc2055df53cd9a3b639814b7e64f91e3c2e05faa4675ce
4
- data.tar.gz: f4c0f98c8b6597cbd136e2990f50767892ba2797d9b351ec8e3e277ff7d67910
3
+ metadata.gz: f79913870ce4e07e94a76c49bfdb2bdf671b72cfe28b9c8d23d3dcfe723b9093
4
+ data.tar.gz: 1fbbe5ecbb1b9b093997cf96f4102c089305ef35f5bf0523406924120cb5906e
5
5
  SHA512:
6
- metadata.gz: 1e9a9a9912071e338b36f0e4db34a8077c896fa6356d3ffa31a064a5ce7201d31a778895fbf051003640dcd92b837456202487c8b275236457063b451dc5c752
7
- data.tar.gz: c4923a5c46669684793406b8dd70ce9b0d8f974fd280f846da920e018613e292ac235137254cb17b8c15ea8eebcf5da0c059602dce83a2b95df99f98760a6626
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (1.22.0)
4
+ standard (1.22.1)
5
5
  language_server-protocol (~> 3.17.0.2)
6
6
  rubocop (= 1.42.0)
7
7
  rubocop-performance (= 1.15.2)
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:` setting:
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
- Which in turn would refer to a RuboCop configuration file:
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
- When Standard runs, it will merge your configuration files with Standard's base
431
- ruleset. To ensure that this feature does not result in Standard's rules being
432
- modified, any configuration of rules includued in `rubocop` or
433
- `rubocop-performance` will be ignored. Most settings under `AllCops:` can be
434
- configured, unless they'd conflict with a setting used by Standard (like
435
- `TargetRubyVersion`) or prevent Standard's own rules from running (like
436
- `StyleGuideCopsOnly`). If you specify multiple YAML files under `extend_config`,
437
- note that their resulting RuboCop configurations will be merged in order (i.e.
438
- last-in-wins).
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
@@ -1269,6 +1269,7 @@ Style/EmptyCaseCondition:
1269
1269
 
1270
1270
  Style/EmptyElse:
1271
1271
  Enabled: true
1272
+ AllowComments: true
1272
1273
  EnforcedStyle: both
1273
1274
 
1274
1275
  Style/EmptyHeredoc:
@@ -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
- "AllCops" => {}
25
- }.tap do |config|
26
- standard_config[:extend_config].each do |path|
27
- extension = RuboCop::ConfigLoader.load_file(Standard::FileFinder.new.call(path, Dir.pwd)).to_h
28
- config["AllCops"].merge!(extension["AllCops"]) if extension.key?("AllCops")
29
- config.merge!(except(extension, ["AllCops"]))
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 except(hash, keys)
47
- hash.reject { |key, _| keys.include?(key) }.to_h
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
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("1.22.0")
2
+ VERSION = Gem::Version.new("1.22.1")
3
3
  end
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.0
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-14 00:00:00.000000000 Z
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.26
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