All files / plugins spacing.js

100% Statements 12/12
100% Branches 0/0
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 323x 3x   3x 3x   3x     7x 14x 7x 7x 91x   7x                                
const anymatch = require('anymatch')
const {createVariableRule} = require('./lib/variable-rules')
 
const spacerVarPatterns = ['$spacer-*', '$em-spacer-*']
const values = [...spacerVarPatterns, '0', 'auto', 'inherit']
 
module.exports = createVariableRule(
  'primer/spacing',
  ({variables}) => {
    const spacerVars = Object.keys(variables).filter(anymatch(spacerVarPatterns))
    const negativeValues = spacerVarPatterns.map(p => `-${p}`)
    const replacements = {}
    for (const name of spacerVars) {
      replacements[`-${variables[name].computed}`] = `-${name}`
    }
    return {
      margin: {
        expects: 'a spacer variable',
        props: 'margin{,-top,-right,-bottom,-left}',
        values: values.concat(negativeValues),
        replacements
      },
      padding: {
        expects: 'a non-negative spacer variable',
        props: 'padding{,-top,-right,-bottom,-left}',
        values
      }
    }
  },
  'https://primer.style/css/support/spacing'
)