Socket
Socket
Sign inDemoInstall

stylehacks

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylehacks - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

dist/plugins/htmlCombinatorCommentBody.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 2.1.0
* Added `html ~ /**/ body .selector` hack.
* Added a method to detect if a PostCSS node has any hacks.
# 2.0.0

@@ -2,0 +7,0 @@

15

dist/index.js

@@ -31,2 +31,6 @@ 'use strict';

var _pluginsHtmlCombinatorCommentBody = require('./plugins/htmlCombinatorCommentBody');
var _pluginsHtmlCombinatorCommentBody2 = _interopRequireDefault(_pluginsHtmlCombinatorCommentBody);
var _pluginsHtmlFirstChild = require('./plugins/htmlFirstChild');

@@ -64,3 +68,3 @@

var plugins = [_pluginsBodyEmpty2['default'], _pluginsHtmlFirstChild2['default'], _pluginsImportant2['default'], _pluginsLeadingStar2['default'], _pluginsLeadingUnderscore2['default'], _pluginsMediaSlash02['default'], _pluginsMediaSlash92['default'], _pluginsStarHtml2['default'], _pluginsTrailingSlashComma2['default']];
var plugins = [_pluginsBodyEmpty2['default'], _pluginsHtmlCombinatorCommentBody2['default'], _pluginsHtmlFirstChild2['default'], _pluginsImportant2['default'], _pluginsLeadingStar2['default'], _pluginsLeadingUnderscore2['default'], _pluginsMediaSlash02['default'], _pluginsMediaSlash92['default'], _pluginsStarHtml2['default'], _pluginsTrailingSlashComma2['default']];

@@ -92,2 +96,11 @@ var stylehacks = _postcss2['default'].plugin('stylehacks', function () {

stylehacks.detect = function (node) {
var hacked = plugins.some(function (Plugin) {
var hack = new Plugin();
return hack.any(node);
});
return hacked;
};
stylehacks.process = function (css) {

@@ -94,0 +107,0 @@ var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

25

dist/plugin.js

@@ -13,3 +13,3 @@ 'use strict';

function plugin(hack, targets, _detect) {
function plugin(targets, nodeTypes, _detect) {
var Plugin = (function () {

@@ -23,3 +23,3 @@ function Plugin(css, result) {

this.targets = targets;
this.id = hack;
this.nodeTypes = nodeTypes;
}

@@ -30,5 +30,2 @@

value: function push(node, message) {
if (!message) {
message = this.id;
}
node._stylehacks = message;

@@ -38,5 +35,21 @@ this.nodes.push(node);

}, {
key: 'any',
value: function any(node) {
var hasHack = false;
if (~this.nodeTypes.indexOf(node.type)) {
_detect.apply(this, arguments);
if (node._stylehacks) {
hasHack = true;
}
}
return hasHack;
}
}, {
key: 'detect',
value: function detect() {
return _detect.apply(this, arguments);
this.css.walk((function (node) {
if (~this.nodeTypes.indexOf(node.type)) {
_detect.apply(this, arguments);
}
}).bind(this));
}

@@ -43,0 +56,0 @@ }, {

@@ -21,3 +21,2 @@ 'use strict';

var hack = 'stylehacks-body-empty';
var targets = ['firefox 2'];

@@ -35,11 +34,7 @@

exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkRules(function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(_this, rule)).process(rule.selector);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['rule'], function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(this, rule)).process(rule.selector);
}
});
module.exports = exports['default'];

@@ -21,3 +21,2 @@ 'use strict';

var hack = 'stylehacks-html-first-child';
var targets = ['opera 9'];

@@ -35,11 +34,7 @@

exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkRules(function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(_this, rule)).process(rule.selector);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['rule'], function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(this, rule)).process(rule.selector);
}
});
module.exports = exports['default'];

@@ -13,16 +13,11 @@ 'use strict';

var hack = 'stylehacks-important';
var targets = ['ie 5.5', 'ie 6', 'ie 7'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkDecls(function (decl) {
var match = decl.value.match(/!\w/);
if (match) {
var text = decl.value.substr(match.index, decl.value.length - 1);
_this.push(decl, 'Bad !important: ' + text);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['decl'], function (decl) {
var match = decl.value.match(/!\w/);
if (match) {
var text = decl.value.substr(match.index, decl.value.length - 1);
this.push(decl, 'Bad !important: ' + text);
}
});
module.exports = exports['default'];

@@ -13,38 +13,45 @@ 'use strict';

var hack = 'stylehacks-leading-star';
var targets = ['ie 5.5', 'ie 6', 'ie 7'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
exports['default'] = (0, _plugin2['default'])(targets, ['decl', 'atrule'], function (node) {
var _this = this;
this.css.walkDecls(function (decl) {
var before = decl.raws.before;
if (!before) {
return;
}
var hacks = '!_$_&_*_)_=_%_+_,_._/_`_]_#_~_?_:_|'.split('_');
var hasBefore = hacks.some(function (hack) {
if (~before.indexOf(hack)) {
_this.push(decl, 'Bad property: ' + before.trim() + decl.prop);
return true;
if (node.type === 'decl') {
var _ret = (function () {
var before = node.raws.before;
if (!before) {
return {
v: undefined
};
}
});
if (!hasBefore) {
// some values are not picked up by before, so ensure they are
// at the beginning of the value
hacks.some(function (hack) {
if (!decl.prop.indexOf(hack)) {
_this.push(decl, 'Bad property: ' + decl.prop);
var hacks = '!_$_&_*_)_=_%_+_,_._/_`_]_#_~_?_:_|'.split('_');
var hasBefore = hacks.some(function (hack) {
if (~before.indexOf(hack)) {
_this.push(node, 'Bad property: ' + before.trim() + node.prop);
return true;
}
});
}
});
this.css.walkAtRules(function (rule) {
if (!hasBefore) {
// some values are not picked up by before, so ensure they are
// at the beginning of the value
hacks.some(function (hack) {
if (!node.prop.indexOf(hack)) {
_this.push(node, 'Bad property: ' + node.prop);
return true;
}
});
}
})();
if (typeof _ret === 'object') return _ret.v;
}
if (node.type === 'atrule') {
// test for the @property: value; hack
if (rule.name.lastIndexOf(':') === rule.name.length - 1) {
_this.push(rule, 'Bad property: @' + rule.name.substr(0, rule.name.length - 1));
var _name = node.name;
var len = _name.length - 1;
if (_name.lastIndexOf(':') === len) {
this.push(node, 'Bad property: @' + _name.substr(0, len));
}
});
}
});
module.exports = exports['default'];

@@ -13,18 +13,13 @@ 'use strict';

var hack = 'stylehacks-leading-underscore';
var targets = ['ie 6'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkDecls(function (decl) {
var before = decl.raws.before;
if (!before) {
return;
}
if (~before.indexOf('_') || ~before.indexOf('-')) {
_this.push(decl, 'Bad property: ' + before.trim() + decl.prop);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['decl'], function (decl) {
var before = decl.raws.before;
if (!before) {
return;
}
if (~before.indexOf('_') || ~before.indexOf('-')) {
this.push(decl, 'Bad property: ' + before.trim() + decl.prop);
}
});
module.exports = exports['default'];

@@ -13,15 +13,10 @@ 'use strict';

var hack = 'stylehacks-media-slash0';
var targets = ['ie 8'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkAtRules('media', function (rule) {
var params = rule.params.trim();
if (params === '\\0screen') {
_this.push(rule, 'Bad media query: ' + params);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['atrule'], function (rule) {
var params = rule.params.trim();
if (params === '\\0screen') {
this.push(rule, 'Bad media query: ' + params);
}
});
module.exports = exports['default'];

@@ -13,15 +13,10 @@ 'use strict';

var hack = 'stylehacks-media-slash9';
var targets = ['ie 5.5', 'ie 6', 'ie 7'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkAtRules('media', function (rule) {
var params = rule.params.trim();
if (params === 'screen\\9') {
_this.push(rule, 'Bad media query: ' + params);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['atrule'], function (rule) {
var params = rule.params.trim();
if (params === 'screen\\9') {
this.push(rule, 'Bad media query: ' + params);
}
});
module.exports = exports['default'];

@@ -21,3 +21,2 @@ 'use strict';

var hack = 'stylehacks-star-html';
var targets = ['ie 6', 'ie 5.5'];

@@ -35,11 +34,7 @@

exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkRules(function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(_this, rule)).process(rule.selector);
}
});
exports['default'] = (0, _plugin2['default'])(targets, ['rule'], function (rule) {
if (rule.selector) {
(0, _postcssSelectorParser2['default'])(analyse(this, rule)).process(rule.selector);
}
});
module.exports = exports['default'];

@@ -13,17 +13,12 @@ 'use strict';

var hack = 'stylehacks-trailing-slash-comma';
var targets = ['ie 7', 'ie 6', 'ie 5.5'];
exports['default'] = (0, _plugin2['default'])(hack, targets, function () {
var _this = this;
this.css.walkRules(function (rule) {
if (rule.selector) {
var sel = rule.selector;
if (sel.trim().lastIndexOf(',') === sel.length - 1 || sel.trim().lastIndexOf('\\') === sel.length - 1) {
_this.push(rule, 'Bad selector: ' + sel);
}
exports['default'] = (0, _plugin2['default'])(targets, ['rule'], function (rule) {
if (rule.selector) {
var sel = rule.selector;
if (sel.trim().lastIndexOf(',') === sel.length - 1 || sel.trim().lastIndexOf('\\') === sel.length - 1) {
this.push(rule, 'Bad selector: ' + sel);
}
});
}
});
module.exports = exports['default'];
{
"name": "stylehacks",
"version": "2.0.0",
"version": "2.1.0",
"description": "Detect/remove browser hacks from CSS files.",

@@ -49,4 +49,4 @@ "main": "dist/index.js",

"plur": "^2.0.0",
"postcss": "^5.0.4",
"postcss-reporter": "^1.1.0",
"postcss": "^5.0.5",
"postcss-reporter": "^1.2.1",
"postcss-selector-parser": "^1.2.0",

@@ -53,0 +53,0 @@ "read-file-stdin": "^0.2.0",

@@ -37,2 +37,17 @@ # stylehacks [![Build Status](https://travis-ci.org/ben-eb/stylehacks.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/stylehacks.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/stylehacks.svg)][deps]

### `stylehacks.detect(node)`
Type: `function`
Returns: `boolean`
This method will take any PostCSS *node*, run applicable plugins depending on
its type, then will return a boolean depending on whether it found any of
the supported hacks. For example, if the `decl` node found below is passed to
the `detect` function, it will return `true`. But if the `rule` node is passed,
it will return `false` instead.
```css
h1 { _color: red }
```
### `stylehacks.process(css, [options]).then(function(result) {})`

@@ -39,0 +54,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc