Skip to content

Commit

Permalink
Merge pull request #23 from warisa-r/elena_test2
Browse files Browse the repository at this point in the history
Format check
  • Loading branch information
warisa-r authored Sep 27, 2024
2 parents 05fda43 + 62ca9ef commit 5482e9e
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 0 deletions.
34 changes: 34 additions & 0 deletions format_check/generic/generic_valid_format_check.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using FilePaths

# Function to recursively check format of all .jl files in a directory
function check_format(directory::String)
unformatted_files = String[] # List to store unformatted files
for (root, dirs, files) in walkdir(directory)
for file in files
if endswith(file, ".jl")
file_path = joinpath(root, file)
# Check formatting
result = run(`julia --check-bounds=no --color=yes --project -e "using JuliaFormatter; is_formatted(\"$file_path\")"`)
if result != 0 # If the file is not formatted
push!(unformatted_files, file_path)
end
end
end
end

return unformatted_files
end

# Specify the directory to search using relative path
# Assuming the script is located inside ShockwaveDetection.jl-main
project_directory = joinpath(@__DIR__, "src") # Adjust "src" as needed

unformatted_files = check_format(project_directory)

if !isempty(unformatted_files)
println("The following files are not formatted:")
println(join(unformatted_files, "\n"))
exit(1) # Exit with an error code
end

println("All files are properly formatted.")
42 changes: 42 additions & 0 deletions format_check/src/format_check_cluster.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using JuliaFormatter

# Provide the relative path to your clustering.jl file
relative_path_to_check = joinpath("src", "cluster.jl")

# Get the current working directory
current_dir = pwd()

# Combine current directory and relative path
file_to_check = joinpath(current_dir, relative_path_to_check)

@info "Checking format of $file_to_check"
try
# Resolve the file path
resolved_path = realpath(file_to_check)
@info "Running format check on $resolved_path"

# Format the file
formatted_code = format(resolved_path) # This will return the formatted code

# Read the original code to check for differences
original_code = read(resolved_path, String)

# Check if the original and formatted codes are different
if formatted_code == original_code
@info "Formatting is good."
println("Formatting is good.")
else
@warn "Formatting is bad. Please check the differences."
println("Formatting is bad. Please check the differences.")
println("\n--- Original Code ---\n")
println(original_code)
println("\n--- Formatted Code ---\n")
println(formatted_code)

# Optionally, you can overwrite the original file with formatted code
# write(resolved_path, formatted_code)
end
catch e
@error "Error checking $file_to_check: $e"
println("Error checking file: $e")
end
20 changes: 20 additions & 0 deletions format_check/src/format_check_fitting.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using JuliaFormatter

# Provide the relative path to your fitting.jl file
relative_path_to_check = joinpath("src", "fitting.jl")

# Get the current working directory
current_dir = pwd()

# Combine current directory and relative path
file_to_check = joinpath(current_dir, relative_path_to_check)

@info "Checking format of $file_to_check"
try
# Resolve the file path
resolved_path = realpath(file_to_check)
@info "Running format check on $resolved_path"
format(resolved_path) # Run the format check on the resolved path
catch e
@error "Error checking $file_to_check: $e"
end
42 changes: 42 additions & 0 deletions format_check/src/format_check_input.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using JuliaFormatter

# Provide the relative path to your input.jl file
relative_path_to_check = joinpath("src", "input.jl")

# Get the current working directory
current_dir = pwd()

# Combine current directory and relative path
file_to_check = joinpath(current_dir, relative_path_to_check)

@info "Checking format of $file_to_check"
try
# Resolve the file path
resolved_path = realpath(file_to_check)
@info "Running format check on $resolved_path"

# Format the file
formatted_code = format(resolved_path) # This will return the formatted code

# Read the original code to check for differences
original_code = read(resolved_path, String)

# Check if the original and formatted codes are different
if formatted_code == original_code
@info "Formatting is good."
println("Formatting is good.")
else
@warn "Formatting is bad. Please check the differences."
println("Formatting is bad. Please check the differences.")
println("\n--- Original Code ---\n")
println(original_code)
println("\n--- Formatted Code ---\n")
println(formatted_code)

# Optionally, you can overwrite the original file with formatted code
# write(resolved_path, formatted_code)
end
catch e
@error "Error checking $file_to_check: $e"
println("Error checking file: $e")
end
42 changes: 42 additions & 0 deletions format_check/src/format_check_pipeline.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using JuliaFormatter

# Provide the relative path to your pipeline.jl file
relative_path_to_check = joinpath("src", "pipeline.jl")

# Get the current working directory
current_dir = pwd()

# Combine current directory and relative path
file_to_check = joinpath(current_dir, relative_path_to_check)

@info "Checking format of $file_to_check"
try
# Resolve the file path
resolved_path = realpath(file_to_check)
@info "Running format check on $resolved_path"

# Format the file
formatted_code = format(resolved_path) # This will return the formatted code

# Read the original code to check for differences
original_code = read(resolved_path, String)

# Check if the original and formatted codes are different
if formatted_code == original_code
@info "Formatting is good."
println("Formatting is good.")
else
@warn "Formatting is bad. Please check the differences."
println("Formatting is bad. Please check the differences.")
println("\n--- Original Code ---\n")
println(original_code)
println("\n--- Formatted Code ---\n")
println(formatted_code)

# Optionally, you can overwrite the original file with formatted code
# write(resolved_path, formatted_code)
end
catch e
@error "Error checking $file_to_check: $e"
println("Error checking file: $e")
end
22 changes: 22 additions & 0 deletions format_check/src/format_check_variable_utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using JuliaFormatter

# Get the path of the current script (or use the current working directory)
current_dir = dirname(@__FILE__) # If running as a script file, use @__FILE__
# For running directly in REPL, use `pwd()` to get the current working directory
# current_dir = pwd()

# Construct the relative path to the file based on the current directory
file_path = joinpath(current_dir, "src", "variable_utils.jl")

# Read the original file content
original_content = read(file_path, String)

# Format the content without changing the file
formatted_content = format_text(original_content, margin=92) # Adjust margin if needed

# Check if the original content matches the formatted content
if original_content == formatted_content
println("The file is properly formatted.")
else
println("The file is not properly formatted.")
end
26 changes: 26 additions & 0 deletions format_check/src/format_check_visualize.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using JuliaFormatter

function check_format(file::String)
formatted_code = format_file(file)
original_code = read(file, String)

return formatted_code == original_code, formatted_code
end

function main()
# Path to your visualize.jl file using a relative path
file = joinpath(@__DIR__, "src", "visualize.jl")

is_formatted, formatted_code = check_format(file)

if !is_formatted
println("Formatting issue found in: $file")
println("Formatted code:")
println(formatted_code)
error("The file is not properly formatted.")
else
println("The file is properly formatted.")
end
end

main()

0 comments on commit 5482e9e

Please sign in to comment.