.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / isStandardSyntaxTypeSelector.js
1 /* @flow */
2 "use strict";
3
4 /**
5  * Check whether a type selector is standard
6  *
7  * @param {Node} postcss-selector-parser node (of type tag)
8  * @return {boolean} If `true`, the type selector is standard
9  */
10
11 const _ = require("lodash");
12 const keywordSets = require("../reference/keywordSets");
13
14 module.exports = function(node /*: Object*/) /*: boolean*/ {
15   // postcss-selector-parser includes the arguments to nth-child() functions
16   // as "tags", so we need to ignore them ourselves.
17   // The fake-tag's "parent" is actually a selector node, whose parent
18   // should be the :nth-child pseudo node.
19   const _node$parent$parent = node.parent.parent;
20   const parentType = _node$parent$parent.type,
21     parentValue = _node$parent$parent.value;
22
23   if (parentValue) {
24     const normalisedParentName = parentValue.toLowerCase().replace(/:+/, "");
25     if (
26       parentType === "pseudo" &&
27       (keywordSets.aNPlusBNotationPseudoClasses.has(normalisedParentName) ||
28         keywordSets.linguisticPseudoClasses.has(normalisedParentName))
29     ) {
30       return false;
31     }
32   }
33
34   // &-bar is a nesting selector combined with a suffix
35   if (node.prev() && node.prev().type === "nesting") {
36     return false;
37   }
38
39   if (node.value[0] === "%") {
40     return false;
41   }
42
43   // Reference combinators like `/deep/`
44   if (_.startsWith(node.value, "/") && _.endsWith(node.value, "/")) {
45     return false;
46   }
47
48   return true;
49 };