1 | var escapeHTML = require('escape-html'); |
||
2 | var sassdoc = require('sassdoc'); |
||
3 | |||
4 | module.exports = function(value, config, cb, pl) { |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | return sassdoc.parse(value, config).then(function(data) { |
||
7 | cb(null, processTree(data)); |
||
8 | }); |
||
9 | } |
||
10 | |||
11 | module.exports.config = { |
||
12 | verbose: false |
||
13 | } |
||
14 | |||
15 | module.exports.search = function(items, link) { |
||
16 | var results = []; |
||
17 | var tree = [].concat(items.variable || [], items.mixin || [], items.function || []); |
||
18 | |||
19 | for (var i in tree) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
20 | var item = tree[i]; |
||
21 | var name = item.context.name; |
||
22 | var type = item.context.type; |
||
23 | var description = escapeHTML(item.description.replace(/(\n|`)/, '')); |
||
24 | var hash = '#'; |
||
25 | |||
26 | if (type === 'variable') { |
||
27 | name = '$' + name; |
||
28 | hash += 'sass-variables'; |
||
29 | } |
||
30 | |||
31 | if (type === 'mixin' || type === 'function') { |
||
32 | hash += escape(name); |
||
33 | name = name + '()'; |
||
34 | } |
||
35 | |||
36 | results.push({ |
||
37 | name: name, |
||
38 | type: 'sass ' + type, |
||
39 | description: description, |
||
40 | link: link + hash |
||
41 | }); |
||
42 | } |
||
43 | |||
44 | return results; |
||
45 | } |
||
46 | |||
47 | function processTree(tree) { |
||
48 | var sass = {}; |
||
49 | var c = 0; |
||
50 | for (var i in tree) { |
||
0 ignored issues
–
show
A for in loop automatically includes the property of any prototype object, consider checking the key using
hasOwnProperty .
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: var someObject;
for (var key in someObject) {
if ( ! someObject.hasOwnProperty(key)) {
continue; // Skip keys from the prototype.
}
doSomethingWith(key);
}
Loading history...
|
|||
51 | var obj = tree[i]; |
||
52 | var group = obj.context.type |
||
53 | |||
54 | if (!sass[group]) sass[group] = []; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
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 (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed.
Loading history...
|
|||
55 | sass[group].push(obj); |
||
56 | c++; |
||
57 | } |
||
58 | if ( !sass || (sass.length == 0) ) { sass = false }; |
||
59 | return sass; |
||
60 | } |
||
61 | |||
62 | function escape(text) { |
||
63 | if (typeof text === 'undefined') return ''; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
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 (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed.
Loading history...
|
|||
64 | return text.toLowerCase().replace(/[^\w]+/g, '-'); |
||
65 | } |
||
66 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.