xref: /aosp_15_r20/external/executorch/.lintrunner.toml (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1merge_base_with = "origin/main"
2
3[[linter]]
4code = 'FLAKE8'
5include_patterns = ['**/*.py']
6exclude_patterns = [
7    'third-party/**',
8    '**/third-party/**',
9    '.github/scripts/**',
10    'exir/serde/**',
11]
12command = [
13    'python',
14    '-m',
15    'lintrunner_adapters',
16    'run',
17    'flake8_linter',
18    '--',
19    '@{{PATHSFILE}}'
20]
21init_command = [
22    'python',
23    '-m',
24    'lintrunner_adapters',
25    'run',
26    'pip_init',
27    '--dry-run={{DRYRUN}}',
28    '--requirement=requirements-lintrunner.txt',
29]
30
31# Black + usort
32[[linter]]
33code = 'UFMT'
34include_patterns = [
35    '**/*.py',
36    '**/*.pyi',
37]
38exclude_patterns = [
39    'third-party/**',
40    '**/third-party/**',
41    'exir/serde/**',
42]
43command = [
44    'python',
45    '-m',
46    'lintrunner_adapters',
47    'run',
48    'ufmt_linter',
49    '--',
50    '@{{PATHSFILE}}'
51]
52init_command = [
53    'python',
54    '-m',
55    'lintrunner_adapters',
56    'run',
57    'pip_init',
58    '--dry-run={{DRYRUN}}',
59    '--no-black-binary',
60    '--requirement=requirements-lintrunner.txt',
61]
62is_formatter = true
63
64#CLANGFORMAT
65[[linter]]
66code = 'CLANGFORMAT'
67include_patterns = [
68    '**/*.h',
69    '**/*.cpp',
70]
71exclude_patterns = [
72    'third-party/**',
73    '**/third-party/**',
74    # NB: Objective-C is not supported
75    'examples/apple/**',
76    'examples/demo-apps/apple_ios/**',
77    # File contains @generated
78    'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
79    'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',
80]
81command = [
82    'python',
83    '-m',
84    'lintrunner_adapters',
85    'run',
86    'clangformat_linter',
87    '--binary=clang-format',
88    '--fallback',
89    '--',
90    '@{{PATHSFILE}}'
91]
92init_command = [
93    'python',
94    '-m',
95    'lintrunner_adapters',
96    'run',
97    'pip_init',
98    '--dry-run={{DRYRUN}}',
99    '--requirement=requirements-lintrunner.txt',
100]
101is_formatter = true
102
103[[linter]]
104code = 'CMAKE'
105include_patterns = [
106    "**/*.cmake",
107    "**/*.cmake.in",
108    "**/CMakeLists.txt",
109]
110exclude_patterns = [
111    'third-party/**',
112    '**/third-party/**',
113]
114command = [
115    'python',
116    '-m',
117    'lintrunner_adapters',
118    'run',
119    'cmake_linter',
120    '--config=.cmakelintrc',
121    '--',
122    '@{{PATHSFILE}}',
123]
124init_command = [
125    'python',
126    '-m',
127    'lintrunner_adapters',
128    'run',
129    'pip_init',
130    '--dry-run={{DRYRUN}}',
131    '--requirement=requirements-lintrunner.txt',
132]
133
134[[linter]]
135code = 'ETCAPITAL'
136include_patterns = [
137    '**/*.py',
138    '**/*.pyi',
139    '**/*.h',
140    '**/*.cpp',
141    '**/*.md',
142    '**/*.rst',
143]
144exclude_patterns = [
145    'third-party/**',
146    '**/third-party/**',
147]
148command = [
149    'python',
150    '-m',
151    'lintrunner_adapters',
152    'run',
153    'grep_linter',
154    # Exclude "ExecuTorch" pattern within URLs
155    '--pattern= Executorch(?!\\W*(://|\\.[a-z]{2,}))\\W+',
156    '--linter-name=ExecuTorchCapitalization',
157    '--error-name=Incorrect capitalization for ExecuTorch',
158    """--error-description=
159    Please use ExecuTorch with capital T for consistency.
160    https://fburl.com/workplace/nsx6hib2
161    """,
162    '--',
163    '@{{PATHSFILE}}',
164]
165
166[[linter]]
167code = 'NEWLINE'
168include_patterns = ['**']
169exclude_patterns = [
170    'third-party/**',
171    '**/third-party/**',
172    '**/*.png',
173    '**/*.webp',
174    '**/*.jpeg',
175    '**/*.mp4',
176    '**/*.pte',
177    '**/*.pth',
178    '**/*.bin',
179    '**/*.patch',
180    '**/*.svg',
181    '**/*.bat',
182    '**/*.jpg',
183    '**/*.jar',
184    '**/*.gif',
185    # File contains @generated
186    'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
187    'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',
188]
189command = [
190    'python',
191    '-m',
192    'lintrunner_adapters',
193    'run',
194    'newlines_linter',
195    '--',
196    '@{{PATHSFILE}}',
197]
198is_formatter = true
199
200[[linter]]
201code = 'NOSTDINC'
202include_patterns = [
203    "**/*.c",
204    "**/*.cpp",
205    "**/*.h",
206    "**/*.hpp",
207]
208exclude_patterns = [
209    '**/devtools/**',
210    '**/test/**',
211    '**/testing_util/**',
212    '**/third-party/**',
213    'backends/**',
214    'devtools/**',
215    'examples/**',
216    'extension/**',
217    'kernels/optimized/**',
218    'scripts/**',
219    'third-party/**',
220    'util/**',
221]
222command = [
223    'python',
224    '-m',
225    'lintrunner_adapters',
226    'run',
227    'grep_linter',
228    '--pattern=([^\\S\r\n]*#include\s*<(deque|exception|forward_list|functional|list|map|multimap|multiset|priority_queue|queue|set|stack|string|unordered_map|unordered_multimap|unordered_multiset|unordered_set|vector)>)',
229    '--linter-name=NOSTDINC',
230    '--error-name=Standard C++ container include in core',
231    """--error-description=\
232        Standard library containers should not be included in ExecuTorch core \
233        because they may call malloc, which is not allowed in core. \
234    """,
235    '--',
236    '@{{PATHSFILE}}',
237]
238
239[[linter]]
240code = 'NOTORCHINC'
241include_patterns = [
242    "**/*.c",
243    "**/*.cpp",
244    "**/*.h",
245    "**/*.hpp",
246]
247exclude_patterns = [
248    '**/devtools/**',
249    '**/fb/**',
250    '**/test/**',
251    '**/tests/**',
252    '**/testing_util/**',
253    '**/third-party/**',
254    'backends/**',
255    'codegen/templates/RegisterDispatchKeyCustomOps.cpp',
256    'codegen/templates/RegisterSchema.cpp',
257    'devtools/**',
258    'examples/**',
259    'exir/verification/bindings.cpp',
260    'extension/**',
261    'kernels/optimized/**',
262    'runtime/core/exec_aten/**',
263    'runtime/executor/tensor_parser_aten.cpp',
264    'scripts/**',
265    'test/**',
266    'third-party/**',
267    'util/**',
268]
269command = [
270    'python',
271    '-m',
272    'lintrunner_adapters',
273    'run',
274    'grep_linter',
275    '--pattern=#include\s+[<"](aten/|ATen/|torch/)',
276    '--linter-name=NOTORCHINC',
277    '--error-name=ATen or torch include',
278    """--error-description=\
279        PyTorch includes in ExecuTorch core are prohibited to prevent \
280        accidentally breaking core's requirements; please make sure this \
281        header complies (e.g., no streams/malloc/syscalls) and then include \
282        a patch to update this linter.\
283    """,
284    '--',
285    '@{{PATHSFILE}}',
286]
287