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,272 @@
# custom-property-empty-line-before
Require or disallow an empty line before custom properties.
<!-- prettier-ignore -->
```css
a {
top: 10px;
/* ← */
--foo: pink; /* ↑ */
} /* ↑ */
/** ↑
* This line */
```
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"`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
top: 10px;
--foo: pink;
--bar: red;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
top: 10px;
--foo: pink;
--bar: red;
}
```
### `"never"`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
top: 10px;
--foo: pink;
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink;
--bar: red;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
top: 10px;
--foo: pink;
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink;
--bar: red;
}
```
## Optional secondary options
### `except: ["after-comment", "after-custom-property", "first-nested"]`
#### `"after-comment"`
Reverse the primary option for custom properties that follow a comment.
Shared-line comments do not trigger this option.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
--foo: pink;
/* comment */
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink; /* comment */
--bar: red;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
--foo: pink;
/* comment */
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink; /* comment */
--bar: red;
}
```
#### `"after-custom-property"`
Reverse the primary option for custom properties that follow another custom property.
Shared-line comments do not affect this option.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
--foo: pink;
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink; /* comment */
--bar: red;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
--foo: pink;
--bar: red;
}
```
<!-- prettier-ignore -->
```css
a {
--foo: pink; /* comment */
--bar: red;
}
```
#### `"first-nested"`
Reverse the primary option for custom properties 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 {
--foo: pink;
--bar: red;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
--foo: pink;
--bar: red;
}
```
### `ignore: ["after-comment", "first-nested", "inside-single-line-block"]`
#### `"after-comment"`
Ignore custom properties that follow a comment.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
/* comment */
--foo: pink;
}
```
#### `"first-nested"`
Ignore custom properties 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
a {
--foo: pink;
--bar: red;
}
```
#### `"inside-single-line-block"`
Ignore custom properties that are inside single-line blocks.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { --foo: pink; --bar: red; }
```
@@ -0,0 +1,129 @@
// @ts-nocheck
'use strict';
const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
const blockString = require('../../utils/blockString');
const getPreviousNonSharedLineCommentNode = require('../../utils/getPreviousNonSharedLineCommentNode');
const hasEmptyLine = require('../../utils/hasEmptyLine');
const isAfterComment = require('../../utils/isAfterComment');
const isCustomProperty = require('../../utils/isCustomProperty');
const isFirstNested = require('../../utils/isFirstNested');
const isSingleLineString = require('../../utils/isSingleLineString');
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
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 = 'custom-property-empty-line-before';
const messages = ruleMessages(ruleName, {
expected: 'Expected empty line before custom property',
rejected: 'Unexpected empty line before custom property',
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always', 'never'],
},
{
actual: options,
possible: {
except: ['first-nested', 'after-comment', 'after-custom-property'],
ignore: ['after-comment', 'first-nested', 'inside-single-line-block'],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkDecls((decl) => {
const prop = decl.prop;
const parent = decl.parent;
if (!isStandardSyntaxDeclaration(decl)) {
return;
}
if (!isCustomProperty(prop)) {
return;
}
// Optionally ignore the node if a comment precedes it
if (optionsMatches(options, 'ignore', 'after-comment') && isAfterComment(decl)) {
return;
}
// Optionally ignore the node if it is the first nested
if (optionsMatches(options, 'ignore', 'first-nested') && isFirstNested(decl)) {
return;
}
// Optionally ignore nodes inside single-line blocks
if (
optionsMatches(options, 'ignore', 'inside-single-line-block') &&
isSingleLineString(blockString(parent))
) {
return;
}
let expectEmptyLineBefore = expectation === 'always';
// Optionally reverse the expectation if any exceptions apply
if (
(optionsMatches(options, 'except', 'first-nested') && isFirstNested(decl)) ||
(optionsMatches(options, 'except', 'after-comment') && isAfterComment(decl)) ||
(optionsMatches(options, 'except', 'after-custom-property') && isAfterCustomProperty(decl))
) {
expectEmptyLineBefore = !expectEmptyLineBefore;
}
const hasEmptyLineBefore = hasEmptyLine(decl.raws.before);
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return;
}
// Fix
if (context.fix) {
if (expectEmptyLineBefore) {
addEmptyLineBefore(decl, context.newline);
} else {
removeEmptyLinesBefore(decl, context.newline);
}
return;
}
const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
report({
message,
node: decl,
result,
ruleName,
});
});
};
}
function isAfterCustomProperty(decl) {
const prevNode = getPreviousNonSharedLineCommentNode(decl);
return prevNode && prevNode.prop && isCustomProperty(prevNode.prop);
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;