False positive on `# skip: fmt` annotation for Black

Black is a popular python formater and is very common across many projects.

When some section of code should not be formatted it can be annotated with a trailing # fmt: skip comment, similar to the # type: ignore annotation for typing and other common tools.

When adding such a notation Sonar flags this as a violation of python:S139. This should be ignored as moving the comment would break the intended behavior control for Black.

See The Black code style — Black 21.9b0 documentation

Possible annotations are # fmt: skip, # fmt: on and # fmt: off.

Example:

my_dict = {
    'a': 1, 'b': 2,
    'c': 3, 'z': 0
}  # fmt: skip
1 Like

Hello @sodul,

Thank you for reporting this false positive. I created SONARPY-905 to track it.

Cheers,
Guillaume

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.