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
+326
View File
@@ -0,0 +1,326 @@
# rule-empty-line-before
Require or disallow an empty line before rules.
<!-- prettier-ignore -->
```css
a {}
/* ← */
b {} /* ↑ */
/** ↑
* This line */
```
This rule ignores rules that are the very first node in a source.
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-multi-line"|"never-multi-line"`
### `"always"`
There _must always_ be an empty line before rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {} b {}
```
<!-- prettier-ignore -->
```css
a {}
b {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {}
b {}
```
### `"never"`
There _must never_ be an empty line before rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {}
b {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {} b {}
```
<!-- prettier-ignore -->
```css
a {}
b {}
```
### `"always-multi-line"`
There _must always_ be an empty line before multi-line rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
}
b {
color: blue;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
}
b {
color: blue;
}
```
### `"never-multi-line"`
There _must never_ be an empty line before multi-line rules.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
}
b {
color: blue;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
}
b {
color: blue;
}
```
## Optional secondary options
### `except: ["after-rule", "after-single-line-comment", "inside-block-and-after-rule", "inside-block", "first-nested"]`
#### `"after-rule"`
Reverse the primary option for rules that follow another rule.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {}
b {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {}
b {}
```
#### `"after-single-line-comment"`
Reverse the primary option for rules that follow a single-line comment.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
/* comment */
a {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
/* comment */
a {}
```
#### `"inside-block-and-after-rule"`
Reverse the primary option for rules that are inside a block and follow another rule.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
@media {
a {}
b {}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@media {
a {}
b {}
}
```
#### `"inside-block"`
Reverse the primary option for rules that are inside a block.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
& b {
color: blue;
}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: red;
& b {
color: blue;
}
}
```
#### `"first-nested"`
Reverse the primary option for 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
@media {
a {}
b {}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@media {
a {}
b {}
}
```
### `ignore: ["after-comment", "first-nested", "inside-block"]`
#### `"after-comment"`
Ignore rules that follow a comment.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
/* comment */
a {}
```
#### `"first-nested"`
Ignore 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
@media {
a {}
b {}
}
```
#### `"inside-block"`
Ignore rules that are inside a block.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@media {
a {}
}
```
<!-- prettier-ignore -->
```css
@media {
a {}
b {}
}
```
+145
View File
@@ -0,0 +1,145 @@
// @ts-nocheck
'use strict';
const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
const getPreviousNonSharedLineCommentNode = require('../../utils/getPreviousNonSharedLineCommentNode');
const hasEmptyLine = require('../../utils/hasEmptyLine');
const isAfterSingleLineComment = require('../../utils/isAfterSingleLineComment');
const isFirstNested = require('../../utils/isFirstNested');
const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
const isSingleLineString = require('../../utils/isSingleLineString');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
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 = 'rule-empty-line-before';
const messages = ruleMessages(ruleName, {
expected: 'Expected empty line before rule',
rejected: 'Unexpected empty line before rule',
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always', 'never', 'always-multi-line', 'never-multi-line'],
},
{
actual: options,
possible: {
ignore: ['after-comment', 'first-nested', 'inside-block'],
except: [
'after-rule',
'after-single-line-comment',
'first-nested',
'inside-block-and-after-rule',
'inside-block',
],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}
// Ignore the first node
if (isFirstNodeOfRoot(ruleNode)) {
return;
}
// Optionally ignore the expectation if a comment precedes this node
if (
optionsMatches(options, 'ignore', 'after-comment') &&
ruleNode.prev() &&
ruleNode.prev().type === 'comment'
) {
return;
}
// Optionally ignore the node if it is the first nested
if (optionsMatches(options, 'ignore', 'first-nested') && isFirstNested(ruleNode)) {
return;
}
const isNested = ruleNode.parent.type !== 'root';
// Optionally ignore the expectation if inside a block
if (optionsMatches(options, 'ignore', 'inside-block') && isNested) {
return;
}
// Ignore if the expectation is for multiple and the rule is single-line
if (expectation.includes('multi-line') && isSingleLineString(ruleNode.toString())) {
return;
}
let expectEmptyLineBefore = Boolean(expectation.includes('always'));
// Optionally reverse the expectation if any exceptions apply
if (
(optionsMatches(options, 'except', 'first-nested') && isFirstNested(ruleNode)) ||
(optionsMatches(options, 'except', 'after-rule') && isAfterRule(ruleNode)) ||
(optionsMatches(options, 'except', 'inside-block-and-after-rule') &&
isNested &&
isAfterRule(ruleNode)) ||
(optionsMatches(options, 'except', 'after-single-line-comment') &&
isAfterSingleLineComment(ruleNode)) ||
(optionsMatches(options, 'except', 'inside-block') && isNested)
) {
expectEmptyLineBefore = !expectEmptyLineBefore;
}
const hasEmptyLineBefore = hasEmptyLine(ruleNode.raws.before);
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return;
}
// Fix
if (context.fix) {
if (expectEmptyLineBefore) {
addEmptyLineBefore(ruleNode, context.newline);
} else {
removeEmptyLinesBefore(ruleNode, context.newline);
}
return;
}
const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
report({
message,
node: ruleNode,
result,
ruleName,
});
});
};
}
function isAfterRule(ruleNode) {
const prevNode = getPreviousNonSharedLineCommentNode(ruleNode);
return prevNode && prevNode.type === 'rule';
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;