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,91 @@
# selector-max-empty-lines
Limit the number of adjacent empty lines within selectors.
```css
a,
/* ← */
b { /* ↑ */
color: red; /* ↑ */
} /* ↑ */
/** ↑
* This empty line */
```
## Options
`int`: Maximum number of empty lines.
For example, with `0`:
The following patterns are considered warnings:
```css
a
b {
color: red;
}
```
```css
a,
b {
color: red;
}
```
```css
a
>
b {
color: red;
}
```
```css
a
>
b {
color: red;
}
```
The following patterns are *not* considered warnings:
```css
a b {
color: red;
}
```
```css
a
b {
color: red;
}
```
```css
a,
b {
color: red;
}
```
```css
a > b {
color: red;
}
```
```css
a
>
b {
color: red;
}
```

View File

@@ -0,0 +1,55 @@
"use strict"
const _ = require("lodash")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const styleSearch = require("style-search")
const ruleName = "selector-max-empty-lines"
const messages = ruleMessages(ruleName, {
expected: max => `Expected no more than ${max} empty line(s)`,
})
const rule = function (max) {
const maxAdjacentNewlines = max + 1
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual: max,
possible: _.isNumber,
})
if (!validOptions) {
return
}
root.walkRules(rule => {
const selector = rule.raws.selector ? rule.raws.selector.raw : rule.selector
const repeatLFNewLines = _.repeat("\n", maxAdjacentNewlines)
const repeatCRLFNewLines = _.repeat("\r\n", maxAdjacentNewlines)
styleSearch({ source: selector, target: "\n" }, match => {
if (selector.substr(match.startIndex + 1, maxAdjacentNewlines) === repeatLFNewLines || selector.substr(match.startIndex + 1, maxAdjacentNewlines * 2) === repeatCRLFNewLines) {
// Put index at `\r` if it's CRLF, otherwise leave it at `\n`
let index = match.startIndex
if (selector[index - 1] === "\r") {
index -= 1
}
report({
message: messages.expected(max),
node: rule,
index,
result,
ruleName,
})
}
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule