This repository was archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (62 loc) · 1.8 KB
/
index.js
File metadata and controls
64 lines (62 loc) · 1.8 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
const postcss = require('postcss');
const helper = require('./helper/helper')
/*
* Properties orders
*/
const positioning = require('./properties/positioning');
const display = require('./properties/display');
const boxModel = require('./properties/box-model');
const layout = require('./properties/layout');
const style = require('./properties/style');
const content = require('./properties/content');
const effects = require('./properties/effects');
/*
* Defaults properties
*/
const defaultProperties = [
...positioning,
...display,
...boxModel,
...layout.grid,
...layout.flexbox,
...layout.shared,
...style,
...content.font.base,
...content.font.variant,
...content.font.special,
...content.text,
...content.list,
...content.table,
...content.columns,
...effects.transition,
...effects.transform,
...effects.animation
]
/*
* Main module
*/
module.exports = postcss.plugin('postcss-standards', function(opts) {
const defaults = {
throwValidateErrors: true,
properties: defaultProperties
}
const options = Object.assign({}, defaults, opts);
const ordering = helper.indexProperties(options.properties);
return function(root, result) {
result.decl_order = {};
root.walkRules(rule => {
const originProperties = helper.getProps(rule);
const correctedProperties = helper.getOrderedProps(originProperties, ordering);
if (helper.compareArray(originProperties, correctedProperties)) {
result.decl_order[rule.selector] = correctedProperties;
const message = `Properties order should be:\n${correctedProperties.join('\n')}\n\n`;
if (options.throwValidateErrors) {
throw rule.error(message, { plugin: 'postcss-standards' });
return;
} else {
rule.warn(result, message);
}
}
});
};
});