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.
@@ -143,7 +143,7 @@ class Linter {
143
143
  scanner.accept(options.parsed.ast);
144
144
 
145
145
  if (scanner.context.partials) {
146
- this.partials = scanner.context.partials.map(p => p.node);
146
+ this.partials = scanner.context.partials;
147
147
  }
148
148
 
149
149
  if (scanner.context.helpers) {
@@ -150,6 +150,9 @@ module.exports = class BaseRule {
150
150
  }
151
151
  }
152
152
  }
153
+
154
+ // The default is that the usage is in scope of the declaration
155
+ return true;
153
156
  });
154
157
  }
155
158
 
@@ -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
- linter.options.inlinePartials = linter.inlinePartials;
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
- partialsFound[partial] = true;
62
- const file = files.find(f => normalizePath(f.file) === `partials/${normalizePath(partial)}.hbs`);
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
- processFile(linter, file);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gscan",
3
- "version": "4.21.1",
3
+ "version": "4.22.0",
4
4
  "description": "Scans Ghost themes looking for errors, deprecations, features and compatibility",
5
5
  "keywords": [
6
6
  "ghost",