Skip to content

Commit b25628e

Browse files
committed
Fix; raise error on missing title before changes
1 parent dbd2af7 commit b25628e

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Fixed
1212

13+
- Raise error on missing title before changes.
1314
- Strip trailing whitespace from text.
1415

1516

@@ -32,7 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3233

3334
### Fixed
3435

35-
- Raise error on wrong title level for changes.
36+
- Raise error on wrong title level before changes.
3637
- Raise error on duplicate version sections.
3738
- Merge duplicate changes sections.
3839

@@ -48,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4849

4950
### Added
5051

51-
- Print output on success.
52+
- Print message on success.
5253

5354
### Changed
5455

ocdc/parser.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,26 @@ def version(p: Parser) -> Tuple[ast.Version, Token]:
252252
else:
253253
v.changes[key] = changes_
254254

255-
detect_wrong_title_level(p, 3)
255+
detect_wrong_title_level(p, 3, "before changes")
256256

257257
return v, title_token
258258

259259

260-
def detect_wrong_title_level(p: Parser, expected: int) -> None:
260+
def detect_wrong_title_level(p: Parser, expected: int, reason: str) -> None:
261261
with p.checkpoint():
262262
level = p.match_many(TokenType.HASH)
263-
if level and level != expected:
263+
if level != expected:
264264
token = p.peek(1)
265265
p.match({TokenType.TEXT})
266266
skip_newlines(p)
267267
if p.match({TokenType.DASH}):
268-
msg = f"Expected a title of H{expected}, but found H{level}"
269-
raise p.error(msg, token, back=level)
268+
msg = f"Expected a title of H{expected} {reason}"
269+
if level:
270+
msg += f", but found H{level}"
271+
raise p.error(msg, token, back=level)
272+
else:
273+
token = p.peek(1)
274+
raise p.error(msg, token, back=len(token.text))
270275
raise p.Rollback
271276

272277

tests/data/wrong_title_level.err.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Expected a title of H3, but found H2 at line 14, column 1:
1+
Expected a title of H3 before changes, but found H2 at line 14, column 1:
22

33
## Removed
44
^^
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
9+
## Unreleased
10+
11+
- Experimental stuff.
12+
13+
14+
## 0.1.0 - 2022-08-04
15+
16+
### Added
17+
18+
- Something.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Expected a title of H3 before changes at line 11, column 1:
2+
3+
- Experimental stuff.
4+
^

0 commit comments

Comments
 (0)