UNPKG

@ec0lint/plugin-css

Version:

ec0lint plugin that provides rules to verify CSS definition objects

82 lines (81 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); const known_css_properties_1 = require("known-css-properties"); const css_utils_1 = require("../utils/css-utils"); const regexp_1 = require("../utils/regexp"); const casing_1 = require("../utils/casing"); exports.default = (0, utils_1.createRule)("no-unknown-property", { meta: { docs: { description: "disallow unknown properties", category: "Possible Errors", recommended: true, stylelint: "property-no-unknown", }, schema: [ { type: "object", properties: { ignoreProperties: { type: "array", items: { type: "string", }, uniqueItems: true, minItems: 1, }, ignorePrefixed: { type: "boolean" }, }, additionalProperties: false, }, ], messages: { unknown: "Unexpected unknown property '{{property}}'.", }, type: "problem", }, create(context) { var _a, _b, _c, _d; const ignoreProperties = [ ...((_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.ignoreProperties) !== null && _b !== void 0 ? _b : []), ].map(regexp_1.toRegExp); const ignorePrefixed = (_d = (_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.ignorePrefixed) !== null && _d !== void 0 ? _d : true; const knownProperties = new Set(known_css_properties_1.all); function validName(name) { return (name.startsWith("--") || knownProperties.has(name) || ignoreProperties.some((r) => r.test(name)) || (ignorePrefixed && (0, css_utils_1.hasVendorPrefix)(name))); } function createVisitor(_cssContext) { return { onProperty(property) { const prop = property.getName(); if (!prop) { return; } if (validName(prop.name) || prop.name === "cssFloat") { return; } if ((0, casing_1.isCamelCase)(prop.name)) { if (validName((0, casing_1.kebabCase)(prop.name))) { return; } } context.report({ node: prop.expression, messageId: "unknown", data: { property: prop.name, }, }); }, }; } return (0, utils_1.defineCSSVisitor)(context, { createVisitor, }); }, });