Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

upgrade to nullable http and github #2465

Merged
merged 2 commits into from
Feb 17, 2021
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
10 changes: 6 additions & 4 deletions lib/src/util/score_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/lint/config.dart'; // ignore: implementation_imports
// ignore: import_of_legacy_library_into_null_safe
import 'package:http/http.dart' as http;

final _pedanticOptionsRootUrl =
Expand All @@ -16,15 +15,18 @@ List<String?>? _pedanticRules;
Future<List<String?>> get pedanticRules async =>
_pedanticRules ??= await _fetchPedanticRules();

Future<List<String?>> fetchRules(Uri optionsUrl) async {
Future<List<String>> fetchRules(Uri optionsUrl) async {
final config = await _fetchConfig(optionsUrl);
if (config == null) {
print('no config found for: $optionsUrl (SKIPPED)');
return <String>[];
}
final rules = <String?>[];
final rules = <String>[];
for (var ruleConfig in config.ruleConfigs) {
rules.add(ruleConfig.name);
var name = ruleConfig.name;
if (name != null) {
rules.add(name);
}
}
return rules;
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
charcode: ^1.2.0
collection: ^1.15.0
glob: ^2.0.0
http: ^0.12.0
http: ^0.13.0
meta: ^1.3.0
path: ^1.8.0
source_span: ^1.8.0
Expand All @@ -29,7 +29,7 @@ dev_dependencies:
cli_util: ^0.3.0
fixnum:
path: test/mock_packages/fixnum
github: '>=6.0.5 <8.0.0'
github: ^7.1.0-nullsafe.0
grinder: ^0.9.0-nullsafety
markdown: ^4.0.0
matcher: ^0.12.10
Expand Down
7 changes: 3 additions & 4 deletions tool/bot/rule_doc_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:convert';

// ignore: import_of_legacy_library_into_null_safe
import 'package:http/http.dart' as http;
import 'package:test/test.dart';

Expand All @@ -28,8 +27,8 @@ void main() async {
test(rule, () async {
// todo (pq): consider replacing w/ lintCode.url
// see: https://github.com/dart-lang/linter/issues/2034
final response = await http
.head('https://dart-lang.github.io/linter/lints/$rule.html');
final response = await http.head(
Uri.parse('https://dart-lang.github.io/linter/lints/$rule.html'));
expect(response.statusCode, 200);
});
}
Expand All @@ -43,4 +42,4 @@ final _client = http.Client();

Future<String> getBody(String url) async => (await getResponse(url)).body;

Future<http.Response> getResponse(String url) async => _client.get(url);
Future<http.Response> getResponse(String url) async => _client.get(Uri.parse(url));
8 changes: 4 additions & 4 deletions tool/bot/version_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:convert';
import 'dart:io';

// ignore: import_of_legacy_library_into_null_safe
import 'package:http/http.dart' as http;

void main() async {
Expand All @@ -17,8 +16,8 @@ void main() async {
print('Checking for a git release tag corresponding to $latestVersion...');

var client = http.Client();
var req = await client
.get('https://github.com/dart-lang/linter/releases/tag/$latestVersion');
var req = await client.get(Uri.parse(
'https://github.com/dart-lang/linter/releases/tag/$latestVersion'));

if (req.statusCode == 404) {
print(
Expand All @@ -35,4 +34,5 @@ final _client = http.Client();

Future<String> getBody(String url) async => (await getResponse(url)).body;

Future<http.Response> getResponse(String url) async => _client.get(url);
Future<http.Response> getResponse(String url) async =>
_client.get(Uri.parse(url));
13 changes: 6 additions & 7 deletions tool/canonical/scorecard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/lint/config.dart'; // ignore: implementation_imports
import 'package:analyzer/src/lint/registry.dart'; // ignore: implementation_imports
// ignore: import_of_legacy_library_into_null_safe
import 'package:github/github.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:http/http.dart' as http;
import 'package:linter/src/analyzer.dart';
import 'package:linter/src/rules.dart';
Expand Down Expand Up @@ -285,7 +283,8 @@ class ScoreCard {

var bugReferences = <String>[];
for (var bug in bugs) {
if (bug.title.contains(lint.name)) {
var title = bug.title;
if (title != null && title.contains(lint.name)) {
bugReferences.add('#${bug.number.toString()}');
}
}
Expand Down Expand Up @@ -331,8 +330,8 @@ class ScoreCard {

static Future<List<String>> _getLintsWithBulkFixes() async {
var client = http.Client();
var req = await client.get(
'https://raw.githubusercontent.com/dart-lang/sdk/master/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart');
var req = await client.get(Uri.parse(
'https://raw.githubusercontent.com/dart-lang/sdk/master/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart'));

var parser = CompilationUnitParser();
var cu = parser.parse(contents: req.body, name: 'bulk_fix_processor.dart');
Expand All @@ -346,8 +345,8 @@ class ScoreCard {

static Future<List<String>> _getLintsWithFixes() async {
var client = http.Client();
var req = await client.get(
'https://raw.githubusercontent.com/dart-lang/sdk/master/pkg/analysis_server/lib/src/services/linter/lint_names.dart');
var req = await client.get(Uri.parse(
'https://raw.githubusercontent.com/dart-lang/sdk/master/pkg/analysis_server/lib/src/services/linter/lint_names.dart'));

var parser = CompilationUnitParser();
var cu = parser.parse(contents: req.body, name: 'lint_names.dart');
Expand Down
58 changes: 32 additions & 26 deletions tool/crawl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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: import_of_legacy_library_into_null_safe

import 'dart:async';
import 'dart:io';

Expand All @@ -16,6 +14,8 @@ import 'package:linter/src/util/score_utils.dart' as score_utils;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';

/// todo (pq): reign in the nullable types

const _allPathSuffix = '/example/all.yaml';
final _effectiveDartOptionsRootUrl = Uri.https(
'raw.githubusercontent.com', '/tenhobi/effective_dart/master/lib/');
Expand All @@ -36,7 +36,7 @@ final _stagehandOptionsUrl = Uri.https('raw.githubusercontent.com',
/// We don't care about SDKs previous to this bottom.
final Version bottomDartSdk = Version(2, 0, 0);

Map<String, String> _dartSdkToLinterMap = <String, String>{};
Map<String, String?> _dartSdkToLinterMap = <String, String?>{};

List<String?>? _effectiveDartRules;
List<String?>? _flutterRepoRules;
Expand All @@ -45,11 +45,11 @@ int? _latestMinor;

Iterable<LintRule>? _registeredLints;

List<String>? _sdkTags;
List<String?>? _sdkTags;

Map<String, List<String>> _sinceMap = <String, List<String>>{};
Map<String, List<String?>> _sinceMap = <String, List<String>>{};

List<String?>? _stagehandRules;
List<String>? _stagehandRules;

Future<List<String?>> get effectiveDartRules async =>
_effectiveDartRules ??= await _fetchEffectiveDartRules();
Expand All @@ -65,46 +65,50 @@ Future<int> get latestMinor async =>

Future<List<String?>> get pedanticRules async => score_utils.pedanticRules;

Iterable<LintRule>? get registeredLints {
Iterable<LintRule> get registeredLints {
if (_registeredLints == null) {
registerLintRules();
_registeredLints = Registry.ruleRegistry;
}
return _registeredLints;
return _registeredLints!;
}

Future<List<String>> get sdkTags async => _sdkTags ??= await _fetchSdkTags();
Future<List<String?>> get sdkTags async => _sdkTags ??= await _fetchSdkTags();

Future<List<String?>> get stagehandRules async =>
Future<List<String>> get stagehandRules async =>
_stagehandRules ??= await score_utils.fetchRules(_stagehandOptionsUrl);

Future<String?> dartSdkForLinter(String version) async {
var sdkVersions = <String>[];
var sdks = await sdkTags;
for (var sdk in sdks) {
var linterVersion = await linterForDartSdk(sdk);
if (linterVersion == version) {
sdkVersions.add(sdk);
if (sdk != null) {
var linterVersion = await linterForDartSdk(sdk);
if (linterVersion == version) {
sdkVersions.add(sdk);
}
}
}

sdkVersions.sort();
return sdkVersions.isNotEmpty ? sdkVersions.first : null;
}

Future<List<String?>> fetchRulesForVersion(String version) async =>
Future<List<String>> fetchRulesForVersion(String version) async =>
score_utils.fetchRules(_repoPathPrefix.resolve('$version$_allPathSuffix'));

Future<String?> findSinceDartSdk(String linterVersion) async =>
await dartSdkForLinter(linterVersion);

Future<String?> findSinceLinter(String lint) async {
// History recorded in `all.yaml` starts in minor 31.
var rules_31 = await (rulesForVersion(31) as FutureOr<List<String>>);
if (rules_31.contains(lint)) {
var version = await _crawlForVersion(lint);
if (version != null) {
return version;
var rules_31 = await rulesForVersion(31);
if (rules_31 != null) {
if (rules_31.contains(lint)) {
var version = await _crawlForVersion(lint);
if (version != null) {
return version;
}
}
}

Expand All @@ -121,15 +125,14 @@ Future<String?> findSinceLinter(String lint) async {
return null;
}

Future<String> linterForDartSdk(String sdk) async =>
_dartSdkToLinterMap[sdk] ??=
await (_fetchLinterForVersion(sdk) as FutureOr<String>);
Future<String?> linterForDartSdk(String sdk) async =>
_dartSdkToLinterMap[sdk] ??= await _fetchLinterForVersion(sdk);

Future<List<String>?> rulesForVersion(int minor) async {
Future<List<String?>?> rulesForVersion(int minor) async {
var version = '0.1.$minor';
if (minor >= 31) {
return _sinceMap[version] ??=
await (fetchRulesForVersion(version) as FutureOr<List<String>>);
var rules = await fetchRulesForVersion(version);
return _sinceMap[version] ??= rules;
}
return null;
}
Expand Down Expand Up @@ -179,7 +182,7 @@ Future<String?> _fetchLinterForVersion(String version) async {
return null;
}

Future<List<String>> _fetchSdkTags() {
Future<List<String?>> _fetchSdkTags() {
final github = GitHub();
final slug = RepositorySlug('dart-lang', 'sdk');

Expand All @@ -189,6 +192,9 @@ Future<List<String>> _fetchSdkTags() {
.listTags(slug)
.map((t) => t.name)
.where((t) {
if (t == null) {
pq marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
// Filter on numeric release tags.
if (!t.startsWith(RegExp(r'\d+'))) {
return false;
Expand Down
40 changes: 21 additions & 19 deletions tool/doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'dart:io';
import 'package:analyzer/src/lint/config.dart';
import 'package:analyzer/src/lint/registry.dart';
import 'package:args/args.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:http/http.dart' as http;
import 'package:linter/src/analyzer.dart';
import 'package:linter/src/rules.dart';
Expand Down Expand Up @@ -79,7 +78,7 @@ Future<String> get effectiveDartLatestVersion async {
'https://raw.githubusercontent.com/tenhobi/effective_dart/master/lib/analysis_options.yaml';
var client = http.Client();
print('loading $url...');
var req = await client.get(url);
var req = await client.get(Uri.parse(url));
var parts = req.body.split('package:effective_dart/analysis_options.');
return parts[1].split('.yaml')[0];
}
Expand Down Expand Up @@ -109,7 +108,7 @@ Future<String> get pedanticLatestVersion async {
'https://raw.githubusercontent.com/dart-lang/pedantic/master/lib/analysis_options.yaml';
var client = http.Client();
print('loading $url...');
var req = await client.get(url);
var req = await client.get(Uri.parse(url));
var parts = req.body.split('package:pedantic/analysis_options.');
return parts[1].split('.yaml')[0];
}
Expand All @@ -121,32 +120,35 @@ Future<void> fetchBadgeInfo() async {
var latestPedantic = await pedanticLatestVersion;
var latestEffectiveDart = await effectiveDartLatestVersion;

var pedantic = await (fetchConfig(
'https://raw.githubusercontent.com/dart-lang/pedantic/master/lib/analysis_options.$latestPedantic.yaml')
as FutureOr<LintConfig>);
for (var ruleConfig in pedantic.ruleConfigs) {
pedanticRules.add(ruleConfig.name);
var pedantic = await fetchConfig(
'https://raw.githubusercontent.com/dart-lang/pedantic/master/lib/analysis_options.$latestPedantic.yaml');
if (pedantic != null) {
for (var ruleConfig in pedantic.ruleConfigs) {
pedanticRules.add(ruleConfig.name);
}
}

var effectiveDart = await (fetchConfig(
'https://raw.githubusercontent.com/tenhobi/effective_dart/master/lib/analysis_options.$latestEffectiveDart.yaml')
as FutureOr<LintConfig>);
for (var ruleConfig in effectiveDart.ruleConfigs) {
effectiveDartRules.add(ruleConfig.name);
var effectiveDart = await fetchConfig(
'https://raw.githubusercontent.com/tenhobi/effective_dart/master/lib/analysis_options.$latestEffectiveDart.yaml');
if (effectiveDart != null) {
for (var ruleConfig in effectiveDart.ruleConfigs) {
effectiveDartRules.add(ruleConfig.name);
}
}

var flutter = await (fetchConfig(
'https://raw.githubusercontent.com/flutter/flutter/master/packages/flutter/lib/analysis_options_user.yaml')
as FutureOr<LintConfig>);
for (var ruleConfig in flutter.ruleConfigs) {
flutterRules.add(ruleConfig.name);
var flutter = await fetchConfig(
'https://raw.githubusercontent.com/flutter/flutter/master/packages/flutter/lib/analysis_options_user.yaml');
if (flutter != null) {
for (var ruleConfig in flutter.ruleConfigs) {
flutterRules.add(ruleConfig.name);
}
}
}

Future<LintConfig?> fetchConfig(String url) async {
var client = http.Client();
print('loading $url...');
var req = await client.get(url);
var req = await client.get(Uri.parse(url));
return processAnalysisOptionsFile(req.body);
}

Expand Down
Loading