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,62 @@
# block-closing-brace-empty-line-before
Require or disallow an empty line before the closing brace of blocks.
```css
a {
color: pink;
/* ← */
} /* ↑ */
/** ↑
* This line */
```
## Options
`string`: `"always-multi-line"|"never"`
### `always-multi-line`
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`
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,89 @@
"use strict"
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 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",
})
const rule = function (expectation) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"always-multi-line",
"never",
],
})
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(/;+/, "")
if (before === undefined) {
return
}
// Calculate index
const statementString = statement.toString()
let index = statementString.length - 1
if (statementString[index - 1] === "\r") {
index -= 1
}
// Set expectation
const expectEmptyLineBefore = expectation === "always-multi-line"
&& !isSingleLineString(blockString(statement))
? true
: false
// Check for at least one empty line
const hasEmptyLineBefore = hasEmptyLine(before)
// Return if the expectation is met
if (expectEmptyLineBefore === hasEmptyLineBefore) {
return
}
const message = expectEmptyLineBefore
? messages.expected
: messages.rejected
report({
message,
result,
ruleName,
node: statement,
index,
})
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule