UNPKG

1.25 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 */
10function rule(analyzer) {
11 var re = {
12 property: /^(\*|-ms-filter)/,
13 selector: /^(\* html|html\s?>\s?body) /,
14 value: /progid:DXImageTransform\.Microsoft|!ie$/
15 };
16
17 analyzer.setMetric('oldIEFixes');
18
19 // * html // below IE7 fix
20 // html>body // IE6 excluded fix
21 // @see http://blogs.msdn.com/b/ie/archive/2005/09/02/460115.aspx
22 analyzer.on('selector', function(rule, selector) {
23 if (re.selector.test(selector)) {
24 analyzer.incrMetric('oldIEFixes');
25 analyzer.addOffender('oldIEFixes', selector);
26 }
27 });
28
29 // *foo: bar // IE7 and below fix
30 // -ms-filter // IE9 and below specific property
31 // !ie // IE 7 and below equivalent of !important
32 // @see http://www.impressivewebs.com/ie7-ie8-css-hacks/
33 analyzer.on('declaration', function(rule, property, value) {
34 if (re.property.test(property) || re.value.test(value)) {
35 analyzer.incrMetric('oldIEFixes');
36 analyzer.addOffender('oldIEFixes', format('%s {%s: %s}', rule.selectors.join(', '), property, value));
37 }
38 });
39}
40
41rule.description = 'Reports fixes for old versions of Internet Explorer (IE9 and below)';
42module.exports = rule;