snippet_fmt.formatters

Formatters and syntax checkers.

Classes:

Formatter

typing.Protocol for formatter functions.

Functions:

format_ini(code, **config)

Check the syntax of, and reformat, the given INI configuration.

format_json(code, **config)

Check the syntax of, and reformat, the given JSON source.

format_python(code, **config)

Check the syntax of, and reformat, the given Python code.

format_toml(code, **config)

Check the syntax of, and reformat, the given TOML configuration.

noformat(code, **config)

A no-op formatter.

protocol Formatter[source]

Bases: Protocol

typing.Protocol for formatter functions.

Classes that implement this protocol must have the following methods / attributes:

__call__(code, **config)[source]

Call self as a function.

Return type

str

format_ini(code, **config)[source]

Check the syntax of, and reformat, the given INI configuration.

Parameters
  • code (str) – The code to check.

  • **config – The language-specific configuration.

Return type

str

Returns

The original code unchanged.

format_json(code, **config)[source]

Check the syntax of, and reformat, the given JSON source.

Parameters
  • code (str) – The code to check.

  • **config – The language-specific configuration.

Return type

str

Returns

The original code unchanged.

format_python(code, **config)[source]

Check the syntax of, and reformat, the given Python code.

Parameters
  • code (str) – The code to check and reformat.

  • **config – The language-specific configuration.

Return type

str

Returns

The reformatted code.

format_toml(code, **config)[source]

Check the syntax of, and reformat, the given TOML configuration.

Parameters
  • code (str) – The code to check.

  • **config – The language-specific configuration.

Return type

str

Returns

The original code unchanged.

noformat(code, **config)[source]

A no-op formatter.

Parameters
  • code (str) – The code to check and reformat.

  • **config – The language-specific configuration.

Return type

str

Returns

The original code unchanged.