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,125 @@
# declaration-block-semicolon-space-after
Require a single space or disallow whitespace after the semicolons of declaration blocks.
```css
a { color: pink; top: 0; }
/** ↑
* The space after this semicolon */
```
This rule ignores semicolons that are preceded by Less mixins.
This rule ignores the last semicolon of declaration blocks. Use the `block-closing-brace-*-before` rules to control the whitespace between the last semicolon and the closing brace instead.
## Options
`string`: `"always"|"never"|"always-single-line"|"never-single-line"`
### `"always"`
There *must always* be a single space after the semicolon.
The following patterns are considered warnings:
```css
a { color: pink;top: 0; }
```
```css
a {
color: pink;
top: 0;
}
```
The following patterns are *not* considered warnings:
```css
a { color: pink;}
```
```css
a { color: pink; }
```
```css
a { color: pink; top: 0; }
```
### `"never"`
There *must never* be whitespace after the semicolon.
The following patterns are considered warnings:
```css
a { color: pink; top: 0; }
```
```css
a {
color: pink;
top: 0;
}
```
The following patterns are *not* considered warnings:
```css
a { color: pink;}
```
```css
a { color: pink; }
```
```css
a { color: pink;top: 0; }
```
### `"always-single-line"`
There *must always* be a single space after the semicolon in single-line declaration blocks.
The following patterns are considered warnings:
```css
a { color: pink;top: 0; }
```
The following patterns are *not* considered warnings:
```css
a { color: pink; top: 0; }
```
```css
a {
color: pink;
top: 0;
}
```
### `"never-single-line"`
There *must never* be whitespace after the semicolon in single-line declaration blocks.
The following patterns are considered warnings:
```css
a { color: pink; top: 0; }
```
The following patterns are *not* considered warnings:
```css
a { color: pink;top: 0; }
```
```css
a {
color: pink;
top: 0;
}
```

View File

@@ -0,0 +1,68 @@
"use strict"
const blockString = require("../../utils/blockString")
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 = "declaration-block-semicolon-space-after"
const messages = ruleMessages(ruleName, {
expectedAfter: () => "Expected single space after \";\"",
rejectedAfter: () => "Unexpected whitespace after \";\"",
expectedAfterSingleLine: () => "Expected single space after \";\" in a single-line declaration block",
rejectedAfterSingleLine: () => "Unexpected whitespace after \";\" in a single-line declaration block",
})
const rule = function (expectation) {
const checker = whitespaceChecker("space", expectation, messages)
return function (root, result) {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"always",
"never",
"always-single-line",
"never-single-line",
],
})
if (!validOptions) {
return
}
root.walkDecls(function (decl) {
// Ignore last declaration if there's no trailing semicolon
const parentRule = decl.parent
if (!parentRule.raws.semicolon && parentRule.last === decl) {
return
}
const nextDecl = decl.next()
if (!nextDecl) {
return
}
checker.after({
source: rawNodeString(nextDecl),
index: -1,
lineCheckStr: blockString(parentRule),
err: m => {
report({
message: m,
node: decl,
index: decl.toString().length + 1,
result,
ruleName,
})
},
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule