Skip to content

Commit 0712a4b

Browse files
committed
Update Rubocop config to match CC styleguide
A small update to bring our rubocop config up-to-date with our styleguide. Following the refactor in #16, few changes in the codebase were needed.
1 parent 7d1b766 commit 0712a4b

File tree

6 files changed

+109
-28
lines changed

6 files changed

+109
-28
lines changed

.codeclimate.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
engines:
2+
bundler-audit:
3+
enabled: true
4+
duplication:
5+
enabled: true
6+
config:
7+
languages:
8+
- ruby
9+
fixme:
10+
enabled: true
211
rubocop:
312
enabled: true
413
exclude_fingerprints:
@@ -7,3 +16,5 @@ engines:
716
ratings:
817
paths:
918
- "**.rb"
19+
exclude_paths:
20+
- spec/

.rubocop.yml

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,113 @@
1-
AllCops:
2-
TargetRubyVersion: 2.2
3-
Metrics/AbcSize:
4-
Enabled: false
1+
################################################################################
2+
# Metrics
3+
################################################################################
54

65
Metrics/LineLength:
76
Enabled: false
87

9-
Rails/TimeZone:
8+
Metrics/AbcSize:
109
Enabled: false
1110

12-
SignalException:
11+
################################################################################
12+
# Style
13+
################################################################################
14+
15+
# Executables are conventionally named bin/foo-bar
16+
Style/FileName:
17+
Exclude:
18+
- bin/**/*
19+
20+
# We don't (currently) document our code
21+
Style/Documentation:
1322
Enabled: false
1423

24+
# Always use double-quotes to keep things simple
1525
Style/StringLiterals:
16-
Enabled: false
26+
EnforcedStyle: double_quotes
1727

18-
Style/Documentation:
28+
# Use a trailing comma to keep diffs clean when elements are inserted or removed
29+
Style/TrailingComma:
30+
EnforcedStyleForMultiline: comma
31+
32+
# We avoid GuardClause because it can result in "suprise return"
33+
Style/GuardClause:
1934
Enabled: false
2035

21-
Style/TrailingCommaInLiteral:
36+
# We avoid IfUnlessModifier because it can result in "suprise if"
37+
Style/IfUnlessModifier:
2238
Enabled: false
2339

24-
Style/ClassAndModuleChildren:
40+
# We don't care about the fail/raise distinction
41+
Style/SignalException:
42+
EnforcedStyle: only_raise
43+
44+
Style/DotPosition:
45+
EnforcedStyle: trailing
46+
47+
# Common globals we allow
48+
Style/GlobalVars:
49+
AllowedVariables:
50+
- "$statsd"
51+
- "$mongo"
52+
- "$rollout"
53+
54+
# Allow $! in config/initializers
55+
Style/SpecialGlobalVars:
2556
Exclude:
26-
- 'spec/**/*'
57+
- config/initializers/**/*
2758

28-
Style/IfUnlessModifier:
59+
# We have common cases where has_ and have_ make sense
60+
Style/PredicateName:
61+
Enabled: true
62+
NamePrefixBlacklist:
63+
- is_
64+
65+
# We use %w[ ], not %w( ) because the former looks like an array
66+
Style/PercentLiteralDelimiters:
67+
PreferredDelimiters:
68+
"%w": []
69+
"%W": []
70+
71+
# Allow "trivial" accessors when defined as a predicate? method
72+
Style/TrivialAccessors:
73+
AllowPredicates: true
74+
75+
Style/Next:
2976
Enabled: false
3077

31-
Style/DotPosition:
78+
# We think it's OK to use the "extend self" module pattern
79+
Style/ModuleFunction:
3280
Enabled: false
3381

34-
Style/GuardClause:
82+
################################################################################
83+
# Rails - disable things because we're primarily non-rails
84+
################################################################################
85+
86+
Rails/Delegate:
3587
Enabled: false
3688

37-
Style/StringLiteralsInInterpolation:
89+
Rails/Output:
3890
Enabled: false
3991

40-
Style/PercentLiteralDelimiters:
41-
PreferredDelimiters:
42-
'%w': []
43-
'%W': []
92+
Rails/TimeZone:
93+
Enabled: false
94+
95+
################################################################################
96+
# Specs - be more lenient on length checks and block styles
97+
################################################################################
98+
99+
Metrics/ModuleLength:
100+
Exclude:
101+
- spec/**/*
102+
103+
Metrics/MethodLength:
104+
Exclude:
105+
- spec/**/*
106+
107+
Style/ClassAndModuleChildren:
108+
Exclude:
109+
- spec/**/*
110+
111+
Style/BlockDelimiters:
112+
Exclude:
113+
- spec/**/*

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'rspec/core/rake_task'
1+
require "rspec/core/rake_task"
22
RSpec::Core::RakeTask.new(:spec)
33

44
task default: :spec

bin/bundler-audit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../lib")))
44

5-
require 'cc/engine/bundler_audit'
5+
require "cc/engine/bundler_audit"
66

77
CC::Engine::BundlerAudit::Analyzer.new(directory: "/code").run

lib/cc/engine/bundler_audit/issue.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Issue
66
SEVERITIES = {
77
high: "critical",
88
medium: "normal",
9-
low: "info"
9+
low: "info",
1010
}.freeze
1111

1212
def initialize(result, gemfile_lock_lines)
@@ -27,12 +27,12 @@ def to_json(*a)
2727
path: "Gemfile.lock",
2828
lines: {
2929
begin: line_number,
30-
end: line_number
31-
}
30+
end: line_number,
31+
},
3232
},
3333
remediation_points: remediation_points,
3434
severity: severity,
35-
type: "Issue"
35+
type: "Issue",
3636
}.to_json(a)
3737
end
3838

@@ -45,7 +45,7 @@ def content_body
4545
"**Advisory**: #{identifier}",
4646
"**Criticality**: #{advisory.criticality.capitalize}",
4747
"**URL**: #{advisory.url}",
48-
"**Solution**: #{solution}"
48+
"**Solution**: #{solution}",
4949
].join("\n\n")
5050
end
5151

spec/cc/engine/bundler_audit/analyzer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module CC::Engine::BundlerAudit
77
directory = fixture_directory("no_gemfile_lock")
88
io = StringIO.new
99

10-
expect { Analyzer.new(directory: directory, io: io).run }
11-
.to raise_error(Analyzer::GemfileLockNotFound)
10+
expect { Analyzer.new(directory: directory, io: io).run }.
11+
to raise_error(Analyzer::GemfileLockNotFound)
1212
end
1313

1414
it "emits issues for Gemfile.lock problems" do

0 commit comments

Comments
 (0)