Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a1ae78
commit fbfdb59
Showing
7 changed files
with
175 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": patch | ||
--- | ||
|
||
Fixed: `block-no-empty` false positives for `reportNeedlessDisables` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const postcss = require('postcss'); | ||
|
||
const { extractStylelintCommand, isStylelintCommand } = require('../stylelintCommand'); | ||
|
||
test('extractStylelintCommand', () => { | ||
expect(extractStylelintCommand(comment('stylelint-disable'))).toBe('stylelint-disable'); | ||
expect(extractStylelintCommand(comment('stylelint-disable '))).toBe('stylelint-disable'); | ||
expect(extractStylelintCommand(comment('stylelint-disable\t'))).toBe('stylelint-disable'); | ||
expect(extractStylelintCommand(comment('stylelint-disable --'))).toBe('stylelint-disable'); | ||
|
||
expect(extractStylelintCommand(comment(''))).toBe(''); | ||
expect(extractStylelintCommand(comment(' '))).toBe(''); | ||
expect(extractStylelintCommand(comment('\t'))).toBe(''); | ||
}); | ||
|
||
test('isStylelintCommand', () => { | ||
expect(isStylelintCommand(comment('stylelint-disable'))).toBe(true); | ||
expect(isStylelintCommand(comment('stylelint-disable-line'))).toBe(true); | ||
expect(isStylelintCommand(comment('stylelint-disable-next-line'))).toBe(true); | ||
expect(isStylelintCommand(comment('stylelint-enable'))).toBe(true); | ||
|
||
expect(isStylelintCommand(comment('stylelint-'))).toBe(false); | ||
expect(isStylelintCommand(comment('stylelint-disable-'))).toBe(false); | ||
expect(isStylelintCommand(comment('stylelint-disable-lineee'))).toBe(false); | ||
expect(isStylelintCommand(comment('stylelint-disable-next'))).toBe(false); | ||
expect(isStylelintCommand(comment('stylelint-enable-'))).toBe(false); | ||
expect(isStylelintCommand(comment(''))).toBe(false); | ||
expect(isStylelintCommand(comment(' '))).toBe(false); | ||
expect(isStylelintCommand(comment('\t'))).toBe(false); | ||
}); | ||
|
||
function comment(text) { | ||
return postcss.comment({ text }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
'use strict'; | ||
|
||
const hasBlock = require('./hasBlock'); | ||
|
||
/** | ||
* Check if a statement has an empty block. | ||
* | ||
* @param {import('postcss').Rule | import('postcss').AtRule} statement - postcss rule or at-rule node | ||
* @return {boolean} True if the statement has a block and it is empty | ||
*/ | ||
module.exports = function hasEmptyBlock(statement) { | ||
return ( | ||
statement.nodes !== undefined && statement.nodes.length === 0 // has block | ||
); // and is empty | ||
return hasBlock(statement) && statement.nodes.length === 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const { assertString } = require('./validateTypes'); | ||
|
||
const DISABLE_COMMAND = 'stylelint-disable'; | ||
const DISABLE_LINE_COMMAND = 'stylelint-disable-line'; | ||
const DISABLE_NEXT_LINE_COMMAND = 'stylelint-disable-next-line'; | ||
const ENABLE_COMMAND = 'stylelint-enable'; | ||
|
||
const ALL_COMMANDS = new Set([ | ||
DISABLE_COMMAND, | ||
DISABLE_LINE_COMMAND, | ||
DISABLE_NEXT_LINE_COMMAND, | ||
ENABLE_COMMAND, | ||
]); | ||
|
||
/** @typedef {import('postcss').Comment} Comment */ | ||
|
||
/** | ||
* Extract a command from a given comment. | ||
* | ||
* @param {Comment} comment | ||
* @returns {string} | ||
*/ | ||
function extractStylelintCommand(comment) { | ||
const [command] = comment.text.split(/\s/, 1); | ||
|
||
assertString(command); | ||
|
||
return command; | ||
} | ||
|
||
/** | ||
* Tests if the given comment is a Stylelint command. | ||
* | ||
* @param {Comment} comment | ||
* @returns {boolean} | ||
*/ | ||
function isStylelintCommand(comment) { | ||
const command = extractStylelintCommand(comment); | ||
|
||
return command !== undefined && ALL_COMMANDS.has(command); | ||
} | ||
|
||
module.exports = { | ||
DISABLE_COMMAND, | ||
DISABLE_LINE_COMMAND, | ||
DISABLE_NEXT_LINE_COMMAND, | ||
ENABLE_COMMAND, | ||
|
||
extractStylelintCommand, | ||
isStylelintCommand, | ||
}; |