Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: deprecated 'blockless-group' in favor of 'blockless-after-blockless' #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ stylefmt :heart: stylelint

stylefmt supports the following stylelint rules:

- [at-rule-empty-line-before](https://github.com/stylelint/stylelint/tree/master/lib/rules/at-rule-empty-line-before) ("always"|"never" and except "blockless-group" only)
- [at-rule-empty-line-before](https://github.com/stylelint/stylelint/tree/master/lib/rules/at-rule-empty-line-before) ("always"|"never" and except "blockless-after-blockless" only)
- [at-rule-semicolon-newline-after](https://github.com/stylelint/stylelint/tree/master/lib/rules/at-rule-semicolon-newline-after)
- [block-closing-brace-newline-after](https://github.com/stylelint/stylelint/tree/master/lib/rules/block-closing-brace-newline-after)
- [block-closing-brace-newline-before](https://github.com/stylelint/stylelint/tree/master/lib/rules/block-closing-brace-newline-before)
Expand Down
2 changes: 1 addition & 1 deletion compositor.json

Large diffs are not rendered by default.

51 changes: 24 additions & 27 deletions lib/formatAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var util = require('./util')
var getProperty = util.getProperty
var getOptions = util.getOptions

function formatAtRules (root, params) {
function formatAtRules(root, params) {
var stylelint = params.stylelint
var indentWidth = params.indentWidth

Expand Down Expand Up @@ -103,9 +103,9 @@ function formatAtRules (root, params) {
}

if (atrule.name === 'extend' ||
atrule.name === 'debug' ||
atrule.name === 'warn' ||
atrule.name === 'error' ) {
atrule.name === 'debug' ||
atrule.name === 'warn' ||
atrule.name === 'error') {
atrule.params = atrule.params.replace(/\s+/g, " ")
atrule.raws.before = '\n' + indentation
atrule.raws.between = ''
Expand Down Expand Up @@ -158,12 +158,12 @@ function formatAtRules (root, params) {
}
}

if (atrule.name === 'return' ||
atrule.name === 'custom-media' ||
atrule.name === 'custom-selector' ||
atrule.name === 'apply' ||
atrule.name === 'at-root' ||
/viewport$/.test(atrule.name)) {
if (atrule.name === 'return' ||
atrule.name === 'custom-media' ||
atrule.name === 'custom-selector' ||
atrule.name === 'apply' ||
atrule.name === 'at-root' ||
/viewport$/.test(atrule.name)) {
atrule.raws.between = ''
}

Expand All @@ -172,24 +172,21 @@ function formatAtRules (root, params) {
atRuleEmptyLineBefore = atRuleEmptyLineBefore === 'always' ? true : false
var ignore = false
var ignoreOptions = getOptions(params.stylelint, 'at-rule-empty-line-before', 'ignore')
if ( ignoreOptions && ((ignoreOptions.indexOf('all-nested') > -1 && isNested)
if (ignoreOptions && ((ignoreOptions.indexOf('all-nested') > -1 && isNested)
|| (ignoreOptions.indexOf('inside-block') > -1 && isNested)
|| (ignoreOptions.indexOf('blockless-group') > -1 && isBlocklessGroup(prev, atrule))
|| (ignoreOptions.indexOf('blockless-after-blockless') > -1 && isBlocklessAfterBlockless(prev, atrule))
|| (ignoreOptions.indexOf('blockless-after-same-name-blockless') > -1 && isBlocklessAfterSameNameBlockless(prev, atrule))
|| (ignoreOptions.indexOf('after-comment') > -1 && isAfterComment(prev))))

{
|| (ignoreOptions.indexOf('after-comment') > -1 && isAfterComment(prev)))) {
atrule.raws.before = origAtRuleBefore
ignore = true
}

var exceptOptions = getOptions(params.stylelint, 'at-rule-empty-line-before', 'except')
if ( exceptOptions && ((exceptOptions.indexOf('all-nested') > -1 && isNested)
if (exceptOptions && ((exceptOptions.indexOf('all-nested') > -1 && isNested)
|| (exceptOptions.indexOf('inside-block') > -1 && isNested)
|| (exceptOptions.indexOf('first-nested') > -1 && isFirstNested(prev, atrule, isNested))
|| (exceptOptions.indexOf('blockless-group') > -1 && isBlocklessGroup(prev, atrule))
|| (exceptOptions.indexOf('blockless-after-same-name-blockless') > -1 && isBlocklessAfterSameNameBlockless(prev, atrule))))
{
|| (exceptOptions.indexOf('blockless-after-blockless') > -1 && isBlocklessAfterBlockless(prev, atrule))
|| (exceptOptions.indexOf('blockless-after-same-name-blockless') > -1 && isBlocklessAfterSameNameBlockless(prev, atrule)))) {
atRuleEmptyLineBefore = !atRuleEmptyLineBefore
}

Expand All @@ -212,29 +209,29 @@ function formatAtRules (root, params) {
return root
}

function isAfterComment (prev) {
function isAfterComment(prev) {
return (
prev
&& prev.type === "comment"
)
}

function isFirstNested (prev, atrule, isNested) {
function isFirstNested(prev, atrule, isNested) {
return (
isNested
&& atrule === atrule.parent.first
)
}

function isBlocklessGroup (prev, atrule) {
function isBlocklessAfterBlockless(prev, atrule) {
return (
prev && prev.type === "atrule"
&& !hasBlock(prev)
&& !hasBlock(atrule)
)
}

function isBlocklessAfterSameNameBlockless (prev, atrule) {
function isBlocklessAfterSameNameBlockless(prev, atrule) {
return (
!hasBlock(atrule)
&& prev && !hasBlock(prev)
Expand All @@ -243,7 +240,7 @@ function isBlocklessAfterSameNameBlockless (prev, atrule) {
)
}

function blockOpeningBraceNewlineBefore (atrule, opts) {
function blockOpeningBraceNewlineBefore(atrule, opts) {
if (isIgnoreRule(opts.stylelint, atrule)) {
return atrule.raws.between
}
Expand Down Expand Up @@ -275,7 +272,7 @@ function blockOpeningBraceNewlineBefore (atrule, opts) {
}
}

function isIgnoreRule (stylelint, css) {
function isIgnoreRule(stylelint, css) {
if (!stylelint.ignoreAtRules) {
return false
}
Expand All @@ -284,8 +281,8 @@ function isIgnoreRule (stylelint, css) {
})
}

function isElseIf (params) {
return /if/.test(params)
function isElseIf(params) {
return /if/.test(params)
}

module.exports = formatAtRules
14 changes: 7 additions & 7 deletions test/ignore/extend-stylelint.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
"rules": {
"at-rule-empty-line-before": [ "always", {
except: [ "blockless-group" ]
} ],
"at-rule-empty-line-before": ["always", {
except: ["blockless-after-blockless"]
}],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
Expand All @@ -16,10 +16,10 @@ module.exports = {
"color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
"comment-empty-line-before": ["always", {
except: ["first-nested"],
ignore: ["stylelint-commands"],
} ],
}],
"comment-whitespace-inside": "always",
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
Expand Down Expand Up @@ -62,9 +62,9 @@ module.exports = {
"number-no-trailing-zeros": true,
"length-zero-no-unit": true,
"property-case": "lower",
"rule-non-nested-empty-line-before": [ "always-multi-line", {
"rule-non-nested-empty-line-before": ["always-multi-line", {
ignore: ["after-comment"],
} ],
}],
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"rules": {
"at-rule-empty-line-before": ["always", {
except: ["blockless-group"]
}],
"at-rule-empty-line-before": [
"always",
{
except: [
"blockless-after-blockless"
]
}
],
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"rules": {
"at-rule-empty-line-before": ["always", {
ignore: ["blockless-group"]
}],
"at-rule-empty-line-before": [
"always",
{
ignore: [
"blockless-after-blockless"
]
}
],
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"rules": {
"at-rule-empty-line-before": ["never", {
except: ["blockless-group"]
}],
"at-rule-empty-line-before": [
"never",
{
except: [
"blockless-after-blockless"
]
}
],
}
}
}
14 changes: 7 additions & 7 deletions test/stylelint/extends/extend-stylelint.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
"rules": {
"at-rule-empty-line-before": [ "always", {
except: [ "blockless-group" ]
} ],
"at-rule-empty-line-before": ["always", {
except: ["blockless-after-blockless"]
}],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
Expand All @@ -16,10 +16,10 @@ module.exports = {
"color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
"comment-empty-line-before": ["always", {
except: ["first-nested"],
ignore: ["stylelint-commands"],
} ],
}],
"comment-whitespace-inside": "always",
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
Expand Down Expand Up @@ -62,9 +62,9 @@ module.exports = {
"number-no-trailing-zeros": true,
"length-zero-no-unit": true,
"property-case": "lower",
"rule-non-nested-empty-line-before": [ "always-multi-line", {
"rule-non-nested-empty-line-before": ["always-multi-line", {
ignore: ["after-comment"],
} ],
}],
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
Expand Down
14 changes: 7 additions & 7 deletions test/stylelint/extends2/extend-stylelint2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
"rules": {
"at-rule-empty-line-before": [ "always", {
except: [ "blockless-group" ]
} ],
"at-rule-empty-line-before": ["always", {
except: ["blockless-after-blockless"]
}],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
Expand All @@ -16,10 +16,10 @@ module.exports = {
"color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
"comment-empty-line-before": ["always", {
except: ["first-nested"],
ignore: ["stylelint-commands"],
} ],
}],
"comment-whitespace-inside": "always",
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
Expand Down Expand Up @@ -62,9 +62,9 @@ module.exports = {
"number-no-trailing-zeros": true,
"length-zero-no-unit": true,
"property-case": "lower",
"rule-non-nested-empty-line-before": [ "always-multi-line", {
"rule-non-nested-empty-line-before": ["always-multi-line", {
ignore: ["after-comment"],
} ],
}],
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
Expand Down
10 changes: 5 additions & 5 deletions test/stylelint/extends3/extend-stylelint2.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
"extends": "./extend-stylelint3.js",
"rules": {
"at-rule-empty-line-before": [ "always", {
except: [ "blockless-group" ]
} ],
"at-rule-empty-line-before": ["always", {
except: ["blockless-after-blockless"]
}],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
Expand All @@ -17,10 +17,10 @@ module.exports = {
"color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
"comment-empty-line-before": ["always", {
except: ["first-nested"],
ignore: ["stylelint-commands"],
} ],
}],
"comment-whitespace-inside": "always",
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
Expand Down
Loading