2012-01-04 10 views
19

pep8などのツールはソースコードスタイルをチェックできますが、pep257pep287に従ってドキュメントストリングが処理されていないかどうかはチェックしません。そのようなツールはありますか?PEP257に従って自動的にドキュメントスタイルをチェックするためのツール

更新

が、私は自分自身にそのような静的解析ツールを実装することを決定し、次を参照してください。

https://github.com/GreenSteam/pep257

今、 pep257のほとんどが覆われています。 デザインは前述の pep8ツールの影響を大きく受けました。

答えて

13

私はpythonのドキュメント文字列の静的解析ツールについて知らない。私は実際にPyLintを使い始めた直後にビルドを開始しましたが、すぐに諦めました。

PyLintにはプラグインシステムがあり、PEPを実行可能にするために作業を進めたい場合は、docストリングプラグインを使用できます。

PyLintの "プラグイン"はチェッカーと呼ばれ、ソースファイルを元のテキストドキュメントとして扱うものと、ASTとして動作するものの2つの形式があります。私はASTから始めて試しました。これは振り返ってみると間違いかもしれません。

は、ここで私が持っていたものです:

class DocStringChecker(BaseChecker): 
    """ 
    PyLint AST based checker to eval compliance with PEP 257-ish conventions. 
    """ 
    __implements__ = IASTNGChecker 

    name = 'doc_string_checker' 
    priority = -1 
    msgs = {'W9001': ('One line doc string on >1 lines', 
        ('Used when a short doc string is on multiple lines')), 
      'W9002': ('Doc string does not end with "." period', 
        ('Used when a doc string does not end with a period')), 
      'W9003': ('Not all args mentioned in doc string', 
        ('Used when not all arguments are in the doc string ')), 
      'W9004': ('triple quotes', 
        ('Used when doc string does not use """')), 
      } 
    options =() 

    def visit_function(self, node): 
     if node.doc: self._check_doc_string(node) 

    def visit_module(self, node): 
     if node.doc: self._check_doc_string(node) 

    def visit_class(self, node): 
     if node.doc: self._check_doc_string(node) 

    def _check_doc_string(self, node): 
     self.one_line_one_one_line(node) 
     self.has_period(node) 
     self.all_args_in_doc(node) 

    def one_line_one_one_line(self,node): 
     """One line docs (len < 80) are on one line""" 
     doc = node.doc 
     if len(doc) > 80: return True 
     elif sum(doc.find(nl) for nl in ('\n', '\r', '\n\r')) == -3: return True 
     else: 
      self.add_message('W9001', node=node, line=node.tolineno) 

    def has_period(self,node): 
     """Doc ends in a period""" 
     if not node.doc.strip().endswith('.'): 
      self.add_message('W9002', node=node, line=node.tolineno) 

    def all_args_in_doc(self,node): 
     """All function arguments are mentioned in doc""" 
     if not hasattr(node, 'argnames'): return True 
     for arg in node.argnames: 
      if arg != 'self' and arg in node.doc: continue 
      else: break 
     else: return True 
     self.add_message('W9003', node=node, line=node.tolineno) 

    def triple_quotes(self,node): #This would need a raw checker to work b/c the AST doesn't use """ 
     """Doc string uses tripple quotes""" 
     doc = node.doc.strip() 
     if doc.endswith('"""') and doc.startswith('"""'): return True 
     else: self.add_message('W9004', node=node, line=node.tolineno) 


def register(linter): 
    """required method to auto register this checker""" 
    linter.register_checker(DocStringChecker(linter)) 

私は偉大なドキュメントを持っていないこのシステムを思い出すと(つまり、過去一年間に変更されている場合があります)。これは少なくとも、ドキュメントの代わりに/本当にシンプルなコードをハッキングしようとするものです。

0

私はPEPに対して検証しているとは思わないが、Epydocは、docstrmap内の参照されているすべてのパラメータとオブジェクトが有効なパラメータとオブジェクトであることを確認します。

関連する問題