Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const stylelint = require('stylelint')
const {readFileSync} = require('fs')
const ruleName = 'primer/no-unused-vars'
const cwd = process.cwd()
const COLON = ':'
const SCSS_VARIABLE_PATTERN = /(\$[-\w]+)/g
const messages = stylelint.utils.ruleMessages(ruleName, {
rejected: name => `The variable "${name}" is not referenced.`
})
const cache = new TapMap()
module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}) => {
if (!enabled) {
return noop
}
const {files = ['**/*.scss', '!node_modules'], variablePattern = SCSS_VARIABLE_PATTERN, verbose = false} = options
// eslint-disable-next-line no-console
const log = verbose ? (...args) => console.warn(...args) : noop
const cacheOptions = {files, variablePattern, cwd}
const {refs} = getCachedVariables(cacheOptions, log)
return (root, result) => {
root.walkDecls(decl => {
for (const [name] of matchAll(decl.prop, variablePattern)) {
if (!refs.has(name)) {
stylelint.utils.report({
message: messages.rejected(name),
const stylelint = require('stylelint')
const ruleName = 'primer/selector-no-utility'
module.exports = stylelint.createPlugin(ruleName, (enabled, ...args) => {
if (!enabled) {
return noop
}
let selectorNoUtility
try {
selectorNoUtility = require('stylelint-selector-no-utility')
} catch (error) {
// eslint-disable-next-line no-console
console.warn(`Unable to require('stylelint-selector-no-utility'): ${error}`)
return noop
}
const deprecatedPlugin = selectorNoUtility.rule(enabled, ...args)
return (root, result) => {
if (enabled === false) {
const stylelint = require('stylelint');
const utils = require('./stylelint-utils');
const ruleName = 'stylelint-gitlab/duplicate-selectors';
const messages = stylelint.utils.ruleMessages(ruleName, {
expected: (selector1, selector2) => {
return `"${selector1}" and "${selector2}" have the same properties.`;
},
});
module.exports = stylelint.createPlugin(ruleName, (enabled) => {
if (!enabled) {
return;
}
// eslint-disable-next-line consistent-return
return (root, result) => {
const selectorGroups = {};
utils.createPropertiesHashmap(root, result, ruleName, messages, selectorGroups, true);
};
});
module.exports.ruleName = ruleName;
module.exports.messages = messages;
return;
}
// Report the violation to stylelint
report({
message,
node: decl,
result,
ruleName,
word: value
});
});
}
};
};
module.exports = createPlugin(ruleName, rule);
module.exports.ruleName = ruleName;
module.exports.messages = messages;
result,
ruleName
});
});
});
};
};
const getArguments = node => {
// strip first and last nodes (i.e. the parens)
node.removeChild(node.first);
node.removeChild(node.last);
return node.nodes.toString();
};
module.exports = createPlugin(ruleName, rule);
module.exports.ruleName = ruleName;
module.exports.messages = messages;
const stylelint = require('stylelint')
const {requirePrimerFile} = require('./lib/primer')
const ruleName = 'primer/no-override'
const CLASS_PATTERN = /(\.[-\w]+)/
const CLASS_PATTERN_ALL = new RegExp(CLASS_PATTERN, 'g')
const CLASS_PATTERN_ONLY = /^\.[-\w]+(:{1,2}[-\w]+)?$/
module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}) => {
if (!enabled) {
return noop
}
const {bundles = ['utilities'], ignoreSelectors = []} = options
const isSelectorIgnored =
typeof ignoreSelectors === 'function'
? ignoreSelectors
: selector => {
return ignoreSelectors.some(pattern => {
return pattern instanceof RegExp ? pattern.test(selector) : selector.includes(pattern)
})
}
const primerMeta = requirePrimerFile('dist/meta.json')
const noUtilityReassignment = require("./src/rules/no-utility-reassignment");
const noHackReassignment = require("./src/rules/no-hack-reassignment");
const noStateWithoutComponent = require("./src/rules/no-state-without-component");
const noTypeOutsideScope = require("./src/rules/no-type-outside-scope");
const noNegativeVar = require("./src/rules/no-negative-var");
module.exports = [
stylelint.createPlugin(noUtilityReassignment.ruleName, noUtilityReassignment),
stylelint.createPlugin(noHackReassignment.ruleName, noHackReassignment),
stylelint.createPlugin(
noStateWithoutComponent.ruleName,
noStateWithoutComponent
),
stylelint.createPlugin(noTypeOutsideScope.ruleName, noTypeOutsideScope),
stylelint.createPlugin(noNegativeVar.ruleName, noNegativeVar)
];
const message = messages.rejected(value);
report({
index,
message,
node,
result,
ruleName
});
});
});
};
};
rule.primaryOptionArray = true;
module.exports = createPlugin(ruleName, rule);
module.exports.ruleName = ruleName;
module.exports.messages = messages;
const stylelint = require("stylelint");
const noUtilityReassignment = require("./src/rules/no-utility-reassignment");
const noHackReassignment = require("./src/rules/no-hack-reassignment");
const noStateWithoutComponent = require("./src/rules/no-state-without-component");
const noTypeOutsideScope = require("./src/rules/no-type-outside-scope");
const noNegativeVar = require("./src/rules/no-negative-var");
module.exports = [
stylelint.createPlugin(noUtilityReassignment.ruleName, noUtilityReassignment),
stylelint.createPlugin(noHackReassignment.ruleName, noHackReassignment),
stylelint.createPlugin(
noStateWithoutComponent.ruleName,
noStateWithoutComponent
),
stylelint.createPlugin(noTypeOutsideScope.ruleName, noTypeOutsideScope),
stylelint.createPlugin(noNegativeVar.ruleName, noNegativeVar)
];
if ((value * baseSize) % multiple === 0) return;
const index = declarationValueIndex(node) + sourceIndex;
const message = messages.expected(`${value}${unit}`, multiple);
report({
index,
message,
node,
result,
ruleName
});
});
});
};
};
module.exports = createPlugin(ruleName, rule);
module.exports.ruleName = ruleName;
module.exports.messages = messages;