standard 0.13.0 → 1.0.0

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: f0e6cc49d6d26e0bb428b7d05637a45b00ea6e0542f04a215a621ae5238c35dc
4
- data.tar.gz: b7599f068adeff886b013330d72c2dd8fceb415ac6d53299fee208eec6c7b141
3
+ metadata.gz: b3d6131b141958b49962a43f3f415ede32f3ca768e338e3c2783537f4ac325f7
4
+ data.tar.gz: 998dfccb3c11abced12b56b9225cbd7979055df18c25af5771d0470ffdf79b8a
5
5
  SHA512:
6
- metadata.gz: 5711e67885d2ed2167fc9ec61614a69397967cbe57f97d313973e17b0d932c822b4fc832e4159caec22a204ac4e4a8144b260bd8368ead6917f9429f8464ce41
7
- data.tar.gz: 5f1b78ef4a3962a83bfae6b4593c42efc9cdd588da671e912ed66ff1f9d1bd3571cf05960198989405627211207aa4303f58dc173c8a650d37468d984d66ce3e
6
+ metadata.gz: a92a4ac4920e0394914a3a2e23ec1cfe0f9c383cd48336df1e2d80e60e1c39289233331bd0dbfd4e0af68c3451cd19122fe3da3cb37758b559220808b2b8eec7
7
+ data.tar.gz: 617a43459e7766639e610c149a28c6d9fb888557ff1ba9104384c2e7e1972e83cacdf2b817dc76cb13073db5afcb6011a0044c3bde0857fe727620e818fcb094
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0
4
+
5
+ * Relax multi-line block rules, moving away from enforcing semantic blocks to
6
+ instead allowing code to adhere to whatever multi-line format the author deems
7
+ best [#263](https://github.com/testdouble/standard/pull/263)
8
+ * Allow a `standard:disable` comment directive in addition to `rubocop:disable`
9
+ [#186](https://github.com/testdouble/standard/pull/186)
10
+ * Remove the banner text that standard outputs after failure
11
+ [#264](https://github.com/testdouble/standard/pull/264)
12
+
3
13
  ## 0.13.0
4
14
 
5
15
  * Update rubocop from 1.7.0 to [1.10.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.10.0) enabling:
@@ -12,7 +22,7 @@
12
22
  * Update rubocop from 1.7.0 to [1.8.1](https://github.com/rubocop-hq/rubocop/releases/tag/v1.8.1)
13
23
  * Enabled [`Style/SlicingWithRange`](https://github.com/testdouble/standard/issues/175)
14
24
 
15
- ## 0.11.0
25
+ ## 0.11.0
16
26
 
17
27
  * Update rubocop-performance from 1.9.1 to [1.9.2](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.9.2)
18
28
  * 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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (0.13.0)
4
+ standard (1.0.0)
5
5
  rubocop (= 1.10.0)
6
6
  rubocop-performance (= 1.9.2)
7
7
 
@@ -13,7 +13,7 @@ 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)
@@ -22,7 +22,7 @@ GEM
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
27
  rubocop (1.10.0)
28
28
  parallel (~> 1.10)
@@ -60,4 +60,4 @@ DEPENDENCIES
60
60
  standard!
61
61
 
62
62
  BUNDLED WITH
63
- 2.2.6
63
+ 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`
@@ -302,10 +298,50 @@ ignore:
302
298
  - Style/BlockDelimiters
303
299
  ```
304
300
 
301
+ ## How do I disable a warning within my source code?
302
+
305
303
  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.
304
+ source code.
305
+
306
+ Given this source listing `foo.rb`:
307
+
308
+ ```ruby
309
+ baz = 42
310
+ ```
311
+
312
+ Running `standard foo.rb` would fail:
313
+
314
+ ```
315
+ foo.rb:1:1: Lint/UselessAssignment: Useless assignment to variable - `baz`.
316
+ ```
317
+
318
+ If we wanted to make an exception, we could add the following comment:
319
+
320
+ ```ruby
321
+ baz = 42 # standard:disable Lint/UselessAssignment
322
+ ```
323
+
324
+ The comment directives (both `standard:disable` and `rubocop:disable`) will
325
+ suppress the error and Standard would succeed.
326
+
327
+ If, however, you needed to disable standard for multiple lines, you could use
328
+ open and closing directives like this:
329
+
330
+ ```ruby
331
+ # standard:disable Layout/IndentationWidth
332
+ def foo
333
+ 123
334
+ end
335
+ # standard:enable Layout/IndentationWidth
336
+ ```
337
+
338
+ And if you don't know or care which rule is being violated, you can also
339
+ substitute its name for "all". This line actually triggers three different
340
+ violations, so we can suppress them like this:
341
+
342
+ ```ruby
343
+ baz = ['a'].each do end # standard:disable all
344
+ ```
309
345
 
310
346
  ## How do I specify a Ruby version? What is supported?
311
347
 
data/config/base.yml CHANGED
@@ -738,39 +738,8 @@ Security/YAMLLoad:
738
738
  Enabled: true
739
739
  SafeAutoCorrect: false
740
740
 
741
- Standard/SemanticBlocks:
742
- ProceduralMethods:
743
- - benchmark
744
- - bm
745
- - bmbm
746
- - tap
747
- # Enumerable
748
- - cycle
749
- - each
750
- - each_cons
751
- - each_entry
752
- - each_slice
753
- - each_with_index
754
- # Rails
755
- - transaction
756
- FunctionalMethods:
757
- - given
758
- - given!
759
- - let
760
- - let!
761
- - subject
762
- - watch
763
- - Given
764
- - Given!
765
- - Invariant
766
- - Then
767
- - And
768
- IgnoredMethods:
769
- - lambda
770
- - proc
771
- - describe
772
- - it
773
- - When
741
+ Standard/BlockDelimiters:
742
+ Enabled: true
774
743
 
775
744
  Style/Alias:
776
745
  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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("0.13.0")
2
+ VERSION = Gem::Version.new("1.0.0")
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: 0.13.0
4
+ version: 1.0.0
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-02-16 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -70,7 +70,7 @@ files:
70
70
  - lib/standard.rb
71
71
  - lib/standard/builds_config.rb
72
72
  - lib/standard/cli.rb
73
- - lib/standard/cop/semantic_blocks.rb
73
+ - lib/standard/cop/block_delimiters.rb
74
74
  - lib/standard/creates_config_store.rb
75
75
  - lib/standard/creates_config_store/assigns_rubocop_yaml.rb
76
76
  - lib/standard/creates_config_store/configures_ignored_paths.rb
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.1.4
112
+ rubygems_version: 3.2.3
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Ruby Style Guide, with linter & automatic code fixer
@@ -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