Skip to content

Commit 90c4b98

Browse files
committed
Remove spawn and code linting
1 parent cc200a6 commit 90c4b98

10 files changed

+131
-147
lines changed

src/analyzer/analyzers/analyzer_django.cr

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ class AnalyzerDjango < Analyzer
44
def analyze
55
# Public Dir Analysis
66
Dir.glob("#{@base_path}/static/**/*") do |file|
7-
spawn do
8-
next if File.directory?(file)
9-
relative_path = file.sub("#{@base_path}/static/", "")
10-
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
11-
end
7+
next if File.directory?(file)
8+
relative_path = file.sub("#{@base_path}/static/", "")
9+
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
1210
end
1311

1412
# urls.py Analysis

src/analyzer/analyzers/analyzer_example.cr

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ class AnalyzerExample < Analyzer
44
def analyze
55
# Source Analysis
66
Dir.glob("#{base_path}/**/*") do |path|
7-
spawn do
8-
next if File.directory?(path)
9-
if File.exists?(path)
10-
File.open(path, "r") do |file|
11-
file.each_line do |_|
12-
end
7+
next if File.directory?(path)
8+
if File.exists?(path)
9+
File.open(path, "r") do |file|
10+
file.each_line do |_|
1311
end
1412
end
1513
end

src/analyzer/analyzers/analyzer_express.cr

+28-30
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,38 @@ def analyzer_express(options : Hash(Symbol, String))
1414

1515
# Source Analysis
1616
Dir.glob("#{base_path}/**/*") do |path|
17-
spawn do
18-
next if File.directory?(path)
19-
if File.exists?(path)
20-
File.open(path, "r") do |file|
21-
file.each_line do |line|
22-
if line.includes? ".get('/"
23-
api_path = express_get_endpoint(line)
24-
if api_path != ""
25-
result << Endpoint.new(api_path, "GET")
26-
end
17+
next if File.directory?(path)
18+
if File.exists?(path)
19+
File.open(path, "r") do |file|
20+
file.each_line do |line|
21+
if line.includes? ".get('/"
22+
api_path = express_get_endpoint(line)
23+
if api_path != ""
24+
result << Endpoint.new(api_path, "GET")
2725
end
28-
if line.includes? ".post('/"
29-
api_path = express_get_endpoint(line)
30-
if api_path != ""
31-
result << Endpoint.new(api_path, "POST")
32-
end
26+
end
27+
if line.includes? ".post('/"
28+
api_path = express_get_endpoint(line)
29+
if api_path != ""
30+
result << Endpoint.new(api_path, "POST")
3331
end
34-
if line.includes? ".put('/"
35-
api_path = express_get_endpoint(line)
36-
if api_path != ""
37-
result << Endpoint.new(api_path, "PUT")
38-
end
32+
end
33+
if line.includes? ".put('/"
34+
api_path = express_get_endpoint(line)
35+
if api_path != ""
36+
result << Endpoint.new(api_path, "PUT")
3937
end
40-
if line.includes? ".delete('/"
41-
api_path = express_get_endpoint(line)
42-
if api_path != ""
43-
result << Endpoint.new(api_path, "DELETE")
44-
end
38+
end
39+
if line.includes? ".delete('/"
40+
api_path = express_get_endpoint(line)
41+
if api_path != ""
42+
result << Endpoint.new(api_path, "DELETE")
4543
end
46-
if line.includes? ".patch('/"
47-
api_path = express_get_endpoint(line)
48-
if api_path != ""
49-
result << Endpoint.new(api_path, "PATCH")
50-
end
44+
end
45+
if line.includes? ".patch('/"
46+
api_path = express_get_endpoint(line)
47+
if api_path != ""
48+
result << Endpoint.new(api_path, "PATCH")
5149
end
5250
end
5351
end

src/analyzer/analyzers/analyzer_flask.cr

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ class AnalyzerFlask < Analyzer
44
def analyze
55
# Source Analysis
66
Dir.glob("#{base_path}/**/*") do |path|
7-
spawn do
8-
next if File.directory?(path)
9-
if File.exists?(path) && File.extname(path) == ".py"
10-
File.open(path, "r") do |file|
11-
file.each_line do |line|
12-
line.strip.scan(/@app\.route\((.*)\)/) do |match|
13-
if match.size > 0
14-
splited = match[0].split("(")
15-
if splited.size > 1
16-
endpoint_path = splited[1].gsub("\"", "").gsub("'", "").gsub(")", "").gsub(" ", "")
17-
result << Endpoint.new("#{url}#{endpoint_path}", "GET")
18-
end
7+
next if File.directory?(path)
8+
if File.exists?(path) && File.extname(path) == ".py"
9+
File.open(path, "r") do |file|
10+
file.each_line do |line|
11+
line.strip.scan(/@app\.route\((.*)\)/) do |match|
12+
if match.size > 0
13+
splited = match[0].split("(")
14+
if splited.size > 1
15+
endpoint_path = splited[1].gsub("\"", "").gsub("'", "").gsub(")", "").gsub(" ", "")
16+
result << Endpoint.new("#{url}#{endpoint_path}", "GET")
1917
end
2018
end
2119
end

src/analyzer/analyzers/analyzer_go_echo.cr

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ class AnalyzerGoEcho < Analyzer
44
def analyze
55
# Source Analysis
66
Dir.glob("#{base_path}/**/*") do |path|
7-
spawn do
8-
next if File.directory?(path)
9-
if File.exists?(path) && File.extname(path) == ".go"
10-
File.open(path, "r") do |file|
11-
file.each_line do |line|
12-
if line.includes?(".GET(") || line.includes?(".POST(") || line.includes?(".PUT(") || line.includes?(".DELETE(")
13-
get_route_path_go_echo(line).tap do |route_path|
14-
if route_path.size > 0
15-
result << Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
16-
end
7+
next if File.directory?(path)
8+
if File.exists?(path) && File.extname(path) == ".go"
9+
File.open(path, "r") do |file|
10+
file.each_line do |line|
11+
if line.includes?(".GET(") || line.includes?(".POST(") || line.includes?(".PUT(") || line.includes?(".DELETE(")
12+
get_route_path_go_echo(line).tap do |route_path|
13+
if route_path.size > 0
14+
result << Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
1715
end
1816
end
1917
end

src/analyzer/analyzers/analyzer_kemal.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AnalyzerKemal < Analyzer
4545
return Param.new(param, "", "body")
4646
end
4747

48-
return Param.new("", "", "")
48+
Param.new("", "", "")
4949
end
5050

5151
def line_to_endpoint(content : String) : Endpoint
@@ -99,7 +99,7 @@ class AnalyzerKemal < Analyzer
9999
end
100100
end
101101

102-
return Endpoint.new("", "")
102+
Endpoint.new("", "")
103103
end
104104
end
105105

src/analyzer/analyzers/analyzer_php_pure.cr

+26-28
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,38 @@ class AnalyzerPhpPure < Analyzer
55
def analyze
66
# Source Analysis
77
Dir.glob("#{base_path}/**/*") do |path|
8-
spawn do
9-
next if File.directory?(path)
10-
if base_path[-1].to_s == "/"
11-
relative_path = path.sub("#{base_path}", "").sub("./", "").sub("//", "/")
12-
else
13-
relative_path = path.sub("#{base_path}/", "").sub("./", "").sub("//", "/")
14-
end
15-
relative_path = remove_start_slash(relative_path)
8+
next if File.directory?(path)
9+
if base_path[-1].to_s == "/"
10+
relative_path = path.sub("#{base_path}", "").sub("./", "").sub("//", "/")
11+
else
12+
relative_path = path.sub("#{base_path}/", "").sub("./", "").sub("//", "/")
13+
end
14+
relative_path = remove_start_slash(relative_path)
1615

17-
if File.exists?(path) && File.extname(path) == ".php"
18-
File.open(path, "r") do |file|
19-
params_query = [] of Param
20-
params_body = [] of Param
21-
methods = [] of String
16+
if File.exists?(path) && File.extname(path) == ".php"
17+
File.open(path, "r") do |file|
18+
params_query = [] of Param
19+
params_body = [] of Param
20+
methods = [] of String
2221

23-
file.each_line do |line|
24-
match = line.strip.match(%r{.*\$_(.*?)\['(.*?)'\];})
22+
file.each_line do |line|
23+
match = line.strip.match(%r{.*\$_(.*?)\['(.*?)'\];})
2524

26-
if match
27-
method = match[1]
28-
param_name = match[2]
25+
if match
26+
method = match[1]
27+
param_name = match[2]
2928

30-
methods = methods | [method]
31-
params_query << Param.new(param_name, "string", "query")
32-
params_body << Param.new(param_name, "string", "form")
33-
end
34-
rescue
35-
next
29+
methods = methods | [method]
30+
params_query << Param.new(param_name, "string", "query")
31+
params_body << Param.new(param_name, "string", "form")
3632
end
37-
methods.each do |method|
38-
result << Endpoint.new("#{url}/#{relative_path}", method, params_body)
39-
end
40-
result << Endpoint.new("#{url}/#{relative_path}", "GET", params_query)
33+
rescue
34+
next
35+
end
36+
methods.each do |method|
37+
result << Endpoint.new("#{url}/#{relative_path}", method, params_body)
4138
end
39+
result << Endpoint.new("#{url}/#{relative_path}", "GET", params_query)
4240
end
4341
end
4442
end

src/analyzer/analyzers/analyzer_rails.cr

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ class AnalyzerRails < Analyzer
44
def analyze
55
# Public Dir Analysis
66
Dir.glob("#{@base_path}/public/**/*") do |file|
7-
spawn do
8-
next if File.directory?(file)
9-
relative_path = file.sub("#{@base_path}/public/", "")
10-
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
11-
end
7+
next if File.directory?(file)
8+
relative_path = file.sub("#{@base_path}/public/", "")
9+
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
1210
end
1311

1412
# Config Analysis

src/analyzer/analyzers/analyzer_sinatra.cr

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,54 @@ class AnalyzerSinatra < Analyzer
3434
param = content.split("param[")[1].split("]")[0].gsub("\"", "").gsub("'", "")
3535
return Param.new(param, "", "query")
3636
end
37-
38-
return Param.new("", "", "")
37+
38+
Param.new("", "", "")
3939
end
40-
40+
4141
def line_to_endpoint(content : String) : Endpoint
4242
content.scan(/get\s+['"](.+?)['"]/) do |match|
4343
if match.size > 1
4444
return Endpoint.new("#{@url}#{match[1]}", "GET")
4545
end
4646
end
47-
47+
4848
content.scan(/post\s+['"](.+?)['"]/) do |match|
4949
if match.size > 1
5050
return Endpoint.new("#{@url}#{match[1]}", "POST")
5151
end
5252
end
53-
53+
5454
content.scan(/put\s+['"](.+?)['"]/) do |match|
5555
if match.size > 1
5656
return Endpoint.new("#{@url}#{match[1]}", "PUT")
5757
end
5858
end
59-
59+
6060
content.scan(/delete\s+['"](.+?)['"]/) do |match|
6161
if match.size > 1
6262
return Endpoint.new("#{@url}#{match[1]}", "DELETE")
6363
end
6464
end
65-
65+
6666
content.scan(/patch\s+['"](.+?)['"]/) do |match|
6767
if match.size > 1
6868
return Endpoint.new("#{@url}#{match[1]}", "PATCH")
6969
end
7070
end
71-
71+
7272
content.scan(/head\s+['"](.+?)['"]/) do |match|
7373
if match.size > 1
7474
return Endpoint.new("#{@url}#{match[1]}", "HEAD")
7575
end
7676
end
77-
77+
7878
content.scan(/options\s+['"](.+?)['"]/) do |match|
7979
if match.size > 1
8080
return Endpoint.new("#{@url}#{match[1]}", "OPTIONS")
8181
end
8282
end
83-
84-
return Endpoint.new("", "")
83+
84+
Endpoint.new("", "")
8585
end
8686
end
8787

0 commit comments

Comments
 (0)