Skip to content

Commit b908c2f

Browse files
authored
refactor(nestedpatterns): trigger warning message only after checking for whether it's actually a pattern file (#1311)
* refactor(nestedpatterns): show nested pattern warning only for pattern files #1309 * refactor(nestedpatterns): show nested pattern warning only for pattern files #1309 …iles by moving the pattern test before the warning message #1309
1 parent 437c96e commit b908c2f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

packages/core/src/lib/loadPattern.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
2020
// loads a pattern from disk, creates a Pattern object from it and
2121
// all its associated files, and records it in patternlab.patterns[]
2222
module.exports = function(relPath, patternlab) {
23+
const fileObject = path.parse(relPath);
24+
25+
//extract some information
26+
const filename = fileObject.base;
27+
const ext = fileObject.ext;
28+
const patternsPath = patternlab.config.paths.source.patterns;
29+
30+
// skip non-pattern files
31+
if (!patternEngines.isPatternFile(filename, patternlab)) {
32+
return null;
33+
}
34+
35+
// Determine patterns nested too deep and show a warning
2336
const relativeDepth = (relPath.match(/\w(?=\\)|\w(?=\/)/g) || []).length;
2437
if (relativeDepth > 3) {
2538
logger.warning('');
@@ -51,18 +64,6 @@ module.exports = function(relPath, patternlab) {
5164
logger.warning('');
5265
}
5366

54-
const fileObject = path.parse(relPath);
55-
56-
//extract some information
57-
const filename = fileObject.base;
58-
const ext = fileObject.ext;
59-
const patternsPath = patternlab.config.paths.source.patterns;
60-
61-
// skip non-pattern files
62-
if (!patternEngines.isPatternFile(filename, patternlab)) {
63-
return null;
64-
}
65-
6667
//make a new Pattern Object
6768
const currentPattern = new Pattern(relPath, null, patternlab);
6869

0 commit comments

Comments
 (0)