1+ # (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
2+
13import argparse
24import concurrent .futures
35import json
79import sys
810import time
911from enum import Enum
10- from pathlib import Path
1112from typing import Any , List , NamedTuple , Optional
1213
1314
@@ -26,15 +27,15 @@ class LintSeverity(str, Enum):
2627
2728
2829class 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
4041def 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.\n Run `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 (),
0 commit comments