• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ota-meshi / eslint-plugin-css / 7322741852

25 Dec 2023 03:25PM UTC coverage: 87.256%. Remained the same
7322741852

push

github

web-flow
chore(deps): update dependency stylelint-config-standard to v36 (#124)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

999 of 1210 branches covered (0.0%)

Branch coverage included in aggregate %.

1240 of 1356 relevant lines covered (91.45%)

56.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.91
/lib/rules/no-number-trailing-zeros.ts
1
import type { CSSObjectContext, CSSVisitorHandlers } from "../utils";
2
import { createRule, defineCSSVisitor } from "../utils";
1✔
3

4
export default createRule("no-number-trailing-zeros", {
1✔
5
  meta: {
6
    docs: {
7
      description: "disallow trailing zeros in numbers.",
8
      category: "Stylistic Issues",
9
      recommended: false,
10
      standard: true,
11
      stylelint: "number-no-trailing-zeros",
12
    },
13
    fixable: "code",
14
    schema: [],
15
    messages: {
16
      unexpected: "Unexpected trailing zero(s).",
17
    },
18
    type: "layout",
19
  },
20
  create(context) {
21
    /**
22
     * Create visitor
23
     */
24
    function createVisitor(cssContext: CSSObjectContext): CSSVisitorHandlers {
25
      const sourceCode = context.getSourceCode();
6✔
26
      return {
6✔
27
        onProperty(property) {
28
          const value = property.getValue();
6✔
29
          if (!value) {
6!
30
            return;
×
31
          }
32
          if (typeof value.value === "number" || !value.value.includes(".")) {
6!
33
            return;
×
34
          }
35
          value.parsed.walk((node) => {
6✔
36
            // Ignore `url` function
37
            if (
6!
38
              node.type === "function" &&
6!
39
              node.value.toLowerCase() === "url"
40
            ) {
41
              return false;
×
42
            }
43
            if (node.type !== "word") {
6!
44
              return undefined;
×
45
            }
46
            const match = /\.(?<num>\d{0,100}?)(?<zeros>0+)(?:\D|$)/u.exec(
6✔
47
              node.value,
48
            );
49

50
            if (match == null) {
6✔
51
              return undefined;
4✔
52
            }
53

54
            const startIndex =
55
              value.expression.range![0] +
2✔
56
              node.sourceIndex +
57
              match.index +
58
              1 /* dot */ +
59
              match.groups!.num.length +
60
              1; /* quote */
61
            const endIndex = startIndex + match.groups!.zeros.length;
2✔
62

63
            const loc = value.directExpression
2!
64
              ? {
65
                  start: sourceCode.getLocFromIndex(startIndex),
66
                  end: sourceCode.getLocFromIndex(endIndex),
67
                }
68
              : undefined;
69

70
            context.report({
2✔
71
              node: value.expression,
72
              loc,
73
              messageId: "unexpected",
74
              fix(fixer) {
75
                if (
2!
76
                  cssContext.isFixable(value.directExpression) &&
4✔
77
                  /^0+$/u.test(sourceCode.text.slice(startIndex, endIndex))
78
                ) {
79
                  return fixer.removeRange([startIndex, endIndex]);
2✔
80
                }
81
                return null;
×
82
              },
83
            });
84
            return undefined;
2✔
85
          });
86
        },
87
      };
88
    }
89

90
    return defineCSSVisitor(context, {
6✔
91
      createVisitor,
92
    });
93
  },
94
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc