Skip to content

Commit

Permalink
Merge branch 'master' into misc/dart-3-2-language-version
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Feb 12, 2024
2 parents b2c0360 + b16df04 commit 14d221f
Show file tree
Hide file tree
Showing 33 changed files with 88 additions and 78 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+*'

permissions: read-all

jobs:
publish:
permissions:
id-token: write # This is required for requesting the JWT
id-token: write # Required for authentication using OIDC
runs-on: ubuntu-latest
environment: pub-dev
steps:
- uses: actions/checkout@v4
- uses: isoos/setup-dart@oidc-token
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- name: Install dependencies
run: dart pub get
- name: Analyze
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
env:
PUB_ENVIRONMENT: bot.github

permissions: read-all

jobs:
# Check code formatting and static analysis on a single OS (linux).
analyze:
Expand All @@ -21,7 +23,7 @@ jobs:
matrix:
sdk: [3.2.6]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
with:
sdk: ${{ matrix.sdk }}
Expand Down Expand Up @@ -50,7 +52,7 @@ jobs:
sdk: [3.2.6]
flutter: [3.16.9]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
with:
sdk: ${{ matrix.sdk }}
Expand Down Expand Up @@ -79,11 +81,11 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
with:
sdk: '3.3.0-279.3.beta' # TODO: switch back to rolling 'dev' channel after it gets updated.
- uses: subosito/flutter-action@cc97e1648fff6ca5cc647fa67f47e70f7895510b
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
# flutter-version: '3.4.0-34.1.pre'
channel: 'master' # TODO: switch back to rolling 'dev' channel after it gets updated.
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 0.22.1-wip
## 0.22.2-wip

- Require Dart 3.2.0 or later to run `pana`.
- Require Dart 3.2.0 or later to use `pana`.

## 0.22.1

- Fix: unspecified `--dartdoc-version` will use the latest version in an isolated
environment. To use the SDK's `dartdoc`, set the value to `sdk`.

## 0.22.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Options:
--hosted Download and analyze a hosted package (from https://pub.dev).
--[no-]dartdoc Run dartdoc and score the package on documentation coverage.
(defaults to on)
--dartdoc-version The dartdoc version to use (otherwise the latest stable).
--dartdoc-version The dartdoc version to use: `sdk`, `latest` (default) or `<version constraint>`.
```
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include: package:lints/recommended.yaml
analyzer:
language:
strict-casts: true
strict-inference: true
errors:
unused_import: error
unused_local_variable: error
Expand Down
2 changes: 1 addition & 1 deletion bin/batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import 'package:pana/src/batch/batch_run_command.dart';
///
/// dart bin/batch.dart run --packages packages.txt --config config.yaml
Future<void> main(List<String> args) async {
final runner = CommandRunner('batch',
final runner = CommandRunner<void>('batch',
'Runs analysis on multiple packages and compares granted score impact.')
..addCommand(BatchQueryCommand())
..addCommand(BatchCompareCommand())
Expand Down
7 changes: 4 additions & 3 deletions bin/pana.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ final _parser = ArgParser()
)
..addOption(
'dartdoc-version',
help: 'The dartdoc version to use (otherwise the latest stable).',
help:
'The dartdoc version to use: `sdk`, `latest` (default) or `<version constraint>`.',
)
..addOption(
'resources-output',
Expand Down Expand Up @@ -107,8 +108,8 @@ ${LineSplitter.split(_parser.usage).map((l) => ' $l').join('\n')}''');
exit(ExitCode.usage.code);
}

Future main(List<String> args) async {
ArgResults result;
Future<void> main(List<String> args) async {
final ArgResults result;
try {
result = _parser.parse(args);
} on FormatException catch (e) {
Expand Down
7 changes: 4 additions & 3 deletions lib/src/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ String updatePassthroughOptions({
if (origAnalyzer is Map) {
final origErrors = origAnalyzer['errors'];
if (origErrors is Map) {
final customAnalyzer = customMap.putIfAbsent('analyzer', () => {}) as Map;
final customErrors =
customAnalyzer.putIfAbsent('errors', () => {}) as Map;
final customAnalyzer =
customMap.putIfAbsent('analyzer', () => <String, Object?>{}) as Map;
final customErrors = customAnalyzer.putIfAbsent(
'errors', () => <String, Object?>{}) as Map;

for (var key in _analyzerErrorKeys) {
if (origErrors.containsKey(key)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/batch/batch_compare_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../utils.dart' show withTempDir;
import 'batch_model.dart';

/// Compares pana outcomes on the selected packages.
class BatchCompareCommand extends Command {
class BatchCompareCommand extends Command<void> {
@override
String get name => 'compare';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/batch/batch_query_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:http/http.dart' as http;
///
/// Additional filters are applied in the order of this list, up to the
/// `--limit` parameter.
class BatchQueryCommand extends Command {
class BatchQueryCommand extends Command<void> {
final _client = http.Client();

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/batch/batch_run_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../utils.dart' show withTempDir;
import 'batch_model.dart';

/// Runs pana on the selected packages.
class BatchRunCommand extends Command {
class BatchRunCommand extends Command<void> {
@override
String get name => 'run';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dartdoc/dartdoc_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DartdocIndex {
return DartdocIndex.fromJsonList(json.decode(content) as List);
}

factory DartdocIndex.fromJsonList(List jsonList) {
factory DartdocIndex.fromJsonList(List<Object?> jsonList) {
final list = jsonList
.map((item) => DartdocIndexEntry.fromJson(item as Map<String, dynamic>))
.toList();
Expand Down
3 changes: 2 additions & 1 deletion lib/src/download_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class UrlChecker {
}

/// Extracts a `.tar.gz` file from [tarball] to [destination].
Future _extractTarGz(Stream<List<int>> tarball, String destination) async {
Future<void> _extractTarGz(
Stream<List<int>> tarball, String destination) async {
log.fine('Extracting .tar.gz stream to $destination.');
final reader = TarReader(tarball.transform(gzip.decoder));
while (await reader.moveNext()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/license_detection/tokenizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ String _normalizeWord(String text) {
return text;
}

final _headers = HashSet.from(
final _headers = HashSet.of(
'q w e r t y u i o p a s d f g h j k l z x c v b n m i ii iii iv vi vii ix xi xii xiii xiv xv'
.split(' '));

Expand Down
4 changes: 2 additions & 2 deletions lib/src/maintenance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ List<String> exampleFileCandidates(String package) {
}

/// Returns a markdown-formatted error message for pubspec.yaml parse error.
String pubspecParseError(error) {
String pubspecParseError(Object error) {
// TODO: remove this after json_annotation is updated with CheckedFromJsonException.toString()
var message = error?.toString();
var message = error.toString();
if (error is CheckedFromJsonException) {
final msg =
error.message ?? 'Error with `${error.key}`: ${error.innerError}';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

String runningDartanalyzerFailed(bool usesFlutter, errorMsg) {
String runningDartAnalyzerFailed(bool usesFlutter, String errorMsg) {
final message = usesFlutter ? 'flutter analyze' : 'dart analyze .';

return 'Running `$message` failed with the following output:\n\n'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class PackageAnalyzer {
analyzerItems = await context.staticAnalysis();
} on ToolException catch (e) {
context.errors
.add(runningDartanalyzerFailed(context.usesFlutter, e.message));
.add(runningDartAnalyzerFailed(context.usesFlutter, e.message));
}
} else {
analyzerItems = <CodeProblem>[];
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class PackageContext {
_codeProblems = await _staticAnalysis(packageDir: packageDir);
return _codeProblems!;
} on ToolException catch (e) {
errors.add(messages.runningDartanalyzerFailed(usesFlutter, e.message));
errors.add(messages.runningDartAnalyzerFailed(usesFlutter, e.message));
rethrow;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/report/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class OutdatedVersionDescription {
Future<List<OutdatedVersionDescription>> computeOutdatedVersions(
PackageContext context, OutdatedPackage package) async {
const acceptableUpdateDelay = Duration(days: 30);
T? tryGetFromJson<T>(Map<String, dynamic> json, String key) {
T? tryGetFromJson<T>(Map<String, Object?> json, String key) {
final element = json[key];
return element is T ? element : null;
}
Expand Down Expand Up @@ -293,7 +293,7 @@ Future<List<OutdatedVersionDescription>> computeOutdatedVersions(
pubHostedUrl: hostedDependency.hosted?.url ?? pubHostedUriFromEnv));

try {
final versions = tryGetFromJson<List>(
final versions = tryGetFromJson<List<Object?>>(
versionListing as Map<String, dynamic>, 'versions');
if (versions == null) {
// Bad response from pub host.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/report/template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,18 @@ Future<ReportSection> followsTemplate(PackageContext context) async {

Subsection _licenseSection(LicenseTags tags) {
const title = 'Use an OSI-approved license';
late List<Paragraph> paragraphs;
final maxPoints = 10;
var grantedPoints = 0;
var reportStatus = ReportStatus.failed;

String licensePluralized(List value) =>
String licensePluralized(List<License> value) =>
value.length > 1 ? 'licenses' : 'license';
String licenseList(List<License> values) =>
values.map((e) => '`${e.spdxIdentifier}`').join(', ');
final detected = RawParagraph(
'Detected ${licensePluralized(tags.licenses)}: ${licenseList(tags.licenses)}.');

final List<Paragraph> paragraphs;
if (tags.isOnlyOsiApproved) {
paragraphs = [detected];
grantedPoints = maxPoints;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/repository/check_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Future<VerifiedRepository?> checkRepository({
}
}

void failVerification(String message, [error, StackTrace? st]) {
void failVerification(String message, [Object? error, StackTrace? st]) {
verificationFailure = message;
log.info(message, error, st);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ Future<VerifiedRepository?> checkRepository({
// TODO: consider to allow the exceptions to pass here, to allow an
// unrelated, but badly formatted pubspec.yaml in the repository.
// ignore: prefer_typing_uninitialized_variables
var yamlDoc;
Object? yamlDoc;
try {
yamlDoc = yaml.loadYaml(content);
} on FormatException catch (e, st) {
Expand Down
32 changes: 15 additions & 17 deletions lib/src/sdk_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ToolEnvironment {

PanaRuntimeInfo get runtimeInfo => _runtimeInfo!;

Future _init() async {
Future<void> _init() async {
final dartVersionResult = await runConstrained(
[..._dartSdk.dartCmd, '--version'],
environment: _dartSdk.environment,
Expand Down Expand Up @@ -453,9 +453,16 @@ class ToolEnvironment {
if (sdkDir != null) ...['--sdk-dir', sdkDir],
];

PanaProcessResult pr;

if (_dartdocVersion != null) {
if (_dartdocVersion == 'sdk') {
final command =
usesFlutter ? _flutterSdk._dartSdk.dartCmd : _dartSdk.dartCmd;
return await runConstrained(
[...command, 'doc', ...args],
workingDirectory: packageDir,
environment: _dartSdk.environment,
timeout: timeout,
);
} else {
if (!_globalDartdocActivated) {
await runConstrained(
[
Expand All @@ -464,7 +471,7 @@ class ToolEnvironment {
'global',
'activate',
'dartdoc',
_dartdocVersion,
if (_dartdocVersion != null) _dartdocVersion!,
],
environment: {
..._dartSdk.environment,
Expand All @@ -475,24 +482,14 @@ class ToolEnvironment {
_globalDartdocActivated = true;
}
final command = usesFlutter ? _flutterSdk.flutterCmd : _dartSdk.dartCmd;
pr = await runConstrained(
return await runConstrained(
[...command, 'pub', 'global', 'run', 'dartdoc', ...args],
workingDirectory: packageDir,
environment:
usesFlutter ? _flutterSdk.environment : _dartSdk.environment,
timeout: timeout,
);
} else {
final command =
usesFlutter ? _flutterSdk._dartSdk.dartCmd : _dartSdk.dartCmd;
pr = await runConstrained(
[...command, 'doc', ...args],
workingDirectory: packageDir,
environment: _dartSdk.environment,
timeout: timeout,
);
}
return pr;
}

/// Removes the `dev_dependencies` from the `pubspec.yaml`,
Expand Down Expand Up @@ -547,7 +544,8 @@ class ToolEnvironment {
// and throws an exception if it is missing. While we no longer accept
// new packages without such constraint, the old versions are still valid
// and should be analyzed.
final environment = parsed.putIfAbsent('environment', () => {});
final environment =
parsed.putIfAbsent('environment', () => <String, Object?>{});
if (environment is Map) {
VersionConstraint? vc;
if (environment['sdk'] is String) {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/tool/run_constrained.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Future<PanaProcessResult> _runConstrained(
killProc('Exceeded timeout of $timeout');
});

var items = await Future.wait(<Future>[
final (exitCode, _, _) = await (
process.exitCode,
process.stdout.forEach((outLine) {
stdoutLines.add(outLine);
Expand All @@ -108,12 +108,11 @@ Future<PanaProcessResult> _runConstrained(
killProc('Output exceeded $maxOutputBytes bytes.');
}
})
]);
).wait;

timer.cancel();

final exitCode = items[0] as int;
late PanaProcessResult result;
final PanaProcessResult result;
if (killed) {
final encoding = systemEncoding;
result = PanaProcessResult(
Expand Down
Loading

0 comments on commit 14d221f

Please sign in to comment.