Skip to content

Commit 130dc91

Browse files
author
Federico Moya
committed
Add rucoop && enforce styling
1 parent 6e17016 commit 130dc91

12 files changed

+96
-46
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AllCops:
2+
TargetRubyVersion: 2.4
3+
4+
Style/Documentation:
5+
Enabled: false

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
22

3-
gemspec
3+
source 'https://rubygems.org'
44

55
group :development do
66
gem 'byebug'
7+
gem 'rake', '~> 12.0'
8+
gem 'rubocop'
9+
gem 'test-unit'
710
end

Gemfile.lock

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
PATH
2-
remote: .
3-
specs:
4-
simplecov-json-formatter (0.1.1)
5-
json
6-
simplecov (~> 0.18, >= 0.18.0)
7-
81
GEM
92
remote: https://rubygems.org/
103
specs:
4+
ast (2.4.1)
115
byebug (11.1.3)
12-
docile (1.3.2)
13-
json (2.3.1)
6+
parallel (1.19.2)
7+
parser (2.7.1.4)
8+
ast (~> 2.4.1)
149
power_assert (1.2.0)
15-
rake (13.0.1)
16-
simplecov (0.18.5)
17-
docile (~> 1.1)
18-
simplecov-html (~> 0.11)
19-
simplecov-html (0.12.2)
10+
rainbow (3.0.0)
11+
rake (12.3.3)
12+
regexp_parser (1.7.1)
13+
rexml (3.2.4)
14+
rubocop (0.89.1)
15+
parallel (~> 1.10)
16+
parser (>= 2.7.1.1)
17+
rainbow (>= 2.2.2, < 4.0)
18+
regexp_parser (>= 1.7)
19+
rexml
20+
rubocop-ast (>= 0.3.0, < 1.0)
21+
ruby-progressbar (~> 1.7)
22+
unicode-display_width (>= 1.4.0, < 2.0)
23+
rubocop-ast (0.3.0)
24+
parser (>= 2.7.1.4)
25+
ruby-progressbar (1.10.1)
2026
test-unit (3.3.6)
2127
power_assert
28+
unicode-display_width (1.7.0)
2229

2330
PLATFORMS
2431
ruby
2532

2633
DEPENDENCIES
2734
byebug
28-
rake
29-
simplecov-json-formatter!
35+
rake (~> 12.0)
36+
rubocop
3037
test-unit
3138

3239
BUNDLED WITH

Rakefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
require 'bundler/gem_tasks'
1+
# frozen_string_literal: true
2+
3+
require 'bundler/setup'
24
require 'rake/testtask'
35

46
Rake::TestTask.new(:test) do |t|
@@ -7,4 +9,13 @@ Rake::TestTask.new(:test) do |t|
79
t.test_files = FileList['test/**/*_test.rb']
810
end
911

10-
task :default => :test
12+
begin
13+
require 'rubocop/rake_task'
14+
RuboCop::RakeTask.new
15+
rescue LoadError
16+
task :rubocop do
17+
warn 'Rubocop is disabled'
18+
end
19+
end
20+
21+
task default: %i[rubocop test]

lib/simplecov-json-formatter.rb renamed to lib/simplecov_json_formatter.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
require 'simplecov'
2-
require 'simplecov-json-formatter/result_hash_formatter'
3-
require 'simplecov-json-formatter/result_exporter'
4+
require 'simplecov_json_formatter/result_hash_formatter'
5+
require 'simplecov_json_formatter/result_exporter'
46
require 'json'
57

68
module SimpleCov
@@ -27,7 +29,8 @@ def export_formatted_result(result_hash)
2729
end
2830

2931
def output_message(result)
30-
"JSON Coverage report generated for #{result.command_name} to #{SimpleCov.coverage_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
32+
"JSON Coverage report generated for #{result.command_name} to #{SimpleCov.coverage_path}. \
33+
#{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
3134
end
3235
end
3336
end

lib/simplecov-json-formatter/result_exporter.rb renamed to lib/simplecov_json_formatter/result_exporter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module SimpleCovJSONFormatter
24
class ResultExporter
3-
FILENAME='coverage.json'
5+
FILENAME = 'coverage.json'
46

57
def initialize(result_hash)
68
@result = result_hash

lib/simplecov-json-formatter/result_hash_formatter.rb renamed to lib/simplecov_json_formatter/result_hash_formatter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
require 'simplecov-json-formatter/source_file_formatter'
1+
# frozen_string_literal: true
2+
3+
require 'simplecov_json_formatter/source_file_formatter'
24

35
module SimpleCovJSONFormatter
46
class ResultHashFormatter

lib/simplecov-json-formatter/source_file_formatter.rb renamed to lib/simplecov_json_formatter/source_file_formatter.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1+
# frozen_string_literal: true
2+
13
module SimpleCovJSONFormatter
24
class SourceFileFormatter
35
def initialize(source_file)
46
@source_file = source_file
57
end
68

79
def format
10+
{
11+
lines: lines,
12+
branches: branches
13+
}
14+
end
15+
16+
private
17+
18+
def lines
819
lines = []
920
@source_file.lines.each do |line|
1021
lines << parse_line(line)
1122
end
23+
24+
lines
25+
end
26+
27+
def branches
1228
branches = []
1329
@source_file.branches.each do |branch|
1430
branches << parse_branch(branch)
1531
end
16-
{
17-
lines: lines,
18-
branches: branches,
19-
}
20-
end
2132

22-
private
33+
branches
34+
end
2335

2436
def parse_line(line)
2537
return line.coverage unless line.skipped?
26-
"ignored"
38+
39+
'ignored'
2740
end
2841

2942
def parse_branch(branch)
3043
{
3144
type: branch.type,
3245
start_line: branch.start_line,
3346
end_line: branch.end_line,
34-
coverage: parse_line(branch),
47+
coverage: parse_line(branch)
3548
}
3649
end
3750
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module SimpleCovJSONFormatter
24
VERSION = '0.1.1'
35
end
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
2-
require 'simplecov-json-formatter/version'
1+
# frozen_string_literal: true
32

4-
Gem::Specification.new 'simplecov-json-formatter' do |s|
3+
$LOAD_PATH.push File.expand_path('lib', __dir__)
4+
require 'simplecov_json_formatter/version'
5+
6+
Gem::Specification.new 'simplecov_json_formatter' do |s|
57
s.version = SimpleCovJSONFormatter::VERSION
68
s.platform = Gem::Platform::RUBY
79
s.authors = ['Federico Moya']
810
s.email = ['[email protected]']
9-
s.homepage = 'https://github.com/fede-moya/simplecov-json-formatter'
10-
s.summary = %Q{JSON formatter for SimpleCov}
11+
s.homepage = 'https://github.com/fede-moya/simplecov_json_formatter'
12+
s.summary = %(JSON formatter for SimpleCov)
1113
s.description = s.summary
1214

13-
s.files = Dir['{lib}/**/*.*', "*.md"]
15+
s.files = Dir['{lib}/**/*.*', '*.md']
1416
s.test_files = Dir['{test}/**/*.*']
1517
s.require_paths = ['lib']
1618

1719
s.required_ruby_version = '>= 2.4.0'
18-
19-
s.add_dependency 'simplecov', '~> 0.18', '>= 0.18.0'
20+
2021
s.add_dependency 'json'
21-
22-
s.add_development_dependency 'rake'
23-
s.add_development_dependency 'test-unit'
22+
s.add_dependency 'simplecov', '~> 0.18', '>= 0.18.0'
2423
end

0 commit comments

Comments
 (0)