diff --git a/lib/aslint/base_checkers.py b/lib/aslint/base_checkers.py index 7c9a5b7169daa42d57859e5dc09630ca77f4c676..128bb440ef5b5909918fca418ed81586f641cea0 100644 --- a/lib/aslint/base_checkers.py +++ b/lib/aslint/base_checkers.py @@ -438,9 +438,6 @@ class CheckContext(object): return True if self.brchk(ctg.branch): return True - # in 'asterxx' branch, use same checkers as for 'default' - if ctg.branch.startswith("asterxx") and self.brchk("default"): - return True # 'main' and 'default' if ctg.branch in ("main", "default") and (self.brchk("main") or self.brchk("default")): return True @@ -568,12 +565,7 @@ class CheckList(object): def get_type(self, types): """Return a sub-Checklist of the given types""" - types = tuple( - force_list(types) - + [ - HiddenMsg, - ] - ) + types = tuple(force_list(types) + [HiddenMsg]) return CheckList([msg for msg in self if issubclass(msg, types)]) def on_content(self, apply_to=None): @@ -835,11 +827,7 @@ class Context(object): """Store contextual values attached to a Report""" - __slots__ = ( - "repository", - "submission", - "username", - ) + __slots__ = ("repository", "submission", "username") def __init__(self): """Initialization""" diff --git a/lib/aslint/check_global.py b/lib/aslint/check_global.py index f9e7e52dfc6889637edd15835d053b7dfc5d32b4..f5afcba74be36cc3d48c5e1cb394ac389ea62e31 100644 --- a/lib/aslint/check_global.py +++ b/lib/aslint/check_global.py @@ -50,35 +50,6 @@ class ErrorMessages(DirnameCat, GenericMsg): return result -class Supv002aRequirement(DirnameCat, GenericMsg): - - """Requirements missed to check spelling of messages (supv002a will fail) - The testcase supv002a checks the spelling of error messages. - It requires ``aspell`` and the dictionnaries - ``<DEVTOOLS>/share/spell/code_aster_dict.aspell.per`` and - ``code_aster_cata.aspell.per``. - """ - - id = "W9004" - fmt = "%(id)s: %(label)s" - apply_ctxt = CheckContext(branch="v15") - - def search(self, srcdir): - """Check pre-requisites for supv002a""" - share = osp.join(ASCFG.get("devtools_root"), "share", "spell") - fdict = osp.join(share, "code_aster_dict.aspell.per") - if not osp.isfile(fdict): - return [": french dictionnary is missing: %s" % fdict] - fdict = osp.join(share, "code_aster_cata.aspell.per") - if not osp.isfile(fdict): - return [": dictionnary of keywords is missing: %s (see help)" % fdict] - try: - check_call(["aspell", "--version"], stdout=PIPE) - except (CalledProcessError, FileNotFoundError): - return [": 'aspell' not found, not in $PATH"] - return [] - - CHECK_LIST = checkers_from_context(globals(), TextMsg) diff --git a/lib/aslint/common_checkers.py b/lib/aslint/common_checkers.py index 9d04e53a50b3558b31a3a5466a4c9ff332376d53..fe7ba726550d8643eecf02ea7bb2d193dff4409c 100644 --- a/lib/aslint/common_checkers.py +++ b/lib/aslint/common_checkers.py @@ -198,7 +198,6 @@ def check_encoding(text, encoding): class InvalidEndOfLine(FileContentCat, GenericMsg): - r"""Invalid end of line, expecting '\n' not '\r\n'""" id = "C8502" fmt = "%(id)s: %(label)s" @@ -324,7 +323,7 @@ class EDFCopyright(TextMsgNotFound): Example: - Copyright 2008 Company ABC - - Copyright 2008-2019 EDF R&D www.code-aster.org + - Copyright 2008-2023 EDF R&D www.code-aster.org """ # id must be defined in subclasses @@ -364,7 +363,6 @@ class EncodingDeclNotFound(TextMsgNotFound): class InvalidCharacter(GenericMsg): - r"""Invalid character, unexpected tabulation '\t' Tabulation character is not allowed.""" # id must be defined in subclasses @@ -382,7 +380,7 @@ class ReformatPy(GenericMsg): """Reformat Python source with black.""" fixme = "black %(filenames)s" - apply_ctxt = CheckContext(branch="default", opts=CheckContext.FormatOpt) + apply_ctxt = CheckContext(opts=CheckContext.FormatOpt) _check = have_program("black") def search(self, filename): @@ -410,7 +408,7 @@ class ReformatFort(GenericMsg): """Reformat Fortran source with fprettify""" fixme = "fprettify %(filenames)s" - apply_ctxt = CheckContext(branch="default", opts=CheckContext.FormatOpt) + apply_ctxt = CheckContext(opts=CheckContext.FormatOpt) _check = have_program("fprettify") def search(self, filename): @@ -442,7 +440,7 @@ class ReformatC(GenericMsg): """Reformat C/C++ source with clang-format""" fixme = "clang-format -i %(filenames)s" - apply_ctxt = CheckContext(branch="default", opts=CheckContext.FormatOpt) + apply_ctxt = CheckContext(opts=CheckContext.FormatOpt) _check = have_program("clang-format") def search(self, filename): diff --git a/lib/aslint/other/c_checkers.py b/lib/aslint/other/c_checkers.py index 464e021eb03d832c49f074349f0a28b4c39bbed3..3803632a704eaa5fe29dca8e088313a022b59ad0 100644 --- a/lib/aslint/other/c_checkers.py +++ b/lib/aslint/other/c_checkers.py @@ -40,7 +40,7 @@ class EDFCopyright(FileContentCat, COMM.EDFCopyright): Example: - Copyright 2008 Company ABC - - Copyright 2008-2013 EDF R&D www.code-aster.org + - Copyright 2008-2023 EDF R&D www.code-aster.org """ id = "C3003" @@ -54,7 +54,6 @@ class ExternalCopyright(FileContentCat, COMM.ExternalCopyright): class InvalidCharacter(FileContentCat, COMM.InvalidCharacter): - r"""Invalid character, unexpected tabulation '\t' Tabulation character is not allowed.""" id = "C3005" @@ -68,7 +67,6 @@ class UniqueIncludePython(FileContentCat, TextMsg): """ id = "C3401" - apply_ctxt = CheckContext(branch="main") search = search_msg("^ *(?P<main># *include +['\"]Python\.h['\"])") diff --git a/lib/aslint/test/test_checkers.py b/lib/aslint/test/test_checkers.py index 5787b463cb38a13f2a567f3c2ad2a92471c9a009..032c4617a7ebaea9d240b2fea678c1416a15bcfb 100644 --- a/lib/aslint/test/test_checkers.py +++ b/lib/aslint/test/test_checkers.py @@ -61,65 +61,6 @@ class UnsupportedExtension(FilenameCat, GenericMsg): return [fname] -class InvalidFilename(FilenameCat, TextMsgNotFound): - - """Invalid filename for a testcase - Filenames matching 'aaaaNNNm.*' are expected. - See C9002 message for the allowed extensions. - """ - - id = "C2015" - fmt = "%(id)s: %(label)s" - apply_ctxt = CheckContext(reponame=("src", "validation"), branch="v14") - - def search(self, txt): - """Check for unauthorized filenames.""" - # most of names are: aaaaNNNm - # - some have only 2 numbers, - # - aspic/ascouf need 5 letters, - # - mac3c needs the '3' - _expr = re.compile( - r"/(?P<root>[a-z3]{3,5}[0-9]{2,3}[a-z]{1})" r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$" - ) - found = _expr.findall(txt) - # accept .mfront files too - if not found and osp.splitext(txt)[1] == ".mfront": - found = [txt] - return found - - -class InvalidFilenameTestsData(FilenameCat, TextMsgNotFound): - - """Invalid filename for a testcase - Filenames matching 'aaaaNNNm.*' or 'aaaaNNNm_*.*' are expected. - See C9002 message for the allowed extensions. - """ - - id = "C2019" - fmt = "%(id)s: %(label)s" - apply_ctxt = CheckContext(reponame=("data",), branch="v14") - - def search(self, txt): - """Check for unauthorized filenames.""" - # most of names are: aaaaNNNm - # - some have only 2 numbers, - # - aspic/ascouf need 5 letters, - # - mac3c needs the '3' - _expr1 = re.compile( - r"/(?P<root>[a-z3]{3,5}[0-9]{2,3}[a-z]{1})" r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$" - ) - _expr2 = re.compile( - r"/(?P<root>[a-z3]{3,5}[0-9]{2,3}[a-z]{1}" - r"_\w{1,16})" - r"(?P<ext>\.(" + "|".join(REG_EXT) + "))$" - ) - found = _expr1.findall(txt) or _expr2.findall(txt) - # accept .mfront files too - if not found and osp.splitext(txt)[1] == ".mfront": - found = [txt] - return found - - class InvalidFilenameXX(FilenameCat, TextMsgNotFound): """Invalid filename for a testcase @@ -263,7 +204,7 @@ class CommonFilesSrcValidation(DirnameCat, GenericMsg): files are installed into the same destination directory.""" id = "C2021" - apply_ctxt = CheckContext(reponame=["src", "validation"], branch="default") + apply_ctxt = CheckContext(reponame=["src", "validation"]) def search(self, txt): """Check if files exist in src and validation""" @@ -536,9 +477,7 @@ class BaseUnrecommendedKeyword(TextMsg): This keyword should not be used in a testcase: TOLE_MACHINE.""" # id must be defined in subclasses - kwd = [ - "TOLE_MACHINE", - ] + kwd = ["TOLE_MACHINE"] search = search_msg(r"^ *[^\#].*(?P<main>(%s))" % "|".join(kwd)) @@ -563,9 +502,7 @@ class ObsoleteKeyword(FileContentCat, TextMsg): This keyword should not be used in a testcase: PAR_LOT.""" id = "C2020" - kwd = [ - "PAR_LOT", - ] + kwd = ["PAR_LOT"] search = search_msg(r"^ *[^\#].*(?P<main>(%s))" % "|".join(kwd)) @@ -575,12 +512,8 @@ class InvalidKeywordValue(FileContentCat, GenericMsg): This value should be assigned with care in this repository.""" id = "W2012" - _invalid = [ - ("NIV_PUB_WEB", "['\"]INTRANET['\"]"), - ] - _expr = [ - re.compile("(?P<kwd>%s) *= *(?P<value>%s)" % (kwd, val), re.M) for kwd, val in _invalid - ] + _invalid = [("NIV_PUB_WEB", "['\"]INTRANET['\"]")] + _expr = [re.compile(f"(?P<kwd>{kwd}) *= *(?P<value>{val})", re.M) for kwd, val in _invalid] _recom = re.compile("^ *#.*$", re.M) apply_ctxt = CheckContext(reponame=["src"]) @@ -599,12 +532,8 @@ class InvalidKeywordValueError(FileContentCat, GenericMsg): """Invalid value assigned to a keyword in a command file""" id = "C2014" - _invalid = [ - ("UNITE", "15"), - ] - _expr = [ - re.compile("(?P<kwd>%s) *= *(?P<value>%s)" % (kwd, val), re.M) for kwd, val in _invalid - ] + _invalid = [("UNITE", "15")] + _expr = [re.compile(f"(?P<kwd>{kwd}) *= *(?P<value>{val})", re.M) for kwd, val in _invalid] _recom = re.compile("^ *#.*$", re.M) def search(self, txt): @@ -626,9 +555,7 @@ class DeprecatedComment(FileContentCat, TextMsg): id = "C2017" apply_to = COMM_EXT - kwd = [ - "TITRE", - ] + kwd = ["TITRE"] search = search_msg("^ *# *(?P<main>(%s) .*)" % "|".join(kwd)) @@ -671,16 +598,16 @@ class RequiredKeyword(FileContentCat, GenericMsg): CODE.""" apply_to = COMM_EXT - apply_ctxt = CheckContext(reponame=["src"]) + apply_ctxt = CheckContext(reponame=["src"], branch="main") id = "C2011" _debut = re.compile("^DEBUT", re.M) _debcod = re.compile(r"^DEBUT *\([^\#\)]*CODE *= *_F\(", re.M) _deberr = r"""'CODE=_F(...)'""" _pours = re.compile("^POURSUITE", re.M) - _poucod = re.compile(r"^POURSUITE *\([^\#]*CODE *= *[\'\"]OUI", re.M) - _pouerr = r"""'CODE='OUI''""" - _init = re.compile(r"^code_aster\.init", re.M) - _inittst = re.compile(r"^code_aster\.init *\([^\#\)]*\-\-test", re.M) + _poucod = re.compile(r"^POURSUITE *\([^\#]*CODE *= *_F\(", re.M) + _poucodalt = re.compile(r"^POURSUITE *\([^\#]*CODE *= *[\'\"]OUI", re.M) + _init = re.compile(r"^CA\.init", re.M) + _inittst = re.compile(r"^CA\.init *\([^\#\)]*\-\-test", re.M) _initerr = r"""'--test'""" def search(self, txt): @@ -688,13 +615,13 @@ class RequiredKeyword(FileContentCat, GenericMsg): err = [] if self._init.search(txt): if not self._inittst.search(txt): - err.append(": %s not found in 'code_aster.init'" % self._initerr) + err.append(": %s not found in 'CA.init'" % self._initerr) elif self._debut.search(txt): if not self._debcod.search(txt): err.append(": %s not found in DEBUT" % self._deberr) elif self._pours.search(txt): - if not self._poucod.search(txt): - err.append(": %s not found in POURSUITE" % self._pouerr) + if not (self._poucod.search(txt) or self._poucodalt.search(txt)): + err.append(": %s not found in POURSUITE" % self._deberr) else: # pure python file pass