UNPKG

534 BJavaScriptView Raw
1'use strict';
2
3/**
4 * Detect not minified CSS
5 */
6function rule(analyzer) {
7 analyzer.setMetric('notMinified');
8
9 /**
10 * A simple CSS minification detector
11 */
12 function isMinified(css) {
13 // analyze the first 1024 characters
14 css = css.trim().substring(0, 1024);
15
16 // there should be no newline in minified file
17 return /\n/.test(css) === false;
18 }
19
20 analyzer.on('css', function(css) {
21 analyzer.setMetric('notMinified', isMinified(css) ? 0 : 1);
22 });
23}
24
25rule.description = 'Reports not minified CSS ';
26module.exports = rule;