Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stylehacks

Package Overview
Dependencies
Maintainers
7
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 5.0.3 to 5.1.0

types/dictionary/browsers.d.ts

6

package.json
{
"name": "stylehacks",
"version": "5.0.3",
"version": "5.1.0",
"description": "Detect/remove browser hacks from CSS files.",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"LICENSE-MIT",
"src"
"src",
"types"
],

@@ -10,0 +12,0 @@ "keywords": [

'use strict';
/**
* @param {import('postcss-selector-parser').Selector} selector
* @param {number} index
* @param {string} value
* @return {boolean | undefined | ''}
*/
module.exports = function exists(selector, index, value) {

@@ -3,0 +10,0 @@ const node = selector.at(index);

@@ -5,2 +5,9 @@ 'use strict';

/** @typedef {{lint?: boolean}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts = {}) {

@@ -11,2 +18,3 @@ return {

OnceExit(css, { result }) {
/** @type {typeof result.opts & browserslist.Options} */
const resultOpts = result.opts || {};

@@ -19,2 +27,3 @@ const browsers = browserslist(null, {

/** @type {import('./plugin').Plugin[]} */
const processors = [];

@@ -44,2 +53,3 @@ for (const Plugin of plugins) {

/** @type {(node: import('postcss').Node) => boolean} */
pluginCreator.detect = (node) => {

@@ -46,0 +56,0 @@ return plugins.some((Plugin) => {

'use strict';
/**
* @param {import('postcss').Rule} node
* @return {boolean}
*/
module.exports = function isMixin(node) {

@@ -3,0 +7,0 @@ const { selector } = node;

'use strict';
/**
* @typedef {object} Plugin
* @prop {Set<string>} targets
* @prop {Set<string>} nodeTypes
* @prop {(node: import('postcss').Node) => void} detectAndResolve
* @prop {(node: import('postcss').Node) => void} detectAndWarn
*/
/**
* @typedef {import('postcss').Node & {_stylehacks: {
message: string,
browsers: Set<string>,
identifier: string,
hack: string }}} NodeWithInfo
*/
module.exports = class BasePlugin {
/**
* @param {string[]} targets
* @param {string[]} nodeTypes
* @param {import('postcss').Result=} result
*/
constructor(targets, nodeTypes, result) {
/** @type {NodeWithInfo[]} */
this.nodes = [];

@@ -10,11 +32,24 @@ this.targets = new Set(targets);

/**
* @param {import('postcss').Node} node
* @param {{identifier: string, hack: string}} metadata
* @return {void}
*/
push(node, metadata) {
node._stylehacks = Object.assign({}, metadata, {
message: `Bad ${metadata.identifier}: ${metadata.hack}`,
browsers: this.targets,
});
/** @type {NodeWithInfo} */ (node)._stylehacks = Object.assign(
{},
metadata,
{
message: `Bad ${metadata.identifier}: ${metadata.hack}`,
browsers: this.targets,
}
);
this.nodes.push(node);
this.nodes.push(/** @type {NodeWithInfo} */ (node));
}
/**
* @param {import('postcss').Node} node
* @return {boolean}
*/
any(node) {

@@ -24,3 +59,3 @@ if (this.nodeTypes.has(node.type)) {

return !!node._stylehacks;
return /** @type {NodeWithInfo} */ (node)._stylehacks !== undefined;
}

@@ -31,2 +66,6 @@

/**
* @param {import('postcss').Node} node
* @return {void}
*/
detectAndResolve(node) {

@@ -40,2 +79,6 @@ this.nodes = [];

/**
* @param {import('postcss').Node} node
* @return {void}
*/
detectAndWarn(node) {

@@ -48,2 +91,3 @@ this.nodes = [];

}
/** @param {import('postcss').Node} node */
// eslint-disable-next-line no-unused-vars

@@ -54,2 +98,3 @@ detect(node) {

/** @return {void} */
resolve() {

@@ -63,5 +108,8 @@ return this.nodes.forEach((node) => node.remove());

return node.warn(this.result, message, { browsers, identifier, hack });
return node.warn(
/** @type {import('postcss').Result} */ (this.result),
message + JSON.stringify({ browsers, identifier, hack })
);
});
}
};

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

module.exports = class BodyEmpty extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {

@@ -17,2 +18,6 @@ super([FF_2], [RULE], result);

/**
* @param {import('postcss').Rule} rule
* @return {void}
*/
detect(rule) {

@@ -25,2 +30,6 @@ if (isMixin(rule)) {

/**
* @param {import('postcss').Rule} rule
* @return {parser.SyncProcessor<void>}
*/
analyse(rule) {

@@ -27,0 +36,0 @@ return (selectors) => {

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

module.exports = class HtmlCombinatorCommentBody extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {

@@ -17,2 +18,6 @@ super([IE_5_5, IE_6, IE_7], [RULE], result);

/**
* @param {import('postcss').Rule} rule
* @return {void}
*/
detect(rule) {

@@ -27,2 +32,5 @@ if (isMixin(rule)) {

/** @param {import('postcss').Rule} rule
* @return {parser.SyncProcessor<void>}
*/
analyse(rule) {

@@ -29,0 +37,0 @@ return (selectors) => {

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

module.exports = class HtmlFirstChild extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {

@@ -17,2 +18,6 @@ super([OP_9], [RULE], result);

/**
* @param {import('postcss').Rule} rule
* @return {void}
*/
detect(rule) {

@@ -26,2 +31,6 @@ if (isMixin(rule)) {

/**
* @param {import('postcss').Rule} rule
* @return {parser.SyncProcessor<void>}
*/
analyse(rule) {

@@ -28,0 +37,0 @@ return (selectors) => {

@@ -7,9 +7,13 @@ 'use strict';

module.exports = class Important extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {
super([IE_5_5, IE_6, IE_7], [DECL], result);
}
/**
* @param {import('postcss').Declaration} decl
* @return {void}
*/
detect(decl) {
const match = decl.value.match(/!\w/);
if (match) {
if (match && match.index) {
const hack = decl.value.substr(match.index, decl.value.length - 1);

@@ -16,0 +20,0 @@ this.push(decl, {

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

module.exports = class LeadingStar extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {

@@ -15,2 +16,6 @@ super([IE_5_5, IE_6, IE_7], [ATRULE, DECL], result);

/**
* @param {import('postcss').Declaration | import('postcss').AtRule} node
* @return {void}
*/
detect(node) {

@@ -28,3 +33,3 @@ if (node.type === DECL) {

});
let { before } = node.raws;
const { before } = node.raws;
if (!before) {

@@ -43,4 +48,4 @@ return;

// test for the @property: value; hack
let { name } = node;
let len = name.length - 1;
const { name } = node;
const len = name.length - 1;
if (name.lastIndexOf(':') === len) {

@@ -47,0 +52,0 @@ this.push(node, {

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

/**
* @param {string} prop
* @return {string}
*/
function vendorPrefix(prop) {

@@ -18,2 +22,3 @@ let match = prop.match(/^(-\w+-)/);

module.exports = class LeadingUnderscore extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {

@@ -23,2 +28,6 @@ super([IE_6], [DECL], result);

/**
* @param {import('postcss').Declaration} decl
* @return {void}
*/
detect(decl) {

@@ -25,0 +34,0 @@ const { before } = decl.raws;

@@ -8,6 +8,10 @@ 'use strict';

module.exports = class MediaSlash0 extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {
super([IE_8], [ATRULE], result);
}
/**
* @param {import('postcss').AtRule} rule
* @return {void}
*/
detect(rule) {

@@ -14,0 +18,0 @@ const params = rule.params.trim();

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

module.exports = class MediaSlash0Slash9 extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {

@@ -13,2 +14,6 @@ super([IE_5_5, IE_6, IE_7, IE_8], [ATRULE], result);

/**
* @param {import('postcss').AtRule} rule
* @return {void}
*/
detect(rule) {

@@ -15,0 +20,0 @@ const params = rule.params.trim();

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

module.exports = class MediaSlash9 extends BasePlugin {
/** @param {import('postcss').Result} result */
constructor(result) {

@@ -13,2 +14,6 @@ super([IE_5_5, IE_6, IE_7], [ATRULE], result);

/**
* @param {import('postcss').AtRule} rule
* @return {void}
*/
detect(rule) {

@@ -15,0 +20,0 @@ const params = rule.params.trim();

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

module.exports = class Slash9 extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {

@@ -13,2 +14,6 @@ super([IE_6, IE_7, IE_8], [DECL], result);

/**
* @param {import('postcss').Declaration} decl
* @return {void}
*/
detect(decl) {

@@ -15,0 +20,0 @@ let v = decl.value;

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

module.exports = class StarHtml extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {

@@ -17,2 +18,6 @@ super([IE_5_5, IE_6], [RULE], result);

/**
* @param {import('postcss').Rule} rule
* @return {void}
*/
detect(rule) {

@@ -25,2 +30,6 @@ if (isMixin(rule)) {

/**
* @param {import('postcss').Rule} rule
* @return {parser.SyncProcessor<void>}
*/
analyse(rule) {

@@ -27,0 +36,0 @@ return (selectors) => {

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

module.exports = class TrailingSlashComma extends BasePlugin {
/** @param {import('postcss').Result=} result */
constructor(result) {

@@ -14,2 +15,6 @@ super([IE_5_5, IE_6, IE_7], [RULE], result);

/**
* @param {import('postcss').Rule} rule
* @return {void}
*/
detect(rule) {

@@ -16,0 +21,0 @@ if (isMixin(rule)) {

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