Skip to content

Commit

Permalink
[lint] lintrunner fixes/improvements (pytorch#68292)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#68292

- noqa was typo-d to be the same as type: ignore
- generalize clang-tidy initialization and use it for clang_format as well
- Add a script that lets you update the binaries in s3 relatively easily

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D32403934

Pulled By: suo

fbshipit-source-id: 4e21b22605216f013d87d636a205707ca8e0af36
  • Loading branch information
suo authored and facebook-github-bot committed Nov 15, 2021
1 parent 43874d7 commit 24b60b2
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 228 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ TAGS
# clang tooling storage location
.clang-format-bin
.clang-tidy-bin
.lintbin

# clangd background index
.clangd/
Expand Down
27 changes: 19 additions & 8 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ include_patterns = [
'test/cpp/tensorexpr/**/*.h',
'test/cpp/tensorexpr/**/*.cpp',
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=clang-format',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=clang-format',
]
command = [
'python3',
'tools/linter/adapters/clangformat_linter.py',
'--binary=clang-format',
'--binary=.lintbin/clang-format',
'--',
'@{{PATHSFILE}}'
]
Expand Down Expand Up @@ -159,15 +168,17 @@ exclude_patterns = [
]
init_command = [
'python3',
'tools/linter/adapters/clangtidy_init.py',
'--dry_run={{DRYRUN}}',
'--output_dir=.clang-tidy-bin',
'--output_name=clang-tidy',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=clang-tidy',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=clang-tidy',
]
command = [
'python3',
'tools/linter/adapters/clangtidy_linter.py',
'--binary=.clang-tidy-bin/clang-tidy',
'--binary=.lintbin/clang-tidy',
'--build_dir=./build',
'--',
'@{{PATHSFILE}}'
Expand Down Expand Up @@ -198,8 +209,8 @@ exclude_patterns = ['caffe2/**']
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=# type:\s*ignore(?!\[)',
'--linter-name=TYPEIGNORE',
'--pattern=# noqa(?!: [A-Z]+\d{3})',
'--linter-name=NOQA',
'--error-name=unqualified noqa',
"""--error-description=\
This line has an unqualified `noqa`; \
Expand Down
18 changes: 18 additions & 0 deletions tools/linter/adapters/clangformat_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import time
from enum import Enum
from pathlib import Path
from typing import Any, List, NamedTuple, Optional


Expand Down Expand Up @@ -209,6 +210,23 @@ def main() -> None:
)

binary = os.path.normpath(args.binary) if IS_WINDOWS else args.binary
if not Path(binary).exists():
lint_message = LintMessage(
path=None,
line=None,
char=None,
code="CLANGFORMAT",
severity=LintSeverity.ERROR,
name="init-error",
original=None,
replacement=None,
description=(
f"Could not find clang-format binary at {binary}, "
"did you forget to run `lintrunner init`?"
),
)
print(json.dumps(lint_message._asdict()), flush=True)
sys.exit(0)

with concurrent.futures.ThreadPoolExecutor(
max_workers=os.cpu_count(),
Expand Down
220 changes: 0 additions & 220 deletions tools/linter/adapters/clangtidy_init.py

This file was deleted.

Loading

0 comments on commit 24b60b2

Please sign in to comment.