UNPKG

1.37 kBJavaScriptView Raw
1"use strict";
2
3var format = require("util").format;
4
5/**
6 * Rules below match ugly fixes for IE9 and below
7 *
8 * @see http://browserhacks.com/
9 * @param { import("../lib/css-analyzer") } analyzer
10 */
11function rule(analyzer) {
12 var re = {
13 property: /^(\*|-ms-filter)/,
14 selector: /^(\* html|html\s?>\s?body) /,
15 value: /progid:DXImageTransform\.Microsoft|!ie$/,
16 };
17
18 analyzer.setMetric("oldIEFixes");
19
20 // * html // below IE7 fix
21 // html>body // IE6 excluded fix
22 // @see http://blogs.msdn.com/b/ie/archive/2005/09/02/460115.aspx
23 analyzer.on("selector", function (rule, selector) {
24 if (re.selector.test(selector)) {
25 analyzer.incrMetric("oldIEFixes");
26 analyzer.addOffender("oldIEFixes", selector);
27 }
28 });
29
30 // *foo: bar // IE7 and below fix
31 // -ms-filter // IE9 and below specific property
32 // !ie // IE 7 and below equivalent of !important
33 // @see http://www.impressivewebs.com/ie7-ie8-css-hacks/
34 analyzer.on("declaration", function (rule, property, value) {
35 if (re.property.test(property) || re.value.test(value)) {
36 analyzer.incrMetric("oldIEFixes");
37 analyzer.addOffender(
38 "oldIEFixes",
39 format("%s {%s: %s}", rule.selectors.join(", "), property, value)
40 );
41 }
42 });
43}
44
45rule.description =
46 "Reports fixes for old versions of Internet Explorer (IE9 and below)";
47module.exports = rule;