brick icon indicating copy to clipboard operation
brick copied to clipboard

fix(build): handle line breaks after class names in model dictionary …

Open mastermakrela opened this issue 1 month ago • 1 comments

  • Fixes #662 where model dictionary builder fails when Flutter formatter breaks lines after long class names
  • Replaces fragile string matching with robust regex pattern that handles whitespace including newlines
  • Prevents build failures for projects with class names exceeding 80-character limit

The original code used entry.value.contains('class ${annotation.element.name} ') which expected a space after class names. When Flutter's formatter formatted long declarations like:

class VeryLongClassNameThatExceedsTheEightyCharacterLimit
    extends SomeBaseClass {

The space was replaced with a newline, causing the match to fail and breaking the build with "No element" errors.

Changes:

  • Updated packages/brick_build/lib/src/builders/model_dictionary_builder.dart:67
  • Changed from string match to RegExp(r'class\s+${annotation.element.name}\s*')
  • Now correctly handles spaces, tabs, and newlines after class names

Testing:

  • Verified regex matches all class declaration formats (with/without line breaks)
  • Tested with various whitespace combinations
  • Maintains backward compatibility with existing code

mastermakrela avatar Nov 25 '25 21:11 mastermakrela