Skip to content

Commit 62b41d1

Browse files
committedFeb 11, 2021
Add/update linting and code style
* Add rubocop linting * Add editorconfig for consistent file formatting * Fix code style issues (ignore complexity on main function for now)
1 parent 5858a15 commit 62b41d1

File tree

4 files changed

+64
-34
lines changed

4 files changed

+64
-34
lines changed
 

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

‎.rubocop.yml

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
AllCops:
22
Include:
33
- '**/*.rb'
4-
TargetRubyVersion: 2.1
4+
NewCops: enable
5+
SuggestExtensions: false
6+
TargetRubyVersion: 2.4
7+
8+
Layout/CaseIndentation:
9+
EnforcedStyle: end
10+
IndentOneStep: true
11+
SupportedStyles:
12+
- case
13+
- end
14+
15+
Layout/ArgumentAlignment:
16+
EnforcedStyle: with_fixed_indentation
17+
18+
Layout/SpaceInsideBlockBraces:
19+
EnforcedStyle: space
20+
EnforcedStyleForEmptyBraces: no_space
21+
SpaceBeforeBlockParameters: false
22+
23+
Layout/SpaceInsideHashLiteralBraces:
24+
EnforcedStyle: no_space
25+
526

627
Metrics/BlockLength:
728
Exclude:
8-
- 'spec/**/*_spec.rb'
29+
- Rakefile
30+
- spec/**/*_spec.rb
931

1032
Metrics/LineLength:
1133
Exclude:
12-
- 'spec/**/*_spec.rb'
34+
- spec/**/*_spec.rb
1335

14-
Style/AlignParameters:
15-
EnforcedStyle: with_fixed_indentation
1636

17-
Style/BracesAroundHashParameters:
18-
EnforcedStyle: context_dependent
37+
Naming/FileName:
38+
Exclude:
39+
- lib/rails-timeago.rb
1940

20-
Style/SpaceInsideHashLiteralBraces:
21-
EnforcedStyle: no_space
2241

23-
Style/RaiseArgs:
24-
EnforcedStyle: compact
42+
Style/ClassAndModuleChildren:
43+
Enabled: false
2544

2645
Style/Documentation:
2746
Enabled: false
2847

29-
Style/SpaceInsideBlockBraces:
30-
EnforcedStyle: space
31-
EnforcedStyleForEmptyBraces: no_space
32-
SpaceBeforeBlockParameters: false
48+
Style/RaiseArgs:
49+
EnforcedStyle: compact
3350

3451
Style/SignalException:
3552
EnforcedStyle: only_raise
3653

37-
Style/CaseIndentation:
38-
EnforcedStyle: end
39-
SupportedStyles:
40-
- case
41-
- end
42-
IndentOneStep: true
43-
44-
Style/ClassAndModuleChildren:
45-
Enabled: false
46-
4754
Style/TrivialAccessors:
4855
AllowPredicates: true
49-
50-
Style/FileName:
51-
Exclude:
52-
- Rakefile
53-
- Gemfile

‎Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ gemspec
88
group :development do
99
gem 'rake'
1010
gem 'rake-release'
11+
12+
gem 'rubocop', '~> 1.7'
13+
gem 'rubocop-rspec', '~> 1.42'
1114
end
1215

1316
group :test do

‎lib/rails-timeago/helper.rb

+17-4
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,22 @@ module Helper
4040
#
4141
# All other options will be given as options to tag helper.
4242
#
43+
# rubocop:disable Metrics/AbcSize
44+
# rubocop:disable Metrics/CyclomaticComplexity
45+
# rubocop:disable Metrics/MethodLength
46+
# rubocop:disable Metrics/PerceivedComplexity
4347
def timeago_tag(time, html_options = {})
4448
time_options = Rails::Timeago.default_options
4549

46-
time_options = time_options.merge html_options.extract!(*time_options.keys.select {|k| html_options.include?(k) })
50+
time_options = time_options.merge html_options.extract!(*time_options.keys.select do |k|
51+
html_options.include?(k)
52+
end)
4753
return time_options[:default] if time.nil?
4854

4955
time_options[:format] = time_options[:format].call(time, time_options) if time_options[:format].is_a?(Proc)
5056
if time_options[:title]
51-
html_options[:title] = time_options[:title].is_a?(Proc) ? time_options[:title].call(time, time_options) : time_options[:title]
57+
html_options[:title] =
58+
time_options[:title].is_a?(Proc) ? time_options[:title].call(time, time_options) : time_options[:title]
5259
end
5360
time_options[:limit] = time_options[:limit].call if time_options[:limit].is_a?(Proc)
5461

@@ -63,10 +70,16 @@ def timeago_tag(time, html_options = {})
6370
end
6471
time_tag time, timeago_tag_content(time, time_options), html_options
6572
end
73+
# rubocop:enable Metrics/PerceivedComplexity
74+
# rubocop:enable Metrics/MethodLength
75+
# rubocop:enable Metrics/CyclomaticComplexity
76+
# rubocop:enable Metrics/AbcSize
6677

6778
def timeago_tag_content(time, time_options = {}) # :nodoc:
68-
time = time.to_date if time_options[:date_only]
69-
return time_ago_in_words(time) if time_options[:nojs] && (time_options[:limit].nil? || time_options[:limit] < time)
79+
time = time.to_date if time_options[:date_only]
80+
if time_options[:nojs] && (time_options[:limit].nil? || time_options[:limit] < time)
81+
return time_ago_in_words(time)
82+
end
7083

7184
I18n.l time, format: time_options[:format]
7285
end

0 commit comments

Comments
 (0)
Please sign in to comment.