Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function check(node, value, getIndex) {
// Get out quickly if there are no periods
if (value.indexOf(".") === -1) { return }
valueParser(value).walk(valueNode => {
// Ignore `url` function
if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") { return false }
// Ignore strings, comments, etc
if (valueNode.type !== "word") { return }
// Check leading zero
if (expectation === "always") {
const match = /(?:\D|^)(\.\d+)/.exec(valueNode.value)
if (match === null) { return }
// The regexp above consists of 2 capturing groups (or capturing parentheses).
// We need the index of the second group. This makes sanse when we have "-.5" as an input
// for regex. And we need the index of ".5".
const capturingGroupIndex = match[0].length - match[1].length
root.walkDecls(decl => {
const valueRoot = parseValue(decl.value);
let varFound = false;
valueRoot.walk(({ type, value }) => {
if (!varFound && type === 'function' && value === 'var') {
// Add the imported to results messages
const message = varFunctionMessage(value);
result.messages.push(message);
varFound = true;
}
});
});
}
function check(node, value, getIndex) {
valueParser(value).walk(function (valueNode) {
// Ignore wrong units within `url` function
if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") { return false }
const unit = getUnitFromValueNode(valueNode)
if (!unit) { return }
if (optionsMatches(options, "ignoreUnits", unit)) { return }
if (units.has(unit.toLowerCase())) { return }
report({
index: getIndex(node) + valueNode.sourceIndex,
message: messages.rejected(unit),
node,
result,
ruleName,
css.walkDecls(decl => {
if (decl.value.indexOf('sketch(') !== -1) {
let parsedValue = valueParser(decl.value);
let file = parsedValue.nodes[0].nodes[0].value;
// Resolve the file reference.
let fileRef;
if (decl.source.input.file)
fileRef = path.join(
path.dirname(decl.source.input.file),
file
); // Relative to CSS File
else fileRef = path.join(file); // No CSS file, probably testing
// Retrieve the sketch JSON dump
let sketchData = getSketchJSON(path.resolve(fileRef));
// Add a dependency.
root.walkDecls(decl => {
valueParser(decl.value).walk((node) => {
// Ignore wrong units within `url` function
if (node.type === "function" && node.value.toLowerCase() === "url") { return false }
const unit = getUnitFromValueNode(node)
if (!unit) { return }
const expectedUnit = expectation === "lower" ? unit.toLowerCase() : unit.toUpperCase()
if (unit === expectedUnit) { return }
report({
message: messages.expected(unit, expectedUnit),
node: decl,
index: declarationValueIndex(decl) + node.sourceIndex,
result,
ast.program.walkDecls(decl => {
if (URL_RE.test(decl.value)) {
let parsed = valueParser(decl.value);
let isDirty = false;
parsed.walk(node => {
if (
node.type === 'function' &&
node.value === 'url' &&
node.nodes.length
) {
node.nodes[0].value = asset.addURLDependency(node.nodes[0].value, {
loc: createDependencyLocation(
decl.source.start,
node.nodes[0].value
)
});
isDirty = true;
}
function extractUrlValue(url, source, resolveImagePath) {
const parsedValue = valueParser(url);
let urlValue = '';
parsedValue.walk((node) => {
if (node.type !== 'function' || (node.type === 'function' && node.value !== 'url')) {
return;
}
node.nodes.forEach((fp) => {
if (!isUrl(fp.value)) {
urlValue = resolveImagePath(fp.value, source);
}
});
});
return urlValue;
}
function resemblePromise (decl, opts, wrapped = true) {
const promises = [];
let url;
let toString;
decl.value = valueParser(decl.value).walk((node, index, nodes) => {
const {type, value} = node;
if (type !== 'function') {
return false;
}
if (wrapped && value === resembleFunction) {
url = node.nodes[0].nodes[0].value;
toString = node.nodes[0];
}
if (!wrapped && value === 'url') {
url = node.nodes[0].value;
toString = node;
}
if (!url) {
return false;
}
const second = node.nodes[2];
const baseTransformShorthandValue = (propName, inputValue) => {
const ast = parse(inputValue.trim())
const tokenStream = new TokenStream(ast.nodes)
return transforms[propName](tokenStream)
}