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
@@ -0,0 +1,136 @@
# selector-pseudo-element-colon-notation
Specify single or double colon notation for applicable pseudo-elements.
<!-- prettier-ignore -->
```css
a::before {}
/** ↑
* This notation */
```
The `::` notation was chosen for _pseudo-elements_ to establish a discrimination between _pseudo-classes_ (which subclass existing elements) and _pseudo-elements_ (which are elements not represented in the document tree).
However, for compatibility with existing style sheets, user agents also accept the previous one-colon notation for _pseudo-elements_ introduced in CSS levels 1 and 2 (namely, `:first-line`, `:first-letter`, `:before` and `:after`).
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
`string`: `"single"|"double"`
### `"single"`
Applicable pseudo-elements _must always_ use the single colon notation.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a::before { color: pink; }
```
<!-- prettier-ignore -->
```css
a::after { color: pink; }
```
<!-- prettier-ignore -->
```css
a::first-letter { color: pink; }
```
<!-- prettier-ignore -->
```css
a::first-line { color: pink; }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a:before { color: pink; }
```
<!-- prettier-ignore -->
```css
a:after { color: pink; }
```
<!-- prettier-ignore -->
```css
a:first-letter { color: pink; }
```
<!-- prettier-ignore -->
```css
a:first-line { color: pink; }
```
<!-- prettier-ignore -->
```css
input::placeholder { color: pink; }
```
<!-- prettier-ignore -->
```css
li::marker { font-variant-numeric: tabular-nums; }
```
### `"double"`
Applicable pseudo-elements _must always_ use the double colon notation.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a:before { color: pink; }
```
<!-- prettier-ignore -->
```css
a:after { color: pink; }
```
<!-- prettier-ignore -->
```css
a:first-letter { color: pink; }
```
<!-- prettier-ignore -->
```css
a:first-line { color: pink; }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a::before { color: pink; }
```
<!-- prettier-ignore -->
```css
a::after { color: pink; }
```
<!-- prettier-ignore -->
```css
a::first-letter { color: pink; }
```
<!-- prettier-ignore -->
```css
a::first-line { color: pink; }
```
<!-- prettier-ignore -->
```css
input::placeholder { color: pink; }
```
<!-- prettier-ignore -->
```css
li::marker { font-variant-numeric: tabular-nums; }
```
@@ -0,0 +1,94 @@
// @ts-nocheck
'use strict';
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const keywordSets = require('../../reference/keywordSets');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const styleSearch = require('style-search');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'selector-pseudo-element-colon-notation';
const messages = ruleMessages(ruleName, {
expected: (q) => `Expected ${q} colon pseudo-element notation`,
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: ['single', 'double'],
});
if (!validOptions) {
return;
}
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}
const selector = ruleNode.selector;
// get out early if no pseudo elements or classes
if (!selector.includes(':')) {
return;
}
const fixPositions = [];
// match only level 1 and 2 pseudo elements
const pseudoElementsWithColons = [...keywordSets.levelOneAndTwoPseudoElements].map(
(x) => `:${x}`,
);
styleSearch({ source: selector.toLowerCase(), target: pseudoElementsWithColons }, (match) => {
const prevCharIsColon = selector[match.startIndex - 1] === ':';
if (expectation === 'single' && !prevCharIsColon) {
return;
}
if (expectation === 'double' && prevCharIsColon) {
return;
}
if (context.fix) {
fixPositions.unshift({ ruleNode, startIndex: match.startIndex });
return;
}
report({
message: messages.expected(expectation),
node: ruleNode,
index: match.startIndex,
result,
ruleName,
});
});
if (fixPositions.length) {
// If expecting : then we found :: so remove one of the colons
// If expecting :: then we found : so add one extra colon
const expectedSingle = expectation === 'single';
const offset = expectedSingle ? 1 : 0;
const extraColon = expectedSingle ? '' : ':';
fixPositions.forEach((fixPosition) => {
ruleNode.selector =
ruleNode.selector.substring(0, fixPosition.startIndex - offset) +
extraColon +
ruleNode.selector.substring(fixPosition.startIndex);
});
}
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;