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
+421
View File
@@ -0,0 +1,421 @@
# at-rule-empty-line-before
Require or disallow an empty line before at-rules.
<!-- prettier-ignore -->
```css
a {}
/* ← */
@media {} /* ↑ */
/** ↑
* This line */
```
This rule ignores:
- at-rules that are the very first node in the source
- `@import` in Less.
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule. We recommend to enable [`indentation`](../indentation/README.md) rule for better autofixing results with this rule.
## Options
`string`: `"always"|"never"`
### `"always"`
There _must always_ be an empty line before at-rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {} @media {}
```
<!-- prettier-ignore -->
```css
a {}
@media {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {}
@media {}
```
### `"never"`
There _must never_ be an empty line before at-rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {}
@media {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {} @media {}
```
<!-- prettier-ignore -->
```css
a {}
@media {}
```
## Optional secondary options
### `except: ["after-same-name", "inside-block", "blockless-after-same-name-blockless", "blockless-after-blockless", "first-nested"]`
#### `"after-same-name"`
Reverse the primary option for at-rules that follow another at-rule with the same name.
This means that you can group your at-rules by name.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@charset "UTF-8";
@import url(x.css);
@import url(y.css);
@media (min-width: 100px) {}
@media (min-width: 200px) {}
```
<!-- prettier-ignore -->
```css
a {
@extends .foo;
@extends .bar;
@include x;
@include y {}
}
```
#### `"inside-block"`
Reverse the primary option for at-rules that are inside a block.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
@extend foo;
color: pink;
}
b {
color: pink;
@extend foo;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
@extend foo;
color: pink;
}
b {
color: pink;
@extend foo;
}
```
#### `"blockless-after-same-name-blockless"`
Reverse the primary option for blockless at-rules that follow another blockless at-rule with the same name.
This means that you can group your blockless at-rules by name.
Shared-line comments do not affect this option.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@charset "UTF-8";
@import url(x.css);
@import url(y.css);
```
<!-- prettier-ignore -->
```css
@charset "UTF-8";
@import url(x.css); /* comment */
@import url(y.css);
```
<!-- prettier-ignore -->
```css
a {
@extends .foo;
@extends .bar;
@include loop;
@include doo;
}
```
#### `"blockless-after-blockless"`
Reverse the primary option for blockless at-rules that follow another blockless at-rule.
Shared-line comments do not affect this option.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
@import url(x.css);
@import url(y.css);
@media print {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@import url(x.css);
@import url(y.css);
@media print {}
```
<!-- prettier-ignore -->
```css
@import url(x.css); /* comment */
@import url(y.css);
@media print {}
```
#### `"first-nested"`
Reverse the primary option for at-rules that are nested and the first child of their parent node.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
@extend foo;
color: pink;
}
b {
color: pink;
@extend foo;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
@extend foo;
color: pink;
}
b {
color: pink;
@extend foo;
}
```
### `ignore: ["after-comment", "first-nested", "inside-block", "blockless-after-same-name-blockless", "blockless-after-blockless"]`
#### `"after-comment"`
Ignore at-rules that follow a comment.
Shared-line comments do not trigger this option.
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
/* comment */
@media {}
```
<!-- prettier-ignore -->
```css
/* comment */
@media {}
```
<!-- prettier-ignore -->
```css
@media {} /* comment */
@media {}
```
#### `"first-nested"`
Ignore at-rules that are nested and the first child of their parent node.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@supports {
@media {}
@media {}
}
```
#### `"inside-block"`
Ignore at-rules that are inside a block.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
@extend foo;
color: pink;
}
a {
@extend foo;
color: pink;
}
b {
color: pink;
@extend foo;
}
b {
color: pink;
@extend foo;
}
```
#### `"blockless-after-same-name-blockless"`
Ignore blockless at-rules that follow another blockless at-rule with the same name.
This means that you can group your blockless at-rules by name.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@charset "UTF-8";
@import url(x.css);
@import url(y.css);
```
<!-- prettier-ignore -->
```css
a {
@extends .foo;
@extends .bar;
@include loop;
@include doo;
}
```
#### `"blockless-after-blockless"`
Ignore blockless at-rules that follow another blockless at-rule.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@import url(x.css);
@import url(y.css);
@media print {}
```
<!-- prettier-ignore -->
```css
@import url(x.css);
@import url(y.css);
@media print {}
```
### `ignoreAtRules: ["array", "of", "at-rules"]`
Ignore specified at-rules.
For example, with `"always"`.
Given:
```
["import"]
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@charset "UTF-8";
@import {}
```
+161
View File
@@ -0,0 +1,161 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
const getPreviousNonSharedLineCommentNode = require('../../utils/getPreviousNonSharedLineCommentNode');
const hasEmptyLine = require('../../utils/hasEmptyLine');
const isAfterComment = require('../../utils/isAfterComment');
const isBlocklessAtRuleAfterBlocklessAtRule = require('../../utils/isBlocklessAtRuleAfterBlocklessAtRule');
const isBlocklessAtRuleAfterSameNameBlocklessAtRule = require('../../utils/isBlocklessAtRuleAfterSameNameBlocklessAtRule');
const isFirstNested = require('../../utils/isFirstNested');
const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const optionsMatches = require('../../utils/optionsMatches');
const removeEmptyLinesBefore = require('../../utils/removeEmptyLinesBefore');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'at-rule-empty-line-before';
const messages = ruleMessages(ruleName, {
expected: 'Expected empty line before at-rule',
rejected: 'Unexpected empty line before at-rule',
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always', 'never'],
},
{
actual: options,
possible: {
except: [
'after-same-name',
'inside-block',
'blockless-after-same-name-blockless',
'blockless-after-blockless',
'first-nested',
],
ignore: [
'after-comment',
'first-nested',
'inside-block',
'blockless-after-same-name-blockless',
'blockless-after-blockless',
],
ignoreAtRules: [_.isString],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkAtRules((atRule) => {
const isNested = atRule.parent.type !== 'root';
// Ignore the first node
if (isFirstNodeOfRoot(atRule)) {
return;
}
if (!isStandardSyntaxAtRule(atRule)) {
return;
}
// Return early if at-rule is to be ignored
if (optionsMatches(options, 'ignoreAtRules', atRule.name)) {
return;
}
// Optionally ignore the expectation if the node is blockless
if (
optionsMatches(options, 'ignore', 'blockless-after-blockless') &&
isBlocklessAtRuleAfterBlocklessAtRule(atRule)
) {
return;
}
// Optionally ignore the node if it is the first nested
if (optionsMatches(options, 'ignore', 'first-nested') && isFirstNested(atRule)) {
return;
}
// Optionally ignore the expectation if the node is blockless
// and following another blockless at-rule with the same name
if (
optionsMatches(options, 'ignore', 'blockless-after-same-name-blockless') &&
isBlocklessAtRuleAfterSameNameBlocklessAtRule(atRule)
) {
return;
}
// Optionally ignore the expectation if the node is inside a block
if (optionsMatches(options, 'ignore', 'inside-block') && isNested) {
return;
}
// Optionally ignore the expectation if a comment precedes this node
if (optionsMatches(options, 'ignore', 'after-comment') && isAfterComment(atRule)) {
return;
}
const hasEmptyLineBefore = hasEmptyLine(atRule.raws.before);
let expectEmptyLineBefore = expectation === 'always';
// Optionally reverse the expectation if any exceptions apply
if (
(optionsMatches(options, 'except', 'after-same-name') &&
isAtRuleAfterSameNameAtRule(atRule)) ||
(optionsMatches(options, 'except', 'inside-block') && isNested) ||
(optionsMatches(options, 'except', 'first-nested') && isFirstNested(atRule)) ||
(optionsMatches(options, 'except', 'blockless-after-blockless') &&
isBlocklessAtRuleAfterBlocklessAtRule(atRule)) ||
(optionsMatches(options, 'except', 'blockless-after-same-name-blockless') &&
isBlocklessAtRuleAfterSameNameBlocklessAtRule(atRule))
) {
expectEmptyLineBefore = !expectEmptyLineBefore;
}
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return;
}
// Fix
if (context.fix) {
if (expectEmptyLineBefore) {
addEmptyLineBefore(atRule, context.newline);
} else {
removeEmptyLinesBefore(atRule, context.newline);
}
return;
}
const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
report({ message, node: atRule, result, ruleName });
});
};
}
function isAtRuleAfterSameNameAtRule(atRule) {
const previousNode = getPreviousNonSharedLineCommentNode(atRule);
return previousNode && previousNode.type === 'atrule' && previousNode.name === atRule.name;
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;