help_formatter.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. import argparse
  6. from pylint.config.callback_actions import _CallbackAction
  7. from pylint.constants import DEFAULT_PYLINT_HOME
  8. class _HelpFormatter(argparse.RawDescriptionHelpFormatter):
  9. """Formatter for the help message emitted by argparse."""
  10. def _get_help_string(self, action: argparse.Action) -> str | None:
  11. """Copied from argparse.ArgumentDefaultsHelpFormatter."""
  12. assert action.help
  13. help_string = action.help
  14. # CallbackActions don't have a default
  15. if isinstance(action, _CallbackAction):
  16. return help_string
  17. if "%(default)" not in help_string:
  18. if action.default is not argparse.SUPPRESS:
  19. defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
  20. if action.option_strings or action.nargs in defaulting_nargs:
  21. help_string += " (default: %(default)s)"
  22. return help_string
  23. @staticmethod
  24. def get_long_description() -> str:
  25. return f"""
  26. Environment variables:
  27. The following environment variables are used:
  28. * PYLINTHOME Path to the directory where persistent data for the run will
  29. be stored. If not found, it defaults to '{DEFAULT_PYLINT_HOME}'.
  30. * PYLINTRC Path to the configuration file. See the documentation for the method used
  31. to search for configuration file.
  32. Output:
  33. Using the default text output, the message format is :
  34. MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
  35. There are 5 kind of message types :
  36. * (I) info, for informational messages
  37. * (C) convention, for programming standard violation
  38. * (R) refactor, for bad code smell
  39. * (W) warning, for python specific problems
  40. * (E) error, for probable bugs in the code
  41. * (F) fatal, if an error occurred which prevented pylint from doing further processing.
  42. Output status code:
  43. Pylint should leave with following bitwise status codes:
  44. * 0 if everything went fine
  45. * 1 if a fatal message was issued
  46. * 2 if an error message was issued
  47. * 4 if a warning message was issued
  48. * 8 if a refactor message was issued
  49. * 16 if a convention message was issued
  50. * 32 on usage error
  51. """