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
+195
View File
@@ -0,0 +1,195 @@
# comment-empty-line-before
Require or disallow an empty line before comments.
<!-- prettier-ignore -->
```css
a {}
/* ← */
/* comment */ /* ↑ */
/** ↑
* This line */
```
This rule ignores:
- comments that are the very first node in the source
- shared-line comments
- single-line comments with `//` (when you're using a custom syntax that supports them)
- comments within selector and value lists
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 comments.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {}
/* comment */
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {}
/* comment */
```
<!-- prettier-ignore -->
```css
a {} /* comment */
```
### `"never"`
There _must never_ be an empty line before comments.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {}
/* comment */
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {}
/* comment */
```
<!-- prettier-ignore -->
```css
a {} /* comment */
```
## Optional secondary options
### `except: ["first-nested"]`
Reverse the primary option for comments 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 {
/* comment */
color: pink;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
/* comment */
color: pink;
}
```
### `ignore: ["after-comment", "stylelint-commands"]`
#### `"after-comment"`
Ignore comments that follow another comment.
For example, with `"always"`:
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
background: pink;
/* comment */
/* comment */
color: #eee;
}
```
<!-- prettier-ignore -->
```css
a {
background: pink;
/* comment */
/* comment */
color: #eee;
}
```
#### `"stylelint-commands"`
Ignore comments that deliver commands to stylelint, e.g. `/* stylelint-disable color-no-hex */`.
For example, with `"always"`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
background: pink;
/* not a stylelint command */
color: #eee;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
background: pink;
/* stylelint-disable color-no-hex */
color: pink;
}
```
### `ignoreComments: ["/regex/", /regex/, "string"]`
Ignore comments matching the given regular expressions or strings.
For example, with `"always"` and given:
```
[/^ignore/, "string-ignore"]
```
The following comments are _not_ considered violations:
```css
:root {
background: pink;
/* ignore this comment because of the regex */
color: pink;
}
```
```css
:root {
background: pink;
/* string-ignore */
color: pink;
}
```
+126
View File
@@ -0,0 +1,126 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const addEmptyLineBefore = require('../../utils/addEmptyLineBefore');
const hasEmptyLine = require('../../utils/hasEmptyLine');
const isAfterComment = require('../../utils/isAfterComment');
const isFirstNested = require('../../utils/isFirstNested');
const isFirstNodeOfRoot = require('../../utils/isFirstNodeOfRoot');
const isSharedLineComment = require('../../utils/isSharedLineComment');
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 = 'comment-empty-line-before';
const messages = ruleMessages(ruleName, {
expected: 'Expected empty line before comment',
rejected: 'Unexpected empty line before comment',
});
const stylelintCommandPrefix = 'stylelint-';
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always', 'never'],
},
{
actual: options,
possible: {
except: ['first-nested'],
ignore: ['stylelint-commands', 'after-comment'],
ignoreComments: [_.isString, _.isRegExp],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkComments((comment) => {
// Ignore the first node
if (isFirstNodeOfRoot(comment)) {
return;
}
// Optionally ignore stylelint commands
if (
comment.text.startsWith(stylelintCommandPrefix) &&
optionsMatches(options, 'ignore', 'stylelint-commands')
) {
return;
}
// Optionally ignore newlines between comments
if (optionsMatches(options, 'ignore', 'after-comment') && isAfterComment(comment)) {
return;
}
// Ignore comments matching the ignoreComments option.
if (optionsMatches(options, 'ignoreComments', comment.text)) {
return;
}
// Ignore shared-line comments
if (isSharedLineComment(comment)) {
return;
}
// Ignore SCSS comments
if (comment.raws.inline || comment.inline) {
return;
}
const expectEmptyLineBefore = (() => {
if (optionsMatches(options, 'except', 'first-nested') && isFirstNested(comment)) {
return false;
}
return expectation === 'always';
})();
const before = comment.raws.before || '';
const hasEmptyLineBefore = hasEmptyLine(before);
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return;
}
// Fix
if (context.fix) {
if (expectEmptyLineBefore) {
addEmptyLineBefore(comment, context.newline);
} else {
removeEmptyLinesBefore(comment, context.newline);
}
return;
}
const message = expectEmptyLineBefore ? messages.expected : messages.rejected;
report({
message,
node: comment,
result,
ruleName,
});
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;