Skip to content

Commit f619834

Browse files
authored
Rubocop (#31)
* Install rubocop * Correct Style/HashSyntax * Correct Layout/SpaceInsideHashLiteralBraces * Correct Style/Lambda * Correct Style/SymbolArray * Correct Layout/SpaceAfterComma * Correct Layout/SpaceAroundOperators * Correct Style/FrozenStringLiteralComment * Correct hash related cops * Correct Layout/TrailingWhitespace * Correct all Layout cops * Correct all Style cops * Correct all RSpec cops possible * Final rubocop config and TODO * Add rubocop action
1 parent 80800d1 commit f619834

31 files changed

+2201
-1893
lines changed

.github/workflows/linters.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Linters
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
rubocop:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Ruby
16+
uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: 3.0
19+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
20+
- name: Run rubocop
21+
run: bundle exec rubocop

.rubocop.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
require:
4+
- rubocop-performance
5+
- rubocop-rspec
6+
7+
AllCops:
8+
NewCops: enable
9+
10+
Naming/VariableNumber:
11+
Enabled: false
12+
13+
Metrics/BlockLength:
14+
IgnoredMethods: ['describe', 'context']
15+
16+
RSpec/MultipleExpectations:
17+
Enabled: false
18+
19+
RSpec/NestedGroups:
20+
Max: 5
21+
22+
RSpec/ImplicitSubject:
23+
EnforcedStyle: single_statement_only
24+
25+
Style/NumericLiterals:
26+
Enabled: false

.rubocop_todo.yml

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2021-09-18 01:17:40 UTC using RuboCop version 1.21.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
# Cop supports --auto-correct.
11+
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12+
# Include: **/*.gemspec
13+
Gemspec/OrderedDependencies:
14+
Exclude:
15+
- 'fit.gemspec'
16+
17+
# Offense count: 1
18+
# Configuration parameters: Include.
19+
# Include: **/*.gemspec
20+
Gemspec/RequiredRubyVersion:
21+
Exclude:
22+
- 'fit.gemspec'
23+
24+
# Offense count: 6
25+
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
26+
Lint/DuplicateBranch:
27+
Exclude:
28+
- 'lib/fit/file/definition.rb'
29+
30+
# Offense count: 1
31+
Lint/FloatComparison:
32+
Exclude:
33+
- 'spec/fit/file/record_spec.rb'
34+
35+
# Offense count: 1
36+
# Cop supports --auto-correct.
37+
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
38+
Lint/UnusedBlockArgument:
39+
Exclude:
40+
- 'lib/fit/file/data.rb'
41+
42+
# Offense count: 2
43+
# Cop supports --auto-correct.
44+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
45+
Lint/UnusedMethodArgument:
46+
Exclude:
47+
- 'lib/fit/file/types.rb'
48+
49+
# Offense count: 4
50+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
51+
Metrics/AbcSize:
52+
Max: 72
53+
54+
# Offense count: 3
55+
# Configuration parameters: IgnoredMethods.
56+
Metrics/CyclomaticComplexity:
57+
Max: 18
58+
59+
# Offense count: 5
60+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
61+
Metrics/MethodLength:
62+
Max: 65
63+
64+
# Offense count: 2
65+
# Configuration parameters: IgnoredMethods.
66+
Metrics/PerceivedComplexity:
67+
Max: 23
68+
69+
# Offense count: 1
70+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
71+
# NamePrefix: is_, has_, have_
72+
# ForbiddenPrefixes: is_, has_, have_
73+
# AllowedMethods: is_a?
74+
# MethodDefinitionMacros: define_method, define_singleton_method
75+
Naming/PredicateName:
76+
Exclude:
77+
- 'spec/**/*'
78+
- 'lib/fit/file/type.rb'
79+
80+
# Offense count: 8
81+
RSpec/BeforeAfterAll:
82+
Exclude:
83+
- 'spec/spec_helper.rb'
84+
- 'spec/rails_helper.rb'
85+
- 'spec/support/**/*.rb'
86+
- 'spec/fit/file/data_spec.rb'
87+
- 'spec/fit/file/definitions_spec.rb'
88+
- 'spec/fit/file/type_spec.rb'
89+
- 'spec/fit/file/types_spec.rb'
90+
91+
# Offense count: 18
92+
# Configuration parameters: Prefixes.
93+
# Prefixes: when, with, without
94+
RSpec/ContextWording:
95+
Exclude:
96+
- 'spec/fit/file/data_spec.rb'
97+
- 'spec/fit/file/definition_spec.rb'
98+
- 'spec/fit/file/record_spec.rb'
99+
- 'spec/fit/file/type_spec.rb'
100+
- 'spec/fit/file/types_spec.rb'
101+
102+
# Offense count: 1
103+
RSpec/EmptyExampleGroup:
104+
Exclude:
105+
- 'spec/fit/file/record_spec.rb'
106+
107+
# Offense count: 1
108+
# Configuration parameters: CountAsOne.
109+
RSpec/ExampleLength:
110+
Max: 6
111+
112+
# Offense count: 36
113+
# Configuration parameters: AssignmentOnly.
114+
RSpec/InstanceVariable:
115+
Exclude:
116+
- 'spec/fit/file/data_spec.rb'
117+
- 'spec/fit/file/definitions_spec.rb'
118+
- 'spec/fit/file/type_spec.rb'
119+
- 'spec/fit/file/types_spec.rb'
120+
121+
# Offense count: 16
122+
# Configuration parameters: IgnoreSharedExamples.
123+
RSpec/NamedSubject:
124+
Exclude:
125+
- 'spec/fit/file/definition_spec.rb'
126+
- 'spec/fit/file/record_spec.rb'
127+
128+
# Offense count: 17
129+
Style/ClassVars:
130+
Exclude:
131+
- 'lib/fit/file/definitions.rb'
132+
- 'lib/fit/file/record.rb'
133+
- 'lib/fit/file/type.rb'
134+
- 'lib/fit/file/types.rb'
135+
- 'spec/fit/file/data_spec.rb'
136+
- 'spec/fit/file/definitions_spec.rb'
137+
- 'spec/fit/file/type_spec.rb'
138+
- 'spec/fit/file/types_spec.rb'
139+
140+
# Offense count: 1
141+
Style/DocumentDynamicEvalDefinition:
142+
Exclude:
143+
- 'lib/fit/file/data.rb'
144+
145+
# Offense count: 11
146+
# Configuration parameters: AllowedConstants.
147+
Style/Documentation:
148+
Exclude:
149+
- 'spec/**/*'
150+
- 'test/**/*'
151+
- 'lib/fit.rb'
152+
- 'lib/fit/file.rb'
153+
- 'lib/fit/file/data.rb'
154+
- 'lib/fit/file/definition.rb'
155+
- 'lib/fit/file/definitions.rb'
156+
- 'lib/fit/file/header.rb'
157+
- 'lib/fit/file/record.rb'
158+
- 'lib/fit/file/record_header.rb'
159+
- 'lib/fit/file/type.rb'
160+
- 'lib/fit/file/types.rb'
161+
162+
# Offense count: 3
163+
# Cop supports --auto-correct.
164+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
165+
# URISchemes: http, https
166+
Layout/LineLength:
167+
Max: 131

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
# Specify your gem's dependencies in fit.gemspec
46
gemspec
7+
8+
gem 'rubocop'
9+
gem 'rubocop-performance'
10+
gem 'rubocop-rspec'

Rakefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require "bundler/gem_tasks"
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
24

35
require 'rspec/core/rake_task'
46
RSpec::Core::RakeTask.new(:spec)
5-
task :default => :spec
7+
task default: :spec

fit.gemspec

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
require 'English'
4+
lib = File.expand_path('lib', __dir__)
35
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
46
require 'fit/version'
57

68
Gem::Specification.new do |spec|
7-
spec.name = "fit-parser"
9+
spec.name = 'fit-parser'
810
spec.version = Fit::VERSION
9-
spec.authors = ["Jeff Wallace"]
10-
spec.email = ["[email protected]"]
11-
spec.description = %q{Ruby gem for reading Garmin FIT files}
12-
spec.summary = %q{Ruby gem for reading Garmin FIT files}
13-
spec.homepage = "https://github.com/tjwallace/fit"
14-
spec.license = "MIT"
11+
spec.authors = ['Jeff Wallace']
12+
spec.email = ['[email protected]']
13+
spec.description = 'Ruby gem for reading Garmin FIT files'
14+
spec.summary = 'Ruby gem for reading Garmin FIT files'
15+
spec.homepage = 'https://github.com/tjwallace/fit'
16+
spec.license = 'MIT'
1517

16-
spec.files = `git ls-files`.split($/)
18+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
1719
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
1820
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19-
spec.require_paths = ["lib"]
21+
spec.require_paths = ['lib']
2022

21-
spec.add_dependency "bindata", "~> 2.4"
22-
spec.add_dependency "activesupport", "~> 6.1"
23+
spec.add_dependency 'bindata', '~> 2.4'
24+
spec.add_dependency 'activesupport', '~> 6.1'
2325

24-
spec.add_development_dependency "bundler", "~> 2.1"
25-
spec.add_development_dependency "rake"
26-
spec.add_development_dependency "rspec", "~> 3.10"
27-
spec.add_development_dependency "rspec-its"
28-
spec.add_development_dependency "simplecov"
29-
spec.add_development_dependency "pry"
26+
spec.add_development_dependency 'bundler', '~> 2.1'
27+
spec.add_development_dependency 'rake'
28+
spec.add_development_dependency 'rspec', '~> 3.10'
29+
spec.add_development_dependency 'rspec-its'
30+
spec.add_development_dependency 'simplecov'
31+
spec.add_development_dependency 'pry'
3032
end

lib/fit.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bindata'
24
require 'active_support'
35
require 'active_support/core_ext/class'
@@ -15,9 +17,7 @@
1517
require 'fit/version'
1618

1719
module Fit
18-
1920
def self.load_file(path)
2021
File.read ::File.open(path)
2122
end
22-
2323
end

lib/fit/file.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# frozen_string_literal: true
2+
13
module Fit
24
class File
3-
45
def self.read(io)
56
new.read(io)
67
end
@@ -16,14 +17,11 @@ def read(io)
1617

1718
Record.clear_definitions!
1819

19-
while io.pos < @header.end_pos
20-
@records << Record.read(io)
21-
end
20+
@records << Record.read(io) while io.pos < @header.end_pos
2221

2322
@crc = io.read(2)
2423

2524
self
2625
end
27-
2826
end
2927
end

0 commit comments

Comments
 (0)