@penskemediacorp/stylelint-css-algorithms 1.24.1 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/stylelint-css-algorithms.test.js +41 -31
- package/index.js +3 -3
- package/lib/rule.js +31 -34
- package/package.json +2 -2
|
@@ -7,95 +7,105 @@ testRule( rule.rule, {
|
|
|
7
7
|
ruleName: rule.name,
|
|
8
8
|
skipBasicChecks: true,
|
|
9
9
|
config: {
|
|
10
|
-
'a-space-children': [
|
|
10
|
+
'a-space-children': [
|
|
11
|
+
'margin-top',
|
|
12
|
+
'margin-left',
|
|
13
|
+
'display',
|
|
14
|
+
'flex-wrap',
|
|
15
|
+
'--a-space-children-spacer',
|
|
16
|
+
],
|
|
11
17
|
},
|
|
12
18
|
accept: [
|
|
13
19
|
{
|
|
14
20
|
code: '.a-space-children { margin-top: 0; }',
|
|
15
|
-
description: 'passes with an allowed property'
|
|
16
|
-
}
|
|
21
|
+
description: 'passes with an allowed property',
|
|
22
|
+
},
|
|
17
23
|
],
|
|
18
24
|
reject: [
|
|
19
25
|
{
|
|
20
26
|
code: '.a-space-children { background: 0; }',
|
|
21
27
|
message: rule.messages.rejected( 'background', 'a-space-children' ),
|
|
22
|
-
description: 'disallows a property missing from allowed properties'
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
});
|
|
28
|
+
description: 'disallows a property missing from allowed properties',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
} );
|
|
26
32
|
|
|
27
33
|
testRule( rule.rule, {
|
|
28
34
|
ruleName: rule.name,
|
|
29
35
|
skipBasicChecks: true,
|
|
30
36
|
config: {
|
|
31
|
-
'pmc-a-glue': [ 'margin-top' ]
|
|
37
|
+
'pmc-a-glue': [ 'margin-top' ],
|
|
32
38
|
},
|
|
33
39
|
reject: [
|
|
34
40
|
{
|
|
35
41
|
code: '.pmc-a-glue { background: red; }',
|
|
36
42
|
message: rule.messages.rejected( 'background', 'pmc-a-glue' ),
|
|
37
|
-
description: 'checks with a pmc- namespace'
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
});
|
|
43
|
+
description: 'checks with a pmc- namespace',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
} );
|
|
41
47
|
|
|
42
48
|
testRule( rule.rule, {
|
|
43
49
|
ruleName: rule.name,
|
|
44
50
|
skipBasicChecks: true,
|
|
45
51
|
config: {
|
|
46
|
-
|
|
52
|
+
card: [ 'margin-top' ],
|
|
47
53
|
},
|
|
48
54
|
reject: [
|
|
49
55
|
{
|
|
50
56
|
code: '.card { background: red; }',
|
|
51
57
|
message: rule.messages.rejected( 'background', 'card' ),
|
|
52
|
-
description: 'works with a non a-* namespace'
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
});
|
|
58
|
+
description: 'works with a non a-* namespace',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
} );
|
|
56
62
|
|
|
57
63
|
testRule( rule.rule, {
|
|
58
64
|
ruleName: rule.name,
|
|
59
65
|
skipBasicChecks: true,
|
|
60
66
|
config: {
|
|
61
|
-
'a-icon': [ 'height', 'width' ]
|
|
67
|
+
'a-icon': [ 'height', 'width' ],
|
|
62
68
|
},
|
|
63
69
|
accept: [
|
|
64
70
|
{
|
|
65
71
|
code: '.a-icon::before { height: 1rem; }',
|
|
66
72
|
message: rule.messages.rejected( 'background', 'card' ),
|
|
67
|
-
description: 'works with a pseudo-element'
|
|
68
|
-
}
|
|
73
|
+
description: 'works with a pseudo-element',
|
|
74
|
+
},
|
|
69
75
|
],
|
|
70
76
|
reject: [
|
|
71
77
|
{
|
|
72
78
|
code: '.a-icon::before { font-family: 1rem; }',
|
|
73
79
|
message: rule.messages.rejected( 'font-family', 'a-icon' ),
|
|
74
|
-
description: 'works with a pseudo-element'
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
});
|
|
80
|
+
description: 'works with a pseudo-element',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
} );
|
|
78
84
|
|
|
79
85
|
testRule( rule.rule, {
|
|
80
86
|
ruleName: rule.name,
|
|
81
87
|
skipBasicChecks: true,
|
|
82
88
|
config: {
|
|
83
89
|
'a-space-children': [ 'margin-left', 'margin-right' ],
|
|
84
|
-
'pmc-a-glue': [ 'position', 'top', 'left' ]
|
|
90
|
+
'pmc-a-glue': [ 'position', 'top', 'left' ],
|
|
85
91
|
},
|
|
86
92
|
reject: [
|
|
87
93
|
{
|
|
88
|
-
code: fs
|
|
94
|
+
code: fs
|
|
95
|
+
.readFileSync( __dirname + '/__fixture__/a-space-children.css' )
|
|
96
|
+
.toString(),
|
|
89
97
|
description: 'works with multiple rules',
|
|
90
98
|
message: rule.messages.rejected( 'display', 'a-space-children' ),
|
|
91
99
|
},
|
|
92
100
|
{
|
|
93
|
-
code: fs
|
|
101
|
+
code: fs
|
|
102
|
+
.readFileSync( __dirname + '/__fixture__/a-glue.css' )
|
|
103
|
+
.toString(),
|
|
94
104
|
description: 'works with multiple rules',
|
|
95
105
|
message: rule.messages.rejected( 'z-index', 'pmc-a-glue' ),
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
});
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
} );
|
|
99
109
|
|
|
100
110
|
// Note: this is for a future iteration when this becomes selector-property-whitelist
|
|
101
111
|
// and supports regex in the key.
|
|
@@ -112,4 +122,4 @@ testRule( rule.rule, {
|
|
|
112
122
|
// message: rule.messages.rejected( 'display', 'a-space-children' ),
|
|
113
123
|
// }
|
|
114
124
|
// ]
|
|
115
|
-
// });
|
|
125
|
+
// });
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const stylelint = require(
|
|
2
|
-
const chalk = require(
|
|
3
|
-
const path = require(
|
|
1
|
+
const stylelint = require( 'stylelint' );
|
|
2
|
+
const chalk = require( 'chalk' );
|
|
3
|
+
const path = require( 'path' );
|
|
4
4
|
const { rule, name, messages } = require( './lib/rule' );
|
|
5
5
|
|
|
6
6
|
module.exports = stylelint.createPlugin( name, rule );
|
package/lib/rule.js
CHANGED
|
@@ -2,57 +2,54 @@ const stylelint = require( 'stylelint' );
|
|
|
2
2
|
const path = require( 'path' );
|
|
3
3
|
|
|
4
4
|
const ruleName = 'plugin/css-algorithms';
|
|
5
|
-
const isString = s => typeof s === 'string';
|
|
6
|
-
const isObject = o => typeof o === 'object';
|
|
5
|
+
const isString = ( s ) => typeof s === 'string';
|
|
6
|
+
const isObject = ( o ) => typeof o === 'object';
|
|
7
7
|
|
|
8
8
|
const messages = {
|
|
9
|
-
rejected: ( prop, algorithmName ) =>
|
|
9
|
+
rejected: ( prop, algorithmName ) =>
|
|
10
|
+
`The property '${ prop }' is not permitted in the algorithm '${ algorithmName }'.`,
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
module.exports = {
|
|
13
|
-
|
|
14
14
|
name: ruleName,
|
|
15
|
-
|
|
16
|
-
messages: stylelint.utils.ruleMessages( ruleName, messages ),
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return function( cssRoot, result ) {
|
|
16
|
+
messages: stylelint.utils.ruleMessages( ruleName, messages ),
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
rule( options ) {
|
|
19
|
+
return function ( cssRoot, result ) {
|
|
20
|
+
const validOptions = stylelint.utils.validateOptions(
|
|
21
|
+
result,
|
|
22
|
+
ruleName,
|
|
25
23
|
{
|
|
26
24
|
actual: options,
|
|
27
|
-
possible: [isObject]
|
|
25
|
+
possible: [ isObject ],
|
|
28
26
|
}
|
|
29
27
|
);
|
|
30
28
|
|
|
31
|
-
if (! validOptions) {
|
|
29
|
+
if ( ! validOptions ) {
|
|
32
30
|
console.error( 'Invalid options', validOptions );
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
Object.keys( options ).map( function( key, index ) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
ruleset.walkDecls( function( decl ) {
|
|
32
|
+
|
|
33
|
+
Object.keys( options ).map( function ( key, index ) {
|
|
34
|
+
const selector = new RegExp( '^.' + key + '.*' );
|
|
35
|
+
const allowedProperties = options[ key ];
|
|
36
|
+
|
|
37
|
+
cssRoot.walkRules( selector, function ( ruleset ) {
|
|
38
|
+
ruleset.walkDecls( function ( decl ) {
|
|
43
39
|
if ( ! allowedProperties.includes( decl.prop ) ) {
|
|
44
|
-
stylelint.utils.report({
|
|
40
|
+
stylelint.utils.report( {
|
|
45
41
|
ruleName,
|
|
46
42
|
result,
|
|
47
43
|
node: decl,
|
|
48
|
-
message: `${messages.rejected(
|
|
49
|
-
|
|
44
|
+
message: `${ messages.rejected(
|
|
45
|
+
decl.prop,
|
|
46
|
+
key
|
|
47
|
+
) } (${ ruleName })`,
|
|
48
|
+
} );
|
|
50
49
|
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
};
|
|
50
|
+
} );
|
|
51
|
+
} );
|
|
52
|
+
} );
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@penskemediacorp/stylelint-css-algorithms",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "laras126 <laras126@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/penske-media-corp/pmc-larva#readme",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"stylelint": "^10.1.0"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "b9202e08f96e47041512b3b1a743c58f89b39152"
|
|
26
26
|
}
|