Skip to content

Commit 5100cb5

Browse files
committed
Make lintrunner support specific to multipy
ghstack-source-id: 77a44c8 Pull Request resolved: #289
1 parent 04049d5 commit 5100cb5

File tree

11 files changed

+122
-1024
lines changed

11 files changed

+122
-1024
lines changed

.lintbin/actionlint

-3.68 MB
Binary file not shown.

.lintbin/clang-format

-1.86 MB
Binary file not shown.

.lintrunner.toml

Lines changed: 105 additions & 510 deletions
Large diffs are not rendered by default.
File renamed without changes.

scripts/linter/adapters/circleci_linter.py

Lines changed: 0 additions & 159 deletions
This file was deleted.

scripts/linter/adapters/clangformat_linter.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
13
import argparse
24
import concurrent.futures
35
import json
@@ -7,7 +9,6 @@
79
import sys
810
import time
911
from enum import Enum
10-
from pathlib import Path
1112
from typing import Any, List, NamedTuple, Optional
1213

1314

@@ -26,15 +27,15 @@ class LintSeverity(str, Enum):
2627

2728

2829
class LintMessage(NamedTuple):
29-
path: Optional[str]
30+
path: str
3031
line: Optional[int]
3132
char: Optional[int]
32-
code: str
3333
severity: LintSeverity
3434
name: str
3535
original: Optional[str]
3636
replacement: Optional[str]
3737
description: Optional[str]
38+
bypassChangedLineFiltering: Optional[bool]
3839

3940

4041
def as_posix(name: str) -> str:
@@ -105,16 +106,17 @@ def check_file(
105106
path=filename,
106107
line=None,
107108
char=None,
108-
code="CLANGFORMAT",
109109
severity=LintSeverity.ERROR,
110110
name="timeout",
111111
original=None,
112112
replacement=None,
113113
description=(
114-
"clang-format timed out while trying to process a file. "
115-
"Please report an issue in pytorch/pytorch with the "
116-
"label 'module: lint'"
114+
"Please report this in https://fb.workplace.com/groups/lintqa/\n"
115+
"If clang-format is timing out over a file, it can lock up "
116+
"the daily clang-format CodemodService codemods "
117+
"(see T115674339)."
117118
),
119+
bypassChangedLineFiltering=None,
118120
)
119121
]
120122
except (OSError, subprocess.CalledProcessError) as err:
@@ -123,7 +125,6 @@ def check_file(
123125
path=filename,
124126
line=None,
125127
char=None,
126-
code="CLANGFORMAT",
127128
severity=LintSeverity.ADVICE,
128129
name="command-failed",
129130
original=None,
@@ -143,6 +144,7 @@ def check_file(
143144
stdout=err.stdout.decode("utf-8").strip() or "(empty)",
144145
)
145146
),
147+
bypassChangedLineFiltering=None,
146148
)
147149
]
148150

@@ -153,14 +155,14 @@ def check_file(
153155
return [
154156
LintMessage(
155157
path=filename,
156-
line=None,
157-
char=None,
158-
code="CLANGFORMAT",
158+
line=1,
159+
char=1,
159160
severity=LintSeverity.WARNING,
160161
name="format",
161162
original=original.decode("utf-8"),
162163
replacement=replacement.decode("utf-8"),
163-
description="See https://clang.llvm.org/docs/ClangFormat.html.\nRun `lintrunner -a` to apply this patch.",
164+
description="See https://fburl.com/fbsource-linters#clang-format",
165+
bypassChangedLineFiltering=True,
164166
)
165167
]
166168

@@ -210,23 +212,6 @@ def main() -> None:
210212
)
211213

212214
binary = os.path.normpath(args.binary) if IS_WINDOWS else args.binary
213-
if not Path(binary).exists():
214-
lint_message = LintMessage(
215-
path=None,
216-
line=None,
217-
char=None,
218-
code="CLANGFORMAT",
219-
severity=LintSeverity.ERROR,
220-
name="init-error",
221-
original=None,
222-
replacement=None,
223-
description=(
224-
f"Could not find clang-format binary at {binary}, "
225-
"did you forget to run `lintrunner init`?"
226-
),
227-
)
228-
print(json.dumps(lint_message._asdict()), flush=True)
229-
sys.exit(0)
230215

231216
with concurrent.futures.ThreadPoolExecutor(
232217
max_workers=os.cpu_count(),

scripts/linter/adapters/mypy_linter.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def check_files(
8787
filenames: List[str],
8888
config: str,
8989
retries: int,
90-
code: str,
9190
) -> List[LintMessage]:
9291
try:
9392
proc = run_command(
@@ -101,7 +100,7 @@ def check_files(
101100
path=None,
102101
line=None,
103102
char=None,
104-
code=code,
103+
code="MYPY",
105104
severity=LintSeverity.ERROR,
106105
name="command-failed",
107106
original=None,
@@ -119,7 +118,7 @@ def check_files(
119118
char=int(match["column"])
120119
if match["column"] is not None and not match["column"].startswith("-")
121120
else None,
122-
code=code,
121+
code="MYPY",
123122
severity=severities.get(match["severity"], LintSeverity.ERROR),
124123
original=None,
125124
replacement=None,
@@ -144,11 +143,6 @@ def main() -> None:
144143
required=True,
145144
help="path to an mypy .ini config file",
146145
)
147-
parser.add_argument(
148-
"--code",
149-
default="MYPY",
150-
help="the code this lint should report as",
151-
)
152146
parser.add_argument(
153147
"--verbose",
154148
action="store_true",
@@ -188,7 +182,7 @@ def main() -> None:
188182
else:
189183
filenames[filename] = True
190184

191-
lint_messages = check_files(list(filenames), args.config, args.retries, args.code)
185+
lint_messages = check_files(list(filenames), args.config, args.retries)
192186
for lint_message in lint_messages:
193187
print(json.dumps(lint_message._asdict()), flush=True)
194188

0 commit comments

Comments
 (0)