source_gen icon indicating copy to clipboard operation
source_gen copied to clipboard

SharedPartBuilder partId validation regex and error message are inconsistent

Open Clavum opened this issue 3 years ago • 1 comments

https://github.com/dart-lang/source_gen/blob/master/source_gen/lib/src/builder.dart

If partId provided to the SharedPartBuilder doesn't meet regex validation, an error is thrown:

if (!_partIdRegExp.hasMatch(partId)) {
  throw ArgumentError.value(
    partId,
    'partId',
    '`partId` can only contain letters, numbers, `_` and `.`. '
        'It cannot start or end with `.`.',
  );
}

It states partId can contain a period, however, here's the regex:

const partIdRegExpLiteral = r'[A-Za-z_\d-]+';

final _partIdRegExp = RegExp('^$partIdRegExpLiteral\$');

As you can see, no period is allowed.

Either the error message or regex should be updated to be consistent.

Clavum avatar Jun 24 '22 01:06 Clavum