doc_widget icon indicating copy to clipboard operation
doc_widget copied to clipboard

Documentation parse fail

Open LaurentiuSimionescu opened this issue 2 years ago • 2 comments

Describe the bug If there is more the one line documentation line for fields then parsing fails.

/// Title description
final String title;

The above will pass.

  /// Title description
  /// Second line of description
  final String title;

The above will not pass.

To Reproduce Steps to reproduce the behavior:

/// ```dart
/// final description = Description('Text');
/// ```
@docWidget
class Description extends StatelessWidget {
  Description(this.title);

  /// Title description
  /// Second line of description
  final String title;

  @override
  Widget build(BuildContext context) => const Text('Test');
}

Expected behavior Documentation should be parsed for the field title.

Additional context Error that is returned:

`  Could not format because the source could not be parsed:
  
  line 5, column 31 of .: Unterminated string literal.
    ╷
  5 │ description: 'Title description
    │                               ^
    ╵
  line 6, column 33 of .: Unterminated string literal.
    ╷
  6 │  Second line of description',),];
    │                                 ^
`

LaurentiuSimionescu avatar Mar 07 '23 18:03 LaurentiuSimionescu

String? getDescription(String name, List<FieldElement> fields) {
  final hasField = fields.any((field) => field.name == name);
  if (hasField) {
    final field = fields.firstWhere((element) => element.name == name);
    final hasDocumentation = field.documentationComment != null;
    if (hasDocumentation)
      return hasDocumentation
          ? removeDocumentationComment(field.documentationComment)
          : null;
  }
  return null;
}

All my search leads me to this method

LaurentiuSimionescu avatar Mar 07 '23 19:03 LaurentiuSimionescu

Has the same problem

ViktorJasch avatar Jan 14 '24 07:01 ViktorJasch