fix(parser): reject whitespace-only scope - #56
Open
svyatov wants to merge 1 commit into
Open
Conversation
feat( ): x parsed with a scope of " ". Spec rule 4 requires a scope to be "a noun describing a section of the codebase", and a value with no non-whitespace character cannot be one. Padded scopes such as feat( parser ): x still parse, padding included. Rule 4 constrains the noun, not the space around it, and rule 9 shows the spec bans whitespace explicitly where it means to, so rejecting padding would be our judgement rather than the spec's. trim() rather than the local isWhitespace, because it also covers <USP>, which the grammar lists at README line 59 but isWhitespace omits. Closes conventional-commits#39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat( ): xparses today with a scope of" ". Spec rule 4 requires a scope to be "a noun describing a section of the codebase", and a value with no non-whitespace character is not one. @wesleytodd confirmed on #39 that this was unintended and pointed at the guard inscope(), which is the line this widens.The change
node.value === ''becomesnode.value.trim() === ''. Rejection reuses the existingabortpath, sofeat( ): xnow fails exactly the wayfeat(): xalready did, with the error pointing at the space.trim()rather than the localisWhitespacefromlib/type-checks.js, becausetrim()also covers<USP>, the UnicodeSpace_Separatorclass that the README grammar lists at line 59 butisWhitespaceomits. Scopes cannot contain newlines, sotrim()stripping line terminators does not matter here.What deliberately did not change
Padded scopes still parse, padding included:
Rule 4 constrains the noun, not the space around it. Rule 9 shows the spec bans whitespace explicitly where it means to ("A footer's token MUST use
-in place of whitespace characters"), and no such clause exists for scope. Rejecting padding would be my judgement rather than the spec's, so I left it out. Happy to add it if you read rule 4 more strictly.Blast radius
Only whitespace-only scopes change verdict. A body line that looks like one still falls back to text rather than failing the parse, because the rejection rewinds:
Tests
Three, all plain assertions so
test/parser.js.snapstays untouched. One fails without the parser change; the other two pin the padded-scope and body-fallback behavior above and pass either way, on purpose.Locally the suite goes from 34 passing to 37,
standardstays clean, andnpm run coverageclears the.nycrcthresholds.Closes #39