index.js
/**
   * Check the selectors in a rule against the input HTML. If a selector doesn't exist in the HTML,
   * remove it.
   *
   * This function filters the `selectors` property of a rule in-place, and also returns a boolean
   * value indicating if the entire rule should be thrown out. If all selectors in a rule are
   * filtered out, then the function returns `false`. If at least one selector remains after
   * filtering, the function returns `true`.
   *
   * This boolean value is used by an array `filter()` to remove rules that have no matching
   * selectors.
   *
   * @param {Object} rule - Rule to examine the selectors of. Selectors are modified in-place.
   * @returns {Boolean} If value should be kept (`true`) or filtered out (`false`).
   */
Check the selectors in a rule against the input HTML. If a selector doesn't exist in the HTML,
remove it.

This function filters the `selectors` property of a rule in-place, and also returns a boolean
value indicating if the entire rule should be thrown out. If all selectors in a rule are
filtered out, then the function returns `false`. If at least one selector remains after
filtering, the function returns `true`.

This boolean value is used by an array `filter()` to remove rules that have no matching
selectors.

@param {Object} rule - Rule to examine the selectors of. Selectors are modified in-place.
@returns {Boolean} If value should be kept (`true`) or filtered out (`false`).
Check the selectors in a rule against the input HTML . If a selector doesn ' t exist in the HTML remove it . This function filters the ` selectors ` property of a rule in - place and also returns a boolean value indicating if the entire rule should be thrown out . If all selectors in a rule are filtered out then the function returns ` false ` . If at least one selector remains after filtering the function returns ` true ` . This boolean value is used by an array ` filter () ` to remove rules that have no matching selectors . @param { Object } rule - Rule to examine the selectors of . Selectors are modified in - place . @returns { Boolean } If value should be kept ( ` true ` ) or filtered out ( ` false ` ) .
function ruleCheck(rule) {
    if (rule.selectors) {
      rule.selectors = rule.selectors.filter(sel => {
        const selector = sel.split(/\s+/).map(s => s.replace(/:.*/, '')).join(' ');
        return $(selector).length > 0;
      });
      if (rule.selectors.length === 0) {
        return false;
      }
    }
    if (rule.rules) {
      rule.rules = rulesCheck(rule);
      return rule.rules.length > 0;
    }
    return true;
  }
function ruleCheck ( rule ) { if ( rule . selectors ) { rule . selectors = rule . selectors . filter ( sel => { const selector = sel . split ( / \s+ / ) . map ( s => s . replace ( / :.* / , '' ) ) . join ( ' ' ) ; return $ ( selector ) . length > 0 ; } ) ; if ( rule . selectors . length === 0 ) { return false ; } } if ( rule . rules ) { rule . rules = rulesCheck ( rule ) ; return rule . rules . length > 0 ; } return true ; }
Check the selectors in a rule against the input HTML.
Check the selectors in a rule against the input HTML .
// Actual rules will have a `selectors` property, whereas, say, a media query won't // Filter selectors by the ones that actually match an element in the HTML // Filter out pseudo-selectors // If a rule has no valid selectors, it should be removed from the CSS entirely // Media queries and other directives with nested rules will have a `rules` property // If all nested rules within a rule are filtered out, remove it