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

fela-plugin-validator

Package Overview
Dependencies
Maintainers
2
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fela-plugin-validator - npm Package Compare versions

Comparing version 5.1.1 to 5.2.0

49

es/index.js
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { RULE_TYPE, KEYFRAME_TYPE, isNestedSelector, isMediaQuery, isSupport } from 'fela-utils';

@@ -8,2 +10,7 @@ import cssifyDeclaration from 'css-in-js-utils/lib/cssifyDeclaration';

var defaultRules = CSSLint.getRules().reduce(function (rules, _ref) {
var id = _ref.id;
return _extends({}, rules, _defineProperty({}, id, 1));
}, {});
function handleError(property, style, logInvalid, deleteInvalid, message, logObject) {

@@ -19,3 +26,3 @@ if (deleteInvalid) {

function validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint) {
function validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules) {
var _loop = function _loop(property) {

@@ -26,3 +33,3 @@ var value = style[property];

if (isNestedSelector(property) || isMediaQuery(property) || isSupport(property)) {
validateStyleObject(value, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(value, logInvalid, deleteInvalid, useCSSLint, cssRules);
} else {

@@ -34,16 +41,14 @@ handleError(property, style, logInvalid, deleteInvalid, 'Invalid nested property. Only use nested media queries, pseudo classes, child selectors or &-combinators.\n Maybe you forgot to add a plugin that resolves "' + property + '".', {

}
} else {
if (useCSSLint) {
var _CSSLint$verify = CSSLint.verify('.fela {' + cssifyDeclaration(property, value) + ';}'),
messages = _CSSLint$verify.messages;
} else if (useCSSLint) {
var _CSSLint$verify = CSSLint.verify('.fela {' + cssifyDeclaration(property, value) + ';}', cssRules),
messages = _CSSLint$verify.messages;
messages.forEach(function (_ref) {
var message = _ref.message;
messages.forEach(function (_ref2) {
var message = _ref2.message;
handleError(property, style, logInvalid, deleteInvalid, 'Invalid property "' + property + '" with value "' + value + '". ' + message.replace(/ at line .+, col .+\./, '.'), {
property: property,
value: value
});
handleError(property, style, logInvalid, deleteInvalid, 'Invalid property "' + property + '" with value "' + value + '". ' + message.replace(/ at line .+, col .+\./, '.'), {
property: property,
value: value
});
}
});
}

@@ -63,3 +68,3 @@ };

function validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint) {
function validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules) {
for (var percentage in style) {

@@ -79,3 +84,3 @@ var _value = style[percentage];

} else {
validateStyleObject(_value, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(_value, logInvalid, deleteInvalid, useCSSLint, cssRules);
}

@@ -88,9 +93,10 @@ }

deleteInvalid = options.deleteInvalid,
useCSSLint = options.useCSSLint;
useCSSLint = options.useCSSLint,
cssRules = options.cssRules;
if (type === KEYFRAME_TYPE) {
validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint);
validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules);
} else if (type === RULE_TYPE) {
validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules);
}

@@ -109,6 +115,11 @@

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var useCSSLint = options.useCSSLint;
var preparedOptions = _extends({}, defaultOptions, options);
preparedOptions.cssRules = isPlainObject(useCSSLint) ? _extends({}, defaultRules, useCSSLint) : defaultRules;
return function (style, type) {
return validateStyle(style, type, _extends({}, defaultOptions, options));
return validateStyle(style, type, preparedOptions);
};
}

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var defaultRules = _csslint.CSSLint.getRules().reduce(function (rules, _ref) {
var id = _ref.id;
return _extends({}, rules, _defineProperty({}, id, 1));
}, {});
function handleError(property, style, logInvalid, deleteInvalid, message, logObject) {

@@ -36,3 +43,3 @@ if (deleteInvalid) {

function validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint) {
function validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules) {
var _loop = function _loop(property) {

@@ -43,3 +50,3 @@ var value = style[property];

if ((0, _felaUtils.isNestedSelector)(property) || (0, _felaUtils.isMediaQuery)(property) || (0, _felaUtils.isSupport)(property)) {
validateStyleObject(value, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(value, logInvalid, deleteInvalid, useCSSLint, cssRules);
} else {

@@ -51,16 +58,14 @@ handleError(property, style, logInvalid, deleteInvalid, 'Invalid nested property. Only use nested media queries, pseudo classes, child selectors or &-combinators.\n Maybe you forgot to add a plugin that resolves "' + property + '".', {

}
} else {
if (useCSSLint) {
var _CSSLint$verify = _csslint.CSSLint.verify('.fela {' + (0, _cssifyDeclaration2.default)(property, value) + ';}'),
messages = _CSSLint$verify.messages;
} else if (useCSSLint) {
var _CSSLint$verify = _csslint.CSSLint.verify('.fela {' + (0, _cssifyDeclaration2.default)(property, value) + ';}', cssRules),
messages = _CSSLint$verify.messages;
messages.forEach(function (_ref) {
var message = _ref.message;
messages.forEach(function (_ref2) {
var message = _ref2.message;
handleError(property, style, logInvalid, deleteInvalid, 'Invalid property "' + property + '" with value "' + value + '". ' + message.replace(/ at line .+, col .+\./, '.'), {
property: property,
value: value
});
handleError(property, style, logInvalid, deleteInvalid, 'Invalid property "' + property + '" with value "' + value + '". ' + message.replace(/ at line .+, col .+\./, '.'), {
property: property,
value: value
});
}
});
}

@@ -80,3 +85,3 @@ };

function validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint) {
function validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules) {
for (var percentage in style) {

@@ -96,3 +101,3 @@ var _value = style[percentage];

} else {
validateStyleObject(_value, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(_value, logInvalid, deleteInvalid, useCSSLint, cssRules);
}

@@ -105,9 +110,10 @@ }

deleteInvalid = options.deleteInvalid,
useCSSLint = options.useCSSLint;
useCSSLint = options.useCSSLint,
cssRules = options.cssRules;
if (type === _felaUtils.KEYFRAME_TYPE) {
validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint);
validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules);
} else if (type === _felaUtils.RULE_TYPE) {
validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint);
validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint, cssRules);
}

@@ -126,6 +132,11 @@

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var useCSSLint = options.useCSSLint;
var preparedOptions = _extends({}, defaultOptions, options);
preparedOptions.cssRules = (0, _isobject2.default)(useCSSLint) ? _extends({}, defaultRules, useCSSLint) : defaultRules;
return function (style, type) {
return validateStyle(style, type, _extends({}, defaultOptions, options));
return validateStyle(style, type, preparedOptions);
};
}
{
"name": "fela-plugin-validator",
"version": "5.1.1",
"version": "5.2.0",
"description": "Fela plugin to validate style objects",

@@ -27,5 +27,5 @@ "main": "lib/index.js",

"csslint": "^1.0.5",
"fela-utils": "^8.0.5",
"fela-utils": "^8.0.7",
"isobject": "^3.0.1"
}
}

@@ -39,3 +39,3 @@ # fela-plugin-validator

| deleteInvalid | *(boolean?)* | `false` | deletes invalid properties/values |
| useCSSLint | *(boolean?)* | `false` | use CSSLint for style validation |
| useCSSLint | *(boolean?)*<br>*(Object?)* | `false` | use CSSLint for style validation. <br> If an object is transferred, it will be interpreted as a set of rules for the validation (see [here](https://github.com/CSSLint/csslint/wiki/Rules)) |

@@ -42,0 +42,0 @@ ##### Example

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