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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.22.13

- Pass-through for `formatter/page_width` in `analysis_options.yaml`.
- Upgraded `lints` to `^5.0.0`

## 0.22.12

- Updated report text for `wasm` readiness.
Expand Down
10 changes: 10 additions & 0 deletions lib/src/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,15 @@ String updatePassthroughOptions({
}
}

final origFormatter = origMap['formatter'];
if (origFormatter is Map) {
final pageWidth = origFormatter['page_width'];
if (pageWidth is int) {
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.

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)


return json.encode(customMap);
}
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pana
description: PAckage aNAlyzer - produce a report summarizing the health and quality of a Dart package.
version: 0.22.12
version: 0.22.13
repository: https://github.com/dart-lang/pana
topics:
- tool
Expand All @@ -20,7 +20,7 @@ dependencies:
http: ^1.0.0
io: ^1.0.0
json_annotation: ^4.9.0
lints: ^4.0.0
lints: '>=4.0.0 <6.0.0'
logging: ^1.0.0
markdown: ^7.0.0
meta: ^1.4.0
Expand Down
6 changes: 6 additions & 0 deletions test/analysis_options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ analyzer:
enable-experiment:
- ignored
- macros
formatter:
unknown_key: true
page_width: 123
''', custom: '');
expect(json.decode(content), {
'analyzer': {
Expand All @@ -46,6 +49,9 @@ analyzer:
'macros',
],
},
'formatter': {
'page_width': 123,
},
});
});
}
2 changes: 1 addition & 1 deletion test/goldens/end2end/async-2.11.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"grantedPoints": 10,
"maxPoints": 20,
"status": "failed",
"summary": "### [*] 10/10 points: 20% or more of the public API has dartdoc comments\n\n246 out of 263 API elements (93.5 %) have documentation comments.\n\nSome symbols that are missing documentation: `async.AsyncMemoizer.AsyncMemoizer`, `async.ChunkedStreamReader.ChunkedStreamReader`, `async.DelegatingFuture.DelegatingFuture`, `async.DelegatingStream.DelegatingStream`, `async.ErrorResult.ErrorResult`.\n\n### [x] 0/10 points: Package has an example\n\n<details>\n<summary>\nNo example found.\n</summary>\n\nSee [package layout](https://dart.dev/tools/pub/package-layout#examples) guidelines on how to add an example.\n</details>\n"
"summary": "### [*] 10/10 points: 20% or more of the public API has dartdoc comments\n\n246 out of 246 API elements (100.0 %) have documentation comments.\n\n### [x] 0/10 points: Package has an example\n\n<details>\n<summary>\nNo example found.\n</summary>\n\nSee [package layout](https://dart.dev/tools/pub/package-layout#examples) guidelines on how to add an example.\n</details>\n"
},
{
"id": "platform",
Expand Down
4 changes: 1 addition & 3 deletions test/goldens/end2end/async-2.11.0.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ Detected license: `BSD-3-Clause`.

### [*] 10/10 points: 20% or more of the public API has dartdoc comments

246 out of 263 API elements (93.5 %) have documentation comments.

Some symbols that are missing documentation: `async.AsyncMemoizer.AsyncMemoizer`, `async.ChunkedStreamReader.ChunkedStreamReader`, `async.DelegatingFuture.DelegatingFuture`, `async.DelegatingStream.DelegatingStream`, `async.ErrorResult.ErrorResult`.
246 out of 246 API elements (100.0 %) have documentation comments.

### [x] 0/10 points: Package has an example

Expand Down