Skip to content

Commit

Permalink
use dart_flutter_team_lints in this repo (#31)
Browse files Browse the repository at this point in the history
* use dart_flutter_team_lints.svg in this repo

* use the lint set on package: dart_flutter_team_lints as well

* fix tests
  • Loading branch information
devoncarew authored Jan 12, 2023
1 parent 889491b commit e2c7686
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 79 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This repository is home to general Dart Ecosystem tools and packages.

## Packages

| Package | Description | Published Version |
| --- | --- | --- |
| [blast_repo](pkgs/blast_repo/) | | --- |
| [corpus](pkgs/corpus/) | A tool to calculate the API usage for a package. | --- |
| [dart_flutter_team_lints](pkgs/dart_flutter_team_lints/) | An analysis rule set used by the Dart and Flutter teams. | --- |
| Package | Description | Version |
|---|---|---|
| [blast_repo](pkgs/blast_repo/) | A tool to bulk validate and fix GitHub repos. | |
| [corpus](pkgs/corpus/) | A tool to calculate the API usage for a package. | |
| [dart_flutter_team_lints](pkgs/dart_flutter_team_lints/) | An analysis rule set used by the Dart and Flutter teams. | [![pub package](https://img.shields.io/pub/v/dart_flutter_team_lints.svg)](https://pub.dev/packages/dart_flutter_team_lints) |
44 changes: 1 addition & 43 deletions pkgs/blast_repo/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- always_declare_return_types
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_dynamic_calls
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_null
- avoid_returning_null_for_future
- avoid_returning_this
- avoid_unused_constructor_parameters
- cancel_subscriptions
- cascade_invocations
- comment_references
- directives_ordering
- join_return_with_assignment
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_runtimeType_toString
- omit_local_variable_types
- only_throw_errors
- package_api_docs
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- prefer_interpolation_to_compose_strings
- prefer_relative_imports
- prefer_single_quotes
- require_trailing_commas
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- unawaited_futures
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_parenthesis
- unnecessary_statements
- use_string_buffers
3 changes: 2 additions & 1 deletion pkgs/blast_repo/lib/src/tweaks/github_action_tweak.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ Future<List<String>> _fixFile(
);

items.add(
'Updated ${path.join('/')} from $currentVersion to $targetActionVersion',
'Updated ${path.join('/')} from $currentVersion to '
'$targetActionVersion',
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/blast_repo/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: blast_repo
description: A tool to bulk validate and fix GitHub repos.
publish_to: none

environment:
Expand All @@ -18,8 +19,12 @@ dependencies:
yaml_edit: ^2.0.3

dev_dependencies:
lints: ^2.0.0
dart_flutter_team_lints: ^0.1.0
test: ^1.22.0

executables:
blast_repo:

dependency_overrides:
dart_flutter_team_lints:
path: ../dart_flutter_team_lints
2 changes: 1 addition & 1 deletion pkgs/corpus/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/corpus/bin/api_usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main(List<String> args) async {

final packageName = argResults.rest.first;
final packageLimit = int.tryParse(argResults['package-limit'])!;
bool showSrcReferences = argResults['show-src-references'] as bool;
var showSrcReferences = argResults['show-src-references'] as bool;

await analyzeUsage(
packageName: packageName,
Expand Down
4 changes: 2 additions & 2 deletions pkgs/corpus/bin/deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main(List<String> args) async {

final packageName = argResults.rest.first;
String? packageLimit = argResults['package-limit'];
bool excludeOld = argResults['exclude-old'] as bool;
var excludeOld = argResults['exclude-old'] as bool;

var log = Logger.standard();

Expand All @@ -61,7 +61,7 @@ void main(List<String> args) async {

var usageInfos = <PackageUsageInfo>[];

int count = 0;
var count = 0;

for (var package in packages) {
progress = log.progress(' $package');
Expand Down
15 changes: 8 additions & 7 deletions pkgs/corpus/lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ApiUsage {
}

void toFile(File file) {
Map json = {
var json = {
'packages': fromPackages.toJson(),
'libraries': fromLibraries.toJson(),
};
Expand All @@ -58,11 +58,12 @@ class ApiUsage {
}

String describeUsage() {
int libraryCount = fromPackages.sortedLibraryReferences.length;
int classCount = fromPackages.sortedClassReferences.length;
int extensionCount = fromPackages.sortedExtensionReferences.length;
int symbolCount = fromPackages.sortedTopLevelReferences.length;
return 'referenced $libraryCount ${pluralize(libraryCount, 'library', plural: 'libraries')}, '
var libraryCount = fromPackages.sortedLibraryReferences.length;
var classCount = fromPackages.sortedClassReferences.length;
var extensionCount = fromPackages.sortedExtensionReferences.length;
var symbolCount = fromPackages.sortedTopLevelReferences.length;
var librariesStr = pluralize(libraryCount, 'library', plural: 'libraries');
return 'referenced $libraryCount $librariesStr, '
'$classCount ${pluralize(classCount, 'class', plural: 'classes')}, '
'$extensionCount ${pluralize(extensionCount, 'extension')}, '
'and $symbolCount top-level ${pluralize(symbolCount, 'symbol')}';
Expand Down Expand Up @@ -415,7 +416,7 @@ class EntityReferences {
Map<String, int> get sortedReferences => _sortByCount(_references);

Map<String, int> _sortByCount(Map<String, Set<Entity>> refs) {
List<String> keys = refs.keys.toList();
var keys = refs.keys.toList();
keys.sort((a, b) => refs[b]!.length - refs[a]!.length);
return Map.fromIterable(keys, value: (key) => refs[key]!.length);
}
Expand Down
6 changes: 3 additions & 3 deletions pkgs/corpus/lib/api_usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Future analyzeUsage({

progress.finish(showTiming: true);

List<ApiUsage> usageInfo = [];
var usageInfo = <ApiUsage>[];

var count = 0;

Expand Down Expand Up @@ -83,7 +83,7 @@ Future analyzeUsage({
}
}

bool downloadSuccess =
var downloadSuccess =
await packageManager.retrievePackageArchive(package, logger: log);
if (!downloadSuccess) {
log.stdout('error downloading ${package.archiveUrl}');
Expand Down Expand Up @@ -153,7 +153,7 @@ Future<ApiUsage> _analyzePackage(
));

if (file.existsSync()) {
ApiUsage usage = ApiUsage.fromFile(analyzingPackage, file);
var usage = ApiUsage.fromFile(analyzingPackage, file);
return usage;
}

Expand Down
4 changes: 2 additions & 2 deletions pkgs/corpus/lib/packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class PackageManager {
var progress =
logger?.progress('downloading ${path.basename(archiveFile.path)}');
try {
Uint8List data = await _getPackageTarGzArchive(package);
var data = await _getPackageTarGzArchive(package);
archiveFile.writeAsBytesSync(data);
return true;
} finally {
progress?.finish(showTiming: true);
}

// This is live as _getPackageTarGzArchive can throw.
// This is live as _getPackageTarGzArchive() can throw.
// ignore: dead_code
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions pkgs/corpus/lib/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

// ignore_for_file: lines_longer_than_80_chars

import 'dart:convert';

import 'package:http/http.dart';
Expand Down Expand Up @@ -110,7 +112,7 @@ class Pub {
}) async* {
final uri = Uri.parse('https://pub.dev/api/search');

int count = 0;
var count = 0;

for (;;) {
final targetUri = uri.replace(queryParameters: {
Expand Down Expand Up @@ -190,7 +192,8 @@ class PackageInfo {
String? get homepage => _pubspec['homepage'];

String? get repo => repository ?? homepage;
String? get sdkConstraint => (_pubspec['environment'] ?? {})['sdk'];
Map<String, dynamic>? get environment => _pubspec['environment'];
String? get sdkConstraint => (environment ?? {})['sdk'];

String get version => _latest['version'];
String get archiveUrl => _latest['archive_url'];
Expand Down Expand Up @@ -231,7 +234,7 @@ class PackageInfo {
}

VersionConstraint? get sdkContraint {
var environment = (_pubspec['environment'] as Map?);
var environment = _pubspec['environment'] as Map?;
var sdk = environment?['sdk'] as String?;
if (sdk == null) return null;
return VersionConstraint.parse(sdk);
Expand Down
6 changes: 5 additions & 1 deletion pkgs/corpus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ dev_dependencies:
git:
url: https://github.com/dart-lang/test
path: pkgs/checks
lints: ^2.0.0
dart_flutter_team_lints: ^0.1.0
test: ^1.22.0
test_descriptor: ^2.0.0

dependency_overrides:
dart_flutter_team_lints:
path: ../dart_flutter_team_lints
3 changes: 2 additions & 1 deletion pkgs/corpus/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void main() {
late ApiUsage sampleUsage;

setUp(() {
var json = JsonDecoder().convert(_sampleUsageJson);
var json =
JsonDecoder().convert(_sampleUsageJson) as Map<String, dynamic>;
sampleUsage = ApiUsage(
PackageInfo.from(JsonDecoder().convert(_packageInfoJson)),
References.fromJson(json['packages']),
Expand Down
10 changes: 5 additions & 5 deletions pkgs/corpus/test/visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import 'package:test/test.dart';

void main() {
group('ApiUseCollector - packages', () {
PackageInfo targetPackage = PackageInfo.from({
var targetPackage = PackageInfo.from({
'name': 'path',
'latest': {
'version': '0.1.2',
'pubspec': <String, dynamic>{},
}
});
ReportTarget reportTarget = PackageTarget.fromPackage(targetPackage);
PackageInfo referencingPackage = PackageInfo.from({'name': 'foo'});
Directory packageDir = Directory('test/data');
var referencingPackage = PackageInfo.from({'name': 'foo'});
var packageDir = Directory('test/data');

late ApiUseCollector apiUsageCollector;

Expand Down Expand Up @@ -122,8 +122,8 @@ void main() {
name: 'collection',
version: _sdkVersion,
);
PackageInfo referencingPackage = PackageInfo.from({'name': 'foo'});
Directory packageDir = Directory('test/data');
var referencingPackage = PackageInfo.from({'name': 'foo'});
var packageDir = Directory('test/data');

late ApiUseCollector apiUsageCollector;

Expand Down
1 change: 1 addition & 0 deletions pkgs/dart_flutter_team_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:dart_flutter_team_lints/analysis_options.yaml
6 changes: 3 additions & 3 deletions pkgs/dart_flutter_team_lints/test/validate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ void main() {
});

test('references recommended', () {
var result = yaml.loadYaml(content);
var result = yaml.loadYaml(content) as yaml.YamlMap;
expect(result['include'], equals('package:lints/recommended.yaml'));
});

test('defines linter rules', () {
var result = yaml.loadYaml(content);
expect(result['linter']['rules'], isNotEmpty);
var result = yaml.loadYaml(content) as yaml.YamlMap;
expect((result['linter'] as Map)['rules'], isNotEmpty);
});
}

0 comments on commit e2c7686

Please sign in to comment.