UNPKG

729 BJavaScriptView Raw
1"use strict";
2
3const format = require("util").format,
4 MAX_LENGTH = 256;
5
6/**
7 * @param { import("../lib/css-analyzer") } analyzer
8 */
9function rule(analyzer) {
10 analyzer.setMetric("comments");
11 analyzer.setMetric("commentsLength");
12
13 analyzer.on("comment", function (comment) {
14 analyzer.incrMetric("comments");
15 analyzer.incrMetric("commentsLength", comment.length);
16
17 // report too long comments
18 if (comment.length > MAX_LENGTH) {
19 analyzer.addOffender(
20 "comments",
21 format(
22 '"%s" is too long (%d characters)',
23 comment.substr(0, 100),
24 comment.length
25 )
26 );
27 }
28 });
29}
30
31rule.description = "Reports too long CSS comments";
32module.exports = rule;