Example #1
0
def get_at_hints(node, at_hints=None):
    if at_hints is None:
        at_hints = defaultdict(dict)
    commentsArray = Comment.parseNode(node, process_txt=False)  # searches comment "around" this node
    for commentAttributes in commentsArray:
        for entry in commentAttributes:
             # {'arguments': ['a', 'b'],
             #  'category': u'lint',
             #  'functor': u'ignoreReferenceField',
             #  'text': u'<p>ignoreReferenceField(a,b)</p>'
             # }
            cat = entry['category']
            if cat=='lint':
                functor = entry['functor']
                if functor not in at_hints[cat]:
                    at_hints[cat][functor] = set()
                at_hints[cat][functor].update(entry['arguments']) 
            elif cat=="ignore":
                if cat not in at_hints:
                    at_hints[cat] = set()
                at_hints[cat].update(entry['arguments'])
    # include @hints of parent scopes
    scope = scopes.find_enclosing(node)
    if scope:
        at_hints = get_at_hints(scope.node, at_hints)
    return at_hints
Example #2
0
def get_at_hints(node, at_hints=None):
    if at_hints is None:
        at_hints = defaultdict(dict)
    commentsArray = Comment.parseNode(
        node)  # searches comment "around" this node
    for commentAttributes in commentsArray:
        for entry in commentAttributes:
            # {'arguments': ['a', 'b'],
            #  'category': u'lint',
            #  'functor': u'ignoreReferenceField',
            #  'text': u'<p>ignoreReferenceField(a,b)</p>'
            # }
            cat = entry['category']
            if cat == 'lint':
                functor = entry['functor']
                if functor not in at_hints[cat]:
                    at_hints[cat][functor] = set()
                at_hints[cat][functor].update(entry['arguments'])
            elif cat == "ignore":
                if cat not in at_hints:
                    at_hints[cat] = set()
                at_hints[cat].update(entry['arguments'])
    # include @hints of parent scopes
    scope = scopes.find_enclosing(node)
    if scope:
        if 0: print "debug:", file_name, node, scope.node
        at_hints = get_at_hints(scope.node, at_hints)
    return at_hints
Example #3
0
 def process_comments(self, node):
     hint = None
     if node.comments:
         commentsArray = Comment.parseNode(
             node, process_txt=False)  #, want_errors=True)
         if any(commentsArray):
             hint = Hint()
             # fill hint from commentAttributes
             for commentAttributes in commentsArray:
                 for entry in commentAttributes:
                     cat = entry['category']
                     if cat not in ('ignore', 'lint', 'require', 'use',
                                    'asset', 'cldr'):
                         continue
                     # the next is currently not used (Comment.parseNode doesn't return error commentAttributes)
                     # but would be suitable for error reporting with file and line number
                     elif hasattr(entry, 'error'):
                         filename = node.getRoot().get('file', '<Unknown>')
                         lineno = node.get('line')
                         msg = "%s (%s): %s: %s" % (filename, lineno,
                                                    entry['message'],
                                                    entry['text'])
                         context.console.warn(msg)
                     else:
                         functor = entry.get(
                             'functor'
                         )  # will be None for non-functor keys like @ignore, @require, ...
                         hint.add_entries(
                             (cat, functor), entry['arguments']
                         )  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                         # hint.hints['ignore'][None]{'foo','bar'}
     return hint
Example #4
0
    def process_comments(self, node):
        hint = None
        if node.comments:
            commentsArray = Comment.parseNode(node, process_txt=False, want_errors=True)
            if any(commentsArray):
                hint = Hint()
                # fill hint from commentAttributes
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        # errors treated later
                        if 'error' in entry:
                            continue
                        # add interesting entries to tree
                        cat = entry['category']
                        if cat not in ('ignore', 'lint', 'require', 'use', 'asset', 'cldr'):
                            continue
                        else:
                            functor = entry.get('functor') # will be None for non-functor keys like @ignore, @require, ...
                            hint.add_entries((cat,functor), entry['arguments'])  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                                                                         # hint.hints['ignore'][None]{'foo','bar'}

                # loop again for error logging (here, so you can ignore error entries in the same comment)
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        if 'error' in entry:
                            if self._key_is_ignored(entry['category'], hint):
                                continue
                            else:
                                msg = "%s (%s): %s" % (entry['filename'], entry['lineno'], entry['message'])
                                msg += (": %s" % entry['text']) if 'text' in entry and entry['text'] else ''
                                context.console.warn(msg)

        return hint
Example #5
0
    def process_comments(self, node):
        hint = None
        if node.comments:
            commentsArray = Comment.parseNode(node,
                                              process_txt=False,
                                              want_errors=True)
            if any(commentsArray):
                hint = Hint()
                # fill hint from commentAttributes
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        # errors treated later
                        if 'error' in entry:
                            continue
                        # add interesting entries to tree
                        cat = entry['category']
                        if cat not in ('ignore', 'lint', 'require', 'use',
                                       'asset', 'cldr'):
                            continue
                        else:
                            functor = entry.get(
                                'functor'
                            )  # will be None for non-functor keys like @ignore, @require, ...
                            hint.add_entries(
                                (cat, functor), entry['arguments']
                            )  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                            # hint.hints['ignore'][None]{'foo','bar'}

                # loop again for error logging (here, so you can ignore error entries in the same comment)
                #
                # TODO: separation of concerns -  it's a kludge to be outputting warnings here; they should
                # be returned to the caller of the module, together with the genuine result. the caller
                # should decide how to handle warnings. if he handles them warnings should be transformed
                # into a generic format and passed to a dedicated handler, e.g. the Log module. this handler
                # might in turn consult the hint tree, to check for ignore hints.
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        if 'error' in entry:
                            if self._key_is_ignored(entry['category'], hint):
                                continue
                            else:
                                msg = "%s (%s): %s" % (entry['filename'],
                                                       entry['lineno'],
                                                       entry['message'])
                                msg += (
                                    ": %s" % entry['text']
                                ) if 'text' in entry and entry['text'] else ''
                                context.console.warn(msg)

        return hint
Example #6
0
 def process_comments(self, node):
     hint = None
     if node.comments:
         commentsArray = Comment.parseNode(node, process_txt=False)
         if any(commentsArray):
             hint = Hint()
             # fill hint from commentAttributes
             for commentAttributes in commentsArray:
                 for entry in commentAttributes:
                     cat = entry['category']
                     if cat not in ('ignore', 'lint', 'require', 'use'):
                         continue
                     functor = entry.get('functor') # will be None for non-functor keys like @ignore, @require, ...
                     hint.add_entries((cat,functor), entry['arguments'])  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                                                                  # hint.hints['ignore'][None]{'foo','bar'}
     return hint
Example #7
0
def get_at_hints(node):
    commentAttributes = Comment.parseNode(node)  # searches comment "around" this node
    at_hints = {}
    for entry in commentAttributes:
        cat = entry['category']
        if cat not in at_hints:
            at_hints[cat] = {}
        if cat=='lint':
             # {'arguments': ['a', 'b'],
             #  'category': u'lint',
             #  'functor': u'ignoreReferenceField',
             #  'text': u'<p>ignoreReferenceField(a,b)</p>'
             # }
            functor = entry['functor']
            if functor not in at_hints['lint']:
                at_hints['lint'][functor] = set()
            at_hints['lint'][functor].update(entry['arguments'])
    return at_hints
Example #8
0
def get_at_hints(node):
    commentAttributes = Comment.parseNode(
        node)  # searches comment "around" this node
    at_hints = {}
    for entry in commentAttributes:
        cat = entry['category']
        if cat not in at_hints:
            at_hints[cat] = {}
        if cat == 'lint':
            # {'arguments': ['a', 'b'],
            #  'category': u'lint',
            #  'functor': u'ignoreReferenceField',
            #  'text': u'<p>ignoreReferenceField(a,b)</p>'
            # }
            functor = entry['functor']
            if functor not in at_hints['lint']:
                at_hints['lint'][functor] = set()
            at_hints['lint'][functor].update(entry['arguments'])
    return at_hints
Example #9
0
    def visit(self, node):

        if node.comments:
            commentsArray = Comment.parseNode(node)
            if any(commentsArray):
                hint = Hint()
                # maintain hint tree
                self.curr_hint.children.append(hint)
                hint.parent = self.curr_hint
                # fill hint from commentAttributes
                hint = self.commentAttributes_to_hint(commentsArray, hint)
                # get main node from node
                main_node = treeutil.findCommentedRoot(node)
                # cross-link hint and node
                main_node.hint = hint
                hint.node = main_node # node?!
                # scope nested hints
                self.curr_hint = hint
        for cld in node.children:
            self.visit(cld)
Example #10
0
    def process_comments(self, node):
        hint = None
        if node.comments:
            commentsArray = Comment.parseNode(node, process_txt=False, want_errors=True)
            if any(commentsArray):
                hint = Hint()
                # fill hint from commentAttributes
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        # errors treated later
                        if 'error' in entry:
                            continue
                        # add interesting entries to tree
                        cat = entry['category']
                        if cat not in ('ignore', 'lint', 'require', 'use', 'asset', 'cldr'):
                            continue
                        else:
                            functor = entry.get('functor') # will be None for non-functor keys like @ignore, @require, ...
                            hint.add_entries((cat,functor), entry['arguments'])  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                                                                         # hint.hints['ignore'][None]{'foo','bar'}

                # loop again for error logging (here, so you can ignore error entries in the same comment)
                #
                # TODO: separation of concerns -  it's a kludge to be outputting warnings here; they should
                # be returned to the caller of the module, together with the genuine result. the caller
                # should decide how to handle warnings. if he handles them warnings should be transformed
                # into a generic format and passed to a dedicated handler, e.g. the Log module. this handler
                # might in turn consult the hint tree, to check for ignore hints.
                for commentAttributes in commentsArray:
                    for entry in commentAttributes:
                        if 'error' in entry:
                            if self._key_is_ignored(entry['category'], hint):
                                continue
                            else:
                                msg = "%s (%s): %s" % (entry['filename'], entry['lineno'], entry['message'])
                                msg += (": %s" % entry['text']) if 'text' in entry and entry['text'] else ''
                                context.console.warn(msg)

        return hint
Example #11
0
 def process_comments(self, node):
     hint = None
     if node.comments:
         commentsArray = Comment.parseNode(node, process_txt=False) #, want_errors=True)
         if any(commentsArray):
             hint = Hint()
             # fill hint from commentAttributes
             for commentAttributes in commentsArray:
                 for entry in commentAttributes:
                     cat = entry['category']
                     if cat not in ('ignore', 'lint', 'require', 'use', 'asset', 'cldr'):
                         continue
                     # the next is currently not used (Comment.parseNode doesn't return error commentAttributes)
                     # but would be suitable for error reporting with file and line number
                     elif hasattr(entry, 'error'):
                         filename = node.getRoot().get('file', '<Unknown>')
                         lineno = node.get('line')
                         msg = "%s (%s): %s: %s" % (filename, lineno, entry['message'], entry['text'])
                         context.console.warn(msg)
                     else:
                         functor = entry.get('functor') # will be None for non-functor keys like @ignore, @require, ...
                         hint.add_entries((cat,functor), entry['arguments'])  # hint.hints['lint']['ignoreUndefined']{'foo','bar'}
                                                                      # hint.hints['ignore'][None]{'foo','bar'}
     return hint