@ec0lint/plugin-css
Version:
ec0lint plugin that provides rules to verify CSS definition objects
97 lines (96 loc) • 3.57 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isStringLiteral = exports.isStaticTemplateLiteral = exports.findExpression = exports.getScope = exports.getStaticValue = exports.getPropertyName = exports.findVariable = exports.getParent = void 0;
const eslintUtils = __importStar(require("eslint-utils"));
function getParent(node) {
if (!node) {
return null;
}
return node.parent;
}
exports.getParent = getParent;
function findVariable(context, node) {
return eslintUtils.findVariable(getScope(context, node), node);
}
exports.findVariable = findVariable;
function getPropertyName(context, node) {
return eslintUtils.getPropertyName(node, getScope(context, node));
}
exports.getPropertyName = getPropertyName;
function getStaticValue(context, node) {
return eslintUtils.getStaticValue(node, getScope(context, node));
}
exports.getStaticValue = getStaticValue;
function getScope(context, currentNode) {
const scopeManager = context.getSourceCode()
.scopeManager;
let node = currentNode;
for (; node; node = node.parent || null) {
const scope = scopeManager.acquire(node, false);
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
}
return scope;
}
}
return scopeManager.scopes[0];
}
exports.getScope = getScope;
function findExpression(context, id) {
let target = id;
const set = new Set();
while (target.type === "Identifier") {
if (set.has(target)) {
return null;
}
set.add(target);
const variable = findVariable(context, target);
if (!variable) {
return null;
}
if (variable.defs.length !== 1) {
return null;
}
const def = variable.defs[0];
if (def.type !== "Variable" ||
def.parent.kind !== "const" ||
!def.node.init) {
return null;
}
target = def.node.init;
}
return target;
}
exports.findExpression = findExpression;
function isStaticTemplateLiteral(node) {
return node.type === "TemplateLiteral" && node.quasis.length === 1;
}
exports.isStaticTemplateLiteral = isStaticTemplateLiteral;
function isStringLiteral(node) {
return node.type === "Literal" && typeof node.value === "string";
}
exports.isStringLiteral = isStringLiteral;