added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
# selector-max-universal
Limit the number of universal selectors in a selector.
<!-- prettier-ignore -->
```css
* {}
/** ↑
* This universal selector */
```
This rule resolves nested selectors before counting the number of universal selectors. Each selector in a [selector list](https://www.w3.org/TR/selectors4/#selector-list) is evaluated separately.
The logical combinations pseudo-class (e.g. `:not`, `:has`) is also evaluated separately. The rule processes the argument as if it were an independent selector, and the result does not count toward the total for the entire selector.
## Options
`int`: Maximum universal selectors allowed.
For example, with `2`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
* * * {}
```
<!-- prettier-ignore -->
```css
* * {
& * {}
}
```
<!-- prettier-ignore -->
```css
* * {
& > * {}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
* {}
```
<!-- prettier-ignore -->
```css
* * {}
```
<!-- prettier-ignore -->
```css
.foo * {}
```
<!-- prettier-ignore -->
```css
*.foo * {}
```
<!-- prettier-ignore -->
```css
/* each selector in a selector list is evaluated separately */
*.foo,
*.bar * {}
```
<!-- prettier-ignore -->
```css
/* `*` is inside `:not()`, so it is evaluated separately */
* > * .foo:not(*) {}
```
+84
View File
@@ -0,0 +1,84 @@
// @ts-nocheck
'use strict';
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
const ruleMessages = require('../../utils/ruleMessages');
const selectorParser = require('postcss-selector-parser');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'selector-max-universal';
const messages = ruleMessages(ruleName, {
expected: (selector, max) =>
`Expected "${selector}" to have no more than ${max} universal ${
max === 1 ? 'selector' : 'selectors'
}`,
});
function rule(max) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: max,
possible: isNonNegativeInteger,
});
if (!validOptions) {
return;
}
function checkSelector(selectorNode, ruleNode) {
const count = selectorNode.reduce((total, childNode) => {
// Only traverse inside actual selectors
// All logical combinations will be resolved as nested selector in `postcss-resolve-nested-selector`
if (childNode.type === 'selector') {
checkSelector(childNode, ruleNode);
}
return (total += childNode.type === 'universal' ? 1 : 0);
}, 0);
if (selectorNode.type !== 'root' && selectorNode.type !== 'pseudo' && count > max) {
report({
ruleName,
result,
node: ruleNode,
message: messages.expected(selectorNode, max),
word: selectorNode,
});
}
}
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}
const selectors = [];
selectorParser()
.astSync(ruleNode.selector)
.walk((node) => {
if (node.type === 'selector') {
selectors.push(String(node).trim());
}
});
selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
checkSelector(container, ruleNode),
);
});
});
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;