Skip to content

Commit f524a5a

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 f524a5a

File tree

5 files changed

+95
-28
lines changed

5 files changed

+95
-28
lines changed

.rubocop.yml

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,110 @@
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/TimeZone:
3890
Enabled: false
3991

40-
Style/PercentLiteralDelimiters:
41-
PreferredDelimiters:
42-
'%w': []
43-
'%W': []
92+
################################################################################
93+
# Specs - be more lenient on length checks and block styles
94+
################################################################################
95+
96+
Metrics/ModuleLength:
97+
Exclude:
98+
- spec/**/*
99+
100+
Metrics/MethodLength:
101+
Exclude:
102+
- spec/**/*
103+
104+
Style/ClassAndModuleChildren:
105+
Exclude:
106+
- spec/**/*
107+
108+
Style/BlockDelimiters:
109+
Exclude:
110+
- 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)