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

fela-plugin-validator

Package Overview
Dependencies
Maintainers
1
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.0 to 5.1.1

43

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; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
import { RULE_TYPE, KEYFRAME_TYPE, isNestedSelector, isMediaQuery, isSupport } from 'fela-utils';
import cssifyDeclaration from 'css-in-js-utils/lib/cssifyDeclaration';
import isPlainObject from 'isobject';
import { CSSLint } from 'csslint';
function isPlainObject(obj) {
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj);
}
function handleError(property, style, logInvalid, deleteInvalid, message, logObject) {

@@ -23,3 +18,3 @@ if (deleteInvalid) {

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

@@ -30,3 +25,3 @@ var value = style[property];

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

@@ -39,13 +34,15 @@ 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 {
var _CSSLint$verify = CSSLint.verify('.fela {' + cssifyDeclaration(property, value) + ';}'),
messages = _CSSLint$verify.messages;
if (useCSSLint) {
var _CSSLint$verify = CSSLint.verify('.fela {' + cssifyDeclaration(property, value) + ';}'),
messages = _CSSLint$verify.messages;
messages.forEach(function (_ref) {
var message = _ref.message;
messages.forEach(function (_ref) {
var message = _ref.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
});
});
});
}
}

@@ -65,3 +62,3 @@ };

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

@@ -81,3 +78,3 @@ var _value = style[percentage];

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

@@ -89,9 +86,10 @@ }

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

@@ -104,3 +102,4 @@

logInvalid: true,
deleteInvalid: false
deleteInvalid: false,
useCSSLint: false
};

@@ -107,0 +106,0 @@

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

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.default = validator;

@@ -20,2 +18,6 @@

var _isobject = require('isobject');
var _isobject2 = _interopRequireDefault(_isobject);
var _csslint = require('csslint');

@@ -25,6 +27,2 @@

function isPlainObject(obj) {
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj);
}
function handleError(property, style, logInvalid, deleteInvalid, message, logObject) {

@@ -40,9 +38,9 @@ if (deleteInvalid) {

function validateStyleObject(style, logInvalid, deleteInvalid) {
function validateStyleObject(style, logInvalid, deleteInvalid, useCSSLint) {
var _loop = function _loop(property) {
var value = style[property];
if (isPlainObject(value)) {
if ((0, _isobject2.default)(value)) {
if ((0, _felaUtils.isNestedSelector)(property) || (0, _felaUtils.isMediaQuery)(property) || (0, _felaUtils.isSupport)(property)) {
validateStyleObject(value, logInvalid, deleteInvalid);
validateStyleObject(value, logInvalid, deleteInvalid, useCSSLint);
} else {

@@ -55,13 +53,15 @@ 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 {
var _CSSLint$verify = _csslint.CSSLint.verify('.fela {' + (0, _cssifyDeclaration2.default)(property, value) + ';}'),
messages = _CSSLint$verify.messages;
if (useCSSLint) {
var _CSSLint$verify = _csslint.CSSLint.verify('.fela {' + (0, _cssifyDeclaration2.default)(property, value) + ';}'),
messages = _CSSLint$verify.messages;
messages.forEach(function (_ref) {
var message = _ref.message;
messages.forEach(function (_ref) {
var message = _ref.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
});
});
});
}
}

@@ -81,6 +81,6 @@ };

function validateKeyframeObject(style, logInvalid, deleteInvalid) {
function validateKeyframeObject(style, logInvalid, deleteInvalid, useCSSLint) {
for (var percentage in style) {
var _value = style[percentage];
if (!isPlainObject(_value)) {
if (!(0, _isobject2.default)(_value)) {
handleError(percentage, style, logInvalid, deleteInvalid, 'Invalid keyframe value. An object was expected.', {

@@ -97,3 +97,3 @@ percentage: percentage,

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

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

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

@@ -120,3 +121,4 @@

logInvalid: true,
deleteInvalid: false
deleteInvalid: false,
useCSSLint: false
};

@@ -123,0 +125,0 @@

{
"name": "fela-plugin-validator",
"version": "5.1.0",
"version": "5.1.1",
"description": "Fela plugin to validate style objects",

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

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

@@ -5,4 +5,6 @@ # fela-plugin-validator

Enforces object validation for keyframes and rules.
Logs invalid properties to the `console`. A [csslint](https://github.com/CSSLint/csslint) is used to check the CSS. One might also enable automatic property deletion.
Enforces object validation for keyframes and rules.<br>
Logs invalid properties to the `console`. <br>
If enabled, [csslint](https://github.com/CSSLint/csslint) is used to check the CSS.<br>
One might also enable automatic property deletion.

@@ -36,4 +38,5 @@ ## Installation

| --- | --- | --- | --- |
| `logInvalid` | *(boolean)* | `true` | logs invalid properties/values |
| `deleteInvalid` | *(boolean)* | `false` | deletes invalid properties/values |
| logInvalid | *(boolean?)* | `true` | logs invalid properties/values |
| deleteInvalid | *(boolean?)* | `false` | deletes invalid properties/values |
| useCSSLint | *(boolean?)* | `false` | use CSSLint for style validation |

@@ -47,3 +50,4 @@ ##### Example

logInvalid: true,
deleteInvalid: true
deleteInvalid: true,
useCSSLint: true
})

@@ -50,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