Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 397 additions & 0 deletions utils/fortran_rc_default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,397 @@

# 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-args-should-be-lowercased:
message: Intrinsics named argument should be lowercased
regexp: \b({named-args_upper})(?=\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

# 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*\([^)(]*(?:\([^)(]*(?:\([^)(]*\)[^)(]*)*\)[^)(]*)*(?<!\s))\)
# replacement: \1 )

excessive-use-of-space:
message: Except for indentation, single spaces are sufficient
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-after-punctuation:
# message: Missing space after punctuation
# regexp: ({punctuations})(\S)
# replacement: \1 \2
# active: false

# missing-space-before-parenthesis:
# message: Missing space before parenthesis
# regexp: ({structs})\(
# replacement: \1 (
# active: false

prepend-with-!$:
message: Should prepend with "!$"
regexp: ^(\s*)(use\s+omp_lib)
replacement: '\1!$ \2'

tabulation-insteadof-twospaces:
message: Should use 2 spaces instead of tabulation
regexp: \t
replacement: ' '

use-new-syntax-type:
message: Use new syntax TYPE(kind)
regexp: ({types})\*(\w+)
replacement: \1(\2)

one-space-before-comment:
message: At least one space before comment
regexp: (\S)\!
replacement: \1 !

one-space-after-comment:
message: Exactly one space after comment
regexp: (\!\!)(\S)
replacement: '! \1'
include-comments: true

useless-eol-dotcomma:
message: Useless ";" at end of line
regexp: ;\s*$
replacement: ''

nospace-endif:
message: Missing space after "end"
regexp: \#endif
replacement: null
active: true

nospace-end:
message: Missing space after "end"
regexp: end({blocks}|{structs})
replacement: end \1

missing-space-around-=:
message: Missing space around "="
regexp: ([^\s=])(?<!kind|.len)=([^\s=])
replacement: \1 = \2

missing-space-after-=:
message: Missing space after "="
regexp: (?<!kind|.len|...\s)\s+=([^\s=])
replacement: = \1
active: false

missing-space-before-=:
message: Missing space before "="
regexp: ([^\s=])(?<!kind|.len)=(?=\s)
replacement: \1 =
active: false

trailing-whitespaces:
message: Trailing whitespaces
regexp: ([ \t])+$
replacement: ''
include-comments: true

reommended-use-of-sp-dp:
message: You should use "sp" or "dp" instead
regexp: \(kind\s*=\s*\d\s*\)

reommended-use-of-brackets:
message: You should use "[]" instead
regexp: \(\\([^\)]*)\\\)
replacement: '[\1]'

reommended-use-mpi_f08:
message: Should use "use mpi_f08" instead (or "use mpi" if not available)
regexp: include\s+["\']mpif.h[\'"]

not-recommended-bare-end:
message: Bare end statement not recommended
regexp: ^\s*end\s*$

not-recommended-bare-stop:
message: Bare stop statement not recommended
regexp: ^\s*stop\s*$

not-recommended-use-exit:
message: exit is an extension and should be avoided
regexp: \bexit\b

not-recommended-use-goto:
message: goto is hard to maintain, prone to spaghetti code.
regexp: \bgoto\b

not-recommended-use-double-precision:
message: double precision is discouraged; use real instead.
regexp: \bdouble\s+precision\b

not-recommended-use-pause:
message: pause is discouraged.
regexp: \bpause\b

not-recommended-use-include:
message: include is discouraged, prefer use.
regexp: \binclude\b


# These are rules that span over multiple lines, not accessible by regexp
# If you want to edit these rules or add your own, two options:
# - ask us.
# - fork the code.
structure-rules:
max-statements-in-context: 50
max-declared-locals: 12
min-varlen: 3
max-varlen: 20
max-arguments: 5
min-arglen: 3
max-arglen: 20
max-nesting-levels: 5
var-declaration: '(?:{types})\s*(?:\(.*\))?\s*(?:::| )\s*([A-Za-z_]\w*(?:\s*,\s*[A-Za-z_]\w*)*)'


######################################################################################
# These are the fortran syntax we use to parse the source
# A priori there is no need to edit, but Fortran is so vast in time...
######################################################################################

syntax:
types:
- real
- character
- logical
- integer
- complex
- double precision

operators:
- '\.eq\.'
- '=='
- '\.neq\.'
- '/='
- '\.gt\.'
- '>'
- '\.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
Loading