Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkSymbol(symbol) {
const styleSearchOptions = {
source: expression,
target: symbol,
functionArguments: "skip",
}
styleSearch(styleSearchOptions, match => {
const index = match.startIndex
// Deal with signs.
// (@ and $ are considered "digits" here to allow for variable syntaxes
// that permit signs in front of variables, e.g. `-$number`)
// As is "." to deal with fractional numbers without a leading zero
if ((symbol === "+" || symbol === "-") && /[\d@\$.]/.test(expression[index + 1])) {
const expressionBeforeSign = expression.substr(0, index)
// Ignore signs that directly follow a opening bracket
if (expressionBeforeSign[expressionBeforeSign.length - 1] === "(") { return }
// Ignore signs at the beginning of the expression
if (/^\s*$/.test(expressionBeforeSign)) { return }
// Otherwise, ensure that there is a real operator preceeding them
optional: true,
})
if (!validOptions) { return }
// Collapse all urls into something nice and short,
// so they do not throw the game
const rootString = root.toString().replace(/url\(.*\)/ig, "url()")
const ignoreNonComments = optionsMatches(options, "ignore", "non-comments")
const ignoreComments = optionsMatches(options, "ignore", "comments")
// Check first line
checkNewline({ endIndex: 0 })
// Check subsequent lines
styleSearch({ source: rootString, target: ["\n"], comments: "check" }, checkNewline)
function complain(index) {
report({
index,
result,
ruleName,
message: messages.expected(maxLength),
node: root,
})
}
function checkNewline(match) {
const endOfLineIndicator = (rootString.indexOf("\r\n", match.endIndex) !== -1) ? "\r\n" : "\n"
let nextNewlineIndex = rootString.indexOf(endOfLineIndicator, match.endIndex)
// Accommodate last line