Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Add Error format support, and JSON output option#11396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
393820c282bd28ccda5b0c849a77fd2feabb18800151c1acc9177dabbc5ceac9d29ab0bd6d48dba8d17fa2bc04d35974e41e5ec91723219f2228c0a33d81b063001ead27be7eefe5c5d1872ae63abc9cb6c9ab11627ed8ee425cbe47f1b07e00ad4ac1fb6a2aafe3aafae321589ad1d37a3f7366d46f75e71a3728cca20379e16a88bf48905899f26880b8f30aafadf4cab2497fe71c3ad8f1d6e2fd45e4b03c5ce0e6896a0dc6d1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import json | ||
| from abc import ABC, abstractmethod | ||
| from typing import TYPE_CHECKING | ||
| if TYPE_CHECKING: | ||
| from mypy.errors import ErrorTuple | ||
| class ErrorFormatter(ABC): | ||
| """Defines how errors are formatted before being printed.""" | ||
| @abstractmethod | ||
| def report_error(self, error: 'ErrorTuple') -> str: | ||
| raise NotImplementedError | ||
| class JSONFormatter(ErrorFormatter): | ||
| def report_error(self, error: 'ErrorTuple') -> str: | ||
| file, line, column, severity, message, _, errorcode = error | ||
| return json.dumps({ | ||
| 'file': file, | ||
| 'line': line, | ||
| 'column': column, | ||
| ||
| 'severity': severity, | ||
| 'message': message, | ||
| 'code': None if errorcode is None else errorcode.code, | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,7 @@ | ||
| from typing import Tuple, List, TypeVar, Set, Dict, Optional, TextIO, Callable | ||
| from typing_extensions import Final | ||
| from mypy.error_formatter import ErrorFormatter | ||
| from mypy.scope import Scope | ||
| from mypy.options import Options | ||
| @@ -575,19 +576,27 @@ def format_messages(self, error_info: List[ErrorInfo], | ||
| a.append(' ' * (DEFAULT_SOURCE_OFFSET + column) + '^') | ||
| return a | ||
| def file_messages(self, path: str, formatter: ErrorFormatter = None) -> List[str]: | ||
| """Return a string list of new error messages from a given file. | ||
| Use a form suitable for displaying to the user. | ||
| """ | ||
| if path not in self.error_info_map: | ||
| return [] | ||
| error_info = self.error_info_map[path] | ||
| if formatter is not None: | ||
| error_info = [info for info in error_info if not info.hidden] | ||
| ||
| errors = self.render_messages(self.sort_messages(error_info)) | ||
| errors = self.remove_duplicates(errors) | ||
| return [formatter.report_error(err) for err in errors] | ||
| self.flushed_files.add(path) | ||
| source_lines = None | ||
| if self.pretty: | ||
| assert self.read_source | ||
| source_lines = self.read_source(path) | ||
| return self.format_messages(error_info, source_lines) | ||
| def new_messages(self) -> List[str]: | ||
| """Return a string list of new error messages. | ||