-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't apply
properties-alphabetical-order
autofixing if there are n…
- Loading branch information
Showing
5 changed files
with
79 additions
and
54 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,55 @@ | ||
import { isStandardSyntaxProperty } from '../../utils/isStandardSyntaxProperty.js'; | ||
import { isCustomProperty } from '../../utils/isCustomProperty.js'; | ||
import * as vendor from '../../utils/vendor.js'; | ||
import { checkAlphabeticalOrder } from '../checkAlphabeticalOrder.js'; | ||
|
||
export function checkChild(child, allPropData) { | ||
if (child.type !== 'decl') { | ||
return null; | ||
} | ||
|
||
let { prop } = child; | ||
|
||
if (!isStandardSyntaxProperty(prop)) { | ||
return null; | ||
} | ||
|
||
if (isCustomProperty(prop)) { | ||
return null; | ||
} | ||
|
||
let unprefixedPropName = vendor.unprefixed(prop); | ||
|
||
// Hack to allow -moz-osx-font-smoothing to be understood | ||
// just like -webkit-font-smoothing | ||
if (unprefixedPropName.startsWith('osx-')) { | ||
unprefixedPropName = unprefixedPropName.slice(4); | ||
} | ||
|
||
let propData = { | ||
name: prop, | ||
unprefixedName: unprefixedPropName, | ||
index: allPropData.length, | ||
node: child, | ||
}; | ||
|
||
let previousPropData = allPropData[allPropData.length - 1]; // eslint-disable-line unicorn/prefer-at -- Need to support older Node.js | ||
|
||
allPropData.push(propData); | ||
|
||
// Skip first decl | ||
if (!previousPropData) { | ||
return null; | ||
} | ||
|
||
let isCorrectOrder = checkAlphabeticalOrder(previousPropData, propData); | ||
|
||
if (isCorrectOrder) { | ||
return null; | ||
} | ||
|
||
return { | ||
expectedFirst: propData.name, | ||
expectedSecond: previousPropData.name, | ||
}; | ||
} |
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,63 +1,20 @@ | ||
import stylelint from 'stylelint'; | ||
import { checkAlphabeticalOrder } from '../checkAlphabeticalOrder.js'; | ||
import { isCustomProperty } from '../../utils/isCustomProperty.js'; | ||
import { isStandardSyntaxProperty } from '../../utils/isStandardSyntaxProperty.js'; | ||
import * as vendor from '../../utils/vendor.js'; | ||
import { checkChild } from './checkChild.js'; | ||
|
||
// eslint-disable-next-line max-params | ||
export function checkNode(node, result, ruleName, messages) { | ||
let allPropData = []; | ||
|
||
node.each(function processEveryNode(child) { | ||
if (child.type !== 'decl') { | ||
return; | ||
const problem = checkChild(child, allPropData); | ||
|
||
if (problem) { | ||
stylelint.utils.report({ | ||
message: messages.expected(problem.expectedFirst, problem.expectedSecond), | ||
node: child, | ||
result, | ||
ruleName, | ||
}); | ||
} | ||
|
||
let { prop } = child; | ||
|
||
if (!isStandardSyntaxProperty(prop)) { | ||
return; | ||
} | ||
|
||
if (isCustomProperty(prop)) { | ||
return; | ||
} | ||
|
||
let unprefixedPropName = vendor.unprefixed(prop); | ||
|
||
// Hack to allow -moz-osx-font-smoothing to be understood | ||
// just like -webkit-font-smoothing | ||
if (unprefixedPropName.startsWith('osx-')) { | ||
unprefixedPropName = unprefixedPropName.slice(4); | ||
} | ||
|
||
let propData = { | ||
name: prop, | ||
unprefixedName: unprefixedPropName, | ||
index: allPropData.length, | ||
node: child, | ||
}; | ||
|
||
let previousPropData = allPropData[allPropData.length - 1]; // eslint-disable-line unicorn/prefer-at -- Need to support older Node.js | ||
|
||
allPropData.push(propData); | ||
|
||
// Skip first decl | ||
if (!previousPropData) { | ||
return; | ||
} | ||
|
||
let isCorrectOrder = checkAlphabeticalOrder(previousPropData, propData); | ||
|
||
if (isCorrectOrder) { | ||
return; | ||
} | ||
|
||
stylelint.utils.report({ | ||
message: messages.expected(propData.name, previousPropData.name), | ||
node: child, | ||
result, | ||
ruleName, | ||
}); | ||
}); | ||
} |
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,9 @@ | ||
import { checkChild } from './checkChild.js'; | ||
|
||
export function isOrderCorrect(node) { | ||
const allPropData = []; | ||
|
||
return node.every(function isChildCorrect(child) { | ||
return !checkChild(child, allPropData); | ||
}); | ||
} |
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