mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 13:23:32 -06:00
Initial commit
This commit is contained in:
81
node_modules/stylelint/lib/rules/block-closing-brace-newline-before/README.md
generated
vendored
Normal file
81
node_modules/stylelint/lib/rules/block-closing-brace-newline-before/README.md
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
# block-closing-brace-newline-before
|
||||
|
||||
Require a newline or disallow whitespace before the closing brace of blocks.
|
||||
|
||||
```css
|
||||
a { color: pink;
|
||||
}
|
||||
/** ↑
|
||||
* The newline before this brace */
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
`string`: `"always"|"always-multi-line"|"never-multi-line"`
|
||||
|
||||
### `"always"`
|
||||
|
||||
There *must always* be a newline before the closing brace.
|
||||
|
||||
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;
|
||||
}
|
||||
```
|
||||
|
||||
### `"always-multi-line"`
|
||||
|
||||
There *must always* be a newline before the closing 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 before the closing 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;}
|
||||
```
|
103
node_modules/stylelint/lib/rules/block-closing-brace-newline-before/index.js
generated
vendored
Normal file
103
node_modules/stylelint/lib/rules/block-closing-brace-newline-before/index.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
"use strict"
|
||||
|
||||
const _ = require("lodash")
|
||||
const blockString = require("../../utils/blockString")
|
||||
const hasBlock = require("../../utils/hasBlock")
|
||||
const hasEmptyBlock = require("../../utils/hasEmptyBlock")
|
||||
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-newline-before"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
expectedBefore: "Expected newline before \"}\"",
|
||||
expectedBeforeMultiLine: "Expected newline before \"}\" of a multi-line block",
|
||||
rejectedBeforeMultiLine: "Unexpected whitespace before \"}\" of a multi-line block",
|
||||
})
|
||||
|
||||
const rule = function (expectation) {
|
||||
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 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
|
||||
}
|
||||
|
||||
// Ignore extra semicolon
|
||||
const after = (statement.raws.after || "").replace(/;+/, "")
|
||||
if (after === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const blockIsMultiLine = !isSingleLineString(blockString(statement))
|
||||
const statementString = statement.toString()
|
||||
|
||||
let index = statementString.length - 2
|
||||
if (statementString[index - 1] === "\r") {
|
||||
index -= 1
|
||||
}
|
||||
|
||||
// We're really just checking whether a
|
||||
// newline *starts* the block's final space -- between
|
||||
// the last declaration and the closing brace. We can
|
||||
// ignore any other whitespace between them, because that
|
||||
// will be checked by the indentation rule.
|
||||
if (
|
||||
!_.startsWith(after, "\n")
|
||||
&& !_.startsWith(after, "\r\n")
|
||||
) {
|
||||
if (expectation === "always") {
|
||||
complain(messages.expectedBefore)
|
||||
} else if (
|
||||
blockIsMultiLine
|
||||
&& expectation === "always-multi-line"
|
||||
) {
|
||||
complain(messages.expectedBeforeMultiLine)
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
after !== ""
|
||||
&& blockIsMultiLine
|
||||
&& expectation === "never-multi-line"
|
||||
) {
|
||||
complain(messages.rejectedBeforeMultiLine)
|
||||
}
|
||||
|
||||
function complain(message) {
|
||||
report({
|
||||
message,
|
||||
result,
|
||||
ruleName,
|
||||
node: statement,
|
||||
index,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rule.ruleName = ruleName
|
||||
rule.messages = messages
|
||||
module.exports = rule
|
Reference in New Issue
Block a user