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,142 @@
# stylelint-disable-reason
***Deprecated: See [CHANGELOG](../../../CHANGELOG.md).***
Require a reason comment before or after `stylelint-disable` comments.
```css
a {
/* stylelint-disable no-browser-hacks */
/* Need for IE 6 */ /*←*/
_display: block; /*↑*/
/* stylelint-enable no-browser-hacks */ /*↑*/
} /*↑*/
/** ↑
* This reason comment */
```
## Options
`string`: `"always-before"|"always-after"`
### `"always-before"`
There *must always* be a reason comment before the `stylelint-disable` comment.
The following patterns are considered warnings:
```css
a {
/* stylelint-disable no-browser-hacks */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {
/* stylelint-disable no-browser-hacks */
/* Need for IE 6 */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {} /* stylelint-disable-line block-no-empty */
```
```css
a {
_display: block; /* stylelint-disable-line block-no-empty */
}
```
The following patterns are *not* considered warnings:
```css
a {
/* Reason for disable */
/* stylelint-disable no-browser-hacks */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {} /* Reason for disable */ /* stylelint-disable-line block-no-empty */
```
```css
a {
_display: block; /* Reason for disable */ /* stylelint-disable-line no-browser-hacks */
}
```
```css
a {
/* Reason for disable */
_display: block; /* stylelint-disable-line no-browser-hacks */
}
```
### `"always-after"`
There *must always* be a reason comment after the `stylelint-disable` disable comment.
The following patterns are considered warnings:
```css
a {
/* stylelint-disable no-browser-hacks */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {
/* Need for IE 6 */
/* stylelint-disable no-browser-hacks */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {} /* stylelint-disable-line block-no-empty */
```
```css
a {
_display: block; /* stylelint-disable-line no-browser-hacks */
}
```
The following patterns are *not* considered warnings:
```css
a {
/* stylelint-disable no-browser-hacks */
/* Need for IE 6 */
_display: block;
/* stylelint-enable no-browser-hacks */
}
```
```css
a {} /* stylelint-disable-line block-no-empty */ /* Reason for disable */
```
```css
a {
_display: block; /* stylelint-disable-line no-browser-hacks */ /* Reason for disable */
}
```
```css
a {
_display: block; /* stylelint-disable-line no-browser-hacks */
/* Reason for disable */
}
```

View File

@@ -0,0 +1,93 @@
"use strict"
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "stylelint-disable-reason"
const messages = ruleMessages(ruleName, {
expectedBefore: "Expected comment reason before `stylelint-disable` comment",
expectedAfter: "Expected comment reason after `stylelint-disable` comment",
})
const stylelintDisableCommand = "stylelint-disable"
const stylelintDisableLineCommand = "stylelint-disable-line"
const rule = function (expectation) {
return function (root, result) {
const validOptions = validateOptions(result, ruleName, {
actual: expectation,
possible: [
"always-before",
"always-after",
],
})
if (!validOptions) {
return
}
result.warn((
`'${ruleName}' has been deprecated and in 8.0 will be removed.`
), {
stylelintType: "deprecation",
stylelintReference: `https://stylelint.io/user-guide/rules/${ruleName}/`,
})
root.walkComments(function (comment) {
if (comment.text.indexOf(stylelintDisableCommand) !== 0) {
return
}
if (expectation === "always-before") {
const prev = comment.prev()
const prevIsCommentAndValid = prev && prev.type === "comment" && !isDisableCommand(prev.text)
let prevDisableLineIsCommentAndValid = false
if (comment.text.indexOf(stylelintDisableLineCommand) === 0 && !prevIsCommentAndValid && prev) {
const friendlyPrev = prev.prev()
prevDisableLineIsCommentAndValid = friendlyPrev && friendlyPrev.type === "comment" && !isDisableCommand(friendlyPrev.text)
}
if (!prevIsCommentAndValid && !prevDisableLineIsCommentAndValid) {
const disabledRanges = result.stylelint.disabledRanges
result.stylelint.disabledRanges = false
report({
message: messages.expectedBefore,
node: comment,
result,
ruleName,
})
result.stylelint.disabledRanges = disabledRanges
}
} else if (expectation === "always-after") {
const next = comment.next()
const nextIsCommentAndValid = next && next.type === "comment" && !isDisableCommand(next.text)
if (!nextIsCommentAndValid) {
const disabledRanges = result.stylelint.disabledRanges
result.stylelint.disabledRanges = false
report({
message: messages.expectedAfter,
node: comment,
result,
ruleName,
})
result.stylelint.disabledRanges = disabledRanges
}
}
})
function isDisableCommand(text) {
return text.indexOf(stylelintDisableCommand) === 0
}
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule