Skip to content

Commit

Permalink
Merge pull request #67 from RelationalAI/running-test-every-commit
Browse files Browse the repository at this point in the history
Running test using ] test
  • Loading branch information
bergel authored Aug 5, 2024
2 parents 09e440b + def2c08 commit 25a6aa4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
39 changes: 25 additions & 14 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ using Dates
using JSON3

mutable struct LintResult
files_count::Int64
violations_count::Int64
recommendations_count::Int64
files_count::Integer
violations_count::Integer
recommendations_count::Integer
linted_files::Vector{String}
printout_count::Int64
printout_count::Integer

LintResult(a, b, c, d, e) = new(a, b, c, d, e)
end
Expand Down Expand Up @@ -138,7 +138,7 @@ function lint_file(rootpath, server = setup_server(); gethints = false)
end
end

global global_server = setup_server()
global global_server = nothing
const essential_options = LintOptions(true, false, true, true, true, true, true, true, true, false, true)

const no_filters = LintCodes[]
Expand All @@ -150,7 +150,7 @@ function convert_offset_to_line_from_filename(offset::Union{Int64, Int32}, filen
return convert_offset_to_line_from_lines(offset, all_lines)
end

function convert_offset_to_line(offset::Int, source::String)
function convert_offset_to_line(offset::Integer, source::String)
return convert_offset_to_line_from_lines(offset, split(source, "\n"))
end

Expand Down Expand Up @@ -184,7 +184,7 @@ end
#
# Note: `offset` is measured in codepoints. The returned `column` is a character
# offset, not a codepoint offset.
function convert_offset_to_line_from_lines(offset::Int, all_lines)
function convert_offset_to_line_from_lines(offset::Integer, all_lines)
offset < 0 && throw(BoundsError("source", offset))

current_codepoint = 1
Expand Down Expand Up @@ -367,8 +367,8 @@ end
function print_summary(
::PlainFormat,
io::IO,
count_violations::Int,
count_recommendations::Int
count_violations::Integer,
count_recommendations::Integer
)
nb_hints = count_violations + count_recommendations
if iszero(nb_hints)
Expand Down Expand Up @@ -415,7 +415,13 @@ function print_hint(format::MarkdownFormat, io::IO, coordinates::String, hint::S
end
end

print_summary(::MarkdownFormat, io::IO, count_violations::Int, count_recommendations::Int) = nothing
print_summary(::MarkdownFormat, io::IO, count_violations::Integer, count_recommendations::Integer) = nothing

does_file_server_need_to_be_initialized() = isnothing(StaticLint.global_server)
function initialize_file_server()
StaticLint.global_server = setup_server()
return StaticLint.global_server
end

"""
run_lint(rootpath::String; server = global_server, io::IO=stdout, io_violations::Union{IO,Nothing}, io_recommendations::Union{IO,Nothing})
Expand All @@ -437,6 +443,11 @@ function run_lint(
filters::Vector{LintCodes}=essential_filters,
formatter::AbstractFormatter=PlainFormat()
)
# If no server is defined, then we define it.
if does_file_server_need_to_be_initialized()
server = initialize_file_server()
end

# If already linted, then we merely exit
rootpath in result.linted_files && return result

Expand Down Expand Up @@ -544,9 +555,9 @@ end
function print_datadog_report(
json_output::IO,
report_as_string::String,
files_count::Int64,
violation_count::Int64,
recommandation_count::Int64,
files_count::Integer,
violation_count::Integer,
recommandation_count::Integer,
)
event = Dict(
:source => "StaticLint",
Expand Down Expand Up @@ -631,7 +642,7 @@ function generate_report(
# If analyze_all_file_found_locally is set to true, we discard all the provided files
# and analyze everything accessible from "."
if analyze_all_file_found_locally
julia_filenames = ["."]
julia_filenames = [pwd()]
end

open(output_filename, "w") do output_io
Expand Down
14 changes: 6 additions & 8 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1329,23 +1329,21 @@ end
output_file = tempname()
json_io = IOBuffer()
StaticLint.generate_report(
[file1],
[file1], # Ignored because of analyze_all_file_found_locally
output_file;
json_output=json_io,
github_repository="RelationalAI/raicode",
branch_name="axb-foo-bar",
file_prefix_to_remove="var/",
analyze_all_file_found_locally=true
analyze_all_file_found_locally=true # OVERRIDE THE PROVIDED SET OF FILES
)

json_report = JSON3.read(String(take!(json_io)))
@test json_report[:source] == "StaticLint"

# There are more than 10 files in StaticLint.jl
# and more than 1 violations and recommendations.
@test json_report[:data][:files_count] > 10
@test json_report[:data][:violation_count] > 1
@test json_report[:data][:recommandation_count] > 0
@test json_report[:source] == "StaticLint"
@test json_report[:data][:files_count] > 3
@test json_report[:data][:violation_count] > 10
@test json_report[:data][:recommandation_count] >= 0

local result
open(output_file) do oo
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ function check_resolved(s)
end

include(joinpath(@__DIR__, "static_lint_tests.jl"))

StaticLint.global_server = nothing
include(joinpath(@__DIR__, "rai_rules_tests.jl"))
StaticLint.global_server = nothing

0 comments on commit 25a6aa4

Please sign in to comment.