standard 0.12.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ece6905a02f43b8e9787ca829e9940f6cd811ce19cc5c73aaa29b39308e86de3
4
- data.tar.gz: 420fa134ef9a26d7ab7d6ce72cebb28ca951d03795e95fdf43072af4b5039848
3
+ metadata.gz: b1ffe5112549df3b2c10c013937dc42d459d6ee098971d214ece1d00482d3b97
4
+ data.tar.gz: e796e1c215cc354d9098583b5d1f69860852096c79d293ff935b9c4d3fda9fe6
5
5
  SHA512:
6
- metadata.gz: 70f35192a65faf716fed5b62ebafd6c6de6e8d54e06e38a8d07bd071b2cff8ff4aab81b8cb9089fd7941ff14b19edf19a37b5468e1eb9eaa7a29e0ece6b925d5
7
- data.tar.gz: 00b5ed175cc6e8a47cee92b132dd1a9bbd32f1a2d21284bec0c07be75341eeedc6a44761b1f5f7978517ab4830704b5324df9c28b110371c81ed308589b7641a
6
+ metadata.gz: 7925123a27c8140624f9ec4903f3546c7e7aa9e0ba48244f362e570ed4a4a2a34304621f78e964d6445e15ef1046ee4fd410e80e05ff308886be1d77d2324d6c
7
+ data.tar.gz: f00df60430fabfddd8e2f389a5b7e4d8701d2ce0b0ca92c828e28331d64ee5ca2616053a04094f23ab3d5a340e276561be6a97d0f21bd351d407e2bd94b2598e
data/CHANGELOG.md CHANGED
@@ -1,11 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ * Fix an exit code bug introduced in 1.0.2
6
+ ([#271](https://github.com/testdouble/standard/pull/272)
7
+
8
+ ## 1.0.2
9
+
10
+ * Preserve RuboCop's CLI exit codes
11
+ ([#270](https://github.com/testdouble/standard/pull/270)) by
12
+ [@nicksieger](https://github.com/nicksieger)
13
+
14
+ ## 1.0.1
15
+
16
+ * Update rubocop from 1.10.0 to [1.11.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.11.0)
17
+ * Update rubocop-performance from 1.9.2 to [1.10.1](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.10.1)
18
+
19
+ ## 1.0.0
20
+
21
+ * Relax multi-line block rules, moving away from enforcing semantic blocks to
22
+ instead allowing code to adhere to whatever multi-line format the author deems
23
+ best [#263](https://github.com/testdouble/standard/pull/263)
24
+ * Allow a `standard:disable` comment directive in addition to `rubocop:disable`
25
+ [#186](https://github.com/testdouble/standard/pull/186)
26
+ * Remove the banner text that standard outputs after failure
27
+ [#264](https://github.com/testdouble/standard/pull/264)
28
+
29
+ ## 0.13.0
30
+
31
+ * Update rubocop from 1.7.0 to [1.10.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.10.0) enabling:
32
+ * [`Lint/AmbiguousAssignment`](https://github.com/rubocop-hq/rubocop/issues/9223)
33
+ * [`Style/HashExcept`](https://github.com/rubocop-hq/rubocop/pull/9283)
34
+ * [`Lint/DeprecatedConstants`](https://github.com/rubocop-hq/rubocop/pull/9324)
35
+
3
36
  ## 0.12.0
4
37
 
5
38
  * Update rubocop from 1.7.0 to [1.8.1](https://github.com/rubocop-hq/rubocop/releases/tag/v1.8.1)
6
39
  * Enabled [`Style/SlicingWithRange`](https://github.com/testdouble/standard/issues/175)
7
40
 
8
- ## 0.11.0
41
+ ## 0.11.0
9
42
 
10
43
  * Update rubocop-performance from 1.9.1 to [1.9.2](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.9.2)
11
44
  * Update rubocop from 1.4.2 to [1.7.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.7.0)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (0.12.0)
5
- rubocop (= 1.8.1)
6
- rubocop-performance (= 1.9.2)
4
+ standard (1.0.3)
5
+ rubocop (= 1.11.0)
6
+ rubocop-performance (= 1.10.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -13,18 +13,18 @@ GEM
13
13
  docile (1.3.5)
14
14
  gimme (0.5.0)
15
15
  method_source (1.0.0)
16
- minitest (5.14.3)
16
+ minitest (5.14.4)
17
17
  parallel (1.20.1)
18
18
  parser (3.0.0.0)
19
19
  ast (~> 2.4.1)
20
- pry (0.13.1)
20
+ pry (0.14.0)
21
21
  coderay (~> 1.1)
22
22
  method_source (~> 1.0)
23
23
  rainbow (3.0.0)
24
24
  rake (13.0.3)
25
- regexp_parser (2.0.3)
25
+ regexp_parser (2.1.1)
26
26
  rexml (3.2.4)
27
- rubocop (1.8.1)
27
+ rubocop (1.11.0)
28
28
  parallel (~> 1.10)
29
29
  parser (>= 3.0.0.0)
30
30
  rainbow (>= 2.2.2, < 4.0)
@@ -35,7 +35,7 @@ GEM
35
35
  unicode-display_width (>= 1.4.0, < 3.0)
36
36
  rubocop-ast (1.4.1)
37
37
  parser (>= 2.7.1.5)
38
- rubocop-performance (1.9.2)
38
+ rubocop-performance (1.10.1)
39
39
  rubocop (>= 0.90.0, < 2.0)
40
40
  rubocop-ast (>= 0.4.0)
41
41
  ruby-progressbar (1.11.0)
@@ -49,6 +49,7 @@ GEM
49
49
 
50
50
  PLATFORMS
51
51
  ruby
52
+ x86_64-darwin-20
52
53
 
53
54
  DEPENDENCIES
54
55
  bundler
@@ -60,4 +61,4 @@ DEPENDENCIES
60
61
  standard!
61
62
 
62
63
  BUNDLED WITH
63
- 2.2.6
64
+ 2.2.3
data/LICENSE.txt CHANGED
@@ -2,7 +2,7 @@ Copyright (c) 2019 Test Double, LLC
2
2
 
3
3
  Portions of these files Copyright (c) 2012-18 Bozhidar Batsov:
4
4
  - config/base.yml
5
- - lib/standard/cop/semantic_blocks.rb
5
+ - lib/standard/cop/block_delimiters.rb
6
6
  - test/cop_invoker.rb
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -40,10 +40,12 @@ flag.
40
40
  you'll need interpolation in a string slows people down
41
41
  - **1.9 hash syntax** - When all the keys in a hash literal are symbols,
42
42
  Standard enforces Ruby 1.9's `{hash: syntax}`
43
- - **Semantic blocks** - `{`/`}` for functional blocks that return a value, and
44
- `do`/`end` for procedural blocks that have side effects. More
45
- [here](http://www.virtuouscode.com/2011/07/26/the-procedurefunction-block-convention-in-ruby/)
46
- and [here](https://github.com/rubocop-hq/ruby-style-guide/issues/162)
43
+ - **Braces for single-line blocks** - Require `{`/`}` for one-line blocks, but
44
+ allow either braces or `do`/`end` for multiline blocks. Like using `do`/`end`
45
+ for multiline blocks? Prefer `{`/`}` when chaining? A fan of expressing intent
46
+ with Jim Weirich's [semantic
47
+ block](http://www.virtuouscode.com/2011/07/26/the-procedurefunction-block-convention-in-ruby/)
48
+ approach? Standard lets you do you!
47
49
  - **Leading dots on multi-line method chains** - chosen for
48
50
  [these](https://github.com/testdouble/standard/issues/75) reasons.
49
51
  - **Spaces inside blocks, but not hash literals** - In Ruby, the `{` and `}`
@@ -58,12 +60,6 @@ can look at Standard's current base configuration in
58
60
  significant changes to the configuration will be documented as [GitHub release
59
61
  notes](https://github.com/testdouble/standard/releases).
60
62
 
61
- **[NOTE: until StandardRB hits 1.0.0, we consider this configuration to be a
62
- non-final work in progress and we encourage you to submit your opinions (and
63
- reasoned arguments) for the addition, removal, or change to a rule by [opening
64
- an issue](https://github.com/testdouble/standard/issues/new). If you start using
65
- Standard, don't be shocked if things change a bit!]**
66
-
67
63
  ## Usage
68
64
 
69
65
  Once you've installed Standard, you should be able to use the `standardrb`
@@ -235,11 +231,6 @@ style.
235
231
 
236
232
  ## I disagree with rule X, can you change it?
237
233
 
238
- **[NOTE: until StandardRB hits 1.0.0, the answer is yes! It just requires
239
- [opening an issue](https://github.com/testdouble/standard/issues/new) and
240
- convincing [@searls](https://twitter.com/searls) (the BDFNow) to make the
241
- change.]**
242
-
243
234
  No. The whole point of Standard is to save you time by avoiding
244
235
  [bikeshedding](https://www.freebsd.org/doc/en/books/faq/misc.html#bikeshed-painting)
245
236
  about code style. There are lots of debates online about tabs vs. spaces, etc.
@@ -302,10 +293,50 @@ ignore:
302
293
  - Style/BlockDelimiters
303
294
  ```
304
295
 
296
+ ## How do I disable a warning within my source code?
297
+
305
298
  You can also use special comments to disable all or certain rules within your
306
- source code. See [RuboCop's
307
- docs](https://docs.rubocop.org/en/latest/configuration/#disabling-cops-within-source-code)
308
- for details.
299
+ source code.
300
+
301
+ Given this source listing `foo.rb`:
302
+
303
+ ```ruby
304
+ baz = 42
305
+ ```
306
+
307
+ Running `standard foo.rb` would fail:
308
+
309
+ ```
310
+ foo.rb:1:1: Lint/UselessAssignment: Useless assignment to variable - `baz`.
311
+ ```
312
+
313
+ If we wanted to make an exception, we could add the following comment:
314
+
315
+ ```ruby
316
+ baz = 42 # standard:disable Lint/UselessAssignment
317
+ ```
318
+
319
+ The comment directives (both `standard:disable` and `rubocop:disable`) will
320
+ suppress the error and Standard would succeed.
321
+
322
+ If, however, you needed to disable standard for multiple lines, you could use
323
+ open and closing directives like this:
324
+
325
+ ```ruby
326
+ # standard:disable Layout/IndentationWidth
327
+ def foo
328
+ 123
329
+ end
330
+ # standard:enable Layout/IndentationWidth
331
+ ```
332
+
333
+ And if you don't know or care which rule is being violated, you can also
334
+ substitute its name for "all". This line actually triggers three different
335
+ violations, so we can suppress them like this:
336
+
337
+ ```ruby
338
+ baz = ['a'].each do end # standard:disable all
339
+ ```
309
340
 
310
341
  ## How do I specify a Ruby version? What is supported?
311
342
 
data/config/base.yml CHANGED
@@ -329,6 +329,9 @@ Layout/TrailingWhitespace:
329
329
  Enabled: true
330
330
  AllowInHeredoc: true
331
331
 
332
+ Lint/AmbiguousAssignment:
333
+ Enabled: true
334
+
332
335
  Lint/AmbiguousOperator:
333
336
  Enabled: true
334
337
 
@@ -360,6 +363,9 @@ Lint/Debugger:
360
363
  Lint/DeprecatedClassMethods:
361
364
  Enabled: true
362
365
 
366
+ Lint/DeprecatedConstants:
367
+ Enabled: true
368
+
363
369
  Lint/DeprecatedOpenSSLConstant:
364
370
  Enabled: true
365
371
 
@@ -732,39 +738,8 @@ Security/YAMLLoad:
732
738
  Enabled: true
733
739
  SafeAutoCorrect: false
734
740
 
735
- Standard/SemanticBlocks:
736
- ProceduralMethods:
737
- - benchmark
738
- - bm
739
- - bmbm
740
- - tap
741
- # Enumerable
742
- - cycle
743
- - each
744
- - each_cons
745
- - each_entry
746
- - each_slice
747
- - each_with_index
748
- # Rails
749
- - transaction
750
- FunctionalMethods:
751
- - given
752
- - given!
753
- - let
754
- - let!
755
- - subject
756
- - watch
757
- - Given
758
- - Given!
759
- - Invariant
760
- - Then
761
- - And
762
- IgnoredMethods:
763
- - lambda
764
- - proc
765
- - describe
766
- - it
767
- - When
741
+ Standard/BlockDelimiters:
742
+ Enabled: true
768
743
 
769
744
  Style/Alias:
770
745
  Enabled: true
@@ -880,6 +855,9 @@ Style/GlobalVars:
880
855
  Enabled: true
881
856
  AllowedVariables: []
882
857
 
858
+ Style/HashExcept:
859
+ Enabled: true
860
+
883
861
  Style/HashSyntax:
884
862
  Enabled: true
885
863
  EnforcedStyle: ruby19_no_mixed_keys
data/config/ruby-2.5.yml CHANGED
@@ -1,4 +1,4 @@
1
- inherit_from: ./base.yml
1
+ inherit_from: ./ruby-2.7.yml
2
2
 
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.5
@@ -0,0 +1,7 @@
1
+ inherit_from: ./base.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.7
5
+
6
+ Style/HashExcept:
7
+ Enabled: true
data/docs/RELEASE.md CHANGED
@@ -23,7 +23,7 @@ really the only one we'll need for releasing the gem to
23
23
 
24
24
  1. Make sure git is up to date and `bundle exec rake` exits cleanly
25
25
  2. If you upgraded a Rubocop dependency, be sure to lock it down in
26
- `standard.gemspec`. Until Rubocop hits 1.0, we're going to stick to exact
26
+ `standard.gemspec`. To avoid being broken transitively, we stick to exact
27
27
  release dependencies (e.g. "0.91.0" instead of "~> 0.91")
28
28
  3. Bump the appropriate version segment in `lib/standard/version.rb` (basic
29
29
  semantic versioning rules apply; if the release updates Rubocop, follow its
data/lib/standard.rb CHANGED
@@ -7,7 +7,7 @@ require "standard/cli"
7
7
  require "standard/railtie" if defined?(Rails) && defined?(Rails::Railtie)
8
8
 
9
9
  require "standard/formatter"
10
- require "standard/cop/semantic_blocks"
10
+ require "standard/cop/block_delimiters"
11
11
 
12
12
  module Standard
13
13
  end
data/lib/standard/cli.rb CHANGED
@@ -3,9 +3,6 @@ require_relative "loads_runner"
3
3
 
4
4
  module Standard
5
5
  class Cli
6
- SUCCESS_STATUS_CODE = 0
7
- FAILURE_STATUS_CODE = 1
8
-
9
6
  def initialize(argv)
10
7
  @argv = argv
11
8
  @builds_config = BuildsConfig.new
@@ -14,10 +11,7 @@ module Standard
14
11
 
15
12
  def run
16
13
  config = @builds_config.call(@argv)
17
-
18
- success = @loads_runner.call(config.runner).call(config)
19
-
20
- success ? SUCCESS_STATUS_CODE : FAILURE_STATUS_CODE
14
+ @loads_runner.call(config.runner).call(config).to_i
21
15
  end
22
16
  end
23
17
  end
@@ -0,0 +1,96 @@
1
+ module RuboCop::Cop
2
+ module Standard
3
+ # Check for uses of braces around single line blocks, but allows either
4
+ # braces or do/end for multi-line blocks.
5
+ #
6
+ # @example
7
+ # # bad - single line block
8
+ # items.each do |item| item / 5 end
9
+ #
10
+ # # good - single line block
11
+ # items.each { |item| item / 5 }
12
+ #
13
+ class BlockDelimiters < RuboCop::Cop::Base
14
+ extend RuboCop::Cop::AutoCorrector
15
+
16
+ def on_send(node)
17
+ return unless node.arguments?
18
+ return if node.parenthesized?
19
+ return if node.operator_method? || node.assignment_method?
20
+
21
+ node.arguments.each do |arg|
22
+ get_blocks(arg) do |block|
23
+ # If there are no parentheses around the arguments, then braces
24
+ # and do-end have different meaning due to how they bind, so we
25
+ # allow either.
26
+ ignore_node(block)
27
+ end
28
+ end
29
+ end
30
+
31
+ def on_block(node)
32
+ return if ignored_node?(node)
33
+ return if proper_block_style?(node)
34
+
35
+ message = message(node)
36
+ add_offense(node.loc.begin, message: message) do |corrector|
37
+ autocorrect(corrector, node)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def get_blocks(node, &block)
44
+ case node.type
45
+ when :block
46
+ yield node
47
+ when :send
48
+ get_blocks(node.receiver, &block) if node.receiver
49
+ when :hash
50
+ # A hash which is passed as method argument may have no braces
51
+ # In that case, one of the K/V pairs could contain a block node
52
+ # which could change in meaning if do...end replaced {...}
53
+ return if node.braces?
54
+
55
+ node.each_child_node { |child| get_blocks(child, &block) }
56
+ when :pair
57
+ node.each_child_node { |child| get_blocks(child, &block) }
58
+ end
59
+ end
60
+
61
+ def proper_block_style?(node)
62
+ node.multiline? || node.braces?
63
+ end
64
+
65
+ def message(node)
66
+ "Prefer `{...}` over `do...end` for single-line blocks."
67
+ end
68
+
69
+ def autocorrect(corrector, node)
70
+ return if correction_would_break_code?(node)
71
+
72
+ replace_do_end_with_braces(corrector, node.loc)
73
+ end
74
+
75
+ def correction_would_break_code?(node)
76
+ return unless node.keywords?
77
+
78
+ node.send_node.arguments? && !node.send_node.parenthesized?
79
+ end
80
+
81
+ def replace_do_end_with_braces(corrector, loc)
82
+ b = loc.begin
83
+ e = loc.end
84
+
85
+ corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
86
+
87
+ corrector.replace(b, "{")
88
+ corrector.replace(e, "}")
89
+ end
90
+
91
+ def whitespace_after?(range, length = 1)
92
+ /\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
93
+ end
94
+ end
95
+ end
96
+ end
@@ -20,6 +20,8 @@ class Standard::CreatesConfigStore
20
20
  "ruby-2.3.yml"
21
21
  elsif desired_version < Gem::Version.new("2.6")
22
22
  "ruby-2.5.yml"
23
+ elsif desired_version < Gem::Version.new("3.0")
24
+ "ruby-2.7.yml"
23
25
  else
24
26
  "base.yml"
25
27
  end
@@ -8,11 +8,6 @@ module Standard
8
8
  standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
9
9
  MSG
10
10
 
11
- CALL_TO_ACTION_MESSAGE = <<-MSG.gsub(/^ {6}/, "")
12
- Notice: Disagree with these rules? While StandardRB is pre-1.0.0, feel free to submit suggestions to:
13
- https://github.com/testdouble/standard/issues/new
14
- MSG
15
-
16
11
  def self.fixable_error_message(command)
17
12
  <<-MSG.gsub(/^ {8}/, "")
18
13
  standard: Run `#{command}` to automatically fix some problems.
@@ -24,7 +19,6 @@ module Standard
24
19
  @detects_fixability = DetectsFixability.new
25
20
  @header_printed_already = false
26
21
  @fix_suggestion_printed_already = false
27
- @any_uncorrected_offenses = false
28
22
  end
29
23
 
30
24
  def started(_target_files)
@@ -33,7 +27,6 @@ module Standard
33
27
 
34
28
  def file_finished(file, offenses)
35
29
  return unless (uncorrected_offenses = offenses.reject(&:corrected?)).any?
36
- @any_uncorrected_offenses = true
37
30
 
38
31
  print_header_once
39
32
  print_fix_suggestion_once(uncorrected_offenses)
@@ -43,10 +36,6 @@ module Standard
43
36
  end
44
37
  end
45
38
 
46
- def finished(_)
47
- print_call_for_feedback if @any_uncorrected_offenses
48
- end
49
-
50
39
  private
51
40
 
52
41
  def print_header_once
@@ -90,11 +79,6 @@ module Standard
90
79
  Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
91
80
  end
92
81
 
93
- def print_call_for_feedback
94
- output.print "\n"
95
- output.print CALL_TO_ACTION_MESSAGE
96
- end
97
-
98
82
  def auto_correct_option_provided?
99
83
  options[:auto_correct] || options[:safe_auto_correct]
100
84
  end
@@ -5,4 +5,12 @@ module RuboCop
5
5
  "Wrap assignment in parentheses if intentional"
6
6
  end
7
7
  end
8
+
9
+ class CommentConfig
10
+ remove_const :COMMENT_DIRECTIVE_REGEXP
11
+ COMMENT_DIRECTIVE_REGEXP = Regexp.new(
12
+ ('# (?:standard|rubocop) : ((?:disable|enable|todo))\b ' + COPS_PATTERN)
13
+ .gsub(" ", '\s*')
14
+ )
15
+ end
8
16
  end
@@ -13,7 +13,7 @@ module Standard
13
13
  config.rubocop_options[:formatters] = [["files", temp_file.path]]
14
14
  config.rubocop_options[:format] = "files"
15
15
  config.rubocop_options[:out] = temp_file.path
16
- Runners::Rubocop.new.call(config)
16
+ exit_code = Runners::Rubocop.new.call(config)
17
17
 
18
18
  # Read in the files with errors. It will have the absolute paths
19
19
  # of the files but we only want the relative path.
@@ -37,6 +37,7 @@ module Standard
37
37
  file.puts "# Remove from this list as you refactor files."
38
38
  file.write(yaml_format_errors.to_yaml)
39
39
  end
40
+ exit_code
40
41
  ensure
41
42
  # Clean up temp file.
42
43
  temp_file.close
@@ -4,32 +4,15 @@ module Standard
4
4
  module Runners
5
5
  class Rubocop
6
6
  def call(config)
7
- rubocop_runner = RuboCop::Runner.new(
8
- config.rubocop_options,
9
- config.rubocop_config_store
7
+ rubocop_runner = RuboCop::CLI::Command::ExecuteRunner.new(
8
+ RuboCop::CLI::Environment.new(
9
+ config.rubocop_options,
10
+ config.rubocop_config_store,
11
+ config.paths
12
+ )
10
13
  )
11
14
 
12
- rubocop_runner.run(config.paths).tap do |success|
13
- print_errors_and_warnings(success, rubocop_runner)
14
- print_corrected_code_if_fixing_stdin(config.rubocop_options)
15
- end
16
- end
17
-
18
- private
19
-
20
- def print_errors_and_warnings(success, rubocop_runner)
21
- return unless success
22
-
23
- (rubocop_runner.warnings + rubocop_runner.errors).each do |message|
24
- warn message
25
- end
26
- end
27
-
28
- def print_corrected_code_if_fixing_stdin(rubocop_options)
29
- return unless rubocop_options[:stdin] && rubocop_options[:auto_correct]
30
-
31
- puts "=" * 20
32
- print rubocop_options[:stdin]
15
+ rubocop_runner.run
33
16
  end
34
17
  end
35
18
  end
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("0.12.0")
2
+ VERSION = Gem::Version.new("1.0.3")
3
3
  end
data/standard.gemspec CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "rubocop", "1.8.1"
23
- spec.add_dependency "rubocop-performance", "1.9.2"
22
+ spec.add_dependency "rubocop", "1.11.0"
23
+ spec.add_dependency "rubocop-performance", "1.10.1"
24
24
  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: 0.12.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.1
19
+ version: 1.11.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.1
26
+ version: 1.11.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-performance
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.9.2
33
+ version: 1.10.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.9.2
40
+ version: 1.10.1
41
41
  description:
42
42
  email:
43
43
  - searls@gmail.com
@@ -46,7 +46,6 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".github/dependabot.yml"
50
49
  - ".github/workflows/test.yml"
51
50
  - ".gitignore"
52
51
  - ".standard.yml"
@@ -64,12 +63,13 @@ files:
64
63
  - config/ruby-2.2.yml
65
64
  - config/ruby-2.3.yml
66
65
  - config/ruby-2.5.yml
66
+ - config/ruby-2.7.yml
67
67
  - docs/RELEASE.md
68
68
  - exe/standardrb
69
69
  - lib/standard.rb
70
70
  - lib/standard/builds_config.rb
71
71
  - lib/standard/cli.rb
72
- - lib/standard/cop/semantic_blocks.rb
72
+ - lib/standard/cop/block_delimiters.rb
73
73
  - lib/standard/creates_config_store.rb
74
74
  - lib/standard/creates_config_store/assigns_rubocop_yaml.rb
75
75
  - lib/standard/creates_config_store/configures_ignored_paths.rb
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.1.4
111
+ rubygems_version: 3.2.3
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Ruby Style Guide, with linter & automatic code fixer
@@ -1,8 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: "/"
5
- schedule:
6
- interval: weekly
7
- time: "10:00"
8
- open-pull-requests-limit: 10
@@ -1,165 +0,0 @@
1
- module RuboCop::Cop
2
- module Standard
3
- class SemanticBlocks < RuboCop::Cop::Base
4
- include RuboCop::Cop::IgnoredMethods
5
- extend RuboCop::Cop::AutoCorrector
6
-
7
- def on_send(node)
8
- return unless node.arguments?
9
- return if node.parenthesized? || node.operator_method?
10
-
11
- node.arguments.each do |arg|
12
- get_blocks(arg) do |block|
13
- # If there are no parentheses around the arguments, then braces
14
- # and do-end have different meaning due to how they bind, so we
15
- # allow either.
16
- ignore_node(block)
17
- end
18
- end
19
- end
20
-
21
- def on_block(node)
22
- return if ignored_node?(node) ||
23
- proper_block_style?(node) ||
24
- (!node.braces? && rescue_child_block?(node))
25
-
26
- add_offense(node.loc.begin, message: message(node)) do |corrector|
27
- return if correction_would_break_code?(node)
28
-
29
- if node.braces?
30
- replace_braces_with_do_end(corrector, node.loc)
31
- else
32
- replace_do_end_with_braces(corrector, node.loc)
33
- end
34
- end
35
- end
36
-
37
- private
38
-
39
- def message(node)
40
- if node.single_line?
41
- "Prefer `{...}` over `do...end` for single-line blocks."
42
- elsif node.loc.begin.source == "{"
43
- "Prefer `do...end` over `{...}` for procedural blocks."
44
- else
45
- "Prefer `{...}` over `do...end` for functional blocks."
46
- end
47
- end
48
-
49
- def replace_braces_with_do_end(corrector, loc)
50
- b = loc.begin
51
- e = loc.end
52
-
53
- corrector.insert_before(b, " ") unless whitespace_before?(b)
54
- corrector.insert_before(e, " ") unless whitespace_before?(e)
55
- corrector.insert_after(b, " ") unless whitespace_after?(b)
56
- corrector.replace(b, "do")
57
- corrector.replace(e, "end")
58
- end
59
-
60
- def replace_do_end_with_braces(corrector, loc)
61
- b = loc.begin
62
- e = loc.end
63
-
64
- corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
65
-
66
- corrector.replace(b, "{")
67
- corrector.replace(e, "}")
68
- end
69
-
70
- def whitespace_before?(range)
71
- range.source_buffer.source[range.begin_pos - 1, 1] =~ /\s/
72
- end
73
-
74
- def whitespace_after?(range, length = 1)
75
- range.source_buffer.source[range.begin_pos + length, 1] =~ /\s/
76
- end
77
-
78
- def get_blocks(node, &block)
79
- case node.type
80
- when :block
81
- yield node
82
- when :send
83
- get_blocks(node.receiver, &block) if node.receiver
84
- when :hash
85
- # A hash which is passed as method argument may have no braces
86
- # In that case, one of the K/V pairs could contain a block node
87
- # which could change in meaning if do...end replaced {...}
88
- return if node.braces?
89
-
90
- node.each_child_node { |child| get_blocks(child, &block) }
91
- when :pair
92
- node.each_child_node { |child| get_blocks(child, &block) }
93
- end
94
- end
95
-
96
- def proper_block_style?(node)
97
- method_name = node.method_name
98
-
99
- if ignored_method?(method_name)
100
- true
101
- elsif node.single_line?
102
- node.braces?
103
- elsif node.braces?
104
- !procedural_method?(method_name) &&
105
- (functional_method?(method_name) || functional_block?(node))
106
- else
107
- procedural_method?(method_name) || !return_value_used?(node)
108
- end
109
- end
110
-
111
- def correction_would_break_code?(node)
112
- rescue_child_block?(node) || non_parenthesized_keyword_args?(node)
113
- end
114
-
115
- def rescue_child_block?(node)
116
- node.children.any? { |node| node.rescue_type? || node.ensure_type? }
117
- end
118
-
119
- def non_parenthesized_keyword_args?(node)
120
- return unless node.keywords?
121
-
122
- node.send_node.arguments? && !node.send_node.parenthesized?
123
- end
124
-
125
- def functional_method?(method_name)
126
- cop_config["FunctionalMethods"].map(&:to_sym).include?(method_name)
127
- end
128
-
129
- def functional_block?(node)
130
- return_value_used?(node) || return_value_of_scope?(node)
131
- end
132
-
133
- def procedural_method?(method_name)
134
- cop_config["ProceduralMethods"].map(&:to_sym).include?(method_name)
135
- end
136
-
137
- def return_value_used?(node)
138
- return unless node.parent
139
-
140
- # If there are parentheses around the block, check if that
141
- # is being used.
142
- if node.parent.begin_type?
143
- return_value_used?(node.parent)
144
- else
145
- node.parent.assignment? || node.parent.send_type?
146
- end
147
- end
148
-
149
- def return_value_of_scope?(node)
150
- return unless node.parent
151
-
152
- conditional?(node.parent) || array_or_range?(node.parent) ||
153
- node.parent.children.last == node
154
- end
155
-
156
- def conditional?(node)
157
- node.if_type? || node.or_type? || node.and_type?
158
- end
159
-
160
- def array_or_range?(node)
161
- node.array_type? || node.irange_type? || node.erange_type?
162
- end
163
- end
164
- end
165
- end