@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
19 lines • 760 B
JavaScript
import { namedColors } from './named-colors';
const includesWholeWord = (value, options) => {
const values = value.replace(/[^a-zA-Z ]/g, ' ').trim().split(/(?:,|\.| )+/);
return values.some(value => options.has(value));
};
export const isHardCodedColor = value => {
if (includesWholeWord(value.toLowerCase(), namedColors)) {
return true;
}
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
return true;
}
if (value.startsWith('#') && (
// short hex, hex, or hex with alpha
value.length === 4 || value.length === 7 || value.length === 9)) {
return true;
}
return false;
};