mirror of
https://github.com/snachodog/just-the-docs.git
synced 2026-06-04 22:27:25 -06:00
Initial commit
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
# declaration-colon-newline-after
|
||||
|
||||
Require a newline or disallow whitespace after the colon of declarations.
|
||||
|
||||
```css
|
||||
a {
|
||||
box-shadow:
|
||||
0 0 0 1px #5b9dd9,
|
||||
0 0 2px 1px rgba(30, 140, 190, 0.8);
|
||||
} /* ↑ */
|
||||
/** ↑
|
||||
* The newline after this colon */
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
`string`: `"always"|"always-multi-line"`
|
||||
|
||||
### `"always"`
|
||||
|
||||
There *must always* be a newline after the colon.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a { color:pink; }
|
||||
```
|
||||
|
||||
```css
|
||||
a { color: pink; }
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a {
|
||||
color:
|
||||
pink;
|
||||
}
|
||||
```
|
||||
|
||||
### `"always-multi-line"`
|
||||
|
||||
There *must always* be a newline after the colon *if the declaration's value is multi-line*.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a {
|
||||
box-shadow: 0 0 0 1px #5b9dd9,
|
||||
0 0 2px 1px rgba(30, 140, 190, 0.8);
|
||||
}
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a {
|
||||
box-shadow:
|
||||
0 0 0 1px #5b9dd9,
|
||||
0 0 2px 1px rgba(30, 140, 190, 0.8);
|
||||
}
|
||||
```
|
||||
|
||||
```css
|
||||
a {
|
||||
color: pink;
|
||||
}
|
||||
```
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
"use strict"
|
||||
|
||||
const declarationValueIndex = require("../../utils/declarationValueIndex")
|
||||
const isStandardSyntaxDeclaration = require("../../utils/isStandardSyntaxDeclaration")
|
||||
const report = require("../../utils/report")
|
||||
const ruleMessages = require("../../utils/ruleMessages")
|
||||
const validateOptions = require("../../utils/validateOptions")
|
||||
const whitespaceChecker = require("../../utils/whitespaceChecker")
|
||||
|
||||
const ruleName = "declaration-colon-newline-after"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
expectedAfter: () => "Expected newline after \":\"",
|
||||
expectedAfterMultiLine: () => "Expected newline after \":\" with a multi-line declaration",
|
||||
})
|
||||
|
||||
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",
|
||||
],
|
||||
})
|
||||
if (!validOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
root.walkDecls(decl => {
|
||||
if (!isStandardSyntaxDeclaration(decl)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get the raw prop, and only the prop
|
||||
const endOfPropIndex = declarationValueIndex(decl) + (decl.raws.between || "").length - 1
|
||||
|
||||
// The extra characters tacked onto the end ensure that there is a character to check
|
||||
// after the colon. Otherwise, with `background:pink` the character after the
|
||||
const propPlusColon = decl.toString().slice(0, endOfPropIndex) + "xxx"
|
||||
|
||||
for (let i = 0, l = propPlusColon.length; i < l; i++) {
|
||||
if (propPlusColon[i] !== ":") {
|
||||
continue
|
||||
}
|
||||
const indexToCheck = propPlusColon.substr(propPlusColon[i], 3) === "/*" ? propPlusColon.indexOf("*/", i) + 1 : i
|
||||
|
||||
checker.afterOneOnly({
|
||||
source: propPlusColon,
|
||||
index: indexToCheck,
|
||||
lineCheckStr: decl.value,
|
||||
err: m => {
|
||||
report({
|
||||
message: m,
|
||||
node: decl,
|
||||
index: indexToCheck,
|
||||
result,
|
||||
ruleName,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
rule.ruleName = ruleName
|
||||
rule.messages = messages
|
||||
module.exports = rule
|
||||
Reference in New Issue
Block a user