warder 0.0.5 → 0.1.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
  SHA1:
3
- metadata.gz: fc8cbd6a237c8d556bc4687b9b60e9e15f85f949
4
- data.tar.gz: 2a924aac4f06f29fc2b0d4316d0be2bfb9781985
3
+ metadata.gz: 2a3b747efc10322afbbab18ffee926e8f295d49e
4
+ data.tar.gz: 2e19acd6acafa06d5dbbb0fb2239c9481fa2198d
5
5
  SHA512:
6
- metadata.gz: 2db930a7f422e391811b59e8af1fc81ae3aa4b348887f7339550f819ccf567122570ac906de866e46cced52a8c1ffc23b956c70c6e78d32f4b2fe9dbcaab35c8
7
- data.tar.gz: 70a4af9fe6971c9587db930cd7d6bb24fa29dc77a8a69e1b3e7cc6b0e867cecc3f13e2d7f36e12769184375943b5ff4f5b2a1de7bbca61b628e80b57952e8a46
6
+ metadata.gz: 2833211ec3ab3c9b7b0eb0e9cbd15f78a1efed8b0b0177059cb177fbb655fb8ce53ce7d31dbfd3444bf808af414f35d6e1444fc6695e0f4145f8eeace923ab4c
7
+ data.tar.gz: 56bb3aa2d6837e463ae48f7128c4b1dd70931a65ac83b6d9f21a300aae0e3f6e0a767aa7e5ba339c65a353880ce343c8ace60559236b6dc53dfeec1604d511fd
data/bin/warder CHANGED
@@ -7,6 +7,8 @@ require 'warder'
7
7
 
8
8
  options = {}
9
9
  OptionParser.new do |opts|
10
+ opts.banner = "Usage: warder [options] [dir1 file1 file2 ...]"
11
+
10
12
  desc = 'Run style guide validation'
11
13
  opts.on('-g', '--[no-]style-guide', desc) do |value|
12
14
  options[:style_guide] = value
@@ -18,14 +20,26 @@ OptionParser.new do |opts|
18
20
  end
19
21
 
20
22
  desc = 'Run code duplication validation'
21
- opts.on('-d', '--[no-]code-duplications', desc) do |value|
22
- options[:code_duplications] = value
23
+ opts.on('-d', '--[no-]code-duplication', desc) do |value|
24
+ options[:code_duplication] = value
23
25
  end
24
26
 
25
27
  desc = 'Run code smells validation'
26
28
  opts.on('-s', '--[no-]code-smells', desc) do |value|
27
29
  options[:code_smells] = value
28
30
  end
31
+
32
+ desc = 'Run code complexity validation'
33
+ opts.on('-c', '--[no-]code-complexity', desc) do |value|
34
+ options[:code_complexity] = value
35
+ end
36
+
37
+ opts.on('-v', '--version', 'Show version') do |value|
38
+ puts Warder::VERSION
39
+ exit 0
40
+ end
29
41
  end.parse!
30
42
 
43
+ options[:files] = ARGV.join(' ')
44
+
31
45
  Warder::CLI.new(options).perform
@@ -1,4 +1,4 @@
1
- <% std_opts = "--format 'pretty'" %>
1
+ <% std_opts = "--color --format 'pretty'" %>
2
2
  default: <%= std_opts %> --strict features
3
- ok: <%= std_opts %> --no-color --strict --tags ~@wip features
3
+ ok: <%= std_opts %> --strict --tags ~@wip features
4
4
  wip: <%= std_opts %> --tags @wip:1 --wip features
@@ -0,0 +1,30 @@
1
+ Feature: detects code complexity
2
+ In order to find code complexity
3
+ As a ruby developer
4
+ I want to run warder with --code-complexity option
5
+
6
+ Scenario: run warder with enabled code complexity option
7
+ Given I have valid file in directory
8
+ When I run `warder --code-complexity`
9
+ Then warder detects code complexity
10
+ Then the exit status should be 0
11
+
12
+ Scenario: run warder with enabled code complexity option on invalid file
13
+ Given I have invalid_code_complexity file in directory
14
+ When I run `warder --code-complexity`
15
+ Then warder detects code complexity
16
+ Then the exit status should be 1
17
+
18
+ Scenario: run warder with enabled code complexity option on valid file only
19
+ Given I have valid file in directory
20
+ And I have invalid_code_complexity file in directory
21
+ When I run `warder --code-complexity valid.rb`
22
+ Then warder does nothing
23
+ Then the exit status should be 0
24
+
25
+ Scenario: run warder with disabled code complexity option on invalid file
26
+ Given I have invalid_code_complexity file in directory
27
+ When I run `warder --no-code-complexity`
28
+ Then warder does nothing
29
+ Then the exit status should be 0
30
+
@@ -0,0 +1,29 @@
1
+ Feature: detects code duplication
2
+ In order to find code duplication
3
+ As a ruby developer
4
+ I want to run warder with --code-duplication option
5
+
6
+ Scenario: run warder with enabled code duplication option
7
+ Given I have valid file in directory
8
+ When I run `warder --code-duplication`
9
+ Then warder detects code duplication
10
+ Then the exit status should be 0
11
+
12
+ Scenario: run warder with enabled code duplication option on invalid file
13
+ Given I have invalid_code_duplication file in directory
14
+ When I run `warder --code-duplication`
15
+ Then warder detects code duplication
16
+ Then the exit status should be 1
17
+
18
+ Scenario: run warder with enabled code duplication option on valid file only
19
+ Given I have valid file in directory
20
+ And I have invalid_code_duplication file in directory
21
+ When I run `warder --code-duplication valid.rb`
22
+ Then warder does nothing
23
+ Then the exit status should be 0
24
+
25
+ Scenario: run warder with disabled code duplication option on invalid file
26
+ Given I have invalid_code_duplication file in directory
27
+ When I run `warder --no-code-duplication`
28
+ Then warder does nothing
29
+ Then the exit status should be 0
@@ -15,6 +15,13 @@ Feature: detects code smells
15
15
  Then warder detects code smells
16
16
  Then the exit status should be 1
17
17
 
18
+ Scenario: run warder with enabled code smells option on valid file only
19
+ Given I have valid file in directory
20
+ And I have invalid_code_smells file in directory
21
+ When I run `warder --code-smells valid.rb`
22
+ Then warder does nothing
23
+ Then the exit status should be 0
24
+
18
25
  Scenario: run warder with disabled code smells option on invalid file
19
26
  Given I have invalid_code_smells file in directory
20
27
  When I run `warder --no-code-smells`
@@ -15,6 +15,13 @@ Feature: detects magick numbers
15
15
  Then warder detects magick numbers
16
16
  Then the exit status should be 1
17
17
 
18
+ Scenario: run warder with enabled magick numbers option on valid file only
19
+ Given I have valid file in directory
20
+ And I have invalid_magick_numbers file in directory
21
+ When I run `warder --magick-numbers valid.rb`
22
+ Then warder does nothing
23
+ Then the exit status should be 0
24
+
18
25
  Scenario: run warder with disabled style guide option on invalid file
19
26
  Given I have invalid_magick_numbers file in directory
20
27
  When I run `warder --no-magick-numbers`
@@ -0,0 +1,8 @@
1
+ Feature: show version
2
+ In order to check program version
3
+ I want to run warder with --version option
4
+
5
+ Scenario: run warder with enabled version option
6
+ When I run `warder --version`
7
+ Then warder shows version
8
+ And the exit status should be 0
@@ -0,0 +1,8 @@
1
+ Then(/^warder detects code complexity$/) do
2
+ executing_flog_output = "executing 'flog -a -c -g -m .'"
3
+ success_flog_output = `cd spec/fixtures/ && flog -a -c -g -m ./#{@filename}`
4
+ step "the output should contain \"#{executing_flog_output}\""
5
+ success_flog_output.split("\n").each do |string|
6
+ step "the output should contain \"#{string}\""
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ Then(/^warder detects code duplication$/) do
2
+ executing_flay_output = "executing 'flay -d -m 15 .'"
3
+ success_flay_output = `cd spec/fixtures/ && flay -d ./#{@filename}`
4
+ step "the output should contain \"#{executing_flay_output}\""
5
+ success_flay_output.split("\n").each do |string|
6
+ step "the output should contain \"#{string}\""
7
+ end
8
+ end
@@ -3,6 +3,6 @@ Then(/^warder detects code smells$/) do
3
3
  success_reek_output = `cd spec/fixtures/ && reek #{@filename}`
4
4
  step "the output should contain \"#{executing_reek_output}\""
5
5
  success_reek_output.split("\n").each do |string|
6
- step "the output should contain \"#{string.sub('spec/fixtures/', './')}\""
6
+ step "the output should contain \"#{string}\""
7
7
  end
8
8
  end
@@ -1,8 +1,8 @@
1
1
  Then(/^warder detects magick numbers$/) do
2
- executing_mago_output = "executing 'mago'"
3
- success_mago_output = `mago spec/fixtures/#{@filename}`
2
+ executing_mago_output = "executing 'mago .'"
3
+ success_mago_output = `cd spec/fixtures/ && mago #{@filename}`
4
4
  step "the output should contain \"#{executing_mago_output}\""
5
5
  success_mago_output.split("\n").each do |string|
6
- step "the output should contain \"#{string.sub('spec/fixtures/', './')}\""
6
+ step "the output should contain \"#{string}\""
7
7
  end
8
8
  end
@@ -0,0 +1,3 @@
1
+ Then(/^warder shows version$/) do
2
+ step "the output should contain \"#{Warder::VERSION}\""
3
+ end
@@ -1,6 +1,8 @@
1
1
  Then(/^warder validates style guide$/) do
2
- executing_rubocop_output = "executing 'rubocop'"
3
- success_rubocop_output = `rubocop spec/fixtures/#{@filename} | grep offence`
2
+ executing_rubocop_output = "executing 'rubocop .'"
3
+ success_rubocop_output = `cd spec/fixtures/ && rubocop #{@filename}`
4
4
  step "the output should contain \"#{executing_rubocop_output}\""
5
- step "the output should contain \"#{success_rubocop_output}\""
5
+ success_rubocop_output.split("\n").each do |string|
6
+ step "the output should contain \"#{string}\""
7
+ end
6
8
  end
@@ -15,6 +15,13 @@ Feature: check style guide
15
15
  Then warder validates style guide
16
16
  Then the exit status should be 1
17
17
 
18
+ Scenario: run warder with enabled style guide option on valid file only
19
+ Given I have valid file in directory
20
+ And I have invalid_style_guide file in directory
21
+ When I run `warder --style-guide valid.rb`
22
+ Then warder does nothing
23
+ Then the exit status should be 0
24
+
18
25
  Scenario: run warder with disabled style guide option on invalid file
19
26
  Given I have invalid_style_guide file in directory
20
27
  When I run `warder --no-style-guide`
@@ -1,7 +1,9 @@
1
+ require 'ostruct'
1
2
  require 'warder/version'
2
3
  require 'warder/runner'
3
4
  require 'warder/style_guide_runner'
4
5
  require 'warder/magick_numbers_runner'
5
- require 'warder/code_duplications_runner'
6
+ require 'warder/code_duplication_runner'
6
7
  require 'warder/code_smells_runner'
8
+ require 'warder/code_complexity_runner'
7
9
  require 'warder/cli'
@@ -2,20 +2,22 @@ module Warder
2
2
  # responsible for executing warder tools
3
3
  class CLI
4
4
  def initialize(options)
5
- @options = options
5
+ options[:files] = '.' if options[:files].empty?
6
+ @options = OpenStruct.new(options)
6
7
  end
7
8
 
8
9
  def perform
9
10
  exit perform_style_guide_validation +
10
11
  perform_magick_numbers_validation +
11
- perform_code_duplications_validation +
12
- perform_code_smells_validation
12
+ perform_code_duplication_validation +
13
+ perform_code_smells_validation +
14
+ perform_code_complexity_validation
13
15
  end
14
16
 
15
17
  private
16
18
 
17
19
  def perform_style_guide_validation
18
- if @options[:style_guide]
20
+ if @options.style_guide
19
21
  runner = StyleGuideRunner.new(@options)
20
22
  runner.perform
21
23
  else
@@ -24,7 +26,7 @@ module Warder
24
26
  end
25
27
 
26
28
  def perform_magick_numbers_validation
27
- if @options[:magick_numbers]
29
+ if @options.magick_numbers
28
30
  runner = MagickNumbersRunner.new(@options)
29
31
  runner.perform
30
32
  else
@@ -32,9 +34,9 @@ module Warder
32
34
  end
33
35
  end
34
36
 
35
- def perform_code_duplications_validation
36
- if @options[:code_duplications]
37
- runner = CodeDuplicationsRunner.new(@options)
37
+ def perform_code_duplication_validation
38
+ if @options.code_duplication
39
+ runner = CodeDuplicationRunner.new(@options)
38
40
  runner.perform
39
41
  else
40
42
  0
@@ -42,12 +44,21 @@ module Warder
42
44
  end
43
45
 
44
46
  def perform_code_smells_validation
45
- if @options[:code_smells]
47
+ if @options.code_smells
46
48
  runner = CodeSmellsRunner.new(@options)
47
49
  runner.perform
48
50
  else
49
51
  0
50
52
  end
51
53
  end
54
+
55
+ def perform_code_complexity_validation
56
+ if @options.code_complexity
57
+ runner = CodeComplexityRunner.new(@options)
58
+ runner.perform
59
+ else
60
+ 0
61
+ end
62
+ end
52
63
  end
53
64
  end
@@ -0,0 +1,22 @@
1
+ module Warder
2
+ # responsible for run code complexity validation
3
+ class CodeComplexityRunner < Runner
4
+ FLOG_SCORE = SCORE
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ end
9
+
10
+ private
11
+
12
+ def command
13
+ "flog -a -c -g -m #{@options.files}"
14
+ end
15
+
16
+ def failed?(line)
17
+ match = line.match(/^\s+(\d+.\d):\s+(.*)$/)
18
+
19
+ match && match[1].to_f > FLOG_SCORE && !match[2].match(/^flog/)
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,6 @@
1
1
  module Warder
2
- # responsible for run code duplications validation
3
- class CodeDuplicationsRunner < Runner
2
+ # responsible for run code duplication validation
3
+ class CodeDuplicationRunner < Runner
4
4
  FLAY_SCORE = SCORE / 2
5
5
 
6
6
  def initialize(options = {})
@@ -10,7 +10,7 @@ module Warder
10
10
  private
11
11
 
12
12
  def command
13
- "flay -d -m #{FLAY_SCORE} ."
13
+ "flay -d -m #{FLAY_SCORE} #{@options.files}"
14
14
  end
15
15
 
16
16
  def failed?(line)
@@ -8,7 +8,7 @@ module Warder
8
8
  private
9
9
 
10
10
  def command
11
- 'reek .'
11
+ "reek #{@options.files}"
12
12
  end
13
13
 
14
14
  def failed?(line)
@@ -8,7 +8,7 @@ module Warder
8
8
  private
9
9
 
10
10
  def command
11
- 'mago'
11
+ "mago #{@options.files}"
12
12
  end
13
13
 
14
14
  def failed?(line)
@@ -8,7 +8,7 @@ module Warder
8
8
  private
9
9
 
10
10
  def command
11
- 'rubocop'
11
+ "rubocop #{@options.files}"
12
12
  end
13
13
 
14
14
  def failed?(line)
@@ -1,4 +1,4 @@
1
1
  # define warder version
2
2
  module Warder
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -0,0 +1,13 @@
1
+ def a
2
+ b = 1 + 2 + 3 + 4 + 5
3
+ c = 6 + 7 + 8 + 9 + 0
4
+ d = 1 + 7 + 3 + 9 + 5
5
+ e = 6 + 2 + 8 + 4 + 0
6
+ f = 1 + 2 + 3 + 4 + 5
7
+ g = 6 + 7 + 8 + 9 + 0
8
+ h = 1 + 7 + 3 + 9 + 5
9
+ i = 6 + 2 + 8 + 4 + 0
10
+ j = b + c + d + e + f + g + h + i
11
+ end
12
+
13
+ puts a
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'reek'
23
23
  spec.add_dependency 'flay'
24
24
  spec.add_dependency 'ruby2ruby'
25
- # spec.add_dependency 'flog'
25
+ spec.add_dependency 'flog'
26
26
  spec.add_dependency 'mago'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yura Tolstik
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: flog
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: mago
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -166,26 +180,32 @@ files:
166
180
  - Rakefile
167
181
  - bin/warder
168
182
  - cucumber.yml
169
- - features/detects_code_duplications.feature
183
+ - features/detects_code_complexity.feature
184
+ - features/detects_code_duplication.feature
170
185
  - features/detects_code_smells.feature
171
186
  - features/detects_magick_numbers.feature
172
187
  - features/run.feature
173
- - features/step_definitions/detects_code_duplications_steps.rb
188
+ - features/show_version.feature
189
+ - features/step_definitions/detects_code_complexity_steps.rb
190
+ - features/step_definitions/detects_code_duplication_steps.rb
174
191
  - features/step_definitions/detects_code_smells_steps.rb
175
192
  - features/step_definitions/detects_magick_numbers_steps.rb
176
193
  - features/step_definitions/run_steps.rb
194
+ - features/step_definitions/show_version_steps.rb
177
195
  - features/step_definitions/validates_style_guide_steps.rb
178
196
  - features/support/env.rb
179
197
  - features/validates_style_guide.feature
180
198
  - lib/warder.rb
181
199
  - lib/warder/cli.rb
182
- - lib/warder/code_duplications_runner.rb
200
+ - lib/warder/code_complexity_runner.rb
201
+ - lib/warder/code_duplication_runner.rb
183
202
  - lib/warder/code_smells_runner.rb
184
203
  - lib/warder/magick_numbers_runner.rb
185
204
  - lib/warder/runner.rb
186
205
  - lib/warder/style_guide_runner.rb
187
206
  - lib/warder/version.rb
188
- - spec/fixtures/invalid_code_duplications.rb
207
+ - spec/fixtures/invalid_code_complexity.rb
208
+ - spec/fixtures/invalid_code_duplication.rb
189
209
  - spec/fixtures/invalid_code_smells.rb
190
210
  - spec/fixtures/invalid_magick_numbers.rb
191
211
  - spec/fixtures/invalid_style_guide.rb
@@ -218,18 +238,23 @@ signing_key:
218
238
  specification_version: 4
219
239
  summary: Warder of ruby code
220
240
  test_files:
221
- - features/detects_code_duplications.feature
241
+ - features/detects_code_complexity.feature
242
+ - features/detects_code_duplication.feature
222
243
  - features/detects_code_smells.feature
223
244
  - features/detects_magick_numbers.feature
224
245
  - features/run.feature
225
- - features/step_definitions/detects_code_duplications_steps.rb
246
+ - features/show_version.feature
247
+ - features/step_definitions/detects_code_complexity_steps.rb
248
+ - features/step_definitions/detects_code_duplication_steps.rb
226
249
  - features/step_definitions/detects_code_smells_steps.rb
227
250
  - features/step_definitions/detects_magick_numbers_steps.rb
228
251
  - features/step_definitions/run_steps.rb
252
+ - features/step_definitions/show_version_steps.rb
229
253
  - features/step_definitions/validates_style_guide_steps.rb
230
254
  - features/support/env.rb
231
255
  - features/validates_style_guide.feature
232
- - spec/fixtures/invalid_code_duplications.rb
256
+ - spec/fixtures/invalid_code_complexity.rb
257
+ - spec/fixtures/invalid_code_duplication.rb
233
258
  - spec/fixtures/invalid_code_smells.rb
234
259
  - spec/fixtures/invalid_magick_numbers.rb
235
260
  - spec/fixtures/invalid_style_guide.rb
@@ -1,22 +0,0 @@
1
- Feature: detects code duplications
2
- In order to find code duplications
3
- As a ruby developer
4
- I want to run warder with --code-duplications option
5
-
6
- Scenario: run warder with enabled code duplications option
7
- Given I have valid file in directory
8
- When I run `warder --code-duplications`
9
- Then warder detects code duplications
10
- Then the exit status should be 0
11
-
12
- Scenario: run warder with enabled code duplications option on invalid file
13
- Given I have invalid_code_duplications file in directory
14
- When I run `warder --code-duplications`
15
- Then warder detects code duplications
16
- Then the exit status should be 1
17
-
18
- Scenario: run warder with disabled code duplications option on invalid file
19
- Given I have invalid_code_duplications file in directory
20
- When I run `warder --no-code-duplications`
21
- Then warder does nothing
22
- Then the exit status should be 0
@@ -1,8 +0,0 @@
1
- Then(/^warder detects code duplications$/) do
2
- executing_flay_output = "executing 'flay -d -m 15 .'"
3
- success_flay_output = `flay -d spec/fixtures/#{@filename}`
4
- step "the output should contain \"#{executing_flay_output}\""
5
- success_flay_output.split("\n").each do |string|
6
- step "the output should contain \"#{string.sub('spec/fixtures/', './')}\""
7
- end
8
- end