Skip to content

Commit

Permalink
New has:executable tag for dart files in bin/ (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jun 12, 2024
1 parent 41e9520 commit 5eef805
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.22.6

- New recognized example files in the `example/bin` directory.
- Add `has:executable` tag for packages with `bin/<executable>.dart` files.

## 0.22.5

Expand Down
4 changes: 4 additions & 0 deletions lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class PackageAnalyzer {
final licenses = await context.licenses;
tags.addAll((await context.licenceTags).tags);

if (await context.hasExecutableInBinDirectory) {
tags.add(PanaTags.hasExecutable);
}

List<ProcessedScreenshot>? processedScreenshots = [];
final screenshotResults = await context.screenshots;
for (final r in screenshotResults) {
Expand Down
21 changes: 21 additions & 0 deletions lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,27 @@ class PackageContext {
return null;
}
}();

late final hasExecutableInBinDirectory = () async {
final binDir = Directory(p.join(packageDir, 'bin'));
if (!await binDir.exists()) {
return false;
}
final entries = await binDir.list().toList();
for (final file in entries.whereType<File>()) {
if (!file.path.endsWith('.dart')) {
continue;
}
// minimal sanity check without parsing the source code
final content = await file.readAsString();
if (content.contains('main')) {
continue;
}

return true;
}
return false;
}();
}

class DartdocResult {
Expand Down
1 change: 1 addition & 0 deletions lib/src/tag/pana_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ abstract class PanaTags {

// others
static const hasError = 'has:error';
static const hasExecutable = 'has:executable';
static const hasScreenshot = 'has:screenshot';
static const isPlugin = 'is:plugin';
static const isNullSafe = 'is:null-safe';
Expand Down
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.

2 changes: 1 addition & 1 deletion 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.6-dev
version: 0.22.6
repository: https://github.com/dart-lang/pana
topics:
- tool
Expand Down
3 changes: 2 additions & 1 deletion test/goldens/end2end/steward-0.3.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"is:dart3-compatible",
"license:mit",
"license:fsf-libre",
"license:osi-approved"
"license:osi-approved",
"has:executable"
],
"report": {
"sections": [
Expand Down

0 comments on commit 5eef805

Please sign in to comment.