Skip to content

Commit

Permalink
moving to static analysis, giving 20 points
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed May 13, 2024
1 parent a4cbd74 commit b04231e
Show file tree
Hide file tree
Showing 35 changed files with 235 additions and 235 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.22.4

- Analyze and score `pub downgrade` + `dart analyze`.

## 0.22.3

- Do not emit package names in `allDependencies` with trivial syntax issues.
Expand Down
20 changes: 1 addition & 19 deletions lib/src/report/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,9 @@ Future<ReportSection> trustworthyDependency(PackageContext context) async {
);
}

Future<Subsection> downgrade() async {
final message = await context.downgradeAnalysisErrorMessage;
final issues = message == null
? [
RawParagraph(
'`pub downgrade` does not expose any static analysis error.'),
]
: [Issue('`pub downgrade` finds static analysis issue:\n\n$message')];
return Subsection(
'Dependency constraint lower bounds are not breaking',
issues,
0,
0,
message == null ? ReportStatus.passed : ReportStatus.failed,
);
}

final dependencySection = await dependencies();
final sdkSection = await sdkSupport();
final downgradeSection = await downgrade();
final subsections = [dependencySection, sdkSection, downgradeSection];
final subsections = [dependencySection, sdkSection];
return makeSection(
id: ReportSectionId.dependency,
title: 'Support up-to-date dependencies',
Expand Down
108 changes: 66 additions & 42 deletions lib/src/report/static_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,78 @@ import '_common.dart';

Future<ReportSection> staticAnalysis(PackageContext context) async {
final packageDir = context.packageDir;
final analysisResult = await _analyzePackage(context);

final errors = analysisResult.errors;
final warnings = analysisResult.warnings;
final lints = analysisResult.lints;

// Only try to run dart format if there where no errors.
final formattingIssues = errors.isEmpty
? await _formatPackage(
packageDir,
context.toolEnvironment,
usesFlutter: context.usesFlutter,
lineLength: context.options.lineLength,
)
: <Issue>[];

final status = (errors.isEmpty && warnings.isEmpty)
? (formattingIssues.isEmpty && lints.isEmpty
? ReportStatus.passed
: ReportStatus.partial)
: ReportStatus.failed;

// 30 points: static analysis has 0 errors
// 40 points: static analysis has 0 errors, warnings
// 50 points: static analysis has 0 errors, warnings, lints
var grantedPoints = 0;
if (errors.isEmpty) {
grantedPoints = 30;
if (warnings.isEmpty) {
grantedPoints = 40;
if (lints.isEmpty && formattingIssues.isEmpty) {
grantedPoints = 50;

Future<Subsection> analysis() async {
final analysisResult = await _analyzePackage(context);
final errors = analysisResult.errors;
final warnings = analysisResult.warnings;
final lints = analysisResult.lints;

// Only try to run dart format if there where no errors.
final formattingIssues = errors.isEmpty
? await _formatPackage(
packageDir,
context.toolEnvironment,
usesFlutter: context.usesFlutter,
lineLength: context.options.lineLength,
)
: <Issue>[];

final status = (errors.isEmpty && warnings.isEmpty)
? (formattingIssues.isEmpty && lints.isEmpty
? ReportStatus.passed
: ReportStatus.partial)
: ReportStatus.failed;

// 10 points: static analysis has 0 errors
// 20 points: static analysis has 0 errors, warnings
// 30 points: static analysis has 0 errors, warnings, lints
var grantedPoints = 0;
if (errors.isEmpty) {
grantedPoints = 10;
if (warnings.isEmpty) {
grantedPoints = 20;
if (lints.isEmpty && formattingIssues.isEmpty) {
grantedPoints = 30;
}
}
}
return Subsection(
'code has no errors, warnings, lints, or formatting issues',
[...errors, ...warnings, ...lints, ...formattingIssues],
grantedPoints,
30,
status,
);
}

Future<Subsection> downgrade() async {
final message = await context.downgradeAnalysisErrorMessage;
final passed = message == null;
final issues = passed
? [
RawParagraph(
'`pub downgrade` does not expose any static analysis error.'),
]
: [Issue('`pub downgrade` finds static analysis issue:\n\n$message')];
return Subsection(
'Dependency constraint lower bounds are not breaking',
issues,
passed ? 20 : 0,
20,
passed ? ReportStatus.passed : ReportStatus.failed,
);
}

final subsections = [
await analysis(),
await downgrade(),
];
return makeSection(
id: ReportSectionId.analysis,
title: 'Pass static analysis',
maxPoints: 50,
subsections: [
Subsection(
'code has no errors, warnings, lints, or formatting issues',
[...errors, ...warnings, ...lints, ...formattingIssues],
grantedPoints,
50,
status,
)
],
maxPoints: subsections.fold<int>(0, (a, b) => a + b.maxPoints),
subsections: subsections,
basePath: packageDir,
);
}
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.3
version: 0.22.4-dev
repository: https://github.com/dart-lang/pana
topics:
- tool
Expand Down
4 changes: 2 additions & 2 deletions test/goldens/end2end/_dummy_pkg-1.0.0-null-safety.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
"grantedPoints": 0,
"maxPoints": 50,
"status": "failed",
"summary": "### [x] 0/50 points: code has no errors, warnings, lints, or formatting issues\n\n* Running `dart pub outdated` failed with the following output:\n\n```\nThe current Dart SDK version is {{sdk-version}}.\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.\n```\n"
"summary": "### [x] 0/30 points: code has no errors, warnings, lints, or formatting issues\n\n* Running `dart pub outdated` failed with the following output:\n\n```\nThe current Dart SDK version is {{sdk-version}}.\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.\n```\n\n\n### [x] 0/20 points: Dependency constraint lower bounds are not breaking\n\n* `pub downgrade` finds static analysis issue:\n\n`pub downgrade` failed with:\nOUT:\nResolving dependencies...\nERR:\nThe current Dart SDK version is {{sdk-version}}.\n\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed."
},
{
"id": "dependency",
"title": "Support up-to-date dependencies",
"grantedPoints": 0,
"maxPoints": 20,
"status": "failed",
"summary": "### [x] 0/10 points: All of the package dependencies are supported in the latest version\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}. Cannot run `dart pub outdated`.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n ╷\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n ╵\n```\n\n</details>\n\n### [x] 0/10 points: Package supports latest stable Dart and Flutter SDKs\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n ╷\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n ╵\n```\n\nTry widening the upper boundary of the constraint.\n</details>\n\n### [x] 0/0 points: Dependency constraint lower bounds are not breaking\n\n* `pub downgrade` finds static analysis issue:\n\n`pub downgrade` failed with:\nOUT:\nResolving dependencies...\nERR:\nThe current Dart SDK version is {{sdk-version}}.\n\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed."
"summary": "### [x] 0/10 points: All of the package dependencies are supported in the latest version\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}. Cannot run `dart pub outdated`.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n\n```\n\n</details>\n\n### [x] 0/10 points: Package supports latest stable Dart and Flutter SDKs\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n\n```\n\nTry widening the upper boundary of the constraint.\n</details>"
}
]
},
Expand Down
28 changes: 14 additions & 14 deletions test/goldens/end2end/_dummy_pkg-1.0.0-null-safety.1.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Run `dart pub get` for more information.

## 0/50 Pass static analysis

### [x] 0/50 points: code has no errors, warnings, lints, or formatting issues
### [x] 0/30 points: code has no errors, warnings, lints, or formatting issues

* Running `dart pub outdated` failed with the following output:

Expand All @@ -97,6 +97,18 @@ Because _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving fail
```


### [x] 0/20 points: Dependency constraint lower bounds are not breaking

* `pub downgrade` finds static analysis issue:

`pub downgrade` failed with:
OUT:
Resolving dependencies...
ERR:
The current Dart SDK version is {{sdk-version}}.

Because _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.

## 0/20 Support up-to-date dependencies

### [x] 0/10 points: All of the package dependencies are supported in the latest version
Expand Down Expand Up @@ -134,16 +146,4 @@ Sdk constraint doesn't support current Dart version {{sdk-version}}.
```

Try widening the upper boundary of the constraint.
</details>

### [x] 0/0 points: Dependency constraint lower bounds are not breaking

* `pub downgrade` finds static analysis issue:

`pub downgrade` failed with:
OUT:
Resolving dependencies...
ERR:
The current Dart SDK version is {{sdk-version}}.

Because _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.
</details>
4 changes: 2 additions & 2 deletions test/goldens/end2end/async-2.11.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@
"grantedPoints": 50,
"maxPoints": 50,
"status": "passed",
"summary": "### [*] 50/50 points: code has no errors, warnings, lints, or formatting issues\n"
"summary": "### [*] 30/30 points: code has no errors, warnings, lints, or formatting issues\n\n\n### [*] 20/20 points: Dependency constraint lower bounds are not breaking\n\n`pub downgrade` does not expose any static analysis error."
},
{
"id": "dependency",
"title": "Support up-to-date dependencies",
"grantedPoints": 20,
"maxPoints": 20,
"status": "passed",
"summary": "### [*] 10/10 points: All of the package dependencies are supported in the latest version\n\n|Package|Constraint|Compatible|Latest|\n|:-|:-|:-|:-|\n|[`collection`]|`^1.15.0`|1.18.0|1.18.0|\n|[`meta`]|`^1.1.7`|1.11.0|1.11.0|\n\nTo reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-dependency-overrides`.\n\n[`collection`]: https://pub.dev/packages/collection\n[`meta`]: https://pub.dev/packages/meta\n\n\n### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs\n\n\n### [*] 0/0 points: Dependency constraint lower bounds are not breaking\n\n`pub downgrade` does not expose any static analysis error."
"summary": "### [*] 10/10 points: All of the package dependencies are supported in the latest version\n\n|Package|Constraint|Compatible|Latest|\n|:-|:-|:-|:-|\n|[`collection`]|`^1.15.0`|1.18.0|1.18.0|\n|[`meta`]|`^1.1.7`|1.11.0|1.11.0|\n\nTo reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-dependency-overrides`.\n\n[`collection`]: https://pub.dev/packages/collection\n[`meta`]: https://pub.dev/packages/meta\n\n\n### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs\n"
}
]
},
Expand Down
11 changes: 5 additions & 6 deletions test/goldens/end2end/async-2.11.0.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ See [package layout](https://dart.dev/tools/pub/package-layout#examples) guideli

## 50/50 Pass static analysis

### [*] 50/50 points: code has no errors, warnings, lints, or formatting issues
### [*] 30/30 points: code has no errors, warnings, lints, or formatting issues


### [*] 20/20 points: Dependency constraint lower bounds are not breaking

`pub downgrade` does not expose any static analysis error.

## 20/20 Support up-to-date dependencies

### [*] 10/10 points: All of the package dependencies are supported in the latest version
Expand All @@ -61,8 +65,3 @@ To reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-depe


### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs


### [*] 0/0 points: Dependency constraint lower bounds are not breaking

`pub downgrade` does not expose any static analysis error.
Loading

0 comments on commit b04231e

Please sign in to comment.