From 99ebfbedc188a67ceb3553cc072e0473e5f46aa3 Mon Sep 17 00:00:00 2001 From: jatkinson1000 <109271713+jatkinson1000@users.noreply.github.com> Date: Sat, 21 Oct 2023 15:41:21 +0100 Subject: [PATCH 1/3] Add regex to allow FORD comments. --- fortran_linter/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fortran_linter/main.py b/fortran_linter/main.py index 86b9ab9..ab82a0a 100755 --- a/fortran_linter/main.py +++ b/fortran_linter/main.py @@ -59,8 +59,11 @@ class FortranRules: (r"\t", " ", "Should use 2 spaces instead of tabulation"), # Fix "foo! comment" to "foo ! comment" (r"(\w)(\!(?!\$)|\!\$)", r"\1 \2", "At least one space before comment"), - # Fix "!bar" to "! bar" - (r"\!(|\s\s+)(?!\$)(\S)", r"! \2", "Exactly one space after comment"), + # Enforce space after comments (but ignoring !$): + # # Fix "!bar" to "! bar" (Normal F90) + # (r"\!(|\s\s+)(?!\$)(\S)", r"! \2", "Exactly one space after comment"), + # Fix "<>bar" to "<> bar" where <> can be !, !!, !> (FORD Documentation) + (r"(![!>#]?(?:(?=[^\s!>#$]|(\s\s)|\s\$)|\$(?!\S)))\s*(.*)", r"\1 \3", "Exactly one space after comment"), # Remove trailing ";" (r";\s*$", r"\n", 'Useless ";" at end of line'), [ From db1324cdeb9ef98a59ae7a7eac0ebf3a3369ebbb Mon Sep 17 00:00:00 2001 From: jatkinson1000 <109271713+jatkinson1000@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:19:20 +0100 Subject: [PATCH 2/3] Update tests and remove old comment check from main. --- fortran_linter/main.py | 8 +++++--- tests/test.f90 | 4 ++++ tests/test_comment_detection.py | 6 ++++++ tests/test_reference.f90 | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fortran_linter/main.py b/fortran_linter/main.py index ab82a0a..d9d378a 100755 --- a/fortran_linter/main.py +++ b/fortran_linter/main.py @@ -60,10 +60,12 @@ class FortranRules: # Fix "foo! comment" to "foo ! comment" (r"(\w)(\!(?!\$)|\!\$)", r"\1 \2", "At least one space before comment"), # Enforce space after comments (but ignoring !$): - # # Fix "!bar" to "! bar" (Normal F90) - # (r"\!(|\s\s+)(?!\$)(\S)", r"! \2", "Exactly one space after comment"), # Fix "<>bar" to "<> bar" where <> can be !, !!, !> (FORD Documentation) - (r"(![!>#]?(?:(?=[^\s!>#$]|(\s\s)|\s\$)|\$(?!\S)))\s*(.*)", r"\1 \3", "Exactly one space after comment"), + ( + r"(![!>#]?(?:(?=[^\s!>#$]|(\s\s)|\s\$)|\$(?!\S)))\s*(.*)", + r"\1 \3", + "Exactly one space after comment", + ), # Remove trailing ";" (r";\s*$", r"\n", 'Useless ";" at end of line'), [ diff --git a/tests/test.f90 b/tests/test.f90 index a947852..59ddd73 100644 --- a/tests/test.f90 +++ b/tests/test.f90 @@ -48,6 +48,10 @@ end module merger_commons a = 2!bar - missing spaces around '!' a = 2 ! bar - too many spaces after '!' +a = 2!!bar - missing spaces around FORD '!!' +a = 2!>bar - missing spaces around FORD '!>' +a = 2 !! bar - too many spaces after FORD '!!' +a = 2 !> bar - too many spaces after FORD '!>' integer*4 :: foo ! old syntax, should become integer(4) diff --git a/tests/test_comment_detection.py b/tests/test_comment_detection.py index b47ae48..c596a29 100644 --- a/tests/test_comment_detection.py +++ b/tests/test_comment_detection.py @@ -37,6 +37,12 @@ def test_fortran_comment_detection(): ("! test", 0), (" !test", 4), ("'Contains a string', ! and a comment", 21), + ("!! test", 0), + (" !!test", 4), + ("'Contains a string', !! and a comment", 21), + ("!> test", 0), + (" !>test", 4), + ("'Contains a string', !> and a comment", 21), ) no_comment_lines = ( diff --git a/tests/test_reference.f90 b/tests/test_reference.f90 index 0d6c14b..e93530a 100644 --- a/tests/test_reference.f90 +++ b/tests/test_reference.f90 @@ -48,6 +48,10 @@ end module merger_commons a = 2 ! bar - missing spaces around '!' a = 2 ! bar - too many spaces after '!' +a = 2 !! bar - missing spaces around FORD '!!' +a = 2 !> bar - missing spaces around FORD '!>' +a = 2 !! bar - too many spaces after FORD '!!' +a = 2 !> bar - too many spaces after FORD '!>' integer(4) :: foo ! old syntax, should become integer(4) From 83501415817eb9fb57d81367953f220346367475 Mon Sep 17 00:00:00 2001 From: jatkinson1000 <109271713+jatkinson1000@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:26:17 +0100 Subject: [PATCH 3/3] Add note on FORD to README.md --- Readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 88d43da..d5a611e 100644 --- a/Readme.md +++ b/Readme.md @@ -38,7 +38,7 @@ For more help, you can type ## Rules Here is a non-comprehensive set of rules that are enforced: - * Punctuation should be followed by a space, this include `,`, `;` and `)`. + * Punctuation should be followed by a space, this includes `,`, `;` and `)`. * Binary operators (`==`, `+`, ...) should be surrounded by spaces * The following special characters are surrounded by at least one space: `::`, `=`. * A line should not exceed 120 characters (this is somehow already extreme). The maximum line length can be controlled from the CLI. @@ -48,6 +48,7 @@ Here is a non-comprehensive set of rules that are enforced: * `print` statements should look like `print *, "something"` * `write` statements should look like `write(*, *) "something"` * Lines should be indented consistently (by default, using an indentation of 4 spaces) + * [FORD](https://forddocs.readthedocs.io/en/latest/) Compatibility: `!!` and `!>` are preserved and treated as comments like `!` with one space after and at least one space before. # TODO list