Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/contents/lint/unreachable_code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This cop checks for code that will never run, because it follows a flow control
statement such as `return` or `raise`.

### Example:

# bad
def sad
raise RuntimeError

puts "This line will never be reached, so why even include it?"
end

# good
def happy
raise RuntimeError if problem?

puts "This line of code will sometimes be reached"
end
27 changes: 27 additions & 0 deletions lib/cc/engine/content_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "active_support/core_ext/string"

module CC
module Engine
class ContentResolver
def initialize(cop_name)
@cop_name = cop_name
end

def content
@content ||= File.exist?(content_path) && File.read(content_path)
end

def content_path
@content_path ||= expand_config_path("contents/#{cop_name.sub("RuboCop::Cop::", "").underscore}.md")
end

private

attr_reader :cop_name

def expand_config_path(path)
File.expand_path("../../../../config/#{path}", __FILE__)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/cc/engine/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "safe_yaml"
require "cc/engine/content_resolver"

SafeYAML::OPTIONS[:default_mode] = :safe

Expand Down Expand Up @@ -124,8 +125,7 @@ def lines
def content_body
return @content_body if defined?(@content_body)

content_path = expand_config_path("contents/#{cop_name.underscore}.md")
@content_body = File.exist?(content_path) && File.read(content_path)
@content_body = ContentResolver.new(cop_name.underscore).content
end
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/cc/engine/content_resolver_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "spec_helper"
require "rubocop"
require "cc/engine/content_resolver"

module CC::Engine
describe ContentResolver do
cops = RuboCop::Cop::Cop.all
# The more docs the better -- feel free to unwhitelist cops and add readups
whitelist = File.read("./spec/support/currently_undocumented_cops.txt").lines.map(&:chomp)

it "has cops" do
expect(cops.count).to be > 300
end

describe "#content" do
cops.each do |cop|
if !whitelist.include?(cop.name)
describe "#{cop.name}" do
it "has content" do
resolver = ContentResolver.new(cop.name)
FileUtils.touch(resolver.content_path)
expect(resolver.content).to be_a(String)
expect(resolver.content.length).to (be > 0), "#{cop.name} should have content. Hint, update: #{resolver.content_path}"
end
end
end
end
end
end
end
174 changes: 174 additions & 0 deletions spec/support/currently_undocumented_cops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
RuboCop::Cop::Lint::AssignmentInCondition
RuboCop::Cop::Lint::Debugger
RuboCop::Cop::Lint::DeprecatedClassMethods
RuboCop::Cop::Lint::EmptyEnsure
RuboCop::Cop::Lint::EndInMethod
RuboCop::Cop::Lint::EnsureReturn
RuboCop::Cop::Lint::Eval
RuboCop::Cop::Lint::HandleExceptions
RuboCop::Cop::Lint::InheritException
RuboCop::Cop::Lint::Loop
RuboCop::Cop::Lint::PercentStringArray
RuboCop::Cop::Lint::PercentSymbolArray
RuboCop::Cop::Lint::RescueException
RuboCop::Cop::Lint::ShadowedException
RuboCop::Cop::Lint::ShadowingOuterLocalVariable
RuboCop::Cop::Lint::UnderscorePrefixedVariableName
RuboCop::Cop::Lint::UnifiedInteger
RuboCop::Cop::Lint::UnneededDisable
RuboCop::Cop::Lint::UnneededSplatExpansion
RuboCop::Cop::Lint::UselessAssignment
RuboCop::Cop::Lint::Void
RuboCop::Cop::Metrics::AbcSize
RuboCop::Cop::Metrics::BlockLength
RuboCop::Cop::Metrics::BlockNesting
RuboCop::Cop::Metrics::ClassLength
RuboCop::Cop::Metrics::LineLength
RuboCop::Cop::Metrics::MethodLength
RuboCop::Cop::Metrics::ModuleLength
RuboCop::Cop::Metrics::ParameterLists
RuboCop::Cop::Performance::FixedSize
RuboCop::Cop::Performance::HashEachMethods
RuboCop::Cop::Performance::SortWithBlock
RuboCop::Cop::Style::AccessModifierIndentation
RuboCop::Cop::Style::Alias
RuboCop::Cop::Style::AlignArray
RuboCop::Cop::Style::AlignHash
RuboCop::Cop::Style::AlignParameters
RuboCop::Cop::Style::AndOr
RuboCop::Cop::Style::ArrayJoin
RuboCop::Cop::Style::AsciiComments
RuboCop::Cop::Style::AsciiIdentifiers
RuboCop::Cop::Style::Attr
RuboCop::Cop::Style::BarePercentLiterals
RuboCop::Cop::Style::BeginBlock
RuboCop::Cop::Style::BlockComments
RuboCop::Cop::Style::BlockDelimiters
RuboCop::Cop::Style::BracesAroundHashParameters
RuboCop::Cop::Style::CaseEquality
RuboCop::Cop::Style::CaseIndentation
RuboCop::Cop::Style::CharacterLiteral
RuboCop::Cop::Style::ClassAndModuleCamelCase
RuboCop::Cop::Style::ClassAndModuleChildren
RuboCop::Cop::Style::ClassCheck
RuboCop::Cop::Style::ClassVars
RuboCop::Cop::Style::CollectionMethods
RuboCop::Cop::Style::ColonMethodCall
RuboCop::Cop::Style::CommentAnnotation
RuboCop::Cop::Style::CommentIndentation
RuboCop::Cop::Style::ConditionalAssignment
RuboCop::Cop::Style::ConstantName
RuboCop::Cop::Style::Copyright
RuboCop::Cop::Style::DefWithParentheses
RuboCop::Cop::Style::PreferredHashMethods
RuboCop::Cop::Style::DocumentationMethod
RuboCop::Cop::Style::Documentation
RuboCop::Cop::Style::DotPosition
RuboCop::Cop::Style::EachForSimpleLoop
RuboCop::Cop::Style::ElseAlignment
RuboCop::Cop::Style::EmptyCaseCondition
RuboCop::Cop::Style::EmptyLineBetweenDefs
RuboCop::Cop::Style::EmptyLines
RuboCop::Cop::Style::EmptyLinesAroundAccessModifier
RuboCop::Cop::Style::EmptyLiteral
RuboCop::Cop::Style::Encoding
RuboCop::Cop::Style::EndBlock
RuboCop::Cop::Style::EndOfLine
RuboCop::Cop::Style::ExtraSpacing
RuboCop::Cop::Style::FileName
RuboCop::Cop::Style::FlipFlop
RuboCop::Cop::Style::For
RuboCop::Cop::Style::FormatString
RuboCop::Cop::Style::FrozenStringLiteralComment
RuboCop::Cop::Style::GlobalVars
RuboCop::Cop::Style::HashSyntax
RuboCop::Cop::Style::IfUnlessModifier
RuboCop::Cop::Style::IfUnlessModifierOfIfUnless
RuboCop::Cop::Style::IfWithSemicolon
RuboCop::Cop::Style::ImplicitRuntimeError
RuboCop::Cop::Style::IndentArray
RuboCop::Cop::Style::IndentHash
RuboCop::Cop::Style::InitialIndentation
RuboCop::Cop::Style::InlineComment
RuboCop::Cop::Style::Lambda
RuboCop::Cop::Style::LeadingCommentSpace
RuboCop::Cop::Style::MethodCallParentheses
RuboCop::Cop::Style::MethodDefParentheses
RuboCop::Cop::Style::MethodName
RuboCop::Cop::Style::MethodMissing
RuboCop::Cop::Style::MultilineMemoization
RuboCop::Cop::Style::MultilineTernaryOperator
RuboCop::Cop::Style::NegatedIf
RuboCop::Cop::Style::NegatedWhile
RuboCop::Cop::Style::NestedTernaryOperator
RuboCop::Cop::Style::Not
RuboCop::Cop::Style::NumericLiterals
RuboCop::Cop::Style::NumericLiteralPrefix
RuboCop::Cop::Style::NumericPredicate
RuboCop::Cop::Style::OneLineConditional
RuboCop::Cop::Style::OpMethod
RuboCop::Cop::Style::ParallelAssignment
RuboCop::Cop::Style::ParenthesesAroundCondition
RuboCop::Cop::Style::PercentLiteralDelimiters
RuboCop::Cop::Style::PercentQLiterals
RuboCop::Cop::Style::PerlBackrefs
RuboCop::Cop::Style::Proc
RuboCop::Cop::Style::RaiseArgs
RuboCop::Cop::Style::RescueModifier
RuboCop::Cop::Style::SafeNavigation
RuboCop::Cop::Style::Semicolon
RuboCop::Cop::Style::Send
RuboCop::Cop::Style::SignalException
RuboCop::Cop::Style::SingleLineBlockParams
RuboCop::Cop::Style::SingleLineMethods
RuboCop::Cop::Style::SpaceAfterColon
RuboCop::Cop::Style::SpaceAfterComma
RuboCop::Cop::Style::SpaceAfterSemicolon
RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault
RuboCop::Cop::Style::SpaceAroundOperators
RuboCop::Cop::Style::SpaceBeforeBlockBraces
RuboCop::Cop::Style::SpaceBeforeComma
RuboCop::Cop::Style::SpaceBeforeComment
RuboCop::Cop::Style::SpaceBeforeSemicolon
RuboCop::Cop::Style::SpaceInsideArrayPercentLiteral
RuboCop::Cop::Style::SpaceInsideBlockBraces
RuboCop::Cop::Style::SpaceInsideBrackets
RuboCop::Cop::Style::SpaceInsideHashLiteralBraces
RuboCop::Cop::Style::SpaceInsideParens
RuboCop::Cop::Style::SpaceInsidePercentLiteralDelimiters
RuboCop::Cop::Style::SpecialGlobalVars
RuboCop::Cop::Style::StabbyLambdaParentheses
RuboCop::Cop::Style::StringLiterals
RuboCop::Cop::Style::StringLiteralsInInterpolation
RuboCop::Cop::Style::StringMethods
RuboCop::Cop::Style::SymbolArray
RuboCop::Cop::Style::Tab
RuboCop::Cop::Style::TernaryParentheses
RuboCop::Cop::Style::TrailingBlankLines
RuboCop::Cop::Style::TrailingWhitespace
RuboCop::Cop::Style::TrivialAccessors
RuboCop::Cop::Style::UnlessElse
RuboCop::Cop::Style::UnneededCapitalW
RuboCop::Cop::Style::UnneededPercentQ
RuboCop::Cop::Style::VariableInterpolation
RuboCop::Cop::Style::VariableName
RuboCop::Cop::Style::VariableNumber
RuboCop::Cop::Style::WhenThen
RuboCop::Cop::Style::WhileUntilDo
RuboCop::Cop::Style::WhileUntilModifier
RuboCop::Cop::Style::WordArray
RuboCop::Cop::Rails::ActionFilter
RuboCop::Cop::Rails::DynamicFindBy
RuboCop::Cop::Rails::DelegateAllowBlank
RuboCop::Cop::Rails::Exit
RuboCop::Cop::Rails::HasAndBelongsToMany
RuboCop::Cop::Rails::HttpPositionalArguments
RuboCop::Cop::Rails::NotNullColumn
RuboCop::Cop::Rails::OutputSafety
RuboCop::Cop::Rails::Output
RuboCop::Cop::Rails::RequestReferer
RuboCop::Cop::Rails::SafeNavigation
RuboCop::Cop::Rails::SaveBang
RuboCop::Cop::Rails::UniqBeforePluck
RuboCop::Cop::Rails::Validation
RuboCop::Cop::Security::JSONLoad