Helper function for visitiRuleset

return array|Less_Tree_Ruleset
480442
private function visitRulesetRoot( $rulesetNode ){
		$rulesetNode->accept( $this );
		if( $rulesetNode->firstRoot || $rulesetNode->rules ){
			return $rulesetNode;
		}
		return array();
	}
970220
function Rule(ruleString, params, data) {
    Tools.call(this, ruleString);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.params = _.extend({
        basePath: '',
        queryEq: '=',
        querySep: '&'
    }, params);

    /**
     * @public
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this.data = _.extend({
        name: uniqueId()
    }, data);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array<String>}
     * */
    this._pathParams = this._findPathParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._queryParams = this._compileQueryParams();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Array}
     * */
    this._queryParamsNames = _.keys(this._queryParams);

    this.params.types = _.extend({}, commonTypes, this.params.types);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._kinds = _.mapValues(this.params.types, function (regex, kind) {
        return new Kind(kind, regex);
    });

    _.forEach([{
        rules: this._pathParams,
        defaultKind: 'Segment'
    }, {
        rules: this._pathRule.query,
        defaultKind: 'String'
    }], function (setup) {
        _.forEach(setup.rules, function (rule) {
            if (!rule.kind) {
                if (rule.regex) {
                    rule.setUniqueKindName();
                    this._kinds[rule.kind] = new Kind(rule.kind, rule.regex);
                } else {
                    rule.kind = setup.defaultKind;
                }
            }

            if (!_.has(this._kinds, rule.kind)) {
                throw new TypeError(f('Unknown %j parameter type %j', rule.name, rule.kind));
            }
        }, this);
    }, this);

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {Object}
     * */
    this._paramsCount = this._compileParamsCount();

    /**
     * @protected
     * @memberOf {Rule}
     * @property
     * @type {RegExp}
     * */
    this._matchRegExp = this._compileMatchRegExp();
}
1202896
def nicer_get(di, required, *path):
    

    r = di
    for p in path:
        try:
            r = r[p]
        except KeyError:
            if required:
                logger.error("can't locate %s in ruleset dict, keys present: %s",
                             p, list(r.keys()))
                logger.debug("full dict = %s", r)
                raise ColinRulesetException("Validation error: can't locate %s in ruleset." % p)
            return
    return r
975981
function getRuleOptionsSchema(rule) {
    const schema = rule.schema || rule.meta && rule.meta.schema;

    // Given a tuple of schemas, insert warning level at the beginning
    if (Array.isArray(schema)) {
        if (schema.length) {
            return {
                type: "array",
                items: schema,
                minItems: 0,
                maxItems: schema.length
            };
        }
        return {
            type: "array",
            minItems: 0,
            maxItems: 0
        };

    }

    // Given a full schema, leave it alone
    return schema || null;
}
999967
function (rules) {

    var parsedRules = {};
    rules = this._flattenObject(rules);

    for (var attribute in rules) {

      var rulesArray = rules[attribute];

      this._parseRulesCheck(attribute, rulesArray, parsedRules);
    }
    return parsedRules;


  }
393913
function reduceSet(set) {
  return set.map(member => member && member.uri).filter(Boolean)
}
1366812
function (oTreeViewModelRules) {
			var aSelectedRules = storage.getSelectedRules();

			if (!aSelectedRules) {
				return null;
			}

			if (!oTreeViewModelRules) {
				return null;
			}


			aSelectedRules.forEach(function (oRuleDescriptor) {
				Object.keys(oTreeViewModelRules).forEach(function(iKey) {
					oTreeViewModelRules[iKey].nodes.forEach(function(oRule) {
						if (oRule.id === oRuleDescriptor.ruleId) {
							oRule.selected = oRuleDescriptor.selected;
							if (!oRule.selected) {
								oTreeViewModelRules[iKey].selected = false;
							}
						}
					});
				});
			});

			return oTreeViewModelRules;
		}
829037
function (less) {

        var Keyword = less.tree.Keyword;
        var DetachedRuleset = less.tree.DetachedRuleset;

        var isa = function (n, Type) {
            return (n instanceof Type) ? Keyword.True : Keyword.False;
        };

        if (!functions) {
            functions = {
                isruleset: function (n) {
                    return isa(n, DetachedRuleset);
                }
            };
        }
        return functions;
    }
1348166
@Nonnull
    private List<MixinMatch> getRules( CssFormatter formatter ) throws LessException {
        if( mixinRules != null && stackID == formatter.stackID() ) {
            return mixinRules;
        }
        List<Rule> rules = formatter.getMixin( name );
        if( rules == null ) {
            rules = mixins.get( name );
        }
        if( rules == null ) {
            int idx = name.indexOf( '>' ); // mixin with namespace?
            if( idx > 0 ) {
                String mainName = name.substring( 0, idx ).trim();
                rules = mixins.get( mainName );
                if( rules != null ) {
                    rules = rules.get( 0 ).getMixin( name.substring( idx + 1 ).trim() );
                }
            } else {
                idx = name.indexOf( '.' ); // mixin with namespace?
                if( idx > 0 ) {
                    String mainName = name.substring( 0, idx ).trim();
                    rules = mixins.get( mainName );
                    if( rules != null ) {
                        rules = rules.get( 0 ).getMixin( name.substring( idx ).trim() );
                    }
                }
            }
            if( rules == null ) {
                throw createException( "Undefined mixin: " + name );
            }
        }
        stackID = formatter.stackID();
        mixinRules = new ArrayList<>();
        boolean paramMatch = false;
        List<Rule> defaultMixins = null;
        for( Rule rule : rules ) {
            MixinMatch matching = rule.match( formatter, paramValues, false );
            if( matching != null ) {
                paramMatch = true;
                if( matching.getGuard() ) {
                    mixinRules.add( matching );
                } else if( matching.wasDefault() ) {
                    if( defaultMixins == null ) {
                        defaultMixins = new ArrayList<>();
                    }
                    defaultMixins.add( rule );
                }
            }
        }
        if( !paramMatch ) {
            throw createException( "No matching definition was found for: " + name );
        }
        if( mixinRules.size() == 0 && defaultMixins != null ) {
            for( Rule rule : defaultMixins ) {
                MixinMatch matching = rule.match( formatter, paramValues, true );
                if( matching != null && matching.getGuard() ) {
                    mixinRules.add( matching );
                }
            }
        }
        return mixinRules;
    }
1187209
private function extractRules()
    {
        // Keep in mind we don't support recursive directories (or cache the results)
        $possibleModels = glob(Strata::getSRCPath() . "Model" . DIRECTORY_SEPARATOR . "*.php");
        $this->batchModelFileRegistrationAttempt((array)$possibleModels);

        $possibleTaxonomies = glob(Strata::getSRCPath() . "Model" . DIRECTORY_SEPARATOR . "Taxonomy" . DIRECTORY_SEPARATOR . "*.php");
        $this->batchTaxonomyFileRegistrationAttempt((array)$possibleTaxonomies);
    }
1271148
function checkByAll ( rules, value, fieldMeta ) {
        return (rules || [])
            .map(function ( rule ) { 
                return checkByRule( rule, value, fieldMeta );
            })
            .filter(function ( el ) { return null !== el; });
    }
715953
function createRules() {
  const rules = {};
  sets.forEach((set) => {
    set.lngs.forEach((l) => {
      rules[l] = {
        numbers: set.nr,
        plurals: _rulesPluralsTypes[set.fc]
      };
    });
  });
  return rules;
}
318881
def _nest_at_rules(self, rule, scope, block):
        
        # TODO handle @charset, probably?
        # Interpolate the current block
        # TODO this seems like it should be done in the block header.  and more
        # generally?
        calculator = self._make_calculator(rule.namespace)
        if block.header.argument:
            # TODO is this correct?  do ALL at-rules ALWAYS allow both vars and
            # interpolation?
            node = calculator.parse_vars_and_interpolations(
                block.header.argument)
            block.header.argument = node.evaluate(calculator).render()

        # TODO merge into RuleAncestry
        new_ancestry = list(rule.ancestry.headers)
        if block.directive == '@media' and new_ancestry:
            for i, header in reversed(list(enumerate(new_ancestry))):
                if header.is_selector:
                    continue
                elif header.directive == '@media':
                    new_ancestry[i] = BlockAtRuleHeader(
                        '@media',
                        "%s and %s" % (header.argument, block.argument))
                    break
                else:
                    new_ancestry.insert(i, block.header)
            else:
                new_ancestry.insert(0, block.header)
        else:
            new_ancestry.append(block.header)

        rule.descendants += 1
        new_rule = SassRule(
            source_file=rule.source_file,
            import_key=rule.import_key,
            lineno=block.lineno,
            num_header_lines=block.header.num_lines,
            unparsed_contents=block.unparsed_contents,

            legacy_compiler_options=rule.legacy_compiler_options,
            options=rule.options.copy(),
            #properties
            #extends_selectors
            ancestry=RuleAncestry(new_ancestry),

            namespace=rule.namespace.derive(),
            nested=rule.nested + 1,
        )
        self.rules.append(new_rule)
        rule.namespace.use_import(rule.source_file)
        self.manage_children(new_rule, scope)

        self._warn_unused_imports(new_rule)
1065196
function result(rule) {
  var r = {}

  var reserved = ['filename', 'exists', 'grep', 'jsonKeyExists']

  Object.keys(rule).forEach(function(key) {
    if (reserved.indexOf(key) !== -1) return
    r[key] = rule[key]
  })

  return r
}
1309857
function ruleset(toks, i, n, handler) {
    // toks[s:e] are the selector tokens including internal whitespace.
    var s = i, e = selector(toks, i, n, true);
    if (e < 0) {
      // Skip malformed content per selector calling convention.
      e = ~e;
      // Make sure we skip at least one token.
      return e === s ? e+1 : e;
    }
    var tok = toks[e];
    if (tok !== '{') {
      // Make sure we skip at least one token.
      return e === s ? e+1 : e;
    }
    i = e+1;  // Skip over '{'
    // Don't include any trailing space in the selector slice.
    if (e > s && toks[e-1] === ' ') { --e; }
    if (handler['startRuleset']) {
      handler['startRuleset'](toks.slice(s, e));
    }
    while (i < n) {
      tok = toks[i];
      if (tok === '}') {
        ++i;
        break;
      }
      if (tok === ' ') {
        i = i+1;
      } else {
        i = declaration(toks, i, n, handler);
      }
    }
    if (handler['endRuleset']) {
      handler['endRuleset']();
    }
    return i;
  }
72101
function findRule(path, rules) {
   var matchingRule = null;

   for (var i=0; i < rules.length; i++) {
	   var rule = rules[i];

	   if (typeof rule.pattern === 'string') {
		   if (path.indexOf(rule.pattern) !== 0) {
			   continue;
		   }

		   // The longest matching rule takes precedence
		   if (!matchingRule || rule.pattern.length > matchingRule.pattern.length) {
			   matchingRule = rule;
		   }
	   // The first matching pattern takes precedence
	   // over all other rules including other patterns
	   } else if (rule.pattern.test(path)) {
		   return rule;
	   }
   }

   return matchingRule;
}
381756
function extractRules(model, options) {
  // check if rules are passed manually
  if (options.rules) {
    return options.rules;
  }

  // check if Model class had rules defined statically
  if (
    !model ||
    !model.__proto__ ||
    !model.__proto__.constructor ||
    !model.__proto__.constructor.validationRules
  ) {
    return [];
  }

  const rules = model.__proto__.constructor.validationRules;

  // rules not defined properly
  if (!Array.isArray(rules)) {
    throw Error(`Validation rules not defined correctly in Model`);
  }

  return rules;
}