Skip to content

Commit

Permalink
Fix: Refactor valueTimeCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaguchi1102 committed Sep 6, 2022
1 parent f9d3746 commit 7be15a3
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lib/rules/time-min-milliseconds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const rule = (primary, secondaryOptions) => {

if (!shorthandTimeProperties.has(propertyName)) return;

isValueTimeCount = valueTimeCheck(value, isValueTimeCount);
isValueTimeCount = valueTimeCheck(dimension, value, isValueTimeCount);

if (isAcceptableTime(dimension) || (ignoreDelay && isValueTimeCount !== 1)) return;

Expand All @@ -79,32 +79,21 @@ const rule = (primary, secondaryOptions) => {
});

/**
* @param {import('postcss-value-parser').Dimension | {unit: null, number: null}} dimension
* @param {string} value
* @param {number} valueTimeCount
* @returns {number}
*/
function valueTimeCheck(value, valueTimeCount) {
if (isTime(value)) valueTimeCount++;
function valueTimeCheck(dimension, value, valueTimeCount) {
const { unit } = dimension;

if (unit !== null) valueTimeCount++;

if (value === ',') valueTimeCount = 0;

return valueTimeCount;
}

/**
* @param {string} time
* @returns {boolean}
*/
function isTime(time) {
const parsedTime = valueParser.unit(time);

if (!parsedTime) return false;

const unit = parsedTime.unit.toLowerCase();

return unit === 'ms' || unit === 's';
}

/**
* @param {string} propertyName
* @returns {boolean}
Expand Down

0 comments on commit 7be15a3

Please sign in to comment.