Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit d5f57fb

Browse files
committed
Merge pull request #24 from codeclimate/devon/warn-and-error-without-any-enabled-languages
Warn on stderr and raise an exception if no languages are enabled
2 parents 79da837 + 47e981e commit d5f57fb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

‎lib/cc/engine/duplication.rb‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
module CC
1212
module Engine
1313
class Duplication
14-
DEFAULT_LANGUAGE = 'ruby'.freeze
14+
EmptyLanguagesError = Class.new(StandardError)
15+
1516
LANGUAGES = {
1617
"ruby" => ::CC::Engine::Analyzers::Ruby::Main,
1718
"javascript" => ::CC::Engine::Analyzers::Javascript::Main,
@@ -47,7 +48,9 @@ def languages
4748
languages = engine_config.languages.keys
4849

4950
if languages.empty?
50-
Array(DEFAULT_LANGUAGE)
51+
message = "Config Error: Unable to run the duplication engine without any languages enabled."
52+
$stderr.puts message
53+
raise EmptyLanguagesError, message
5154
else
5255
languages
5356
end

‎spec/cc/engine/duplication_spec.rb‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "spec_helper"
2+
require "cc/engine/duplication"
3+
4+
module CC::Engine
5+
describe "#languages" do
6+
it "Warns to stderr and raises an exception when no languages are enabled" do
7+
engine = Duplication.new(directory: "/code", engine_config: {}, io: StringIO.new)
8+
9+
_, stderr = capture_io do
10+
assert_raises(Duplication::EmptyLanguagesError) { engine.run }
11+
end
12+
13+
stderr.must_match("Config Error: Unable to run the duplication engine without any languages enabled.")
14+
end
15+
end
16+
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /