UNPKG

1.55 kBJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4const isCustomPropertySet = require('../utils/isCustomPropertySet');
5const isStandardSyntaxSelector = require('../utils/isStandardSyntaxSelector');
6
7/**
8 * Check whether a Node is a standard rule
9 *
10 * @param {import('postcss').Rule} rule
11 * @returns {boolean}
12 */
13module.exports = function (rule) {
14 // Get full selector
15 const selector = _.get(rule, 'raws.selector.raw', rule.selector);
16
17 if (!isStandardSyntaxSelector(rule.selector)) {
18 return false;
19 }
20
21 // Custom property set (e.g. --custom-property-set: {})
22 if (isCustomPropertySet(rule)) {
23 return false;
24 }
25
26 // Called Less mixin (e.g. a { .mixin() })
27 // @ts-ignore TODO TYPES support LESS and SASS types somehow
28 if (rule.mixin) {
29 return false;
30 }
31
32 // Less detached rulesets
33 if (selector.startsWith('@') && selector.endsWith(':')) {
34 return false;
35 }
36
37 // Ignore Less &:extend rule
38 // @ts-ignore TODO TYPES support LESS and SASS types somehow
39 if (rule.extend) {
40 return false;
41 }
42
43 // Ignore mixin or &:extend rule
44 // https://github.com/shellscape/postcss-less/blob/master/lib/less-parser.js#L52
45 // @ts-ignore TODO TYPES support LESS and SASS types somehow
46 if (rule.params && rule.params[0]) {
47 return false;
48 }
49
50 // Non-outputting Less mixin definition (e.g. .mixin() {})
51 if (selector.endsWith(')') && !selector.includes(':')) {
52 return false;
53 }
54
55 // Less guards
56 if (/when\s+(not\s+)*\(/.test(selector)) {
57 return false;
58 }
59
60 // Ignore Scss nested properties
61 if (selector.endsWith(':')) {
62 return false;
63 }
64
65 return true;
66};