From db5cef47b5d5fae1943c5f7e718f916813c54a58 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 16 Mar 2023 19:57:30 +0000 Subject: [PATCH 1/6] Add basic flint config --- fortran_rc_default.yaml | 417 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 417 insertions(+) create mode 100644 fortran_rc_default.yaml diff --git a/fortran_rc_default.yaml b/fortran_rc_default.yaml new file mode 100644 index 0000000..8ac23c2 --- /dev/null +++ b/fortran_rc_default.yaml @@ -0,0 +1,417 @@ + +# Flinter configuation file. + + +# These are all the regexp rules + +# Set active to false is you want to skip rule +# All are regexp rules, meaning you can add new rules simply by editing this file +# test your rule on https://regex101.com/ if needed + +extension: f\d* + +regexp-rules: + + intrinsics-should-be-lowercased: + message: Intrinsics keywords should be lowercased + regexp: \b({intrinsics_upper}|end(?:{blocks_upper}|{structs_upper}))\b + case-sensitive: true + active: true + + # intrinsics-should-be-uppercased: + # message: Intrinsics keywords should be uppercased + # regexp: \b({intrinsics_lower}|end(?:{blocks_lower}|{structs_lower}))\b + # case-sensitive: true + # active: true + + intrinsics-args-should-be-lowercased: + message: Intrinsics named argument should be lowercased + regexp: \b({named-args_upper})(?=\s*=) + case-sensitive: true + active: true + + # intrinsics-args-should-be-uppercased: + # message: Intrinsics named argument should be uppercased + # regexp: \b({named-args_lower})(?=\s*=) + # case-sensitive: true + # active: true + + types-should-be-lowercased: + message: Types should be lowercased + regexp: \b({types_upper})\b + case-sensitive: true + active: true + + # types-should-be-uppercased: + # message: Types should be uppercased + # regexp: \b({types_lower})\b + # case-sensitive: true + # active: true + + real-avbp-working-precision: + message: Use AVBP working precision + regexp: (?<=real)(?!\(\s*pr\s*\))\([^\(]*\) + replacement: (pr) + + character-string-length: + message: Use strl or shortstrl + regexp: (?<=character)(\s*\(\s*len\s*=\s*)(?!\s*strl\b|\s*shortstrl\b)[^\(]*?(\s*\)) + + missing-space-before-call-parameters: + message: Missing space between subroutine name and parenthesis + regexp: (?<=call\s)(\s*\w+)\( + replacement: \1 ( + + missing-space-after-call-parenthesis: + message: Missing space after first parenthesis + regexp: (?<=call\s)(\s*\w+\s*)\((\S) + replacement: ( \2 + + missing-space-before-call-parenthesis: + message: Missing space before last parenthesis + regexp: (?<=call\s)(\s*\w+\s*\([^)(]*(?:\([^)(]*(?:\([^)(]*\)[^)(]*)*\)[^)(]*)*(?' + - '\.lt\.' + - '<' + - '\.geq\.' + - '>=' + - '\.leq\.' + - '<=' + - '\.le\.' + - '\.ge\.' + - '\.and\.' + - '\.or\.' + + structs: + - if + - select + - case + - while + + punctuations: + - ',' + - '\)' + - ';' + + namespace_blocks: + - program + - module + + context_blocks: + - function + - subroutine + + intrinsics: + - ALLOCATABLE + - ALLOCATE + - ASSIGN + - ASSIGNMENT + - BACKSPACE + - BLOCK + - CALL + - CASE + - CLOSE + - COMMON + - CONTAINS + - CONTINUE + - CYCLE + - DATA + - DEALLOCATE + - DEFAULT + - DIMENSION + - DO + - ELSE + - ELSEWHERE + - END + - ENDFILE + - ENTRY + - EQUIVALENCE + - EXIT + - EXTERNAL + - FUNCTION + - GO + - GOTO + - IF + - IMPLICIT + - IN + - INOUT + - INQUIRE + - INTENT + - INTERFACE + - INTRINSIC + - MODULE + - NAMELIST + - NONE + - NULLIFY + - ONLY + - OPEN + - OPERATOR + - OPTIONAL + - OUT + - PARAMETER + - PAUSE + - POINTER + - PRINT + - PRIVATE + - PROCEDURE + - PROGRAM + - PUBLIC + - READ + - RECURSIVE + - RESULT + - RETURN + - REWIND + - SAVE + - SELECT + - SEQUENCE + - STOP + - SUBROUTINE + - TARGET + - THEN + - TO + - TYPE + - USE + - WHERE + - WHILE + - WRITE + # should we or not? + #- IFDEF + #- IFNDEF + + + named-args: + - ACCESS + - ACTION + - ADVANCE + - BLANK + - DELIM + - DIRECT + - EOR + - ERR + - EXIST + - FILE + - FMT + - FORM + - FORMAT + - FORMATTED + - IOLENGTH + - IOSTAT + - KIND + - LEN + - NAME + - NAMED + - NEXTREC + - NML + - NUMBER + - OPENED + - PAD + - POSITION + - READWRITE + - REC + - RECL + - SEQUENTIAL + - SIZE + - STAT + - STATUS + - UNFORMATTED + - UNIT \ No newline at end of file From a719577d59a82752b3c36f681080020111925cf0 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 16 Mar 2023 19:59:53 +0000 Subject: [PATCH 2/6] Some cleanup of basic flint config --- fortran_rc_default.yaml | 112 +++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 66 deletions(-) diff --git a/fortran_rc_default.yaml b/fortran_rc_default.yaml index 8ac23c2..90192fa 100644 --- a/fortran_rc_default.yaml +++ b/fortran_rc_default.yaml @@ -18,23 +18,11 @@ regexp-rules: case-sensitive: true active: true - # intrinsics-should-be-uppercased: - # message: Intrinsics keywords should be uppercased - # regexp: \b({intrinsics_lower}|end(?:{blocks_lower}|{structs_lower}))\b - # case-sensitive: true - # active: true - intrinsics-args-should-be-lowercased: message: Intrinsics named argument should be lowercased regexp: \b({named-args_upper})(?=\s*=) case-sensitive: true active: true - - # intrinsics-args-should-be-uppercased: - # message: Intrinsics named argument should be uppercased - # regexp: \b({named-args_lower})(?=\s*=) - # case-sensitive: true - # active: true types-should-be-lowercased: message: Types should be lowercased @@ -42,12 +30,6 @@ regexp-rules: case-sensitive: true active: true - # types-should-be-uppercased: - # message: Types should be uppercased - # regexp: \b({types_lower})\b - # case-sensitive: true - # active: true - real-avbp-working-precision: message: Use AVBP working precision regexp: (?<=real)(?!\(\s*pr\s*\))\([^\(]*\) @@ -77,41 +59,41 @@ regexp-rules: regexp: '(?<=\S) +(?=[^\s!])' replacement: ' ' - # missing-space-around-operator: - # message: Missing space around operator - # regexp: ([^\s=])({operators})([^\s=]) - # replacement: \1 \2 \3 - # active: false - - # missing-space-before-operator: - # message: Missing space before operator - # regexp: ([^\s=])({operators})(?=\s) - # replacement: \1 \2 - # active: false - - # missing-space-after-operator: - # message: Missing space after operator - # regexp: (?<=\s)({operators})([^\s=]) - # replacement: \1 \2 - # active: false - - # missing-space-around-separator: - # message: Missing space around separator - # regexp: (\S)::(\S) - # replacement: '\1 :: \2' - # active: false - - # missing-space-before-separator: - # message: Missing space before separator - # regexp: (\S)::(?=\s) - # replacement: '\1 ::' - # active: false - - # missing-space-after-separator: - # message: Missing space after separator - # regexp: (?<=\s)::(\S) - # replacement: ':: \1' - # active: false + missing-space-around-operator: + message: Missing space around operator + regexp: ([^\s=])({operators})([^\s=]) + replacement: \1 \2 \3 + active: false + + missing-space-before-operator: + message: Missing space before operator + regexp: ([^\s=])({operators})(?=\s) + replacement: \1 \2 + active: false + + missing-space-after-operator: + message: Missing space after operator + regexp: (?<=\s)({operators})([^\s=]) + replacement: \1 \2 + active: false + + missing-space-around-separator: + message: Missing space around separator + regexp: (\S)::(\S) + replacement: '\1 :: \2' + active: false + + missing-space-before-separator: + message: Missing space before separator + regexp: (\S)::(?=\s) + replacement: '\1 ::' + active: false + + missing-space-after-separator: + message: Missing space after separator + regexp: (?<=\s)::(\S) + replacement: ':: \1' + active: false # missing-space-after-punctuation: # message: Missing space after punctuation @@ -172,19 +154,17 @@ regexp-rules: regexp: ([^\s=])(? Date: Thu, 16 Mar 2023 20:02:18 +0000 Subject: [PATCH 3/6] Comment out space around parentheses flint rules Keeping around as might be able to adapt to enforce NO spaces --- fortran_rc_default.yaml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/fortran_rc_default.yaml b/fortran_rc_default.yaml index 90192fa..44337d4 100644 --- a/fortran_rc_default.yaml +++ b/fortran_rc_default.yaml @@ -39,20 +39,20 @@ regexp-rules: message: Use strl or shortstrl regexp: (?<=character)(\s*\(\s*len\s*=\s*)(?!\s*strl\b|\s*shortstrl\b)[^\(]*?(\s*\)) - missing-space-before-call-parameters: - message: Missing space between subroutine name and parenthesis - regexp: (?<=call\s)(\s*\w+)\( - replacement: \1 ( - - missing-space-after-call-parenthesis: - message: Missing space after first parenthesis - regexp: (?<=call\s)(\s*\w+\s*)\((\S) - replacement: ( \2 - - missing-space-before-call-parenthesis: - message: Missing space before last parenthesis - regexp: (?<=call\s)(\s*\w+\s*\([^)(]*(?:\([^)(]*(?:\([^)(]*\)[^)(]*)*\)[^)(]*)*(? Date: Thu, 16 Mar 2023 20:41:33 +0000 Subject: [PATCH 4/6] Fix flint false positive for comments --- fortran_rc_default.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fortran_rc_default.yaml b/fortran_rc_default.yaml index 44337d4..39186f1 100644 --- a/fortran_rc_default.yaml +++ b/fortran_rc_default.yaml @@ -129,7 +129,7 @@ regexp-rules: one-space-after-comment: message: Exactly one space after comment - regexp: \!(\S) + regexp: (\!\!)(\S) replacement: '! \1' include-comments: true From 9a0b40f5963d955e159c9bc48f2191213a4eb07d Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 16 Mar 2023 20:42:46 +0000 Subject: [PATCH 5/6] Don't check for AVBP precision in flint Keep the regex though as it might be useful later --- fortran_rc_default.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fortran_rc_default.yaml b/fortran_rc_default.yaml index 39186f1..a4d3b68 100644 --- a/fortran_rc_default.yaml +++ b/fortran_rc_default.yaml @@ -30,10 +30,10 @@ regexp-rules: case-sensitive: true active: true - real-avbp-working-precision: - message: Use AVBP working precision - regexp: (?<=real)(?!\(\s*pr\s*\))\([^\(]*\) - replacement: (pr) + # real-avbp-working-precision: + # message: Use AVBP working precision + # regexp: (?<=real)(?!\(\s*pr\s*\))\([^\(]*\) + # replacement: (pr) character-string-length: message: Use strl or shortstrl From 9b5f825cb7d70e04d52715c6c8b8555cd72636af Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 16 Mar 2023 21:05:15 +0000 Subject: [PATCH 6/6] Make a lint script to run flint --- fortran_rc_default.yaml => utils/fortran_rc_default.yaml | 0 utils/lint.sh | 5 +++++ 2 files changed, 5 insertions(+) rename fortran_rc_default.yaml => utils/fortran_rc_default.yaml (100%) create mode 100644 utils/lint.sh diff --git a/fortran_rc_default.yaml b/utils/fortran_rc_default.yaml similarity index 100% rename from fortran_rc_default.yaml rename to utils/fortran_rc_default.yaml diff --git a/utils/lint.sh b/utils/lint.sh new file mode 100644 index 0000000..222b2d8 --- /dev/null +++ b/utils/lint.sh @@ -0,0 +1,5 @@ +#!/bin/sh +for f in $(find . -type f -name "*.f90") +do + flint lint $f -r utils/fortran_rc_default.yaml +done