1
0
mirror of https://github.com/thangisme/notes.git synced 2025-11-23 13:12:25 -05:00

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,109 @@
# declaration-block-no-ignored-properties
***Deprecated: See [CHANGELOG](../../../CHANGELOG.md).***
Disallow property values that are ignored due to another property value in the same rule.
```css
a { display: inline; width: 100px; }
/** ↑
* This property */
```
Certain property value pairs rule out other property value pairs, causing them to be ignored by the browser. For example, when an element has display: inline, any further declarations about width, height and margin-top properties will be ignored. Sometimes this is confusing: maybe you forgot that your margin-top will have no effect because the element has display: inline, so you spend a while struggling to figure out what you've done wrong. This rule protects against that confusion by ensuring that within a single rule you don't use property values that are ruled out by other property values in that same rule.
The rule warns when it finds:
- `display: inline` used with `width`, `height`, `margin`, `margin-top`, `margin-bottom`, `overflow` (and all variants).
- `display: list-item` used with `vertical-align`.
- `display: block` used with `vertical-align`.
- `display: flex` used with `vertical-align`.
- `display: table` used with `vertical-align`.
- `display: table-*` used with `margin` (and all variants).
- `display: table-*` (except `table-cell`) used with `vertical-align`.
- `display: table-(row|row-group)` used with `width`, `min-width` or `max-width`.
- `display: table-(column|column-group)` used with `height`, `min-height` or `max-height`.
- `float: left` and `float: right` used with `vertical-align`.
- `position: static` used with `top`, `right`, `bottom`, or `left`.
- `position: absolute` used with `float`, `clear` or `vertical-align`.
- `position: fixed` used with `float`, `clear` or `vertical-align`.
## Options
### `true`
The following patterns are considered warnings:
```css
a { display: inline; width: 100px; }
```
`display: inline` causes `width` to be ignored.
```css
a { display: inline; height: 100px; }
```
`display: inline` causes `height` to be ignored.
```css
a { display: inline; margin: 10px; }
```
`display: inline` causes `margin` to be ignored.
```css
a { display: block; vertical-align: baseline; }
```
`display: block` causes `vertical-align` to be ignored.
```css
a { display: flex; vertical-align: baseline; }
```
`display: flex` causes `vertical-align` to be ignored.
```css
a { position: absolute; vertical-align: baseline; }
```
`position: absolute` causes `vertical-align` to be ignored.
```css
a { float: left; vertical-align: baseline; }
```
`float: left` causes `vertical-align` to be ignored.
The following patterns are *not* considered warnings:
```css
a { display: inline: margin-left: 10px; }
```
```css
a { display: inline: margin-right: 10px; }
```
```css
a { display: inline: padding: 10px; }
```
```css
a { display: inline-block; width: 100px; }
```
Although `display: inline` causes `width` to be ignored, `inline-block` works with `width`.
```css
a { display: table-cell; vertical-align: baseline; }
```
Although `display: block` causes `vertical-align` to be ignored, `table-cell` works with `vertical-align`.
```css
a { position: relative; vertical-align: baseline; }
```
Although `position: absolute` causes `vertical-align` to be ignored, `relative` works with `vertical-align`.

View File

@@ -0,0 +1,182 @@
"use strict"
const matchesStringOrRegExp = require("../../utils/matchesStringOrRegExp")
const postcss = require("postcss")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
const validateOptions = require("../../utils/validateOptions")
const ruleName = "declaration-block-no-ignored-properties"
const messages = ruleMessages(ruleName, {
rejected: (ignored, cause) => `Unexpected "${ignored}" with "${cause}"`,
})
const ignored = [
{
property: "display",
value: "inline",
ignoredProperties: [
"width",
"min-width",
"max-width",
"height",
"min-height",
"max-height",
"margin",
"margin-top",
"margin-bottom",
"overflow",
"overflow-x",
"overflow-y",
],
},
{
property: "display",
value: "list-item",
ignoredProperties: ["vertical-align"],
},
{
property: "display",
value: "block",
ignoredProperties: ["vertical-align"],
},
{
property: "display",
value: "flex",
ignoredProperties: ["vertical-align"],
},
{
property: "display",
value: "table",
ignoredProperties: ["vertical-align"],
},
{
property: "display",
value: "/^table-.*$/",
ignoredProperties: [
"margin",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
],
},
{
property: "display",
value: "/^table-(row|row-group|column|column-group|header-group|footer-group|caption).*$/",
ignoredProperties: ["vertical-align"],
},
{
property: "display",
value: "/^table-(row|row-group).*$/",
ignoredProperties: [
"width",
"min-width",
"max-width",
],
},
{
property: "display",
value: "/^table-(column|column-group).*$/",
ignoredProperties: [
"height",
"min-height",
"max-height",
],
},
{
property: "float",
value: "left",
ignoredProperties: ["vertical-align"],
},
{
property: "float",
value: "right",
ignoredProperties: ["vertical-align"],
},
{
property: "position",
value: "static",
ignoredProperties: [
"top",
"right",
"bottom",
"left",
],
},
{
property: "position",
value: "absolute",
ignoredProperties: [
"float",
"clear",
"vertical-align",
],
},
{
property: "position",
value: "fixed",
ignoredProperties: [
"float",
"clear",
"vertical-align",
],
},
]
const rule = function (actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual })
if (!validOptions) {
return
}
result.warn((
"'declaration-block-no-ignored-properties' has been deprecated and in 8.0 will be removed."
), {
stylelintType: "deprecation",
stylelintReference: "https://stylelint.io/user-guide/rules/declaration-block-no-ignored-properties/",
})
const uniqueDecls = {}
root.walkDecls(decl => {
uniqueDecls[decl.prop] = decl
})
Object.keys(uniqueDecls).forEach((prop, index) => {
const decl = uniqueDecls[prop]
const unprefixedProp = postcss.vendor.unprefixed(prop)
const unprefixedValue = postcss.vendor.unprefixed(decl.value)
ignored.forEach(ignore => {
const matchProperty = matchesStringOrRegExp(unprefixedProp.toLowerCase(), ignore.property)
const matchValue = matchesStringOrRegExp(unprefixedValue.toLowerCase(), ignore.value)
if (!matchProperty || !matchValue) {
return
}
const ignoredProperties = ignore.ignoredProperties
decl.parent.nodes.forEach((node, nodeIndex) => {
if (!node.prop || ignoredProperties.indexOf(node.prop.toLowerCase()) === -1 || index === nodeIndex) {
return
}
report({
message: messages.rejected(node.prop, decl.toString()),
node,
result,
ruleName,
})
})
})
})
}
}
rule.ruleName = ruleName
rule.messages = messages
module.exports = rule