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,125 @@
# block-opening-brace-newline-after
Require a newline after the opening brace of blocks.
<!-- prettier-ignore -->
```css
a {
↑ color: pink; }
/** ↑
* The newline after this brace */
```
This rule allows an end-of-line comment followed by a newline. For example,
<!-- prettier-ignore -->
```css
a { /* end-of-line comment */
color: pink;
}
```
Refer to [combining rules](../../../docs/user-guide/rules/combine.md) for more information on using this rule with [`block-opening-brace-newline-before`](../block-opening-brace-newline-before/README.md) to disallow single-line rules.
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
`string`: `"always"|"always-multi-line"|"never-multi-line"`
### `"always"`
There _must always_ be a newline after the opening brace.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a{ color: pink; }
```
<!-- prettier-ignore -->
```css
a{ color: pink;
}
```
<!-- prettier-ignore -->
```css
a{ /* end-of-line comment
with a newline */
color: pink;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: pink; }
```
<!-- prettier-ignore -->
```css
a
{
color: pink; }
```
<!-- prettier-ignore -->
```css
a { /* end-of-line comment */
color: pink;
}
```
### `"always-multi-line"`
There _must always_ be a newline after the opening brace in multi-line blocks.
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-multi-line"`
There _must never_ be whitespace after the opening brace in multi-line blocks.
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;
}
```
@@ -0,0 +1,145 @@
// @ts-nocheck
'use strict';
const beforeBlockString = require('../../utils/beforeBlockString');
const blockString = require('../../utils/blockString');
const hasBlock = require('../../utils/hasBlock');
const hasEmptyBlock = require('../../utils/hasEmptyBlock');
const rawNodeString = require('../../utils/rawNodeString');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const whitespaceChecker = require('../../utils/whitespaceChecker');
const ruleName = 'block-opening-brace-newline-after';
const messages = ruleMessages(ruleName, {
expectedAfter: () => 'Expected newline after "{"',
expectedAfterMultiLine: () => 'Expected newline after "{" of a multi-line block',
rejectedAfterMultiLine: () => 'Unexpected whitespace after "{" of a multi-line block',
});
function rule(expectation, options, context) {
const checker = whitespaceChecker('newline', expectation, messages);
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: ['always', 'always-multi-line', 'never-multi-line'],
});
if (!validOptions) {
return;
}
// Check both kinds of statement: rules and at-rules
root.walkRules(check);
root.walkAtRules(check);
function check(statement) {
// Return early if blockless or has an empty block
if (!hasBlock(statement) || hasEmptyBlock(statement)) {
return;
}
const backupCommentNextBefores = new Map();
// next node with checking newlines after comment
function nextNode(startNode) {
if (!startNode || !startNode.next) return null;
if (startNode.type === 'comment') {
const reNewLine = /\r?\n/;
const newLineMatch = reNewLine.test(startNode.raws.before);
const next = startNode.next();
if (next && newLineMatch && !reNewLine.test(next.raws.before)) {
backupCommentNextBefores.set(next, next.raws.before);
next.raws.before = startNode.raws.before;
}
return nextNode(next);
}
return startNode;
}
// Allow an end-of-line comment
const nodeToCheck = nextNode(statement.first);
if (!nodeToCheck) {
return;
}
checker.afterOneOnly({
source: rawNodeString(nodeToCheck),
index: -1,
lineCheckStr: blockString(statement),
err: (m) => {
if (context.fix) {
if (expectation.startsWith('always')) {
const index = nodeToCheck.raws.before.search(/\r?\n/);
if (index >= 0) {
nodeToCheck.raws.before = nodeToCheck.raws.before.slice(index);
} else {
nodeToCheck.raws.before = context.newline + nodeToCheck.raws.before;
}
backupCommentNextBefores.delete(nodeToCheck);
return;
}
if (expectation === 'never-multi-line') {
// Restore the `before` of the node next to the comment node.
backupCommentNextBefores.forEach((before, node) => {
node.raws.before = before;
});
backupCommentNextBefores.clear();
// Fix
const reNewLine = /\r?\n/;
let fixTarget = statement.first;
while (fixTarget) {
if (reNewLine.test(fixTarget.raws.before)) {
fixTarget.raws.before = fixTarget.raws.before.replace(/\r?\n/g, '');
}
if (fixTarget.type !== 'comment') {
break;
}
fixTarget = fixTarget.next();
}
nodeToCheck.raws.before = '';
return;
}
}
report({
message: m,
node: statement,
index: beforeBlockString(statement, { noRawBefore: true }).length + 1,
result,
ruleName,
});
},
});
// Restore the `before` of the node next to the comment node.
backupCommentNextBefores.forEach((before, node) => {
node.raws.before = before;
});
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;