Support default values for non-optional properties (name=value syntax)#187
Support default values for non-optional properties (name=value syntax)#187
Conversation
Co-authored-by: syavorsky <455779+syavorsky@users.noreply.github.com> Agent-Logs-Url: https://github.com/syavorsky/comment-parser/sessions/aac64fd7-b4bb-4fe7-be23-0d98267555b2
|
There was a problem hiding this comment.
Pull request overview
Adds support for parsing default values from unbracketed JSDoc @property names using name=value syntax, aligning with common “constant bitmask” documentation patterns (issue #186).
Changes:
- Extend
nameTokenizerto split unbracketedname=valueintospec.name+spec.default. - Add unit tests covering non-optional defaults (string, numeric, and empty-default error).
- Add an e2e regression test for the issue’s canonical
@property BITMASK_VALUE_A=16use case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/parser/tokenizers/name.ts |
Adds non-optional name=value parsing to populate spec.default. |
tests/unit/spec-name-tokenizer.spec.ts |
Adds unit coverage for unbracketed defaults and empty-default error handling. |
tests/e2e/issue-186.spec.js |
Validates end-to-end parsing output for @property constants with defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| const eqIndex = name.indexOf('='); | ||
| if (eqIndex !== -1) { | ||
| defaultValue = name.slice(eqIndex + 1); | ||
| name = name.slice(0, eqIndex); | ||
|
|
||
| if (name === '') { | ||
| spec.problems.push({ | ||
| code: 'spec:name:empty-name', | ||
| message: 'empty name', | ||
| line: spec.source[0].number, | ||
| critical: true, | ||
| }); | ||
| return spec; | ||
| } | ||
|
|
||
| if (defaultValue === '') { | ||
| spec.problems.push({ | ||
| code: 'spec:name:empty-default', | ||
| message: 'empty default value', | ||
| line: spec.source[0].number, | ||
| critical: true, | ||
| }); | ||
| return spec; | ||
| } | ||
| } |
There was a problem hiding this comment.
Non-optional default parsing diverges from the optional [name=value] path: it doesn’t trim around = and it skips the spec:name:invalid-default validation (e.g. name=value=value would now be accepted unbracketed but rejected when bracketed). Consider reusing the same split/join/trim + invalid-default check logic for both branches so defaults behave consistently.
There was a problem hiding this comment.
Already addressed in 786bf5f — the non-optional path now uses the same split/join/trim approach and spec:name:invalid-default check as the optional path.
| test('non-optional with default', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'param=value param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| name: 'param', | ||
| optional: false, | ||
| default: 'value', | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| name: 'param=value', | ||
| postName: ' ', | ||
| description: 'param description', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| test('non-optional with numeric default', () => { | ||
| expect( | ||
| tokenize( | ||
| seedSpec({ | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| description: 'BITMASK_VALUE_A=16 blah blah', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ) | ||
| ).toEqual( | ||
| seedSpec({ | ||
| name: 'BITMASK_VALUE_A', | ||
| optional: false, | ||
| default: '16', | ||
| source: [ | ||
| { | ||
| number: 1, | ||
| source: '...', | ||
| tokens: seedTokens({ | ||
| name: 'BITMASK_VALUE_A=16', | ||
| postName: ' ', | ||
| description: 'blah blah', | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| ); | ||
| }); |
There was a problem hiding this comment.
With the new non-optional name=value behavior, it would be good to add a unit test covering the same invalid-default edge case that exists for optional names (e.g. param=value=value should surface spec:name:invalid-default if you align validation across both paths). This helps ensure the bracketed and unbracketed default syntaxes don’t drift over time.
There was a problem hiding this comment.
Done in 786bf5f. The non-optional name=value path now uses the same split/join/trim approach as the optional path and includes the spec:name:invalid-default validation (rejecting param=value=value). A matching unit test was also added.
…id-default check, test) Agent-Logs-Url: https://github.com/syavorsky/comment-parser/sessions/5da727bd-4934-4851-b3ad-eea43977b1a2 Co-authored-by: syavorsky <455779+syavorsky@users.noreply.github.com>
src/parser/tokenizers/name.tsto handlename=value(non-optional with default value)spec:name:invalid-defaultvalidationtests/unit/spec-name-tokenizer.spec.tsfor the new behavior (includingparam=value=valueinvalid case)tests/e2e/issue-186.spec.jsfor the JSDoc property exampleOriginal prompt
This pull request was created from Copilot chat.
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.