diff --git a/lib/rules/alpha-value-notation/__tests__/index.js b/lib/rules/alpha-value-notation/__tests__/index.js index 497a6d1d90..abee5d8730 100644 --- a/lib/rules/alpha-value-notation/__tests__/index.js +++ b/lib/rules/alpha-value-notation/__tests__/index.js @@ -124,6 +124,22 @@ testRule({ { message: messages.expected('40%', '0.4'), line: 5, column: 29 }, ], }, + { + code: 'a { opacity: 14% }', + fixed: 'a { opacity: 0.14 }', + message: messages.expected('14%', '0.14'), + line: 1, + column: 14, + description: 'properly deals with floating-point conversions', + }, + { + code: 'a { opacity: 0.3% }', + fixed: 'a { opacity: 0.003 }', + message: messages.expected('0.3%', '0.003'), + line: 1, + column: 14, + description: 'properly deals with floating-point conversions', + }, ], }); @@ -199,6 +215,22 @@ testRule({ { message: messages.expected('0.40', '40%'), line: 5, column: 29 }, ], }, + { + code: 'a { opacity: 0.14 }', + fixed: 'a { opacity: 14% }', + message: messages.expected('0.14', '14%'), + line: 1, + column: 14, + description: 'properly deals with floating-point conversions', + }, + { + code: 'a { opacity: 0.003 }', + fixed: 'a { opacity: 0.3% }', + message: messages.expected('0.003', '0.3%'), + line: 1, + column: 14, + description: 'properly deals with floating-point conversions', + }, ], }); diff --git a/lib/rules/alpha-value-notation/index.js b/lib/rules/alpha-value-notation/index.js index c8c2798f50..45c270c1fb 100644 --- a/lib/rules/alpha-value-notation/index.js +++ b/lib/rules/alpha-value-notation/index.js @@ -115,13 +115,13 @@ function rule(primary, options, context) { } function asPercentage(value) { - return `${value * 100}%`; + return `${Number((value * 100).toPrecision(3))}%`; } function asNumber(value) { const { number } = valueParser.unit(value); - return number / 100; + return Number((number / 100).toPrecision(3)); } function findAlphaInValue(node) {