datarockets-style 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: b7abb7599f2b6308e1bf7ba21af09f8d6d10658d
4
- data.tar.gz: 064e54aa27dbe9e00453ad91eac3dcf7b33592c6
3
+ metadata.gz: a3ade75e0b19c3f2b41a520e098d424d304c20be
4
+ data.tar.gz: 3a7e44ccc88f575b2b304fa80dfa92c2264131fd
5
5
  SHA512:
6
- metadata.gz: b751d28c3f3f239d426f2e80f99be7866e1f63562b674175366ca2290e2c8e2cb9a7051abd00a9f3b7b695979ac801556230f7a49f67483ddeaa4fcd7629cf54
7
- data.tar.gz: 72db0bda1af9bb3b9ad45c8b57482014a649d453fdc8dc7218293bb9ee9cfa18085488f1c9c8e40b5a8ccc3c809d39ae895d6c91a6159729dc9556e8a6156e43
6
+ metadata.gz: 4edf5fa617146f569cb0309a3d2afb759bb5cda8dfea4da7c330506771bfbc57a539ce726d5137d186ea3b66258a284974ec2e6a3ec839bade5c4ef587ea8683
7
+ data.tar.gz: 1814b31a4678a7bedc82aa112ee5327234b8c73e8671e3de6c87df41fd97d4e1f8d54da39dd84a71a0a6178e07a40948cd01fba8b239f884fa14041088dcb33b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_from:
2
+ - config/ruby.yml
3
+ - config/rspec.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
data/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
4
4
 
5
5
  ## master (unreleased)
6
6
 
7
+ ## 0.5.0 (2019-11-06)
8
+
9
+ ### Added
10
+
11
+ * [#107](https://github.com/datarockets/datarockets-style/issues/107): Add ToDo list formatter. ([@r.dubrovsky][])
12
+
13
+ ### Changed
14
+
15
+ * Update rubocop to `0.76`. ([@r.dubrovsky][])
16
+ * Change default value for `RSpec/ExampleLength` cop. ([@a.branzeanu][])
17
+ * Disable `RSpec/NestedGroups` cop by default. ([@r.dubrovsky][])
18
+
7
19
  ## 0.5.0 (2019-10-26)
8
20
 
9
21
  ### Changed
@@ -79,3 +91,5 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
79
91
  [@aleks]: https://github.com/AleksSenkou
80
92
  [@ula]: https://github.com/lazycoder9
81
93
  [@v.kuzmik]: https://github.com/TheBlackArroVV/
94
+ [@a.branzeanu]: https://github.com/texpert
95
+
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- # Specify your gem's dependencies in datarockets-style.gemspec
6
5
  gemspec
6
+
7
+ gem "pry-byebug"
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.7"
data/Gemfile.lock CHANGED
@@ -1,21 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datarockets-style (0.5.0)
5
- rubocop (>= 0.74, < 0.76)
4
+ datarockets-style (0.6.0)
5
+ rubocop (~> 0.76)
6
6
  rubocop-rspec (~> 1.36)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.0)
12
- jaro_winkler (1.5.3)
12
+ byebug (11.0.1)
13
+ coderay (1.1.2)
14
+ diff-lcs (1.3)
15
+ jaro_winkler (1.5.4)
16
+ method_source (0.9.2)
13
17
  parallel (1.18.0)
14
18
  parser (2.6.5.0)
15
19
  ast (~> 2.4.0)
20
+ pry (0.12.2)
21
+ coderay (~> 1.1.0)
22
+ method_source (~> 0.9.0)
23
+ pry-byebug (3.7.0)
24
+ byebug (~> 11.0)
25
+ pry (~> 0.10)
16
26
  rainbow (3.0.0)
17
27
  rake (13.0.0)
18
- rubocop (0.75.1)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-expectations (3.9.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.0)
41
+ rubocop (0.76.0)
19
42
  jaro_winkler (~> 1.5.1)
20
43
  parallel (~> 1.10)
21
44
  parser (>= 2.6)
@@ -32,7 +55,9 @@ PLATFORMS
32
55
 
33
56
  DEPENDENCIES
34
57
  datarockets-style!
58
+ pry-byebug
35
59
  rake (~> 13.0)
60
+ rspec (~> 3.7)
36
61
 
37
62
  BUNDLED WITH
38
63
  1.16.1
data/README.md CHANGED
@@ -88,6 +88,65 @@ P.S. The string literals in this gem are using double quotes by default.
88
88
 
89
89
  For an existing project, we suggest to run rubocop with both styles and choose which has fewer offenses (which is more popular in the current project).
90
90
 
91
+ ## Formatters
92
+
93
+ ### ToDo list formatter
94
+
95
+ This formatter allows us to get list of files for some offense and with number of offenses in each file. This file can be useful if you need to fix a large some cop cop step by step.
96
+
97
+ Result of the formatter is compatible with rubocop config or rubocop todo file.
98
+
99
+ For running that cop, just print in your command like
100
+
101
+ ```bash
102
+ $ bundle exec rubocop -f TodoListFormatter -r datarockets/style
103
+ Inspecting 10 files
104
+ ...CC.CC..
105
+ 10 files inspected, 7 offenses detected
106
+
107
+ Layout/IndentationConsistency
108
+ Exclude:
109
+ - 'spec/datarockets/style/formatter/todo_list_formatter_spec.rb' # 1
110
+
111
+ Naming/MemoizedInstanceVariableName
112
+ Exclude:
113
+ - 'lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb' # 1
114
+
115
+ RSpec/ExampleLength
116
+ Exclude:
117
+ - 'spec/datarockets/style/formatter/todo_list_formatter/report_summary_spec.rb' # 1
118
+ - 'spec/datarockets/style/formatter/todo_list_formatter_spec.rb' # 2
119
+
120
+ Style/Documentation
121
+ Exclude:
122
+ - 'lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb' # 1
123
+ - 'lib/datarockets/style/formatter/todo_list_formatter.rb' # 1
124
+ ```
125
+
126
+ #### Autocorrection
127
+
128
+ If you run the formatter with autocorrection options, the formatter skip corrected cop and does not include it to the result.
129
+
130
+ ```bash
131
+ $ bundle exec rubocop -f TodoListFormatter -r datarockets/style -a
132
+ Inspecting 10 files
133
+ ...CC.CC..
134
+ 10 files inspected, 7 offenses detected, 1 offenses corrected
135
+
136
+ Naming/MemoizedInstanceVariableName
137
+ Exclude:
138
+ - 'lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb' # 1
139
+
140
+ RSpec/ExampleLength
141
+ Exclude:
142
+ - 'spec/datarockets/style/formatter/todo_list_formatter/report_summary_spec.rb' # 1
143
+ - 'spec/datarockets/style/formatter/todo_list_formatter_spec.rb' # 2
144
+
145
+ Style/Documentation
146
+ Exclude:
147
+ - 'lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb' # 1
148
+ - 'lib/datarockets/style/formatter/todo_list_formatter.rb' # 1
149
+ ```
91
150
 
92
151
  ## Changelog
93
152
 
data/config/rspec.yml CHANGED
@@ -15,6 +15,10 @@ RSpec/ContextWording:
15
15
  - without
16
16
  - for
17
17
 
18
+ RSpec/ExampleLength:
19
+ Enabled: true
20
+ Max: 10
21
+
18
22
  RSpec/ExpectChange:
19
23
  EnforcedStyle: block
20
24
 
@@ -23,3 +27,6 @@ RSpec/ImplicitSubject:
23
27
 
24
28
  RSpec/MessageSpies:
25
29
  EnforcedStyle: have_received
30
+
31
+ RSpec/NestedGroups:
32
+ Enabled: false
data/config/ruby.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
+ - "bundler/**/*"
3
4
  - "bin/*"
4
5
  - "lib/tasks/**/*"
5
6
  - "vendor/**/*"
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "datarockets/style/version"
4
4
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://github.com/datarockets/datarockets-style"
13
13
  spec.license = "MIT"
14
14
 
15
- spec.required_ruby_version = '>= 2.3.0'
15
+ spec.required_ruby_version = ">= 2.3.0"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -23,15 +23,13 @@ Gem::Specification.new do |spec|
23
23
  "public gem pushes."
24
24
  end
25
25
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
29
  spec.bindir = "exe"
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "rubocop", ">= 0.74", "< 0.76"
33
+ spec.add_dependency "rubocop", "~> 0.76"
34
34
  spec.add_dependency "rubocop-rspec", "~> 1.36"
35
-
36
- spec.add_development_dependency "rake", "~> 13.0"
37
35
  end
@@ -10,6 +10,11 @@ This style guide recommends best practices for writing a clear Rspec tests and e
10
10
  We're not limiting a length of rspec files.
11
11
  <sup>[[link](#rspec-file-length)]</sup>
12
12
 
13
+ * <a name="rspec-nested-groups"></a>
14
+ Nested context is a nice approach for organizing your code and tests structure.
15
+ So there are not any limits for deep or nested groups.
16
+ <sup>[[link](#rspec-nested-groups)]</sup>
17
+
13
18
  * <a name="rspec-subject"></a>
14
19
  Each subject should be named and we should not use `subject` in our test cases.
15
20
  Prefer to use `is_expected` that `expect(subject_name)` for small tests.
@@ -54,6 +59,43 @@ context "when the display name is not present" do
54
59
  end
55
60
  ```
56
61
 
62
+ * <a name="rspec-example-length"></a>
63
+ A long example is usually more difficult to understand. Consider extracting out some behaviour, e.g. with a `let` block, or a helper method.
64
+
65
+ <sup>[[link](#rspec-example-length)]</sup>
66
+
67
+ ```ruby
68
+ # bad
69
+ it 'creates correct deal config object' do
70
+ expect(ZohoUtil::DealConfig).to receive(:new)
71
+ .with(
72
+ deal_name: translated_deal_name,
73
+ stage_uid: zoho_post.stage_uid,
74
+ change_existing_stage: zoho_post.change_existing_stage,
75
+ note_title: translated_note_title,
76
+ note: translated_note
77
+ )
78
+
79
+ execute_action
80
+ end
81
+
82
+ # good
83
+ let(:service_arguments) do
84
+ {
85
+ deal_name: translated_deal_name,
86
+ stage_uid: zoho_post.stage_uid,
87
+ change_existing_stage: zoho_post.change_existing_stage,
88
+ note_title: translated_note_title,
89
+ note: translated_note
90
+ }
91
+ end
92
+
93
+ it 'creates correct deal config object' do
94
+ expect(ZohoUtil::DealConfig).to receive(:new).with(**service_arguments)
95
+ execute_action
96
+ end
97
+ ```
98
+
57
99
  * <a name="rspec-expect-change"></a>
58
100
  Prefer using blocks for change matcher than method calls.
59
101
  <sup>[[link](#rspec-expect-change)]</sup>
@@ -1,6 +1,10 @@
1
+ require "rubocop"
2
+ require "datarockets/style/formatter/todo_list_formatter"
3
+
1
4
  require "datarockets/style/version"
2
5
 
3
6
  module Datarockets
7
+ # Datarickors sharable config
4
8
  module Style
5
9
  # Your code goes here...
6
10
  end
@@ -0,0 +1,50 @@
1
+ require "pathname"
2
+ require_relative "./todo_list_formatter/report_summary"
3
+
4
+ # This formatter works like default formattter (display dots for files with no offenses and
5
+ # letters for files with problems in the them).
6
+ #
7
+ # In the end, it shows report with sorted cops and files which can be added to rubocop config.
8
+ #
9
+ # Here's the format:
10
+ #
11
+ # Inspecting 3 files
12
+ # .CC
13
+ # 3 files inspected, 1005001 offenses detected
14
+ #
15
+ # LineLength
16
+ # Exclude:
17
+ # - "really/bad/file.rb" # 100500
18
+ # - "almost/ok.rb" # 1
19
+ class TodoListFormatter < RuboCop::Formatter::ProgressFormatter
20
+ attr_reader :offense_list
21
+
22
+ FileOffence = Struct.new(:file_path, :cop_name)
23
+
24
+ def started(target_files)
25
+ super
26
+ @offense_list = []
27
+ end
28
+
29
+ def file_finished(file, offenses)
30
+ count_stats(offenses)
31
+ report_file_as_mark(offenses)
32
+
33
+ return if offenses.empty?
34
+
35
+ path = Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
36
+
37
+ offenses.reject(&:corrected?).each do |offense|
38
+ offense_list << FileOffence.new(path, offense.cop_name)
39
+ end
40
+ end
41
+
42
+ def finished(inspected_files)
43
+ report_summary(inspected_files.length,
44
+ @total_offense_count,
45
+ @total_correction_count)
46
+ output.puts
47
+
48
+ Datarockets::Style::Formatter::TodoListFormatter::ReportSummary.new(offense_list).call(output)
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ module Datarockets
2
+ module Style
3
+ module Formatter
4
+ module TodoListFormatter
5
+ # Get file of pairs: file path and cop name - and prepare report for ToDo list formatter.
6
+ #
7
+ # Example of result:
8
+ #
9
+ # LineLength
10
+ # Exclude:
11
+ # - "really/bad/file.rb" # 100500
12
+ # - "almost/ok.rb" # 1
13
+ class ReportSummary
14
+ attr_reader :offense_list
15
+
16
+ FileGroup = Struct.new(:file, :count) do
17
+ def print(output)
18
+ output.puts " - '#{file}' # #{count}"
19
+ end
20
+ end
21
+
22
+ OffenseGroup = Struct.new(:cop_name, :offenses) do
23
+ def file_groups
24
+ @_file_groups ||= offenses.group_by(&:file_path).map do |file, offenses|
25
+ FileGroup.new(file, offenses.length)
26
+ end
27
+ end
28
+
29
+ def print(output)
30
+ output.puts(cop_name)
31
+ output.puts(" Exclude:")
32
+ file_groups.sort_by(&:file).each do |file_group|
33
+ file_group.print(output)
34
+ end
35
+ output.puts
36
+ end
37
+ end
38
+
39
+ def initialize(offense_list)
40
+ @offense_list = offense_list
41
+ end
42
+
43
+ def call(output)
44
+ offense_groups.sort_by(&:cop_name).each { |group| group.print(output) }
45
+ end
46
+
47
+ private
48
+
49
+ def offense_groups
50
+ @_offense_groups ||= offense_list.group_by(&:cop_name)
51
+ .map { |cop_name, offenses| OffenseGroup.new(cop_name, offenses) }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module Datarockets
2
2
  module Style
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,33 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datarockets-style
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Dubrovsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-26 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0.74'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '0.76'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '0.74'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
26
  version: '0.76'
33
27
  - !ruby/object:Gem::Dependency
@@ -44,20 +38,6 @@ dependencies:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
40
  version: '1.36'
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '13.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '13.0'
61
41
  description:
62
42
  email:
63
43
  - r.dubrovsky@datarockets.com
@@ -69,6 +49,8 @@ files:
69
49
  - ".github/ISSUE_TEMPLATE/update-dependencies.md"
70
50
  - ".github/PULL_REQUEST_TEMPLATE.md"
71
51
  - ".gitignore"
52
+ - ".rspec"
53
+ - ".rubocop.yml"
72
54
  - CHANGELOG.md
73
55
  - CODE_OF_CONDUCT.md
74
56
  - CONTRIBUTING.md
@@ -89,6 +71,8 @@ files:
89
71
  - doc/STYLE_GUIDE_RAILS.md
90
72
  - doc/STYLE_GUIDE_RSPEC.md
91
73
  - lib/datarockets/style.rb
74
+ - lib/datarockets/style/formatter/todo_list_formatter.rb
75
+ - lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb
92
76
  - lib/datarockets/style/version.rb
93
77
  homepage: https://github.com/datarockets/datarockets-style
94
78
  licenses: