Skip to content

Commit 62f2058

Browse files
authored
Setup QLTY for code coverage and liniting (#375)
1 parent b5d274b commit 62f2058

File tree

7 files changed

+103
-12
lines changed

7 files changed

+103
-12
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
bundler-cache: true
2727
- name: Tests for Ruby ${{ matrix.ruby }}
2828
run: bundle exec rake
29+
- uses: qltysh/qlty-action/coverage@v2
30+
with:
31+
token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
32+
files: coverage/.resultset.json
2933
# CodeClimate has become qlth.sh, this integration is currently broken.
3034
# coverage:
3135
# needs: test
@@ -43,6 +47,7 @@ jobs:
4347
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
4448
# with:
4549
# coverageCommand: bundle exec rake
50+
4651
yard:
4752
runs-on: ubuntu-latest
4853
env:

.qlty/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*
2+
!configs
3+
!configs/**
4+
!hooks
5+
!hooks/**
6+
!qlty.toml
7+
!.gitignore

.qlty/qlty.toml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This file was automatically generated by `qlty init`.
2+
# You can modify it to suit your needs.
3+
# We recommend you to commit this file to your repository.
4+
#
5+
# This configuration is used by both Qlty CLI and Qlty Cloud.
6+
#
7+
# Qlty CLI -- Code quality toolkit for developers
8+
# Qlty Cloud -- Fully automated Code Health Platform
9+
#
10+
# Try Qlty Cloud: https://qlty.sh
11+
#
12+
# For a guide to configuration, visit https://qlty.sh/d/config
13+
# Or for a full reference, visit https://qlty.sh/d/qlty-toml
14+
config_version = "0"
15+
16+
exclude_patterns = [
17+
"*_min.*",
18+
"*-min.*",
19+
"*.min.*",
20+
"**/.yarn/**",
21+
"**/*.d.ts",
22+
"**/assets/**",
23+
"**/bower_components/**",
24+
"**/build/**",
25+
"**/cache/**",
26+
"**/config/**",
27+
"**/db/**",
28+
"**/deps/**",
29+
"**/dist/**",
30+
"**/extern/**",
31+
"**/external/**",
32+
"**/generated/**",
33+
"**/Godeps/**",
34+
"**/gradlew/**",
35+
"**/mvnw/**",
36+
"**/node_modules/**",
37+
"**/protos/**",
38+
"**/seed/**",
39+
"**/target/**",
40+
"**/templates/**",
41+
"**/testdata/**",
42+
"**/vendor/**",
43+
]
44+
45+
test_patterns = [
46+
"**/test/**",
47+
"**/spec/**",
48+
"**/*.test.*",
49+
"**/*.spec.*",
50+
"**/*_test.*",
51+
"**/*_spec.*",
52+
"**/test_*.*",
53+
"**/spec_*.*",
54+
]
55+
56+
[smells]
57+
mode = "comment"
58+
59+
[smells.boolean_logic]
60+
threshold = 4
61+
62+
[smells.file_complexity]
63+
threshold = 55
64+
65+
[smells.return_statements]
66+
threshold = 4
67+
68+
[smells.nested_control_flow]
69+
threshold = 4
70+
71+
[smells.function_parameters]
72+
threshold = 4
73+
74+
[smells.function_complexity]
75+
threshold = 5
76+
77+
[[source]]
78+
name = "default"
79+
default = true

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require:
3+
plugins:
44
- rubocop-rake
55
- rubocop-rspec
66

lib/ruby_units/math.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def atan(number)
112112
# @return [RubyUnits::Unit] if parameters are units
113113
# @raise [ArgumentError] if parameters are not numbers or compatible units
114114
def atan2(x, y)
115-
raise ArgumentError, "Incompatible RubyUnits::Units" if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && !x.compatible?(y)
115+
raise ArgumentError, "Incompatible RubyUnits::Units" if x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit) && !x.compatible?(y)
116116

117-
if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && x.compatible?(y)
117+
if x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit) && x.compatible?(y)
118118
[super(x.base_scalar, y.base_scalar), "radian"].to_unit
119119
else
120120
super

lib/ruby_units/unit.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def self.inherited(subclass)
180180

181181
# setup internal arrays and hashes
182182
# @return [Boolean]
183-
def self.setup
183+
def self.setup # rubocop:disable Naming/PredicateMethod
184184
clear_cache
185185
self.prefix_values = {}
186186
self.prefix_map = {}
@@ -275,7 +275,7 @@ def self.cached
275275
end
276276

277277
# @return [Boolean]
278-
def self.clear_cache
278+
def self.clear_cache # rubocop:disable Naming/PredicateMethod
279279
cached.clear
280280
base_unit_cache.clear
281281
new(1)
@@ -556,7 +556,7 @@ def initialize(*options)
556556
_opt_scalar, opt_units = self.class.parse_into_numbers_and_units(options[0])
557557
if !(self.class.cached.keys.include?(opt_units) ||
558558
(opt_units =~ %r{\D/[\d+.]+}) ||
559-
(opt_units =~ %r{(#{self.class.temp_regex})|(#{STONE_LB_UNIT_REGEX})|(#{LBS_OZ_UNIT_REGEX})|(#{FEET_INCH_UNITS_REGEX})|%|(#{TIME_REGEX})|i\s?(.+)?|±|\+/-})) && (opt_units && !opt_units.empty?)
559+
(opt_units =~ %r{(#{self.class.temp_regex})|(#{STONE_LB_UNIT_REGEX})|(#{LBS_OZ_UNIT_REGEX})|(#{FEET_INCH_UNITS_REGEX})|%|(#{TIME_REGEX})|i\s?(.+)?|±|\+/-})) && opt_units && !opt_units.empty?
560560
self.class.cached.set(opt_units, scalar == 1 ? self : opt_units.to_unit)
561561
end
562562
end
@@ -682,17 +682,17 @@ def to_s(target_units = nil, precision: 0.0001, format: RubyUnits.configuration.
682682
feet, inches = convert_to("in").scalar.abs.divmod(12)
683683
improper, frac = inches.divmod(1)
684684
frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
685-
out = "#{negative? ? '-' : nil}#{feet}'#{improper}#{frac}\""
685+
out = "#{'-' if negative?}#{feet}'#{improper}#{frac}\""
686686
when :lbs
687687
pounds, ounces = convert_to("oz").scalar.abs.divmod(16)
688688
improper, frac = ounces.divmod(1)
689689
frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
690-
out = "#{negative? ? '-' : nil}#{pounds}#{separator}lbs #{improper}#{frac}#{separator}oz"
690+
out = "#{'-' if negative?}#{pounds}#{separator}lbs #{improper}#{frac}#{separator}oz"
691691
when :stone
692692
stone, pounds = convert_to("lbs").scalar.abs.divmod(14)
693693
improper, frac = pounds.divmod(1)
694694
frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
695-
out = "#{negative? ? '-' : nil}#{stone}#{separator}stone #{improper}#{frac}#{separator}lbs"
695+
out = "#{'-' if negative?}#{stone}#{separator}stone #{improper}#{frac}#{separator}lbs"
696696
when String
697697
out = case target_units.strip
698698
when /\A\s*\Z/ # whitespace only
@@ -1309,7 +1309,7 @@ def units(with_prefix: true, format: nil)
13091309
.uniq
13101310
.map { [_1, output_denominator.count(_1)] }
13111311
.map { |element, power| (element.to_s.strip + (power > 1 ? "^#{power}" : "")) }
1312-
"#{on.join('*')}#{od.empty? ? '' : "/#{od.join('*')}"}".strip
1312+
"#{on.join('*')}#{"/#{od.join('*')}" unless od.empty?}".strip
13131313
end
13141314
end
13151315

@@ -1768,7 +1768,7 @@ def parse(passed_unit_string = "0")
17681768

17691769
# eliminate all known terms from this string. This is a quick check to see if the passed unit
17701770
# contains terms that are not defined.
1771-
used = "#{top} #{bottom}".to_s.gsub(self.class.unit_match_regex, "").gsub(%r{[\d*, "'_^/$]}, "")
1771+
used = "#{top} #{bottom}".gsub(self.class.unit_match_regex, "").gsub(%r{[\d*, "'_^/$]}, "")
17721772
raise(ArgumentError, "'#{passed_unit_string}' Unit not recognized") unless used.empty?
17731773

17741774
@numerator = @numerator.map do |item|

spec/ruby_units/math_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
end
2626

2727
context "with 'PI/4 radians' unit" do
28-
subject(:angle) { RubyUnits::Unit.new((Math::PI / 4), "radians") }
28+
subject(:angle) { RubyUnits::Unit.new(Math::PI / 4, "radians") }
2929

3030
specify { expect(Math.sin(angle)).to be_within(0.01).of(0.70710678) }
3131
specify { expect(Math.cos(angle)).to be_within(0.01).of(0.70710678) }

0 commit comments

Comments
 (0)