standard 0.10.1 → 1.0.0

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: a2a3abdd7be25bbafbbb44f6f6920d077da4a1762190a0c2454b3acf9a3b5e74
4
- data.tar.gz: 36bc5ad4555253f3b5890b388598b501212176cb861697c4849de575f32faf89
3
+ metadata.gz: b3d6131b141958b49962a43f3f415ede32f3ca768e338e3c2783537f4ac325f7
4
+ data.tar.gz: 998dfccb3c11abced12b56b9225cbd7979055df18c25af5771d0470ffdf79b8a
5
5
  SHA512:
6
- metadata.gz: 066fdef60be889c43532fb6d94fc9e5b468455d0bbabe51752009d448e3bd4ea51dbe47cf1e651d3487d48df5985f0c4db1073c9d658f5b28761f2499f805446
7
- data.tar.gz: b58f7b5be9f3df9121a79bf98372a64184ab91a2540d6cf68275a8141fc31734b3bcc527ad86aac45a68079846b1112309fd3cf48194d61932b187b4395a6d7a
6
+ metadata.gz: a92a4ac4920e0394914a3a2e23ec1cfe0f9c383cd48336df1e2d80e60e1c39289233331bd0dbfd4e0af68c3451cd19122fe3da3cb37758b559220808b2b8eec7
7
+ data.tar.gz: 617a43459e7766639e610c149a28c6d9fb888557ff1ba9104384c2e7e1972e83cacdf2b817dc76cb13073db5afcb6011a0044c3bde0857fe727620e818fcb094
@@ -0,0 +1,8 @@
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
@@ -9,15 +9,29 @@ on:
9
9
  jobs:
10
10
  test:
11
11
 
12
- runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ os: [ ubuntu-latest ]
15
+ ruby-version: [2.4, 2.7, 3.0]
16
+
17
+ runs-on: ${{ matrix.os }}
13
18
 
14
19
  steps:
15
20
  - uses: actions/checkout@v2
16
- - name: Set up Ruby
21
+ - name: Set up Ruby ${{ matrix.ruby-version }}
17
22
  uses: ruby/setup-ruby@v1
18
23
  with:
19
- ruby-version: 2.7
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ - name: Set up caching
26
+ uses: actions/cache@v1
27
+ with:
28
+ path: vendor/bundle
29
+ key: bundle-user-ruby-${{ matrix.os }}-${{matrix.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }}
30
+ restore-keys: |
31
+ bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby-version }}-
20
32
  - name: Install dependencies
21
- run: bundle
22
- - name: Run tests
33
+ run: |
34
+ bundle config path vendor/bundle
35
+ bundle install --jobs 4 --retry 3
36
+ - name: Run tests for Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
23
37
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,8 +1,41 @@
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
+
13
+ ## 0.13.0
14
+
15
+ * Update rubocop from 1.7.0 to [1.10.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.10.0) enabling:
16
+ * [`Lint/AmbiguousAssignment`](https://github.com/rubocop-hq/rubocop/issues/9223)
17
+ * [`Style/HashExcept`](https://github.com/rubocop-hq/rubocop/pull/9283)
18
+ * [`Lint/DeprecatedConstants`](https://github.com/rubocop-hq/rubocop/pull/9324)
19
+
20
+ ## 0.12.0
21
+
22
+ * Update rubocop from 1.7.0 to [1.8.1](https://github.com/rubocop-hq/rubocop/releases/tag/v1.8.1)
23
+ * Enabled [`Style/SlicingWithRange`](https://github.com/testdouble/standard/issues/175)
24
+
25
+ ## 0.11.0
26
+
27
+ * Update rubocop-performance from 1.9.1 to [1.9.2](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.9.2)
28
+ * Update rubocop from 1.4.2 to [1.7.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.7.0)
29
+ * Changed `Style/NegatedIf` to `postfix`
30
+
31
+ ## 0.10.2
32
+
33
+ * Remove
34
+ [`Lint/DuplicateBranch`](https://github.com/testdouble/standard/pull/228)
35
+
3
36
  ## 0.10.1
4
37
 
5
- * remove [`Performance/ArraySemiInfiniteRangeSlice`](https://github.com/testdouble/standard/pull/225#discussion_r532678908)
38
+ * Remove [`Performance/ArraySemiInfiniteRangeSlice`](https://github.com/testdouble/standard/pull/225#discussion_r532678908)
6
39
 
7
40
  ## 0.10.0
8
41
 
@@ -13,7 +46,7 @@
13
46
  * Update rubocop from 1.2.0 to [1.4.2](https://github.com/rubocop-hq/rubocop/releases/tag/v1.4.2) enabling:
14
47
  * [`Style/NilLambda`](https://github.com/rubocop-hq/rubocop/pull/9020)
15
48
  * [`Lint/DuplicateBranch`](https://github.com/rubocop-hq/rubocop/pull/8404)
16
-
49
+
17
50
  ## 0.9.0
18
51
 
19
52
  * Update rubocop from 1.0.0 to [1.2.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.2.0) enabling:
data/Gemfile CHANGED
@@ -1,3 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "bundler"
6
+ gem "minitest", "~> 5.0"
7
+ gem "pry"
8
+ gem "rake", "~> 13.0"
9
+ gem "gimme"
10
+
11
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5")
12
+ gem "simplecov"
13
+ end
data/Gemfile.lock CHANGED
@@ -1,49 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (0.10.1)
5
- rubocop (= 1.4.2)
6
- rubocop-performance (= 1.9.1)
4
+ standard (1.0.0)
5
+ rubocop (= 1.10.0)
6
+ rubocop-performance (= 1.9.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.1)
11
+ ast (2.4.2)
12
12
  coderay (1.1.3)
13
- docile (1.3.2)
13
+ docile (1.3.5)
14
14
  gimme (0.5.0)
15
15
  method_source (1.0.0)
16
- minitest (5.14.2)
16
+ minitest (5.14.4)
17
17
  parallel (1.20.1)
18
- parser (2.7.2.0)
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
- rake (13.0.1)
25
- regexp_parser (2.0.0)
24
+ rake (13.0.3)
25
+ regexp_parser (2.1.1)
26
26
  rexml (3.2.4)
27
- rubocop (1.4.2)
27
+ rubocop (1.10.0)
28
28
  parallel (~> 1.10)
29
- parser (>= 2.7.1.5)
29
+ parser (>= 3.0.0.0)
30
30
  rainbow (>= 2.2.2, < 4.0)
31
- regexp_parser (>= 1.8)
31
+ regexp_parser (>= 1.8, < 3.0)
32
32
  rexml
33
- rubocop-ast (>= 1.1.1)
33
+ rubocop-ast (>= 1.2.0, < 2.0)
34
34
  ruby-progressbar (~> 1.7)
35
- unicode-display_width (>= 1.4.0, < 2.0)
36
- rubocop-ast (1.2.0)
35
+ unicode-display_width (>= 1.4.0, < 3.0)
36
+ rubocop-ast (1.4.1)
37
37
  parser (>= 2.7.1.5)
38
- rubocop-performance (1.9.1)
38
+ rubocop-performance (1.9.2)
39
39
  rubocop (>= 0.90.0, < 2.0)
40
40
  rubocop-ast (>= 0.4.0)
41
- ruby-progressbar (1.10.1)
42
- simplecov (0.19.0)
41
+ ruby-progressbar (1.11.0)
42
+ simplecov (0.21.2)
43
43
  docile (~> 1.1)
44
44
  simplecov-html (~> 0.11)
45
- simplecov-html (0.12.2)
46
- unicode-display_width (1.7.0)
45
+ simplecov_json_formatter (~> 0.1)
46
+ simplecov-html (0.12.3)
47
+ simplecov_json_formatter (0.1.2)
48
+ unicode-display_width (2.0.0)
47
49
 
48
50
  PLATFORMS
49
51
  ruby
@@ -58,4 +60,4 @@ DEPENDENCIES
58
60
  standard!
59
61
 
60
62
  BUNDLED WITH
61
- 2.1.4
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
 
@@ -367,7 +403,7 @@ Refer to RuboCop's [documentation on
367
403
  formatters](https://rubocop.readthedocs.io/en/latest/formatters/) for more
368
404
  information.
369
405
 
370
- ## How do I run standard in my editor?
406
+ ## How do I run Standard in my editor?
371
407
 
372
408
  It can be very handy to know about failures while editing to shorten the
373
409
  feedback loop. Some editors support asynchronously running linters.
@@ -378,6 +414,10 @@ feedback loop. Some editors support asynchronously running linters.
378
414
  - [vim (via ALE)](https://github.com/testdouble/standard/wiki/IDE:-vim)
379
415
  - [VS Code](https://github.com/testdouble/standard/wiki/IDE:-vscode)
380
416
 
417
+ ## How do I use Standard with Rubocop extensions?
418
+
419
+ This is not officially supported by Standard. However, Evil Martians wrote up [a regularly updated guide](https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard) on how to do so.
420
+
381
421
  ## Does Standard work with [Insert other tool name here]?
382
422
 
383
423
  Maybe! Start by searching the repository to see if there's an existing issue open for
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,10 +363,10 @@ Lint/Debugger:
360
363
  Lint/DeprecatedClassMethods:
361
364
  Enabled: true
362
365
 
363
- Lint/DeprecatedOpenSSLConstant:
366
+ Lint/DeprecatedConstants:
364
367
  Enabled: true
365
368
 
366
- Lint/DuplicateBranch:
369
+ Lint/DeprecatedOpenSSLConstant:
367
370
  Enabled: true
368
371
 
369
372
  Lint/DuplicateCaseCondition:
@@ -735,39 +738,8 @@ Security/YAMLLoad:
735
738
  Enabled: true
736
739
  SafeAutoCorrect: false
737
740
 
738
- Standard/SemanticBlocks:
739
- ProceduralMethods:
740
- - benchmark
741
- - bm
742
- - bmbm
743
- - tap
744
- # Enumerable
745
- - cycle
746
- - each
747
- - each_cons
748
- - each_entry
749
- - each_slice
750
- - each_with_index
751
- # Rails
752
- - transaction
753
- FunctionalMethods:
754
- - given
755
- - given!
756
- - let
757
- - let!
758
- - subject
759
- - watch
760
- - Given
761
- - Given!
762
- - Invariant
763
- - Then
764
- - And
765
- IgnoredMethods:
766
- - lambda
767
- - proc
768
- - describe
769
- - it
770
- - When
741
+ Standard/BlockDelimiters:
742
+ Enabled: true
771
743
 
772
744
  Style/Alias:
773
745
  Enabled: true
@@ -883,6 +855,9 @@ Style/GlobalVars:
883
855
  Enabled: true
884
856
  AllowedVariables: []
885
857
 
858
+ Style/HashExcept:
859
+ Enabled: true
860
+
886
861
  Style/HashSyntax:
887
862
  Enabled: true
888
863
  EnforcedStyle: ruby19_no_mixed_keys
@@ -942,7 +917,7 @@ Style/MultilineWhenThen:
942
917
 
943
918
  Style/NegatedIf:
944
919
  Enabled: true
945
- EnforcedStyle: both
920
+ EnforcedStyle: postfix
946
921
 
947
922
  Style/NegatedWhile:
948
923
  Enabled: true
@@ -1105,6 +1080,9 @@ Style/SingleLineMethods:
1105
1080
  Enabled: true
1106
1081
  AllowIfMethodIsEmpty: false
1107
1082
 
1083
+ Style/SlicingWithRange:
1084
+ Enabled: true
1085
+
1108
1086
  Style/StabbyLambdaParentheses:
1109
1087
  Enabled: true
1110
1088
  EnforcedStyle: require_parentheses
data/config/ruby-2.3.yml CHANGED
@@ -1,4 +1,4 @@
1
- inherit_from: ./base.yml
1
+ inherit_from: ./ruby-2.5.yml
2
2
 
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.4 # The oldest supported
@@ -0,0 +1,7 @@
1
+ inherit_from: ./ruby-2.7.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+
6
+ Style/SlicingWithRange:
7
+ Enabled: false
@@ -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
@@ -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
@@ -18,6 +18,10 @@ class Standard::CreatesConfigStore
18
18
  "ruby-2.2.yml"
19
19
  elsif desired_version < Gem::Version.new("2.4")
20
20
  "ruby-2.3.yml"
21
+ elsif desired_version < Gem::Version.new("2.6")
22
+ "ruby-2.5.yml"
23
+ elsif desired_version < Gem::Version.new("3.0")
24
+ "ruby-2.7.yml"
21
25
  else
22
26
  "base.yml"
23
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
@@ -28,7 +28,11 @@ module Standard
28
28
  def print_corrected_code_if_fixing_stdin(rubocop_options)
29
29
  return unless rubocop_options[:stdin] && rubocop_options[:auto_correct]
30
30
 
31
- puts "=" * 20
31
+ if rubocop_options[:stderr]
32
+ warn "=" * 20
33
+ else
34
+ puts "=" * 20
35
+ end
32
36
  print rubocop_options[:stdin]
33
37
  end
34
38
  end
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("0.10.1")
2
+ VERSION = Gem::Version.new("1.0.0")
3
3
  end
data/standard.gemspec CHANGED
@@ -19,13 +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.4.2"
23
- spec.add_dependency "rubocop-performance", "1.9.1"
24
-
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "minitest", "~> 5.0"
27
- spec.add_development_dependency "pry"
28
- spec.add_development_dependency "rake", "~> 13.0"
29
- spec.add_development_dependency "simplecov"
30
- spec.add_development_dependency "gimme"
22
+ spec.add_dependency "rubocop", "1.10.0"
23
+ spec.add_dependency "rubocop-performance", "1.9.2"
31
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.10.1
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: 2020-11-30 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
@@ -16,112 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.2
19
+ version: 1.10.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.4.2
26
+ version: 1.10.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.1
33
+ version: 1.9.2
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.1
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '13.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '13.0'
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: gimme
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
40
+ version: 1.9.2
125
41
  description:
126
42
  email:
127
43
  - searls@gmail.com
@@ -130,6 +46,7 @@ executables:
130
46
  extensions: []
131
47
  extra_rdoc_files: []
132
48
  files:
49
+ - ".github/dependabot.yml"
133
50
  - ".github/workflows/test.yml"
134
51
  - ".gitignore"
135
52
  - ".standard.yml"
@@ -146,12 +63,14 @@ files:
146
63
  - config/ruby-1.9.yml
147
64
  - config/ruby-2.2.yml
148
65
  - config/ruby-2.3.yml
66
+ - config/ruby-2.5.yml
67
+ - config/ruby-2.7.yml
149
68
  - docs/RELEASE.md
150
69
  - exe/standardrb
151
70
  - lib/standard.rb
152
71
  - lib/standard/builds_config.rb
153
72
  - lib/standard/cli.rb
154
- - lib/standard/cop/semantic_blocks.rb
73
+ - lib/standard/cop/block_delimiters.rb
155
74
  - lib/standard/creates_config_store.rb
156
75
  - lib/standard/creates_config_store/assigns_rubocop_yaml.rb
157
76
  - lib/standard/creates_config_store/configures_ignored_paths.rb
@@ -190,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
109
  - !ruby/object:Gem::Version
191
110
  version: '0'
192
111
  requirements: []
193
- rubygems_version: 3.1.4
112
+ rubygems_version: 3.2.3
194
113
  signing_key:
195
114
  specification_version: 4
196
115
  summary: Ruby Style Guide, with linter & automatic code fixer
@@ -1,170 +0,0 @@
1
- module RuboCop::Cop
2
- module Standard
3
- class SemanticBlocks < RuboCop::Cop::Cop
4
- include RuboCop::Cop::IgnoredMethods
5
-
6
- def on_send(node)
7
- return unless node.arguments?
8
- return if node.parenthesized? || node.operator_method?
9
-
10
- node.arguments.each do |arg|
11
- get_blocks(arg) do |block|
12
- # If there are no parentheses around the arguments, then braces
13
- # and do-end have different meaning due to how they bind, so we
14
- # allow either.
15
- ignore_node(block)
16
- end
17
- end
18
- end
19
-
20
- def on_block(node)
21
- return if ignored_node?(node) ||
22
- proper_block_style?(node) ||
23
- (!node.braces? && rescue_child_block?(node))
24
-
25
- add_offense(node, location: :begin)
26
- end
27
-
28
- def autocorrect(node)
29
- return if correction_would_break_code?(node)
30
-
31
- if node.braces?
32
- replace_braces_with_do_end(node.loc)
33
- else
34
- replace_do_end_with_braces(node.loc)
35
- end
36
- end
37
-
38
- private
39
-
40
- def message(node)
41
- if node.single_line?
42
- "Prefer `{...}` over `do...end` for single-line blocks."
43
- elsif node.loc.begin.source == "{"
44
- "Prefer `do...end` over `{...}` for procedural blocks."
45
- else
46
- "Prefer `{...}` over `do...end` for functional blocks."
47
- end
48
- end
49
-
50
- def replace_braces_with_do_end(loc)
51
- b = loc.begin
52
- e = loc.end
53
-
54
- lambda do |corrector|
55
- corrector.insert_before(b, " ") unless whitespace_before?(b)
56
- corrector.insert_before(e, " ") unless whitespace_before?(e)
57
- corrector.insert_after(b, " ") unless whitespace_after?(b)
58
- corrector.replace(b, "do")
59
- corrector.replace(e, "end")
60
- end
61
- end
62
-
63
- def replace_do_end_with_braces(loc)
64
- b = loc.begin
65
- e = loc.end
66
-
67
- lambda do |corrector|
68
- corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
69
-
70
- corrector.replace(b, "{")
71
- corrector.replace(e, "}")
72
- end
73
- end
74
-
75
- def whitespace_before?(range)
76
- range.source_buffer.source[range.begin_pos - 1, 1] =~ /\s/
77
- end
78
-
79
- def whitespace_after?(range, length = 1)
80
- range.source_buffer.source[range.begin_pos + length, 1] =~ /\s/
81
- end
82
-
83
- def get_blocks(node, &block)
84
- case node.type
85
- when :block
86
- yield node
87
- when :send
88
- get_blocks(node.receiver, &block) if node.receiver
89
- when :hash
90
- # A hash which is passed as method argument may have no braces
91
- # In that case, one of the K/V pairs could contain a block node
92
- # which could change in meaning if do...end replaced {...}
93
- return if node.braces?
94
-
95
- node.each_child_node { |child| get_blocks(child, &block) }
96
- when :pair
97
- node.each_child_node { |child| get_blocks(child, &block) }
98
- end
99
- end
100
-
101
- def proper_block_style?(node)
102
- method_name = node.method_name
103
-
104
- if ignored_method?(method_name)
105
- true
106
- elsif node.single_line?
107
- node.braces?
108
- elsif node.braces?
109
- !procedural_method?(method_name) &&
110
- (functional_method?(method_name) || functional_block?(node))
111
- else
112
- procedural_method?(method_name) || !return_value_used?(node)
113
- end
114
- end
115
-
116
- def correction_would_break_code?(node)
117
- rescue_child_block?(node) || non_parenthesized_keyword_args?(node)
118
- end
119
-
120
- def rescue_child_block?(node)
121
- node.children.any? { |node| node.rescue_type? || node.ensure_type? }
122
- end
123
-
124
- def non_parenthesized_keyword_args?(node)
125
- return unless node.keywords?
126
-
127
- node.send_node.arguments? && !node.send_node.parenthesized?
128
- end
129
-
130
- def functional_method?(method_name)
131
- cop_config["FunctionalMethods"].map(&:to_sym).include?(method_name)
132
- end
133
-
134
- def functional_block?(node)
135
- return_value_used?(node) || return_value_of_scope?(node)
136
- end
137
-
138
- def procedural_method?(method_name)
139
- cop_config["ProceduralMethods"].map(&:to_sym).include?(method_name)
140
- end
141
-
142
- def return_value_used?(node)
143
- return unless node.parent
144
-
145
- # If there are parentheses around the block, check if that
146
- # is being used.
147
- if node.parent.begin_type?
148
- return_value_used?(node.parent)
149
- else
150
- node.parent.assignment? || node.parent.send_type?
151
- end
152
- end
153
-
154
- def return_value_of_scope?(node)
155
- return unless node.parent
156
-
157
- conditional?(node.parent) || array_or_range?(node.parent) ||
158
- node.parent.children.last == node
159
- end
160
-
161
- def conditional?(node)
162
- node.if_type? || node.or_type? || node.and_type?
163
- end
164
-
165
- def array_or_range?(node)
166
- node.array_type? || node.irange_type? || node.erange_type?
167
- end
168
- end
169
- end
170
- end