From e00194b92ce535c6a222e2dbd059202416a30800 Mon Sep 17 00:00:00 2001 From: Mathieu Courtois <mathieu.courtois@edf.fr> Date: Fri, 7 Mar 2025 13:30:32 +0100 Subject: [PATCH] [#34440] 'return' now allowed, instead of 'goto 999'! --- lib/aslint/fortran/static_fortran_checkers.py | 45 ++----------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/lib/aslint/fortran/static_fortran_checkers.py b/lib/aslint/fortran/static_fortran_checkers.py index a59386c..36274b7 100644 --- a/lib/aslint/fortran/static_fortran_checkers.py +++ b/lib/aslint/fortran/static_fortran_checkers.py @@ -34,7 +34,7 @@ from aslint.fortran.externals import externals COMMENT_FOR = re.compile("^[!].*?$", re.M) STATS = "(call|write|read|do|while|if)" -UNAUTH_STATS = "(stop *$|return *$|intrinsic|entry|dimension|equivalence" "|include|external)" +UNAUTH_STATS = "(stop *$|intrinsic|entry|dimension|equivalence" "|include|external)" AVOID_STATS = "(call +utalrm)" VARLENGTH = 24 @@ -44,7 +44,6 @@ SUBLENGTH = 32 class ImplicitNone(FileContentCat, TextMsgNotFound): - """implicit none""" id = "C1001" @@ -52,9 +51,8 @@ class ImplicitNone(FileContentCat, TextMsgNotFound): class UnauthorizedStatement(FileContentCat, TextMsg): - """Unauthorized statement - These statements should not be used: stop, return, intrinsic, entry, + These statements should not be used: stop, intrinsic, entry, dimension, equivalence, include. Prefer use '#include' instead of the 'include' fortran statement. """ @@ -64,7 +62,6 @@ class UnauthorizedStatement(FileContentCat, TextMsg): class UnrecommendedStatement(FileContentCat, TextMsg): - """Unrecommended statement These statements should not be used: utalrm, allocate, deallocate. ALLOCATE/DEALLOCATE should be replaced by AS_ALLOCATE/AS_DEALLOCATE. @@ -75,7 +72,6 @@ class UnrecommendedStatement(FileContentCat, TextMsg): class LicenseNotFound(FileContentCat, COMM.LicenseNotFound): - """Summary with GPL is required The copyright and GPL summary are required. Even if there is an external copyright, it must mention www.code-aster.org @@ -85,21 +81,19 @@ class LicenseNotFound(FileContentCat, COMM.LicenseNotFound): class EDFCopyright(FileContentCat, COMM.EDFCopyright): - """EDF R&D Copyright not found Even if there is a copyright to another company than EDF R&D, the source has been changed for Code_Aster conformance and version management. Example: - Copyright 2008 Company ABC - - Copyright 2008-2024 EDF R&D www.code-aster.org + - Copyright 2008-2025 EDF R&D www.code-aster.org """ id = "C1005" class ExternalCopyright(FileContentCat, COMM.ExternalCopyright): - """Another Copyright than EDF""" id = "W1006" @@ -146,7 +140,6 @@ def _get_list_files(path): class UniqueFilename(DirnameCat, GenericMsg): - """Filename used more than once A filename must not be used several times.""" @@ -164,7 +157,6 @@ class UniqueFilename(DirnameCat, GenericMsg): class InterfaceRequired(DirnameCat, GenericMsg): - """Interface file is required for each subroutine An interface is required for each fortran subroutine or function. For a ``xxxx.F90`` file, a file defining the interface must exist in @@ -190,7 +182,6 @@ class InterfaceRequired(DirnameCat, GenericMsg): class UnusedInterface(DirnameCat, GenericMsg): - """Interface without a fortran subroutine An interface (.h) exists for a fortran subroutine that does not exist.""" @@ -207,7 +198,6 @@ class UnusedInterface(DirnameCat, GenericMsg): class OutOfRangeSubroutine(FortranCodeCat, GenericMsg): - """Numbered subroutine out of range Developpers must not add 'te', 'op' or 'lc' subroutines out of the predefined range: 'te' <= 600, 'op' < 200, 'lc' <= 1e6.""" @@ -236,7 +226,6 @@ class OutOfRangeSubroutine(FortranCodeCat, GenericMsg): class ExpectedDimension(FileContentCat, TextMsg): - """Expected another dimension in array declaration Size of arrays must be explicitly declared: 'array(0:)' is not tolerated, use 'array(0:N)' instead.""" @@ -246,7 +235,6 @@ class ExpectedDimension(FileContentCat, TextMsg): class DoublePrecision(FileContentCat, TextMsg): - """Double precision type not allowed 'double precision' should be replaced by 'real(kind=8)'. Ref. http://fortranwiki.org/fortran/show/Real+precision""" @@ -256,7 +244,6 @@ class DoublePrecision(FileContentCat, TextMsg): class CharacterTooLong(FileContentCat, TextMsg): - """Character variable too long Character variables size must not exceed 256 characters.""" @@ -276,7 +263,6 @@ class CharacterTooLong(FileContentCat, TextMsg): class AutomaticArray(FortranCodeCat, GenericMsg): - """Automatic arrays Automatic arrays must be used with care of their size.""" @@ -309,7 +295,6 @@ class AutomaticArray(FortranCodeCat, GenericMsg): class VariableLength(FortranCodeCat, GenericMsg): - """Variable name too long The maximum length for a variable name is 24.""" @@ -331,7 +316,6 @@ class VariableLength(FortranCodeCat, GenericMsg): class UninitializedPointer(FortranCodeCat, GenericMsg): - """Uninitialized pointer Pointers must be initialized to 'null()'.""" @@ -360,7 +344,6 @@ class UninitializedPointer(FortranCodeCat, GenericMsg): class SubroutineNameLength(FortranCodeCat, GenericMsg): - """Subroutine name too long The maximum length for a subroutine name is 32.""" @@ -380,7 +363,6 @@ class SubroutineNameLength(FortranCodeCat, GenericMsg): class UnrecommendedIf(FortranCodeCat, GenericMsg): - """Unrecommended IF statement before macros, use `if (...) then ... end if` The syntax without `then` (also called "logical if") is considered archaic and may cause unexpected error when a macro is replaced by several @@ -405,7 +387,6 @@ class UnrecommendedIf(FortranCodeCat, GenericMsg): class RealWithoutKind(FortranCodeCat, GenericMsg): - """Kind value of real/complex must be 4 or 8 Real and complex variables must be declared with an explicit range and in most case, it should be 'real(kind=8)' or 'complex(kind=8)'.""" @@ -422,7 +403,6 @@ class RealWithoutKind(FortranCodeCat, GenericMsg): class ImplicitSave(FortranCodeCat, GenericMsg): - """Unauthorized implicit save Implicit save is too dangerous. If it's intended, 'save' attribute must be explicitly added. @@ -459,7 +439,6 @@ class ImplicitSave(FortranCodeCat, GenericMsg): class NameList(FileContentCat, TextMsg): - """Nonstandard syntax""" id = "C1401" @@ -467,7 +446,6 @@ class NameList(FileContentCat, TextMsg): class NonStdDeclaration(FileContentCat, TextMsg): - """Nonstandard type declaration 'real*8' and similar declarations must no longer be used. Ref. http://fortranwiki.org/fortran/show/Real+precision""" @@ -477,7 +455,6 @@ class NonStdDeclaration(FileContentCat, TextMsg): class NoExecutableStatement(FileContentCat, TextMsgNotFound): - """No executable statement""" id = "W1403" @@ -489,7 +466,6 @@ class NoExecutableStatement(FileContentCat, TextMsgNotFound): class LineNumber(FileContentCat, TextMsg): - """More than 500 lines or than 200 per subroutines in modules""" id = "W1501" @@ -519,7 +495,6 @@ class LineNumber(FileContentCat, TextMsg): class TooManyContinuation(FileContentCat, TextMsg): - """More than 19 continuation lines""" id = "W1502" @@ -546,7 +521,6 @@ class TooManyContinuation(FileContentCat, TextMsg): class TooManyArgs(FortranCodeCat, GenericMsg): - """More than 20 arguments""" id = "W1504" @@ -564,7 +538,6 @@ class TooManyArgs(FortranCodeCat, GenericMsg): class ContinuedDecl(FileContentCat, TextMsg): - """Declaration with continuation line For readibility the declarations must not be continued. This is only allowed for the declarations of constant arrays (with ``parameter`` attribute).""" @@ -579,7 +552,6 @@ class ContinuedDecl(FileContentCat, TextMsg): class InlineComment(FileContentCat, TextMsg): - """Inline comment""" id = "C1506" @@ -591,7 +563,6 @@ class InlineComment(FileContentCat, TextMsg): class NotContinueOrFormatLabel(FileContentCat, DiffCat, TextMsg): - """Label only before continue or format For loop, use do/end do.""" @@ -613,7 +584,6 @@ class NotContinueOrFormatLabel(FileContentCat, DiffCat, TextMsg): class LabelSize(FileContentCat, DiffCat, TextMsg): - """Recommendation: 3 digits max. for labels""" id = "I1508" @@ -621,7 +591,6 @@ class LabelSize(FileContentCat, DiffCat, TextMsg): class LineTooLong(FileContentCat, COMM.LineTooLong): - """Line too long Lines must not be too long for readability and convention. Maximum line length is 100 columns in code_aster fortran source files.""" @@ -631,7 +600,6 @@ class LineTooLong(FileContentCat, COMM.LineTooLong): class DebugMode(FilenameCat, GenericMsg): - """Debug mode in 'calcul' enabled This major subroutine must not be committed with the debug mode enabled.""" @@ -652,12 +620,12 @@ class DebugMode(FilenameCat, GenericMsg): class InvalidCharacter(FileContentCat, COMM.InvalidCharacter): r"""Invalid character, unexpected tabulation '\t' Tabulation character is not allowed.""" + # tabs in source code are detected by NoTabs, this avoids them in comments id = "C1511" class MultilineAssert(FileContentCat, TextMsg): - """ASSERT must be on a single line The fortran preprocessor does not always support macros on several lines. It depends on the preprocessor version.""" @@ -671,7 +639,6 @@ class MultilineAssert(FileContentCat, TextMsg): if ASCFG.get("fortran.form") == "fixed": class FixedFormDisable(HiddenMsg): - """Messages hidden until source are in fixed form""" id = "I8999" @@ -679,7 +646,6 @@ if ASCFG.get("fortran.form") == "fixed": class CompilationDirective(FileContentCat, TextMsg): - """Compilation directives are not recommended Compilation directives must only be used for strong reasons.""" @@ -694,7 +660,6 @@ class ReformatSource(FilenameCat, COMM.ReformatFort): class ForHeaderDisable(HiddenMsg): - """Messages hidden for header files""" id = "I8886" @@ -706,7 +671,6 @@ class ForHeaderDisable(HiddenMsg): class ReservedFilename(FilenameCat, GenericMsg): - """Reserved filename These patterns are reserved to identify fortran types and modules definition : ``xxxx_type.F90`` for public types, ``xxxx_module.F90`` @@ -728,7 +692,6 @@ class ReservedFilename(FilenameCat, GenericMsg): class InvalidFilename(FilenameCat, GenericMsg): - """Invalid filename for a module The module must be names ``xxxx_module.F90`` to allow automatic checkings using different compilers between build and checkings. -- GitLab