Total Complexity | 8 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python |
||
2 | # |
||
3 | # editorconfig-lint.py |
||
4 | # |
||
5 | # Copyright (C) 2019, Takazumi Shirayanagi |
||
6 | # This software is released under the new BSD License, |
||
7 | # see LICENSE |
||
8 | # |
||
9 | |||
10 | import sys |
||
11 | import os |
||
12 | |||
13 | try: |
||
14 | from configparser import ConfigParser |
||
15 | except ImportError: |
||
16 | from ConfigParser import SafeConfigParser as ConfigParser |
||
17 | |||
18 | |||
19 | class EditorConfig(object): |
||
20 | def __init__(self, path): |
||
21 | self.name = os.path.basename(path) |
||
22 | self.fp = open(path) |
||
23 | self.first_head = True |
||
24 | |||
25 | def readline(self): |
||
26 | if self.first_head: |
||
27 | self.first_head = False |
||
28 | return '[global]\n' |
||
29 | return self.fp.readline() |
||
30 | |||
31 | def __iter__(self): |
||
32 | return self |
||
33 | |||
34 | def __next__(self): |
||
35 | line = self.readline() |
||
36 | if not line: |
||
37 | raise StopIteration |
||
38 | return line |
||
39 | |||
40 | next = __next__ # For Python 2 compatibility. |
||
41 | |||
42 | |||
43 | def main(): |
||
44 | path = sys.argv[1] |
||
45 | ini = ConfigParser() |
||
46 | if not os.path.exists(path): |
||
47 | sys.stderr.write('%s not found...' % path) |
||
48 | sys.exit(2) |
||
49 | ini.read_file(EditorConfig(path)) |
||
50 | sys.exit(0) |
||
51 | |||
52 | |||
53 | if __name__ == '__main__': |
||
54 | main() |
||
55 |