◐ Shell
clean mode source ↗

Attempt to add fixing of BOMs by jgowdy · Pull Request #522 · pre-commit/pre-commit-hooks

@jgowdy

I'm attempting to add automatic fixing of BOMs

@jgowdy jgowdy marked this pull request as draft

October 5, 2020 16:39

asottile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should deprecate check-byte-order-marker, but we cannot remove it in this PR

@jgowdy jgowdy marked this pull request as ready for review

October 5, 2020 16:56

@jgowdy

Sorry for the churn, I don't write much Python

@jgowdy jgowdy marked this pull request as draft

October 5, 2020 17:09

@jgowdy jgowdy marked this pull request as ready for review

October 5, 2020 17:10

@jgowdy

Okay, I think this is good now.

rohitjha

@jgowdy

Would you mind adding a hacktoberfest-accepted label to this PR? I didn't make this change specifically for hacktoberfest, I need it, but I am participating in hacktoberfest. Thanks!

@asottile

yeah sorry I've been slow about this -- I'll take a look when I get the chance 👍

asottile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- id: check-byte-order-marker
name: Check for byte-order marker
description: Forbid files which have a UTF-8 byte-order marker
name: 'check BOM - deprecated: use fix-byte-order-marker'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shortened the name here so it doesn't wrap -- I should probably add a test for this

entry: file-contents-sorter
language: python
files: '^$'
- id: fix-byte-order-marker

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this to fix-byte-order-marker so it's more clear what it does


def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the --fix=no -- I'd rather have formatters-only


for filename in args.filenames:
with open(filename, 'rb') as f_b:
bts = f_b.read(3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was a leaking file descriptor here, I fixed that

apricote pushed a commit to hetznercloud/fleeting-plugin-hetzner that referenced this pull request

Aug 11, 2025

pat-s pushed a commit to devxygmbh/ansible-data-science-core that referenced this pull request

Jan 22, 2026