@ohlori/gherkin-lint 4.3.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
const rule = 'no-trailing-spaces';
|
|
2
|
+
const {getStepContainers} = require('./utils/gherkin.js');
|
|
2
3
|
|
|
3
|
-
function
|
|
4
|
+
function getDocStringStartLines(feature) {
|
|
5
|
+
if (!feature) {
|
|
6
|
+
return new Set();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return new Set(getStepContainers(feature).reduce((lines, container) => {
|
|
10
|
+
(container.steps || []).forEach(step => {
|
|
11
|
+
if (step.docString) {
|
|
12
|
+
lines.push(step.docString.location.line);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return lines;
|
|
16
|
+
}, []));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function run(feature, file) {
|
|
4
20
|
let errors = [];
|
|
5
21
|
let lineNo = 1;
|
|
22
|
+
let docStringDelimiter;
|
|
23
|
+
const docStringStartLines = getDocStringStartLines(feature);
|
|
24
|
+
|
|
6
25
|
file.lines.forEach(line => {
|
|
7
|
-
|
|
26
|
+
const trimmedLine = line.trim();
|
|
27
|
+
const isClosingDelimiter = docStringDelimiter &&
|
|
28
|
+
trimmedLine.startsWith(docStringDelimiter);
|
|
29
|
+
const isIndentedBlankDocStringLine = docStringDelimiter &&
|
|
30
|
+
!isClosingDelimiter && /^[\t ]+$/.test(line);
|
|
31
|
+
|
|
32
|
+
if (!isIndentedBlankDocStringLine && /[\t ]+$/.test(line)) {
|
|
8
33
|
errors.push({message: 'Trailing spaces are not allowed',
|
|
9
34
|
rule : rule,
|
|
10
35
|
line : lineNo});
|
|
11
36
|
}
|
|
12
37
|
|
|
38
|
+
if (isClosingDelimiter) {
|
|
39
|
+
docStringDelimiter = undefined;
|
|
40
|
+
} else if (docStringStartLines.has(lineNo)) {
|
|
41
|
+
const openingDelimiter = line.trimStart().match(/^("""|```)/);
|
|
42
|
+
docStringDelimiter = openingDelimiter && openingDelimiter[1];
|
|
43
|
+
}
|
|
44
|
+
|
|
13
45
|
lineNo++;
|
|
14
46
|
});
|
|
15
47
|
|