Skip to content

file-contents-sorter adds an extra blank line if the file to be sorted is empty #935

@paduszyk

Description

@paduszyk

I am on v.4.4.0, Python 3.11.4, macOS Ventura 13.4.1.

My .pre-commit-config.yaml:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: "v4.4.0"
    hooks:
      - id: end-of-file-fixer
      - id: file-contents-sorter
        files: ^requirements\/.+\.in$
        # args: [--unique, --ignore-case]

The files are intentionally empty – I'm in the planning stage, they are just placeholders for requriements1.

To the point: file-contents-sorter adds an extra blank to them, what results in a confict with end-of-file-fixer. I am not sure if that is the expected behavior... Updating args doesn't have any effect.

$ git:(install-and-configure-pre-commit) : pre-commit run --all-files
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing requirements/build.in
Fixing requirements/lint.in
Fixing requirements/test.in

file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting requirements/build.in
Sorting requirements/lint.in
Sorting requirements/test.in

Footnotes

  1. Yes, I know that I can use requirements-txt-fixer particularly for requirements. 😄 I will do. For that issue it doesn't matter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions