diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2023-01-04 00:36:08 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-04 19:44:30 +0000 |
commit | 730905254c27ab918853498fbc9fdd174677497e (patch) | |
tree | 3b0bf6c93bac04e68ac0c4d6c9ef75952fa791ac /buildscripts/linter | |
parent | bd443c34edf399038379a1f131b3842b8ce486b8 (diff) | |
download | mongo-730905254c27ab918853498fbc9fdd174677497e.tar.gz |
SERVER-72498 lint against rand and srand
Annotate legacy srand calls with NOLINT to pass new linter
Diffstat (limited to 'buildscripts/linter')
-rw-r--r-- | buildscripts/linter/simplecpplint.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/buildscripts/linter/simplecpplint.py b/buildscripts/linter/simplecpplint.py index 959f4781504..5ce6ad7541f 100644 --- a/buildscripts/linter/simplecpplint.py +++ b/buildscripts/linter/simplecpplint.py @@ -62,6 +62,7 @@ _RE_STD_OPTIONAL = re.compile(r'\bstd::optional\b') _RE_TRACING_SUPPORT = re.compile(r'\bTracerProvider::(get|initialize)\b') _RE_COLLECTION_SHARDING_RUNTIME = re.compile(r'\bCollectionShardingRuntime\b') _RE_UNINTERRUPTIBLE_LOCK_GUARD = re.compile(r'\bUninterruptibleLockGuard\s+.+\s*;') +_RE_RAND = re.compile(r'\b(srand\(|rand\(\))') _RE_GENERIC_FCV_COMMENT = re.compile(r'\(Generic FCV reference\):') GENERIC_FCV = [ @@ -157,6 +158,7 @@ class Linter: self._check_for_tracing_support(linenum) self._check_for_collection_sharding_runtime(linenum) self._check_for_uninterruptible_lock_guard(linenum) + self._check_for_rand(linenum) # Relax the rule of commenting generic FCV references for files directly related to FCV # implementations. @@ -312,6 +314,12 @@ class Linter: 'Review with care and if the use is warranted, add NOLINT and a comment explaining why.' ) + def _check_for_rand(self, linenum): + line = self.clean_lines[linenum] + if _RE_RAND.search(line): + self._error(linenum, 'mongodb/rand', + 'Use of rand or srand, use <random> or PseudoRandom instead.') + def _license_error(self, linenum, msg, category='legal/license'): style_url = 'https://github.com/mongodb/mongo/wiki/Server-Code-Style' self._error(linenum, category, '{} See {}'.format(msg, style_url)) |