-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from warisa-r/elena_test2
Format check
- Loading branch information
Showing
7 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |