Skip to content

Commit 7423ae7

Browse files
zenspiderAle Paredes
authored and
Ale Paredes
committed
Typescript improvements (#316)
* Consistency fixes for javascript/main.rb. * Consistency fixes for typescript/main.rb * Brought over 99% of the filter improvements from javascript to typescript. I didn't bring over the directives filter as I don't see that in typescript (yet). Otherwise, the files are now nearly identical. This is begging for one to be a subclass of the other w/ just the name/extension differences.
1 parent 92716f8 commit 7423ae7

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

lib/cc/engine/analyzers/javascript/main.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class Main < CC::Engine::Analyzers::Base
1414
LANGUAGE = "javascript"
1515
DEFAULT_MASS_THRESHOLD = 45
1616
DEFAULT_FILTERS = [
17-
"(directives (Directive (value (DirectiveLiteral ___))))",
17+
"(directives (Directive (value (DirectiveLiteral ___))))".freeze,
1818
"(ImportDeclaration ___)".freeze,
1919
"(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))".freeze,
2020
].freeze
2121
DEFAULT_POST_FILTERS = [
22-
"(NUKE ___)",
23-
"(Program _ ___)",
22+
"(NUKE ___)".freeze,
23+
"(Program _ ___)".freeze,
2424
].freeze
2525
POINTS_PER_OVERAGE = 30_000
2626
REQUEST_PATH = "/javascript".freeze

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,39 @@ class Main < CC::Engine::Analyzers::Base
1010
PATTERNS = [
1111
"**/*.ts",
1212
"**/*.tsx",
13-
]
13+
].freeze
1414
LANGUAGE = "typescript"
1515
DEFAULT_MASS_THRESHOLD = 45
1616
DEFAULT_FILTERS = [
17-
"(ImportDeclaration ___)",
18-
"(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))",
19-
]
17+
"(ImportDeclaration ___)".freeze,
18+
"(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))".freeze,
19+
].freeze
20+
DEFAULT_POST_FILTERS = [
21+
"(NUKE ___)".freeze,
22+
"(Program _ ___)".freeze,
23+
].freeze
2024
POINTS_PER_OVERAGE = 30_000
21-
REQUEST_PATH = "/typescript"
25+
REQUEST_PATH = "/typescript".freeze
2226

2327
def use_sexp_lines?
2428
false
2529
end
2630

31+
##
32+
# Transform sexp as such:
33+
#
34+
# s(:Program, :module, s(:body, ... ))
35+
# => s(:NUKE, s(:Program, :module, s(:NUKE, ... )))
36+
37+
def transform_sexp(sexp)
38+
return sexp unless sexp.body
39+
40+
sexp.body.sexp_type = :NUKE # negate top level body
41+
sexp = s(:NUKE, sexp) # wrap with extra node to force full process
42+
43+
sexp
44+
end
45+
2746
private
2847

2948
def process_file(file)
@@ -33,6 +52,10 @@ def process_file(file)
3352
def default_filters
3453
DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
3554
end
55+
56+
def default_post_filters
57+
DEFAULT_POST_FILTERS.map { |filter| Sexp::Matcher.parse filter }
58+
end
3659
end
3760
end
3861
end

0 commit comments

Comments
 (0)