Rev a1f0b35 adds add-missing-docstrings command

17 views
Skip to first unread message

Edward K. Ream

unread,
Jun 15, 2019, 8:12:54 PM6/15/19
to leo-editor
The find-missing-docstrings command is hugely faster than running pylint.

This command uses Vitalije's is_definition_line and has_docstring function. Credit is given.

The command is a rewrite using g.findRootsWithPredicate:

@g.command('find-missing-docstrings')
def find_missing_docstrings(event):
   
'''Report missing docstrings in the log, with clickable links.'''
    c
= event.get('c')
   
if not c:
       
return

   
@others # Define functions

    count
, found, t1 = 0, [], time.clock()
   
for root in g.findRootsWithPredicate(c, c.p, predicate=is_root):
       
for p in root.self_and_subtree():
            lines
= p.b.split('\n')
           
for i, line in enumerate(lines):
               
if is_a_definition(line) and not has_docstring(lines, i):
                    count
+= 1
                   
if root.v not in found:
                        found
.append(root.v)
                        g
.es_print('')
                        g
.es_print(root.h)
                   
print(line)
                    g
.es(line, nodeLink=clickable_link(p, i+1))
                   
break
    g
.es_print('')
    g
.es_print('found %s missing docstring%s in %s file%s in %5.2f sec.' % (
        count
, g.plural(count),
        len
(found), g.plural(len(found)),
       
(time.clock() - t1)))

Here is is_root:

def is_root(p):
   
'''A predicate returning True if p represents an external python file
    that is not under @nopylint.'''

   
for parent in p.self_and_parents():
       
if g.match_word(parent.h, 0, '@nopylint'):
           
return False
   
return p.isAnyAtFileNode() and p.h.strip().endswith('.py')

Edward
Reply all
Reply to author
Forward
0 new messages