diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2020-08-31 13:20:19 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-02 04:09:13 +0000 |
commit | 728b9b30398bd38fcf94c26e7e94bc62a843611e (patch) | |
tree | 518f521c72eb2b10310f2f069ce2f81141d87876 /buildscripts/linter | |
parent | 5f9a904ae5b8d1554516da08e73f1d8b1a1fc8fd (diff) | |
download | mongo-728b9b30398bd38fcf94c26e7e94bc62a843611e.tar.gz |
SERVER-49520: Add linter rule for generic FCV references
Diffstat (limited to 'buildscripts/linter')
-rw-r--r-- | buildscripts/linter/simplecpplint.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/buildscripts/linter/simplecpplint.py b/buildscripts/linter/simplecpplint.py index cf4df8e4b47..5ca79216de0 100644 --- a/buildscripts/linter/simplecpplint.py +++ b/buildscripts/linter/simplecpplint.py @@ -2,6 +2,7 @@ """Simple C++ Linter.""" import argparse +import bisect import io import logging import re @@ -58,6 +59,19 @@ _RE_MUTEX = re.compile('[ ({,]stdx?::mutex[ ({]') _RE_ASSERT = re.compile(r'\bassert\s*\(') _RE_UNSTRUCTURED_LOG = re.compile(r'\blogd\s*\(') +_RE_GENERIC_FCV_COMMENT = re.compile(r'\(Generic FCV reference\):') +GENERIC_FCV = [ + r'::kLatest', + r'::kLastContinuous', + r'::kLastLTS', + r'::kUpgradingFromLastLTSToLatest', + r'::kUpgradingFromLastContinuousToLatest', + r'::kDowngradingFromLatestToLastLTS', + r'::kDowngradingFromLatestToLastContinuous', + r'\.isUpgradingOrDowngrading', +] +_RE_GENERIC_FCV_REF = re.compile(r'(' + '|'.join(GENERIC_FCV) + r')\b') + class Linter: """Simple C++ Linter.""" @@ -68,6 +82,7 @@ class Linter: self.raw_lines = raw_lines self.clean_lines = [] self.nolint_supression = [] + self.generic_fcv_comments = [] self._error_count = 0 self.found_config_header = False @@ -110,6 +125,11 @@ class Linter: self._check_for_mongo_unstructured_log(linenum) self._check_for_mongo_config_header(linenum) + # Relax the rule of commenting generic FCV references for files directly related to FCV + # implementations. + if not "feature_compatibility_version" in self.file_name: + self._check_for_generic_fcv(linenum) + return self._error_count def _check_and_strip_comments(self): @@ -125,6 +145,9 @@ class Linter: if _RE_LINT.search(clean_line): self.nolint_supression.append(linenum) + if _RE_GENERIC_FCV_COMMENT.search(clean_line): + self.generic_fcv_comments.append(linenum) + if not in_multi_line_comment: if "/*" in clean_line and not "*/" in clean_line: in_multi_line_comment = True @@ -255,6 +278,17 @@ class Linter: self._error(linenum, 'build/config_h_include', 'MONGO_CONFIG define used without prior inclusion of config.h.') + def _check_for_generic_fcv(self, linenum): + line = self.clean_lines[linenum] + if _RE_GENERIC_FCV_REF.search(line): + # Find the first generic FCV comment preceding the current line. + i = bisect.bisect_right(self.generic_fcv_comments, linenum) + if not i or self.generic_fcv_comments[i - 1] < (linenum - 10): + self._error( + linenum, 'mongodb/fcv', + 'Please add a comment containing "(Generic FCV reference):" within 10 lines ' + + 'before the generic FCV reference.') + def _error(self, linenum, category, message): if linenum in self.nolint_supression: return |