standard 0.11.0 → 1.0.2

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: ae2564522ac361e37d4c51c9962fe5b0bbca2fd7c4b37ae1880c619778a46966
4
- data.tar.gz: 00b84978d2e64b59ecd757a46a7f562e7d9f1ecaeb0c03062140628c78565658
3
+ metadata.gz: 5243ef8e251d58a567e45ac2ced197b1e7aecebb11fe062017673f60b72c20d9
4
+ data.tar.gz: 1b7b1d75fd42803b4e2ffe96738bcb67ec60d1fc4db7e7fbda7b8e5b7693d113
5
5
  SHA512:
6
- metadata.gz: 91a99adab0683f57682af967b4936777444974f9f19c5cda438df911c3ce1ad37f099968eb1d47a4ebe541c96ae50cdb1967e89056e683e5dc71a7b29b03a3e8
7
- data.tar.gz: 2c26f2ad10033b682b870cdaa66e6b60eb537a483f34d880d2bd90e70a3ef27e8421d06c13d261d74ca196748d8f3be2c915ae2e96e098c3bae1bdbe23f42c14
6
+ metadata.gz: 6cbb608448c4a9da25f2c88941217272dbd133c6e356d380fcd82109b4921eb1d32c930da5974bef9540da9116b5e5dfa469c5b7241b4b1d2af758d7600fd8e3
7
+ data.tar.gz: 18248be1abd1e69c865bf2387fc70bcdc271bdf5c90b99e446370aa2e592438326e59656c84e2b6ab36fd404c27db8d1e5b43bbd4005f05c954eeeaa07dfb585
@@ -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,6 +1,39 @@
1
1
  # Changelog
2
2
 
3
- ## 0.11.0
3
+ ## 1.0.2
4
+
5
+ * Preserve RuboCop's CLI exit codes
6
+ ([#270](https://github.com/testdouble/standard/pull/270)) by
7
+ [@nicksieger](https://github.com/nicksieger)
8
+
9
+ ## 1.0.1
10
+
11
+ * Update rubocop from 1.10.0 to [1.11.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.11.0)
12
+ * Update rubocop-performance from 1.9.2 to [1.10.1](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.10.1)
13
+
14
+ ## 1.0.0
15
+
16
+ * Relax multi-line block rules, moving away from enforcing semantic blocks to
17
+ instead allowing code to adhere to whatever multi-line format the author deems
18
+ best [#263](https://github.com/testdouble/standard/pull/263)
19
+ * Allow a `standard:disable` comment directive in addition to `rubocop:disable`
20
+ [#186](https://github.com/testdouble/standard/pull/186)
21
+ * Remove the banner text that standard outputs after failure
22
+ [#264](https://github.com/testdouble/standard/pull/264)
23
+
24
+ ## 0.13.0
25
+
26
+ * Update rubocop from 1.7.0 to [1.10.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.10.0) enabling:
27
+ * [`Lint/AmbiguousAssignment`](https://github.com/rubocop-hq/rubocop/issues/9223)
28
+ * [`Style/HashExcept`](https://github.com/rubocop-hq/rubocop/pull/9283)
29
+ * [`Lint/DeprecatedConstants`](https://github.com/rubocop-hq/rubocop/pull/9324)
30
+
31
+ ## 0.12.0
32
+
33
+ * Update rubocop from 1.7.0 to [1.8.1](https://github.com/rubocop-hq/rubocop/releases/tag/v1.8.1)
34
+ * Enabled [`Style/SlicingWithRange`](https://github.com/testdouble/standard/issues/175)
35
+
36
+ ## 0.11.0
4
37
 
5
38
  * Update rubocop-performance from 1.9.1 to [1.9.2](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.9.2)
6
39
  * Update rubocop from 1.4.2 to [1.7.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.7.0)
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,52 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (0.11.0)
5
- rubocop (= 1.7.0)
6
- rubocop-performance (= 1.9.2)
4
+ standard (1.0.2)
5
+ rubocop (= 1.11.0)
6
+ rubocop-performance (= 1.10.1)
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
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.3)
24
+ rake (13.0.3)
25
+ regexp_parser (2.1.1)
26
26
  rexml (3.2.4)
27
- rubocop (1.7.0)
27
+ rubocop (1.11.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
31
  regexp_parser (>= 1.8, < 3.0)
32
32
  rexml
33
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.4.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.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)
42
- simplecov (0.19.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
52
+ x86_64-darwin-20
50
53
 
51
54
  DEPENDENCIES
52
55
  bundler
@@ -58,4 +61,4 @@ DEPENDENCIES
58
61
  standard!
59
62
 
60
63
  BUNDLED WITH
61
- 2.1.4
64
+ 2.3.0.dev
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
@@ -1102,6 +1080,9 @@ Style/SingleLineMethods:
1102
1080
  Enabled: true
1103
1081
  AllowIfMethodIsEmpty: false
1104
1082
 
1083
+ Style/SlicingWithRange:
1084
+ Enabled: true
1085
+
1105
1086
  Style/StabbyLambdaParentheses:
1106
1087
  Enabled: true
1107
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
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)
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
@@ -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
@@ -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.11.0")
2
+ VERSION = Gem::Version.new("1.0.2")
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.7.0"
23
- spec.add_dependency "rubocop-performance", "1.9.2"
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.11.0"
23
+ spec.add_dependency "rubocop-performance", "1.10.1"
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.11.0
4
+ version: 1.0.2
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-06 00:00:00.000000000 Z
11
+ date: 2021-03-05 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.7.0
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.7.0
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
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.10.1
125
41
  description:
126
42
  email:
127
43
  - searls@gmail.com
@@ -146,12 +62,14 @@ files:
146
62
  - config/ruby-1.9.yml
147
63
  - config/ruby-2.2.yml
148
64
  - config/ruby-2.3.yml
65
+ - config/ruby-2.5.yml
66
+ - config/ruby-2.7.yml
149
67
  - docs/RELEASE.md
150
68
  - exe/standardrb
151
69
  - lib/standard.rb
152
70
  - lib/standard/builds_config.rb
153
71
  - lib/standard/cli.rb
154
- - lib/standard/cop/semantic_blocks.rb
72
+ - lib/standard/cop/block_delimiters.rb
155
73
  - lib/standard/creates_config_store.rb
156
74
  - lib/standard/creates_config_store/assigns_rubocop_yaml.rb
157
75
  - lib/standard/creates_config_store/configures_ignored_paths.rb
@@ -190,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
108
  - !ruby/object:Gem::Version
191
109
  version: '0'
192
110
  requirements: []
193
- rubygems_version: 3.1.4
111
+ rubygems_version: 3.2.3
194
112
  signing_key:
195
113
  specification_version: 4
196
114
  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