Source code

Revision control

Other Tools

1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5
import os
6
import re
7
8
from mozlint.types import LineType
9
10
here = os.path.abspath(os.path.dirname(__file__))
11
HEADERS_FILE = os.path.join(here, 'mingw-headers.txt')
12
# generated by cd mingw-w64/mingw-w64-headers &&
13
# find . -name "*.h" | xargs -I bob -- basename bob | sort | uniq)
14
15
16
class MinGWCapitalization(LineType):
17
def __init__(self, *args, **kwargs):
18
super(MinGWCapitalization, self).__init__(*args, **kwargs)
19
with open(HEADERS_FILE, 'r') as fh:
20
self.headers = fh.read().strip().splitlines()
21
self.regex = re.compile("^#include\s*<(" + "|".join(self.headers) + ")>")
22
23
def condition(self, payload, line):
24
if not line.startswith("#include"):
25
return False
26
if self.regex.search(line, re.I):
27
return not self.regex.search(line)
28
29
30
def lint(paths, config, **lintargs):
31
results = []
32
33
m = MinGWCapitalization()
34
for path in paths:
35
results.extend(m._lint(path, config, **lintargs))
36
return results