Rules that apply to a class
10953
def class_rules
      [
        Rule.new(:error, 4..6, "Description Markdown", "Above your class you need documentation that covers the scope, and the usage of your plugin.", proc do |json|
          json[:body_md] && json[:body_md].empty?
        end),
        Rule.new(:warning, 30, "Tags", "This plugin does not include `@tags tag1, tag2` and thus will be harder to find in search.", proc do |json|
          json[:tags] && json[:tags].empty?
        end),
        Rule.new(:warning, 29, "References", "Ideally, you have a reference implementation of your plugin that you can show to people, add `@see org/repo` to have the site auto link it.", proc do |json|
          json[:see] && json[:see].empty?
        end),
        Rule.new(:error, 8..27, "Examples", "You should include some examples of common use-cases for your plugin.", proc do |json|
          json[:example_code] && json[:example_code].empty?
        end)
      ]
    end
1305604
def with_class(self, cls):
        
        rcls = []
        for key, value in self._classification.items():
            if value[0] == cls:
                rcls.append(key)
        return rcls
934854
def _set_rules(self, group, rules):
        """"""
        group.clear()

        for rule in rules:
            self._add_rule(group, *rule)

        self.invalidate()
1362912
function( name, method, message ) {
		$.validator.methods[name] = method;
		$.validator.messages[name] = message !== undefined ? message : $.validator.messages[name];
		if ( method.length < 3 ) {
			$.validator.addClassRules(name, $.validator.normalizeRule(name));
		}
	}
396005
def _filter_classes(cls_list, cls_type):
    """"""
    for cls in cls_list:
        if isinstance(cls, type) and issubclass(cls, cls_type):
            if cls_type == TempyPlace and cls._base_place:
                pass
            else:
                yield cls
101494
protected function applyRule(AbstractNode $allocatedClass, ClassNode $classNode): void
    {
        $entityNamePattern = '/^Spy/';
        $queryNamePattern = '/Query$/';

        $classReference = $allocatedClass->getFirstChildOfType('ClassReference');

        if ($classReference === null) {
            return;
        }

        $className = $classReference->getName();
        $className = explode('\\', $className);
        $className = array_pop($className);

        if (!preg_match($entityNamePattern, $className)
            || preg_match($queryNamePattern, $className)
        ) {
            return;
        }

        $message = sprintf(
            'Entity `%s` initialized in `%s`. The class violates rule `%s`.',
            $className,
            $classNode->getFullQualifiedName(),
            static::RULE
        );

        $this->addViolation($classNode, [$message]);
    }
193082
def class_filter(classes, class_name):
    
    result_classes = classes
    if isinstance(class_name, list):
        if set(class_name) <= set(classes):
            result_classes = class_name
    return result_classes
1105245
def match_classes(allowed_classes):
    """"""
    cleaned_allowed_classes = [
        utils.cls_to_cls_name(tmp_cls)
        for tmp_cls in allowed_classes
    ]

    def matcher(cause):
        cause_cls = None
        cause_type_name = cause.exception_type_names[0]
        try:
            cause_cls_idx = cleaned_allowed_classes.index(cause_type_name)
        except ValueError:
            pass
        else:
            cause_cls = allowed_classes[cause_cls_idx]
            if not isinstance(cause_cls, type):
                cause_cls = importutils.import_class(cause_cls)
            cause_cls = ensure_base_exception(cause_type_name, cause_cls)
        return cause_cls

    return matcher
990400
def setRules( self, rules ):
        
        if ( type(rules) in (list, tuple) ):
            self._rules = dict([(x.term(), x) for x in rules])
            self.updateRules()
            return True
            
        elif ( type(rules) == dict ):
            self._rules = rules.copy()
            self.updateRules()
            return True
            
        else:
            return False
650786
function registerClass(rule, className) {
  // Skip falsy values
  if (!className) return true

  // Support array of class names `{composes: ['foo', 'bar']}`
  if (Array.isArray(className)) {
    for (let index = 0; index < className.length; index++) {
      const isSetted = registerClass(rule, className[index])
      if (!isSetted) return false
    }

    return true
  }

  // Support space separated class names `{composes: 'foo bar'}`
  if (className.indexOf(' ') > -1) {
    return registerClass(rule, className.split(' '))
  }

  const {parent} = rule.options

  // It is a ref to a local rule.
  if (className[0] === '$') {
    const refRule = parent.getRule(className.substr(1))

    if (!refRule) {
      warning(false, '[JSS] Referenced rule is not defined. \r\n%s', rule)
      return false
    }

    if (refRule === rule) {
      warning(false, '[JSS] Cyclic composition detected. \r\n%s', rule)
      return false
    }

    parent.classes[rule.key] += ` ${parent.classes[refRule.key]}`

    return true
  }

  rule.options.parent.classes[rule.key] += ` ${className}`

  return true
}
219703
private static int adjustedClassModifiersForInnerClassTable(ClassNode classNode) {
        int modifiers = classNode.getModifiers();
        modifiers = modifiers & ~ACC_SUPER;
        modifiers = fixInterfaceModifiers(classNode, modifiers);

        modifiers = fixInnerClassModifiers(classNode, modifiers);
        return modifiers;
    }
900481
function bgBorderRuleString(className, options) {
    return classRule(className)
        .bg(options.background)
        .border(options.border)
        .build();
}
139602
def rule(self):
        
        if self._rule:
            return self._rule
        return self._make_rule(member_param=self._member_param,
                               unique_member_param=self._unique_member_param)
336604
public function setupRules()
    {
        $identifier = '\w+';
        $number = '[+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?';

        $this->rules->addMany([
            'string'  => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
                'context' => ['!keyword', '!comment', '!string', '!language', '!number'],
            ]),

            'comment' => new Rule(new CommentMatcher(['#'])),

            'keyword' => new Rule(new WordMatcher([
                'case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach',
                'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then',
                'unless', 'until', 'while', 'use', 'print', 'new', 'BEGIN',
                'sub', 'CHECK', 'INIT', 'END', 'return', 'exit'
            ])),

            'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [
                'context' => ['string']
            ]),

            'string.nowdoc'  => new Rule(
                new RegexMatcher('/<<\s*\'(\w+)\';(?P<string>.*?)\R\1/sm', [
                    'string' => Token::NAME,
                          0  => 'keyword.nowdoc'
                ]), ['context' => ['!comment']]
            ),

            'language.shell' => new Rule(new SubStringMatcher('`'), [
                'context' => ['!operator.escape', '!comment', '!string', '!keyword.nowdoc'],
                'factory' => new TokenFactory(ContextualToken::class),
            ]),

            'variable.scalar' => new Rule(new RegexMatcher("/(\\\$$identifier)/")),
            'variable.array'  => new Rule(new RegexMatcher("/(\\@$identifier)/")),
            'variable.hash'   => new Rule(new RegexMatcher("/(\\%$identifier)/")),

            'variable.property'   => new Rule(new RegexMatcher("/\\\$$identifier{($identifier)}/")),

            // Stupidly named var? Perl one, for sure.
            'variable.special'   => new Rule(new RegexMatcher('/([$@%][^\s\w]+[\w]*)/')),

            'operator' => [
                new Rule(new RegexMatcher('/(-[rwxoRWXOezsfdlpSbctugkTBMAC])/')),
                new Rule(new WordMatcher([
                    'not', 'and', 'or', 'xor', 'goto', 'last', 'next', 'redo', 'dump',
                    'eq', 'ne', 'cmp', 'not', 'and', 'or', 'xor'
                ], ['atomic' => true])),
            ],

            'call' => new Rule(new RegexMatcher('/([a-z]\w+)(?:\s*\(|\s+[$%@"\'`{])/i')),

            'number' => [
                new Rule(new RegexMatcher("/(\\b|\"|')$number\\1/", [
                    0 => Token::NAME
                ]), ['priority' => 5]),
            ],

            'string.regex' => [
                new OpenRule(new RegexMatcher('#~\s*[ms]?(/).*?/#m'), [
                    'context' => Validator::everywhere()
                ]),
                new OpenRule(new RegexMatcher('#~\s*(s/).*?/#m')),

                new Rule(new RegexMatcher('#(?=\/.*?(/[gimuy]{0,5}))#m'), [
                    'priority' => 1,
                    'factory'  => new TokenFactory(ContextualToken::class),
                    'context'  => ['!operator.escape', 'string.regex']
                ])
            ],
            
            'symbol.iterator' => [
                new Rule(new RegexMatcher('#(<\w+>)#s'))
            ]
        ]);
    }
415248
def calculate_sets(rules):
    """"""
    symbols = {sym for rule in rules for sym in rule.expansion} | {rule.origin for rule in rules}

    # foreach grammar rule X ::= Y(1) ... Y(k)
    # if k=0 or {Y(1),...,Y(k)} subset of NULLABLE then
    #   NULLABLE = NULLABLE union {X}
    # for i = 1 to k
    #   if i=1 or {Y(1),...,Y(i-1)} subset of NULLABLE then
    #     FIRST(X) = FIRST(X) union FIRST(Y(i))
    #   for j = i+1 to k
    #     if i=k or {Y(i+1),...Y(k)} subset of NULLABLE then
    #       FOLLOW(Y(i)) = FOLLOW(Y(i)) union FOLLOW(X)
    #     if i+1=j or {Y(i+1),...,Y(j-1)} subset of NULLABLE then
    #       FOLLOW(Y(i)) = FOLLOW(Y(i)) union FIRST(Y(j))
    # until none of NULLABLE,FIRST,FOLLOW changed in last iteration

    NULLABLE = set()
    FIRST = {}
    FOLLOW = {}
    for sym in symbols:
        FIRST[sym]={sym} if sym.is_term else set()
        FOLLOW[sym]=set()

    # Calculate NULLABLE and FIRST
    changed = True
    while changed:
        changed = False

        for rule in rules:
            if set(rule.expansion) <= NULLABLE:
                if update_set(NULLABLE, {rule.origin}):
                    changed = True

            for i, sym in enumerate(rule.expansion):
                if set(rule.expansion[:i]) <= NULLABLE:
                    if update_set(FIRST[rule.origin], FIRST[sym]):
                        changed = True

    # Calculate FOLLOW
    changed = True
    while changed:
        changed = False

        for rule in rules:
            for i, sym in enumerate(rule.expansion):
                if i==len(rule.expansion)-1 or set(rule.expansion[i+1:]) <= NULLABLE:
                    if update_set(FOLLOW[sym], FOLLOW[rule.origin]):
                        changed = True

                for j in range(i+1, len(rule.expansion)):
                    if set(rule.expansion[i+1:j]) <= NULLABLE:
                        if update_set(FOLLOW[sym], FIRST[rule.expansion[j]]):
                            changed = True

    return FIRST, FOLLOW, NULLABLE
626229
private static function isRulesClass(string $rulesClass): bool
    {
        return
            class_exists($rulesClass) === true &&
            in_array(JsonApiDataRulesInterface::class, class_implements($rulesClass)) === true;
    }
409317
def rule(pattern, *dependencies, &block)
      if block.nil?
        Rule.new(pattern, *dependencies)
      else
        Rule.new(pattern, *dependencies) do |rule|
          rule.define(&block)
        end
      end
    end