Skip to content

Commit 899dc01

Browse files
committed
chore(lint): Fix lint issues
1 parent f7e6f30 commit 899dc01

File tree

3 files changed

+75
-76
lines changed

3 files changed

+75
-76
lines changed

core/lib/pattern_assembler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const pattern_assembler = function () {
187187
catch (err) {
188188
// do nothing when file not found
189189
if (err.code !== 'ENOENT') {
190-
logger.warning(`'there was an error setting pattern keys after markdown parsing of the companion file for pattern ${currentPattern.patternPartial}`)
190+
logger.warning(`'there was an error setting pattern keys after markdown parsing of the companion file for pattern ${currentPattern.patternPartial}`);
191191
logger.warning(err);
192192
}
193193
}

core/lib/pattern_engines.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33
const {existsSync, lstatSync, readdirSync} = require('fs');
44
const path = require('path');
5-
const chalk = require('chalk');
65
const engineMatcher = /^patternengine-node-(.*)$/;
76
const scopeMatch = /^@(.*)$/;
87
const isDir = fPath => lstatSync(fPath).isDirectory();
@@ -77,7 +76,7 @@ function resolveEngines(dir) {
7776
return {
7877
name: isEngineModule(engine),
7978
modulePath: path.join(fPath, engine)
80-
}
79+
};
8180
})
8281
);
8382

@@ -98,7 +97,7 @@ function resolveEngines(dir) {
9897
}
9998

10099
function findEngineModulesInDirectory(dir) {
101-
const foundEngines = resolveEngines(dir)
100+
const foundEngines = resolveEngines(dir);
102101
return foundEngines;
103102
}
104103

core/lib/patternlab.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const diveSync = require('diveSync');
1414
const dive = require('dive');
1515
const _ = require('lodash');
1616
const path = require('path');
17-
const chalk = require('chalk');
1817
const cleanHtml = require('js-beautify').html;
1918
const inherits = require('util').inherits;
2019
const pm = require('./plugin_manager');
@@ -44,6 +43,11 @@ const lineage_hunter = new lh();
4443
const patternEngines = require('./pattern_engines');
4544
const EventEmitter = require('events').EventEmitter;
4645

46+
function PatternLabEventEmitter() {
47+
EventEmitter.call(this);
48+
}
49+
inherits(PatternLabEventEmitter, EventEmitter);
50+
4751
class PatternLab {
4852
constructor(config) {
4953
// Either use the config we were passed, or load one up from the config file ourselves
@@ -71,10 +75,70 @@ class PatternLab {
7175
this.watchers = {};
7276

7377
// Verify correctness of configuration (?)
74-
checkConfiguration(this);
78+
this.checkConfiguration(this);
7579

7680
// TODO: determine if this is the best place to wire up plugins
77-
initializePlugins(this);
81+
this.initializePlugins(this);
82+
}
83+
84+
checkConfiguration(patternlab) {
85+
86+
//default the output suffixes if not present
87+
const outputFileSuffixes = {
88+
rendered: '.rendered',
89+
rawTemplate: '',
90+
markupOnly: '.markup-only'
91+
};
92+
93+
if (!patternlab.config.outputFileSuffixes) {
94+
logger.warning('');
95+
logger.warning('Configuration key [outputFileSuffixes] not found, and defaulted to the following:');
96+
logger.info(outputFileSuffixes);
97+
logger.warning('Since Pattern Lab Node Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
98+
logger.warning('');
99+
}
100+
patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
101+
102+
if (typeof patternlab.config.paths.source.patternlabFiles === 'string') {
103+
logger.warning('');
104+
logger.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`);
105+
logger.warning('Since Pattern Lab Node Core 3.0.0 this key is an object. Suggest you update this key following this issue: https://github.com/pattern-lab/patternlab-node/issues/683.');
106+
logger.warning('');
107+
}
108+
109+
if (typeof patternlab.config.debug === 'boolean') {
110+
logger.warning('');
111+
logger.warning(`Configuration key [debug] inside patternlab-config.json was found. As of Pattern Lab Node Core 3.0.0 this key is replaced with a new key, [logLevel]. This is a string with possible values ['debug', 'info', 'warning', 'error', 'quiet'].`);
112+
logger.warning(`Turning on 'info', 'warning', and 'error' levels by default, unless [logLevel] is present. If that is the case, [debug] has no effect.`);
113+
logger.warning('');
114+
}
115+
}
116+
117+
/**
118+
* Finds and calls the main method of any found plugins.
119+
* @param patternlab - global data store
120+
*/
121+
//todo, move this to plugin_manager
122+
initializePlugins(patternlab) {
123+
124+
if (!patternlab.config.plugins) { return; }
125+
126+
const plugin_manager = new pm(patternlab.config, path.resolve(__dirname, '../../patternlab-config.json'));
127+
const foundPlugins = plugin_manager.detect_plugins();
128+
129+
if (foundPlugins && foundPlugins.length > 0) {
130+
131+
for (let i = 0; i < foundPlugins.length; i++) {
132+
133+
const pluginKey = foundPlugins[i];
134+
135+
logger.info(`Found plugin: ${pluginKey}`);
136+
logger.info(`Attempting to load and initialize plugin.`);
137+
138+
const plugin = plugin_manager.load_plugin(pluginKey);
139+
plugin(patternlab);
140+
}
141+
}
78142
}
79143

80144
buildGlobalData() {
@@ -86,18 +150,20 @@ class PatternLab {
86150

87151
// data.json
88152
try {
89-
this.data = buildPatternData(paths.source.data, fs);
153+
this.data = buildPatternData(paths.source.data, fs); // eslint-disable-line no-use-before-define
90154
} catch (ex) {
91155
logger.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
92156
this.data = {};
93157
}
158+
94159
// listitems.json
95160
try {
96161
this.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json'));
97162
} catch (ex) {
98163
logger.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
99164
this.listitems = {};
100165
}
166+
101167
// load up all the necessary files from pattern lab that apply to every template
102168
try {
103169
this.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles['general-header']), 'utf8');
@@ -261,7 +327,7 @@ class PatternLab {
261327
logger.log.on('warning', msg => console.info(msg));
262328
logger.log.on('error', msg => console.info(msg));
263329
} else {
264-
if ( logLevel === 'quiet') { return; }
330+
if (logLevel === 'quiet') { return; }
265331
switch (logLevel) {
266332
case 'debug':
267333
logger.log.on('debug', msg => console.info(msg));
@@ -346,68 +412,6 @@ function processAllPatternsRecursive(patterns_dir, patternlab) {
346412
);
347413
}
348414

349-
function checkConfiguration(patternlab) {
350-
351-
//default the output suffixes if not present
352-
const outputFileSuffixes = {
353-
rendered: '.rendered',
354-
rawTemplate: '',
355-
markupOnly: '.markup-only'
356-
};
357-
358-
if (!patternlab.config.outputFileSuffixes) {
359-
logger.warning('');
360-
logger.warning('Configuration key [outputFileSuffixes] not found, and defaulted to the following:');
361-
logger.info(outputFileSuffixes);
362-
logger.warning('Since Pattern Lab Node Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
363-
logger.warning('');
364-
}
365-
patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
366-
367-
if (typeof patternlab.config.paths.source.patternlabFiles === 'string') {
368-
logger.warning('');
369-
logger.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`);
370-
logger.warning('Since Pattern Lab Node Core 3.0.0 this key is an object. Suggest you update this key following this issue: https://github.com/pattern-lab/patternlab-node/issues/683.');
371-
logger.warning('');
372-
}
373-
374-
if (typeof patternlab.config.debug === 'boolean') {
375-
logger.warning('');
376-
logger.warning(`Configuration key [debug] inside patternlab-config.json was found. As of Pattern Lab Node Core 3.0.0 this key is replaced with a new key, [logLevel]. This is a string with possible values ['debug', 'info', 'warning', 'error', 'quiet'].`);
377-
logger.warning(`Turning on 'info', 'warning', and 'error' levels by default, unless [logLevel] is present. If that is the case, [debug] has no effect.`);
378-
logger.warning('');
379-
}
380-
381-
}
382-
383-
/**
384-
* Finds and calls the main method of any found plugins.
385-
* @param patternlab - global data store
386-
*/
387-
388-
//todo, move this to plugin_manager
389-
function initializePlugins(patternlab) {
390-
391-
if (!patternlab.config.plugins) { return; }
392-
393-
const plugin_manager = new pm(patternlab.config, path.resolve(__dirname, '../../patternlab-config.json'));
394-
const foundPlugins = plugin_manager.detect_plugins();
395-
396-
if (foundPlugins && foundPlugins.length > 0) {
397-
398-
for (let i = 0; i < foundPlugins.length; i++) {
399-
400-
const pluginKey = foundPlugins[i];
401-
402-
logger.info(`Found plugin: ${pluginKey}`);
403-
logger.info(`Attempting to load and initialize plugin.`);
404-
405-
const plugin = plugin_manager.load_plugin(pluginKey);
406-
plugin(patternlab);
407-
}
408-
}
409-
}
410-
411415
/**
412416
* Installs a given plugin. Assumes it has already been pulled down via npm
413417
* @param pluginName - the name of the plugin
@@ -421,11 +425,6 @@ function installPlugin(pluginName) {
421425
plugin_manager.install_plugin(pluginName);
422426
}
423427

424-
function PatternLabEventEmitter() {
425-
EventEmitter.call(this);
426-
}
427-
inherits(PatternLabEventEmitter, EventEmitter);
428-
429428
const patternlab_engine = function (config) {
430429
const patternlab = new PatternLab(config);
431430
const paths = patternlab.config.paths;
@@ -631,6 +630,7 @@ const patternlab_engine = function (config) {
631630
// Ensure that the freshly built graph has the latest version again.
632631
patternlab.graph.upgradeVersion();
633632
}
633+
634634
// Flags
635635
patternlab.incrementalBuildsEnabled = !(deletePatternDir || graphNeedsUpgrade);
636636

0 commit comments

Comments
 (0)