Skip to content

Commit 4c08d1d

Browse files
authored
Merge pull request #176 from logsincostan/master
2 parents b1f2741 + 5db0805 commit 4c08d1d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ repos:
2929
- id: no-space-in-cite
3030
- id: tilde-cite
3131
- id: unique-labels
32+
# args:
33+
# [
34+
# # If present only check for uniqueness within each file.
35+
# # Can be useful if a repository contains multiple main files.
36+
# "--individual",
37+
# ]
3238
- id: cleveref-instead-of-autoref
3339
- repo: https://github.com/pre-commit/pre-commit-hooks
3440
rev: v3.3.0

latexhooks/unique_labels.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def search(files: t.List[t.IO[str]]) -> bool:
8080

8181
def main() -> None:
8282
parser = argparse.ArgumentParser()
83+
parser.add_argument(
84+
"--individual",
85+
action="store_true",
86+
help="Allow duplicate labels if they are in different files",
87+
)
8388
parser.add_argument(
8489
"files",
8590
metavar="FILE",
@@ -90,7 +95,10 @@ def main() -> None:
9095
args = parser.parse_args()
9196

9297
files = sorted(args.files, key=lambda f: f.name)
93-
found_multiple_definitions = search(files)
98+
if args.individual:
99+
found_multiple_definitions = any(search([f]) for f in files)
100+
else:
101+
found_multiple_definitions = search(files)
94102
if found_multiple_definitions:
95103
sys.exit("Found multiple definitions of the same label")
96104

0 commit comments

Comments
 (0)