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,78 @@
# block-no-single-line
***Deprecated: instead use the [block-opening-brace-newline-after](../block-opening-brace-newline-after/README.md#always) and [block-closing-brace-newline-before](../block-closing-brace-newline-before/README.md#always) rules with the option `"always"`. See [the FAQs for an example](../../../docs/user-guide/faq.md#how-do-i-disallow-single-line-blocks).***
Disallow single-line blocks.
```css
a { color: pink; top: 0; }
/** ↑ ↑
* Declaration blocks like this */
```
## Options
### `true`
The following patterns are considered warnings:
```css
a { color: pink; }
```
```css
a,
b { color: pink; }
```
```css
a { color: pink; top: 1px; }
```
```css
@media print { a { color: pink; } }
```
```css
@media print {
a { color: pink; }
}
```
```css
a {
color: red;
@media print { color: pink; }
}
```
The following patterns are *not* considered warnings:
```css
a {
color: pink;
}
```
```css
a, b {
color: pink;
}
```
```css
@media print {
a {
color: pink;
}
}
```
```css
a {
color: red;
@media print {
color: pink;
}
}
```

View File

@@ -0,0 +1,61 @@
"use strict"
const beforeBlockString = require("../../utils/beforeBlockString")
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-no-single-line"
const messages = ruleMessages(ruleName, {
rejected: "Unexpected single-line block",
})
const rule = function (actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual })
if (!validOptions) {
return
}
result.warn((
"'block-no-single-line' has been deprecated and in 8.0 will be removed. " +
"Instead use 'block-opening-brace-newline-after' and 'block-closing-brace-newline-before' with the \"always\" option."
), {
stylelintType: "deprecation",
stylelintReference: "https://stylelint.io/user-guide/rules/block-no-single-line/",
})
// Check both kinds of statements: rules and at-rules
root.walkRules(check)
root.walkAtRules(check)
function check(statement) {
if (
!hasBlock(statement)
|| hasEmptyBlock(statement)
) {
return
}
if (!isSingleLineString(blockString(statement))) {
return
}
report({
message: messages.rejected,
node: statement,
index: beforeBlockString(statement, { noRawBefore: true }).length,
result,
ruleName,
})
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule