/
getDescription.js
51 lines (41 loc) · 1017 Bytes
/
getDescription.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { isObject } from '../../utils/validateType.js';
export function getDescription(item) {
const descriptions = {
'custom-properties': 'custom property',
'dollar-variables': '$-variable',
'at-variables': '@-variable',
'less-mixins': 'Less mixin',
declarations: 'declaration',
};
if (isObject(item)) {
let text;
if (item.type === 'at-rule') {
text = 'at-rule';
if (item.name) {
text = `@${item.name}`;
}
if (item.parameter) {
text += ` "${item.parameter}"`;
}
if (item.hasOwnProperty('hasBlock')) {
if (item.hasBlock) {
text += ' with a block';
} else {
text = `blockless ${text}`;
}
}
}
if (item.type === 'rule') {
text = 'rule';
if (item.name) {
// Prefer 'name' property for better error messaging
text += ` "${item.name}"`;
} else if (item.selector) {
text += ` with selector matching "${item.selector}"`;
}
}
return text;
}
// Return description for keyword patterns
return descriptions[item];
}