1 | |||
2 | 1 | var fs = require('fs'); |
|
3 | 1 | var glob = require('glob'); |
|
4 | 1 | var globAll = require('glob-all'); |
|
5 | 1 | var path = require('path'); |
|
6 | 1 | var extend = require('util')._extend; |
|
7 | 1 | var format = require('string-template'); |
|
8 | 1 | var frontMatter = require('front-matter'); |
|
9 | 1 | var sanatizeType = require('../util/sanatize-patterntype'); |
|
10 | |||
11 | 1 | module.exports = function(value, config, cb, pl) { |
|
12 | var data = getPatternSpecs (value, config, pl); |
||
13 | cb(null, processTree(data)); |
||
14 | } |
||
15 | |||
16 | 1 | module.exports.config = { |
|
17 | verbose: false |
||
18 | } |
||
19 | |||
20 | 1 | module.exports.search = function(items, link) { |
|
21 | var results = []; |
||
22 | // this => collider |
||
23 | /* results.push({ |
||
24 | name: name, |
||
25 | type: 'sass ' + type, |
||
26 | description: description, |
||
27 | link: link + hash |
||
28 | }); */ |
||
29 | |||
30 | return results; |
||
31 | } |
||
32 | |||
33 | |||
34 | function getPatternSpecs(value, config, pl) { |
||
35 | 2 | if (!fs.existsSync(value)) return false; |
|
0 ignored issues
–
show
|
|||
36 | |||
37 | var sourceFile = frontMatter(fs.readFileSync(value).toString()); |
||
38 | 4 | if (sourceFile.attributes.pattern && !sourceFile.attributes.pattern.type) { |
|
39 | // 'type' is not set, try to get it from 'name' |
||
40 | var parts = String(sourceFile.attributes.pattern.name).split('/'); |
||
41 | 2 | if (parts.length > 1) { |
|
42 | sourceFile.attributes.pattern.type = sanatizeType(parts[0]); |
||
43 | } |
||
44 | } |
||
45 | return sourceFile.attributes; |
||
46 | } |
||
47 | |||
48 | |||
49 | function processTree(tree) { |
||
50 | |||
51 | // do stuff |
||
52 | |||
53 | return tree; //my_stuff; |
||
54 | } |
||
55 | |||
56 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.