Skip to content

Commit 892bc1c

Browse files
committed
Add test to assert that we have docs for cops
We are missing 175 cops now... Adding them all will be tricky.
1 parent f9c69cc commit 892bc1c

File tree

4 files changed

+234
-2
lines changed

4 files changed

+234
-2
lines changed

lib/cc/engine/content_resolver.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require "active_support/core_ext/string"
2+
3+
module CC
4+
module Engine
5+
class ContentResolver
6+
def initialize(cop_name)
7+
@cop_name = cop_name
8+
end
9+
10+
def content
11+
@content ||= File.exist?(content_path) && File.read(content_path)
12+
end
13+
14+
def content_path
15+
@content_path ||= expand_config_path("contents/#{cop_name.sub("RuboCop::Cop::", "").underscore}.md")
16+
end
17+
18+
private
19+
20+
attr_reader :cop_name
21+
22+
def expand_config_path(path)
23+
File.expand_path("../../../../config/#{path}", __FILE__)
24+
end
25+
end
26+
end
27+
end

lib/cc/engine/issue.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "safe_yaml"
2+
require "cc/engine/content_resolver"
23

34
SafeYAML::OPTIONS[:default_mode] = :safe
45

@@ -124,8 +125,7 @@ def lines
124125
def content_body
125126
return @content_body if defined?(@content_body)
126127

127-
content_path = expand_config_path("contents/#{cop_name.underscore}.md")
128-
@content_body = File.exist?(content_path) && File.read(content_path)
128+
@content_body = ContentResolver.new(cop_name.underscore).content
129129
end
130130
end
131131
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "spec_helper"
2+
require "rubocop"
3+
require "cc/engine/content_resolver"
4+
5+
module CC::Engine
6+
describe ContentResolver do
7+
cops = RuboCop::Cop::Cop.all
8+
# The more docs the better -- feel free to unwhitelist cops and add readups
9+
whitelist = File.read("./spec/support/currently_undocumented_cops.txt").lines.map(&:chomp)
10+
11+
it "has cops" do
12+
expect(cops.count).to be > 300
13+
end
14+
15+
describe "#content" do
16+
cops.each do |cop|
17+
if !whitelist.include?(cop.name)
18+
describe "#{cop.name}" do
19+
it "has content" do
20+
resolver = ContentResolver.new(cop.name)
21+
FileUtils.touch(resolver.content_path)
22+
expect(resolver.content).to be_a(String)
23+
expect(resolver.content.length).to (be > 0), "#{cop.name} should have content. Hint, update: #{resolver.content_path}"
24+
end
25+
end
26+
end
27+
end
28+
end
29+
end
30+
end
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
RuboCop::Cop::Lint::AssignmentInCondition
2+
RuboCop::Cop::Lint::Debugger
3+
RuboCop::Cop::Lint::DeprecatedClassMethods
4+
RuboCop::Cop::Lint::EmptyEnsure
5+
RuboCop::Cop::Lint::EndInMethod
6+
RuboCop::Cop::Lint::EnsureReturn
7+
RuboCop::Cop::Lint::Eval
8+
RuboCop::Cop::Lint::HandleExceptions
9+
RuboCop::Cop::Lint::InheritException
10+
RuboCop::Cop::Lint::Loop
11+
RuboCop::Cop::Lint::PercentStringArray
12+
RuboCop::Cop::Lint::PercentSymbolArray
13+
RuboCop::Cop::Lint::RescueException
14+
RuboCop::Cop::Lint::ShadowedException
15+
RuboCop::Cop::Lint::ShadowingOuterLocalVariable
16+
RuboCop::Cop::Lint::UnderscorePrefixedVariableName
17+
RuboCop::Cop::Lint::UnifiedInteger
18+
RuboCop::Cop::Lint::UnneededDisable
19+
RuboCop::Cop::Lint::UnneededSplatExpansion
20+
RuboCop::Cop::Lint::UnreachableCode
21+
RuboCop::Cop::Lint::UselessAssignment
22+
RuboCop::Cop::Lint::Void
23+
RuboCop::Cop::Metrics::AbcSize
24+
RuboCop::Cop::Metrics::BlockLength
25+
RuboCop::Cop::Metrics::BlockNesting
26+
RuboCop::Cop::Metrics::ClassLength
27+
RuboCop::Cop::Metrics::LineLength
28+
RuboCop::Cop::Metrics::MethodLength
29+
RuboCop::Cop::Metrics::ModuleLength
30+
RuboCop::Cop::Metrics::ParameterLists
31+
RuboCop::Cop::Performance::FixedSize
32+
RuboCop::Cop::Performance::HashEachMethods
33+
RuboCop::Cop::Performance::SortWithBlock
34+
RuboCop::Cop::Style::AccessModifierIndentation
35+
RuboCop::Cop::Style::Alias
36+
RuboCop::Cop::Style::AlignArray
37+
RuboCop::Cop::Style::AlignHash
38+
RuboCop::Cop::Style::AlignParameters
39+
RuboCop::Cop::Style::AndOr
40+
RuboCop::Cop::Style::ArrayJoin
41+
RuboCop::Cop::Style::AsciiComments
42+
RuboCop::Cop::Style::AsciiIdentifiers
43+
RuboCop::Cop::Style::Attr
44+
RuboCop::Cop::Style::BarePercentLiterals
45+
RuboCop::Cop::Style::BeginBlock
46+
RuboCop::Cop::Style::BlockComments
47+
RuboCop::Cop::Style::BlockDelimiters
48+
RuboCop::Cop::Style::BracesAroundHashParameters
49+
RuboCop::Cop::Style::CaseEquality
50+
RuboCop::Cop::Style::CaseIndentation
51+
RuboCop::Cop::Style::CharacterLiteral
52+
RuboCop::Cop::Style::ClassAndModuleCamelCase
53+
RuboCop::Cop::Style::ClassAndModuleChildren
54+
RuboCop::Cop::Style::ClassCheck
55+
RuboCop::Cop::Style::ClassVars
56+
RuboCop::Cop::Style::CollectionMethods
57+
RuboCop::Cop::Style::ColonMethodCall
58+
RuboCop::Cop::Style::CommentAnnotation
59+
RuboCop::Cop::Style::CommentIndentation
60+
RuboCop::Cop::Style::ConditionalAssignment
61+
RuboCop::Cop::Style::ConstantName
62+
RuboCop::Cop::Style::Copyright
63+
RuboCop::Cop::Style::DefWithParentheses
64+
RuboCop::Cop::Style::PreferredHashMethods
65+
RuboCop::Cop::Style::DocumentationMethod
66+
RuboCop::Cop::Style::Documentation
67+
RuboCop::Cop::Style::DotPosition
68+
RuboCop::Cop::Style::EachForSimpleLoop
69+
RuboCop::Cop::Style::ElseAlignment
70+
RuboCop::Cop::Style::EmptyCaseCondition
71+
RuboCop::Cop::Style::EmptyLineBetweenDefs
72+
RuboCop::Cop::Style::EmptyLines
73+
RuboCop::Cop::Style::EmptyLinesAroundAccessModifier
74+
RuboCop::Cop::Style::EmptyLiteral
75+
RuboCop::Cop::Style::Encoding
76+
RuboCop::Cop::Style::EndBlock
77+
RuboCop::Cop::Style::EndOfLine
78+
RuboCop::Cop::Style::ExtraSpacing
79+
RuboCop::Cop::Style::FileName
80+
RuboCop::Cop::Style::FlipFlop
81+
RuboCop::Cop::Style::For
82+
RuboCop::Cop::Style::FormatString
83+
RuboCop::Cop::Style::FrozenStringLiteralComment
84+
RuboCop::Cop::Style::GlobalVars
85+
RuboCop::Cop::Style::HashSyntax
86+
RuboCop::Cop::Style::IfUnlessModifier
87+
RuboCop::Cop::Style::IfUnlessModifierOfIfUnless
88+
RuboCop::Cop::Style::IfWithSemicolon
89+
RuboCop::Cop::Style::ImplicitRuntimeError
90+
RuboCop::Cop::Style::IndentArray
91+
RuboCop::Cop::Style::IndentHash
92+
RuboCop::Cop::Style::InitialIndentation
93+
RuboCop::Cop::Style::InlineComment
94+
RuboCop::Cop::Style::Lambda
95+
RuboCop::Cop::Style::LeadingCommentSpace
96+
RuboCop::Cop::Style::MethodCallParentheses
97+
RuboCop::Cop::Style::MethodDefParentheses
98+
RuboCop::Cop::Style::MethodName
99+
RuboCop::Cop::Style::MethodMissing
100+
RuboCop::Cop::Style::MultilineMemoization
101+
RuboCop::Cop::Style::MultilineTernaryOperator
102+
RuboCop::Cop::Style::NegatedIf
103+
RuboCop::Cop::Style::NegatedWhile
104+
RuboCop::Cop::Style::NestedTernaryOperator
105+
RuboCop::Cop::Style::Not
106+
RuboCop::Cop::Style::NumericLiterals
107+
RuboCop::Cop::Style::NumericLiteralPrefix
108+
RuboCop::Cop::Style::NumericPredicate
109+
RuboCop::Cop::Style::OneLineConditional
110+
RuboCop::Cop::Style::OpMethod
111+
RuboCop::Cop::Style::ParallelAssignment
112+
RuboCop::Cop::Style::ParenthesesAroundCondition
113+
RuboCop::Cop::Style::PercentLiteralDelimiters
114+
RuboCop::Cop::Style::PercentQLiterals
115+
RuboCop::Cop::Style::PerlBackrefs
116+
RuboCop::Cop::Style::Proc
117+
RuboCop::Cop::Style::RaiseArgs
118+
RuboCop::Cop::Style::RescueModifier
119+
RuboCop::Cop::Style::SafeNavigation
120+
RuboCop::Cop::Style::Semicolon
121+
RuboCop::Cop::Style::Send
122+
RuboCop::Cop::Style::SignalException
123+
RuboCop::Cop::Style::SingleLineBlockParams
124+
RuboCop::Cop::Style::SingleLineMethods
125+
RuboCop::Cop::Style::SpaceAfterColon
126+
RuboCop::Cop::Style::SpaceAfterComma
127+
RuboCop::Cop::Style::SpaceAfterSemicolon
128+
RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault
129+
RuboCop::Cop::Style::SpaceAroundOperators
130+
RuboCop::Cop::Style::SpaceBeforeBlockBraces
131+
RuboCop::Cop::Style::SpaceBeforeComma
132+
RuboCop::Cop::Style::SpaceBeforeComment
133+
RuboCop::Cop::Style::SpaceBeforeSemicolon
134+
RuboCop::Cop::Style::SpaceInsideArrayPercentLiteral
135+
RuboCop::Cop::Style::SpaceInsideBlockBraces
136+
RuboCop::Cop::Style::SpaceInsideBrackets
137+
RuboCop::Cop::Style::SpaceInsideHashLiteralBraces
138+
RuboCop::Cop::Style::SpaceInsideParens
139+
RuboCop::Cop::Style::SpaceInsidePercentLiteralDelimiters
140+
RuboCop::Cop::Style::SpecialGlobalVars
141+
RuboCop::Cop::Style::StabbyLambdaParentheses
142+
RuboCop::Cop::Style::StringLiterals
143+
RuboCop::Cop::Style::StringLiteralsInInterpolation
144+
RuboCop::Cop::Style::StringMethods
145+
RuboCop::Cop::Style::SymbolArray
146+
RuboCop::Cop::Style::Tab
147+
RuboCop::Cop::Style::TernaryParentheses
148+
RuboCop::Cop::Style::TrailingBlankLines
149+
RuboCop::Cop::Style::TrailingWhitespace
150+
RuboCop::Cop::Style::TrivialAccessors
151+
RuboCop::Cop::Style::UnlessElse
152+
RuboCop::Cop::Style::UnneededCapitalW
153+
RuboCop::Cop::Style::UnneededPercentQ
154+
RuboCop::Cop::Style::VariableInterpolation
155+
RuboCop::Cop::Style::VariableName
156+
RuboCop::Cop::Style::VariableNumber
157+
RuboCop::Cop::Style::WhenThen
158+
RuboCop::Cop::Style::WhileUntilDo
159+
RuboCop::Cop::Style::WhileUntilModifier
160+
RuboCop::Cop::Style::WordArray
161+
RuboCop::Cop::Rails::ActionFilter
162+
RuboCop::Cop::Rails::DynamicFindBy
163+
RuboCop::Cop::Rails::DelegateAllowBlank
164+
RuboCop::Cop::Rails::Exit
165+
RuboCop::Cop::Rails::HasAndBelongsToMany
166+
RuboCop::Cop::Rails::HttpPositionalArguments
167+
RuboCop::Cop::Rails::NotNullColumn
168+
RuboCop::Cop::Rails::OutputSafety
169+
RuboCop::Cop::Rails::Output
170+
RuboCop::Cop::Rails::RequestReferer
171+
RuboCop::Cop::Rails::SafeNavigation
172+
RuboCop::Cop::Rails::SaveBang
173+
RuboCop::Cop::Rails::UniqBeforePluck
174+
RuboCop::Cop::Rails::Validation
175+
RuboCop::Cop::Security::JSONLoad

0 commit comments

Comments
 (0)