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,238 @@
# block-closing-brace-empty-line-before
Require or disallow an empty line before the closing brace of blocks.
<!-- prettier-ignore -->
```css
a {
color: pink;
/* ← */
} /* ↑ */
/** ↑
* This line */
```
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
`string`: `"always-multi-line"|"never"`
### `always-multi-line`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: pink;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: pink;
}
```
<!-- prettier-ignore -->
```css
a { color: pink; }
```
### `never`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: pink;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: pink;
}
```
<!-- prettier-ignore -->
```css
a { color: pink; }
```
## Optional secondary options
### `except: ["after-closing-brace"]`
When a rule is nested, `after-closing-brace` brace will reverse the primary option.
For example, with `"never"` and `except: ["after-closing-brace"]`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
@media print {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@supports (animation-name: test) {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@keyframes test {
100% {
color: aquamarine;
}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@media print {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@font-face {
font-family: "MyFont";
src: url("myfont.woff2") format("woff2");
}
```
<!-- prettier-ignore -->
```css
@supports (animation-name: test) {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@keyframes test {
100% {
color: aquamarine;
}
}
```
For example, with `"always-multi-line"` and `except: ["after-closing-brace"]`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
@media print {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@supports (animation-name: test) {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@keyframes test {
100% {
color: aquamarine;
}
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@media print {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@font-face {
font-family: "MyFont";
src: url("myfont.woff2") format("woff2");
}
```
<!-- prettier-ignore -->
```css
@supports (animation-name: test) {
a {
color: aquamarine;
}
}
```
<!-- prettier-ignore -->
```css
@keyframes test {
100% {
color: aquamarine;
}
}
```
@@ -0,0 +1,118 @@
// @ts-nocheck
'use strict';
const addEmptyLineAfter = require('../../utils/addEmptyLineAfter');
const blockString = require('../../utils/blockString');
const hasBlock = require('../../utils/hasBlock');
const hasEmptyBlock = require('../../utils/hasEmptyBlock');
const hasEmptyLine = require('../../utils/hasEmptyLine');
const isSingleLineString = require('../../utils/isSingleLineString');
const optionsMatches = require('../../utils/optionsMatches');
const removeEmptyLineAfter = require('../../utils/removeEmptyLinesAfter');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'block-closing-brace-empty-line-before';
const messages = ruleMessages(ruleName, {
expected: 'Expected empty line before closing brace',
rejected: 'Unexpected empty line before closing brace',
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always-multi-line', 'never'],
},
{
actual: options,
possible: {
except: ['after-closing-brace'],
},
optional: true,
},
);
if (!validOptions) {
return;
}
// Check both kinds of statements: rules and at-rules
root.walkRules(check);
root.walkAtRules(check);
function check(statement) {
// Return early if blockless or has empty block
if (!hasBlock(statement) || hasEmptyBlock(statement)) {
return;
}
// Get whitespace after ""}", ignoring extra semicolon
const before = (statement.raws.after || '').replace(/;+/, '');
// Calculate index
const statementString = statement.toString();
let index = statementString.length - 1;
if (statementString[index - 1] === '\r') {
index -= 1;
}
// Set expectation
const expectEmptyLineBefore = (() => {
const childNodeTypes = statement.nodes.map((item) => item.type);
// Reverse the primary options if `after-closing-brace` is set
if (
optionsMatches(options, 'except', 'after-closing-brace') &&
statement.type === 'atrule' &&
!childNodeTypes.includes('decl')
) {
return expectation === 'never';
}
return Boolean(
expectation === 'always-multi-line' && !isSingleLineString(blockString(statement)),
);
})();
// Check for at least one empty line
const hasEmptyLineBefore = hasEmptyLine(before);
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return;
}
if (context.fix) {
if (expectEmptyLineBefore) {
addEmptyLineAfter(statement, context.newline);
} else {
removeEmptyLineAfter(statement, context.newline);
}
return;
}
const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
report({
message,
result,
ruleName,
node: statement,
index,
});
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;