Skip to content

Commit c42815a

Browse files
committed
Add canonical imports detection to deal with false positives
1 parent 3db24bd commit c42815a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

linter.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def tmpdir(self, cmd, dir, files, filename, code):
6464
return ""
6565

6666
def issue_level(self, issue):
67+
"""consider /dev/stderr as errors and /dev/stdout as warnings"""
6768
return "error" if issue["FromLinter"] == "typecheck" else "warning"
6869

6970
def canonical_error(self, issue):
@@ -119,7 +120,8 @@ def formalize(self, issues):
119120
return "\n".join(lines)
120121

121122
def execute(self, cmd):
122-
lines = []
123+
issues = []
124+
ignore = False
123125
output = self.communicate(cmd)
124126
report = json.loads(output)
125127

@@ -145,19 +147,23 @@ def execute(self, cmd):
145147
mark = name.rfind("/")
146148
mark = 0 if mark == -1 else mark+1
147149
issue["Pos"]["Shortname"] = name[mark:]
148-
"""decide if it is a warning or error"""
149150
issue["Level"] = self.issue_level(issue)
150-
"""skip issues from unrelated files"""
151-
if issue["Pos"]["Shortname"] != self.shortname:
151+
152+
"""detect broken canonical imports"""
153+
if ("code in directory" in issue["Text"]
154+
and "expects import" in issue["Text"]):
155+
issues.append(self.canonical_error(issue))
156+
ignore = True
152157
continue
153-
lines.append(
154-
"{}:{}:{}:{}:{}".format(
155-
issue["Pos"]["Shortname"],
156-
issue["Pos"]["Line"],
157-
issue["Pos"]["Column"],
158-
issue["Level"],
159-
issue["Text"]
160-
)
161-
)
162158

163-
return "\n".join(lines)
159+
"""ignore false positive warnings"""
160+
if (ignore
161+
and "could not import" in issue["Text"]
162+
and "missing package:" in issue["Text"]):
163+
continue
164+
165+
"""report issues relevant to this file"""
166+
if issue["Pos"]["Shortname"] == self.shortname:
167+
issues.append(issue)
168+
169+
return self.formalize(issues)

0 commit comments

Comments
 (0)