gscan 4.21.1 → 4.22.0
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/lib/ast-linter/linter.js
CHANGED
|
@@ -7,7 +7,7 @@ const {normalizePath} = require('../utils');
|
|
|
7
7
|
function processFileFunction(files, failures, theme, partialsFound) {
|
|
8
8
|
const processedFiles = [];
|
|
9
9
|
|
|
10
|
-
return function processFile(linter, themeFile) {
|
|
10
|
+
return function processFile(linter, themeFile, parentInlinePartials = []) {
|
|
11
11
|
if (processedFiles.includes(themeFile.file)) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
@@ -28,7 +28,8 @@ function processFileFunction(files, failures, theme, partialsFound) {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// Store the inline partials for the actual partial linting
|
|
31
|
-
|
|
31
|
+
const inlinePartials = linter.inlinePartials;
|
|
32
|
+
linter.options.inlinePartials = [...inlinePartials, ...parentInlinePartials];
|
|
32
33
|
|
|
33
34
|
const astResults = linter.verify({
|
|
34
35
|
parsed: themeFile.parsed,
|
|
@@ -58,10 +59,28 @@ function processFileFunction(files, failures, theme, partialsFound) {
|
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
linter.partials.forEach((partial) => {
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const partialName = partial.node;
|
|
63
|
+
partialsFound[partialName] = true;
|
|
64
|
+
const file = files.find(f => normalizePath(f.file) === `partials/${normalizePath(partialName)}.hbs`);
|
|
63
65
|
if (file) {
|
|
64
|
-
|
|
66
|
+
// Find all inline partial declaration that were within the partial usage block
|
|
67
|
+
const childrenInlinePartials = [...parentInlinePartials];
|
|
68
|
+
for (const inline of inlinePartials) {
|
|
69
|
+
//Only partials that are in scope
|
|
70
|
+
if (inline.parents.some(node => node.type === partial.type &&
|
|
71
|
+
node.loc.source === partial.loc.source &&
|
|
72
|
+
node.loc.start.line === partial.loc.start.line &&
|
|
73
|
+
node.loc.start.column === partial.loc.start.column &&
|
|
74
|
+
node.loc.end.line === partial.loc.end.line &&
|
|
75
|
+
node.loc.end.column === partial.loc.end.column)) {
|
|
76
|
+
// Override the `parents` attribute as the inline partials are in another context than the children file
|
|
77
|
+
childrenInlinePartials.push({
|
|
78
|
+
...inline,
|
|
79
|
+
parents: []
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
processFile(linter, file, childrenInlinePartials);
|
|
65
84
|
}
|
|
66
85
|
});
|
|
67
86
|
};
|
|
@@ -30,7 +30,7 @@ function processFileFunction(files, failures, rules) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
linter.partials.forEach((partial) => {
|
|
33
|
+
linter.partials.forEach(({node: partial}) => {
|
|
34
34
|
const file = files.find(f => normalizePath(f.file) === `partials/${normalizePath(partial)}.hbs`);
|
|
35
35
|
if (file) {
|
|
36
36
|
processFile(linter, file);
|
|
@@ -103,7 +103,7 @@ function parseWithAST({theme, log, file, rules, callback}){
|
|
|
103
103
|
callback(linter);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
linter.partials.forEach((partial) => {
|
|
106
|
+
linter.partials.forEach(({node: partial}) => {
|
|
107
107
|
const partialFile = theme.files.find(f => normalizePath(f.file) === `partials/${normalizePath(partial)}.hbs`);
|
|
108
108
|
if (partialFile) {
|
|
109
109
|
processFile(partialFile);
|