Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass-through for formatter/page_width in analysis_options.yaml #1408

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

isoos
Copy link
Collaborator

@isoos isoos commented Oct 10, 2024

Fixes #1405

@isoos isoos requested review from jonasfj and sigurdm October 10, 2024 14:41
@isoos isoos merged commit 19a2d6c into dart-lang:master Oct 11, 2024
5 checks passed
@isoos isoos deleted the pass-through branch October 11, 2024 13:55
customMap.putIfAbsent('formatter', () => <String, Object?>{}) as Map;
customFormatter['page_width'] = pageWidth;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this could also be:

  if (origMap['formatter'] case {'page_width': int pageWidth}) {
    final customFormatter =
        customMap.putIfAbsent('formatter', () => <String, Object?>{}) as Map;
    customFormatter['page_width'] = pageWidth;
  }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even

if (origMap['formatter'] case {'page_width': int pageWidth}) {
        (customMap.putIfAbsent('formatter', Map<String, Object?>.empty) as Map)['page_width'] = pageWidth;
  }

(But I guess the extra variable was for readability.)

Copy link
Member

@jonasfj jonasfj Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrhn only if you use dart format with a page width of at-least 103 chars 🤣

Otherwise it becomes (once formatted):

  if (origMap['formatter'] case {'page_width': int pageWidth}) {
    (customMap.putIfAbsent('formatter', Map<String, Object?>.empty)
        as Map)['page_width'] = pageWidth;
  }

Personally, I'd suggest it's more readable (albeit a bit dumb) to do:

  if (origMap['formatter'] case {'page_width': int pageWidth}) {
    customMap['formatter'] ??= <String, Object?>{};
    customMap['formatter']['page_width'] = pageWidth;
  }

or

  if (origMap['formatter'] case {'page_width': int pageWidth}) {
    customMap['formatter'] = {
      ...?customMap['formatter'],
      'page_width': pageWidth,
    };
  }

Arguably, they aren't as efficient, but they read nicely -- which is sadly almost always the most important thing (at-least in pana).

(for the record, I have started using records for matching JSON, it's awesome)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect formatter: page-width setting in analysis_options.yaml
5 participants