feat(rfc_tools): add RFC frontmatter and file markdown models - #8
feat(rfc_tools): add RFC frontmatter and file markdown models#8jtmcdole wants to merge 3 commits into
Conversation
9781ddb to
c5ac319
Compare
c5ac319 to
f84b206
Compare
zanderso
left a comment
There was a problem hiding this comment.
Not sure since the frontmatter isn't too long, but would it be helpful to include file line numbers in the error messages?
f84b206 to
1e8f7aa
Compare
| } | ||
| } catch (e) { | ||
| final err = switch (e) { | ||
| YamlException(:final span?, :final message) => |
There was a problem hiding this comment.
[optional nit] This is a somewhat gratuitous use of pattern matching since you can already write on T catch(e) {} clauses to catch exceptions with specific types.
| final bodyLines = <String>[]; | ||
| bool headingReplaced = false; | ||
|
|
||
| for (final line in LineSplitter.split(body)) { |
There was a problem hiding this comment.
Is this just RegExp.matchFirst and then String.replaceFirst?
| ); | ||
| case final rfcVal: | ||
| final rfcStr = '$rfcVal'.trim(); | ||
| if (!RegExp(r'^\d{3}\.\d{4}$').hasMatch(rfcStr)) { |
There was a problem hiding this comment.
This and similar RegExps are repeated a few times.
| bool headingReplaced = false; | ||
|
|
||
| for (final line in LineSplitter.split(body)) { | ||
| if (!headingReplaced) { |
There was a problem hiding this comment.
Will this silently fail on a malformed heading?
| 'Expected format: a list of non-empty category/topic strings (e.g. 000-meta).', | ||
| i, | ||
| ); | ||
| break; |
There was a problem hiding this comment.
authors uses continue and reports every invalid entry, tags here is using break and stops at the first invalid item. Should this also be continue?
| }) { | ||
| final errors = <String>[]; | ||
|
|
||
| void addError(String key, String message, [int? itemIndex]) { |
There was a problem hiding this comment.
Line numbers are baked directly into the message strings ('Line 6: Frontmatter "status"...'). In later PRs like #9, callers receive a list of frontmatterErrors. Because structured line numbers are not preserved separately, RfcLinter will discard the exact line number calculated here.
| }) | ||
| _splitFrontmatter(String content) { | ||
| final lines = [...LineSplitter.split(content)]; | ||
| if (lines.isEmpty || lines.first.trim() != '---') { |
There was a problem hiding this comment.
Do we need to account for Windows evaluating to '\uFEFF---'?
| required Object newCategory, | ||
| required Object newIndex, |
There was a problem hiding this comment.
Can these be more strictly typed?
PR 3 of 7 for testing and automation
RfcFile and RfcFrontmatter are the core models of parsing and validating.
Stack created with GitHub Stacks CLI • Give Feedback 💬