aboutsummaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/lint/global-declarations.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/dev/lint/global-declarations.js b/dev/lint/global-declarations.js
index 5448df85..57097c03 100644
--- a/dev/lint/global-declarations.js
+++ b/dev/lint/global-declarations.js
@@ -22,6 +22,10 @@ const assert = require('assert');
const {getAllFiles} = require('../util');
+function escapeRegExp(string) {
+ return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
+}
+
function countOccurences(string, pattern) {
return (string.match(pattern) || []).length;
}
@@ -38,13 +42,12 @@ function getNewline(string) {
}
function getSubstringCount(string, substring) {
- let start = 0;
let count = 0;
+ const pattern = new RegExp(`\\b${escapeRegExp(substring)}\\b`, 'g');
while (true) {
- const pos = string.indexOf(substring, start);
- if (pos < 0) { break; }
+ const match = pattern.exec(string);
+ if (match === null) { break; }
++count;
- start = pos + substring.length;
}
return count;
}