mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
|
export const PASS = 'pass';
|
||
|
export const WARNING = 'warning';
|
||
|
export const ERROR = 'error';
|
||
|
|
||
|
export type STATUS = typeof PASS | typeof WARNING | typeof ERROR;
|
||
|
|
||
|
export default (line: string) => {
|
||
|
// Compile error
|
||
|
if (line.includes('&')) {
|
||
|
return ERROR;
|
||
|
}
|
||
|
|
||
|
// Fix number
|
||
|
const ignoreStyle = [
|
||
|
'font-size',
|
||
|
'line-height',
|
||
|
'border',
|
||
|
'border-',
|
||
|
'opacity',
|
||
|
'color',
|
||
|
'z-index',
|
||
|
'background',
|
||
|
'background-',
|
||
|
'vertical-align',
|
||
|
'flex',
|
||
|
'width',
|
||
|
'height',
|
||
|
'transition',
|
||
|
'animation',
|
||
|
'animation-',
|
||
|
'transform',
|
||
|
];
|
||
|
const [propName, propValue] = line.split(/:\s+|;/).map(s => s.trim());
|
||
|
|
||
|
if (
|
||
|
propName &&
|
||
|
propValue &&
|
||
|
!ignoreStyle.some(
|
||
|
styleName =>
|
||
|
styleName === propName || (styleName.endsWith('-') && propName.includes(styleName)),
|
||
|
) &&
|
||
|
!line.includes('{') &&
|
||
|
!line.includes(',')
|
||
|
) {
|
||
|
const numberMatch = propValue.match(/\d+(\.\d+)?[\w%]+/g) || [];
|
||
|
|
||
|
for (let j = 0; j < numberMatch.length; j += 1) {
|
||
|
const str = numberMatch[j];
|
||
|
|
||
|
if (str.endsWith('%') || str.endsWith('em')) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
const num = Number(str.match(/\d+(\.\d+)?/g)?.[0] || 0);
|
||
|
if (num % 4 !== 0) {
|
||
|
return WARNING;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return PASS;
|
||
|
};
|