Initial commit

This commit is contained in:
Patrick Marsceill
2017-03-09 13:16:08 -05:00
commit b7b0d0d7bf
4147 changed files with 401224 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
# block-opening-brace-newline-after
Require a newline after the opening brace of blocks.
```css
a {
color: pink; }
/** ↑
* The newline after this brace */
```
This rule allows an end-of-line comment followed by a newline. For example,
```css
a { /* end-of-line comment */
color: pink;
}
```
Refer to [the FAQ](../../../docs/user-guide/faq.md#how-do-i-disallow-single-line-blocks) 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.
## 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 warnings:
```css
a{ color: pink; }
```
```css
a{ color: pink;
}
```
```css
a{ /* end-of-line comment
with a newline */
color: pink;
}
```
The following patterns are *not* considered warnings:
```css
a {
color: pink; }
```
```css
a
{
color: pink; }
```
```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 warnings:
```css
a{color: pink;
}
```
The following patterns are *not* considered warnings:
```css
a { color: pink; }
```
```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 warnings:
```css
a { color: pink;
}
```
The following patterns are *not* considered warnings:
```css
a { color: pink; }
```
```css
a {color: pink;
}
```

View File

@@ -0,0 +1,77 @@
"use strict"
const beforeBlockString = require("../../utils/beforeBlockString")
const blockString = require("../../utils/blockString")
const hasBlock = require("../../utils/hasBlock")
const hasEmptyBlock = require("../../utils/hasEmptyBlock")
const nextNonCommentNode = require("../../utils/nextNonCommentNode")
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",
})
const rule = function (expectation) {
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
}
// Allow an end-of-line comment
const nodeToCheck = nextNonCommentNode(statement.first)
if (!nodeToCheck) {
return
}
checker.afterOneOnly({
source: rawNodeString(nodeToCheck),
index: -1,
lineCheckStr: blockString(statement),
err: m => {
report({
message: m,
node: statement,
index: beforeBlockString(statement, { noRawBefore: true }).length + 1,
result,
ruleName,
})
},
})
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule