Skip to content

Commit

Permalink
Merge pull request #318 from Workiva/greglittlefield-wf-patch-2
Browse files Browse the repository at this point in the history
CPLAT-6464 Improve error message for props/state variables with initializers
  • Loading branch information
rmconsole5-wk authored Jul 15, 2019
2 parents 327f177 + 512538b commit 0167d92
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/builder/generation/impl_generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ class ImplGenerator {
field.fields.variables.forEach((VariableDeclaration variable) {
if (variable.initializer != null) {
logger.severe(messageWithSpan(
'Fields are stubs for generated setters/getters and should not have initializers.',
'Fields are stubs for generated setters/getters and should not have initializers.\n'
'Instead, initialize ${type.isProps
? 'prop values within getDefaultProps()'
: 'state values within getInitialState()'}.',
span: getSpan(sourceFile, variable))
);
}
Expand Down Expand Up @@ -400,8 +403,8 @@ class ImplGenerator {
keyConstants[keyConstantName] = keyValue;
constants[constantName] = constantValue;

final type = field.fields.type?.toSource();
final typeString = type == null ? '' : '$type ';
final typeSource = field.fields.type?.toSource();
final typeString = typeSource == null ? '' : '$typeSource ';
final metadataSrc = new StringBuffer();
for (final annotation in field.metadata) {
metadataSrc.writeln(' ${annotation.toSource()}');
Expand Down

0 comments on commit 0167d92

Please sign in to comment.