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 c2828db

Browse files
toddmazierskiwfleming
authored andcommitted
Add support for TypeScript+React (tsx) files
Add `tsx` files to TypeScript analysis. Add a test for TypeScript+React files. Fix a test broken by the parser change. Ticket: codeclimate/app#6470.
1 parent b5b7a4f commit c2828db

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎lib/cc/engine/analyzers/typescript/main.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module TypeScript
99
class Main < CC::Engine::Analyzers::Base
1010
PATTERNS = [
1111
"**/*.ts",
12+
"**/*.tsx",
1213
]
1314
LANGUAGE = "typescript"
1415
DEFAULT_MASS_THRESHOLD = 45

‎spec/cc/engine/analyzers/typescript/main_spec.rb‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
EOTS
9595

9696
error = CC::Parser::Client::HTTPError.new(500, "Error processing file: ./foo.ts")
97-
allow(CC::Parser).to receive(:parse).with("", "/typescript").and_raise(error)
97+
allow(CC::Parser).to receive(:parse).with("", "/typescript",filename: "./foo.ts").and_raise(error)
9898

9999
expect(CC.logger).to receive(:error).with("Error processing file: ./foo.ts")
100100
expect(CC.logger).to receive(:error).with(error.message)
@@ -182,6 +182,33 @@
182182
})
183183
end
184184

185+
it "supports TypeScript+React files" do
186+
create_source_file("foo.tsx", <<~EOTS)
187+
function ComponentFoo(prop: FooProp) {
188+
return <SomeComponent name="prop.name" />;
189+
}
190+
191+
function ComponentFoo(prop: FooProp) {
192+
return <AnotherComponent name="prop.name" />;
193+
}
194+
EOTS
195+
196+
issues = run_engine(engine_conf).strip.split("0円")
197+
result = issues.first.strip
198+
json = JSON.parse(result)
199+
200+
expect(json["type"]).to eq("issue")
201+
expect(json["check_name"]).to eq("similar-code")
202+
expect(json["location"]).to eq({
203+
"path" => "foo.tsx",
204+
"lines" => { "begin" => 1, "end" => 3 },
205+
})
206+
expect(json["other_locations"]).to eq([
207+
{"path" => "foo.tsx", "lines" => { "begin" => 5, "end" => 7 } }
208+
])
209+
expect(json["fingerprint"]).to eq("d8f0315c3c4e9ba81003a7ec6c823fb0")
210+
end
211+
185212
def engine_conf
186213
CC::Engine::Analyzers::EngineConfig.new({
187214
'config' => {

0 commit comments

Comments
(0)

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