
1 2 |
[*.{cpp,hpp,ipp}} charset = utf-8-bom |
直すのは簡単です。簡単ですが、また同じ失敗をする可能性があります。(にんげんだもの)
というわけで、テスト書きました。
テスト方法
.editorconfig の記法は概ね ini ファイルと一致します。なので、適当な ini ファイルパーサーに読み込ませてエラーが起きないかどうか?で検証できそうです。
iutest は C++ のテスティングフレームワークですが、ツール系には Python も使用しています。
Python には ConfigParser があるのでそちらでテストを書きました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import sys import os try : from configparser import ConfigParser except ImportError: from ConfigParser import SafeConfigParser as ConfigParser class EditorConfig( object ): def __init__( self , path): self .name = os.path.basename(path) self .fp = open (path) self .first_head = True def readline( self ): if self .first_head: self .first_head = False return '[global]\n' return self .fp.readline() def __iter__( self ): return self def __next__( self ): line = self .readline() if not line: raise StopIteration return line next = __next__ # For Python 2 compatibility. def main(): path = sys.argv[ 1 ] ini = ConfigParser() if not os.path.exists(path): sys.stderr.write( '%s not found...' % path) sys.exit( 2 ) ini.readfp(EditorConfig(path)) sys.exit( 0 ) if __name__ = = '__main__' : main() |
基本的には ini ファイルをパーサーにかけるだけなんですが、1点だけポイントがあります。
EditorConfig は、ディレクトリを上がって .editorconfig を探索しますが、root = true を最初に書いておくとそこで探索が打ち切られます。
この root = true が ini ファイルとしてはセクションのない要素のためエラーになってしまいます。
そのため、最初に [global] というダミーセクションを挿入して ConfigParser に渡してます。
CI に組み込む
Python が実行できる CI サービスであればなんでも問題ありません。今回 iutest では Codeship で cpplint やインクルードガードのチェックや絶対パスが混入してないかの、雑多なテストを行っているのでそちらに組み込みました。

こんな感じに検出されます!
これでもう安心ですね。
0 件のコメント:
コメントを投稿