Skip to content

Enable and fix latest pedantic lints #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2020
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
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -932,3 +932,9 @@ linter:
# reason: Trying to assigning a value to void is an error.
# 0 issues
- void_checks

- camel_case_extensions
- omit_local_variable_types
- prefer_conditional_assignment
- prefer_final_fields
- use_function_type_syntax_for_parameters
3 changes: 1 addition & 2 deletions example/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export 'package:github/browser_helper.dart';
Future<void> initViewSourceButton(String script) async {
// query the DOM for the view source button, handle clicks
document.querySelector('#view-source')?.onClick?.listen((_) {
final WindowBase popup =
window.open('view_source.html?script=$script', 'View Source');
final popup = window.open('view_source.html?script=$script', 'View Source');
String code;

var fetched = false;
Expand Down
6 changes: 3 additions & 3 deletions example/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void reloadTable({int accuracy = 4}) {
}

isReloadingTable = true;
final String md = generateMarkdown(accuracy);
final md = generateMarkdown(accuracy);
github.misc.renderMarkdown(md).then((html) {
tableDiv.setInnerHtml(html, treeSanitizer: NodeTreeSanitizer.trusted);
isReloadingTable = false;
Expand All @@ -54,10 +54,10 @@ int totalBytes(LanguageBreakdown breakdown) {
}

String generateMarkdown(int accuracy) {
final int total = totalBytes(breakdown);
final total = totalBytes(breakdown);
final data = breakdown.toList();

String md = '|Name|Bytes|Percentage|\n';
var md = '|Name|Bytes|Percentage|\n';
md += '|-----|-----|-----|\n';
data.sort((a, b) => b[1].compareTo(a[1]));

Expand Down
4 changes: 2 additions & 2 deletions example/organization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Future<void> main() async {

Future<void> loadOrganization(String orgToLoad) async {
try {
final Organization org = await github.organizations.get(orgToLoad);
final String html = '''
final org = await github.organizations.get(orgToLoad);
final html = '''
<br/>Name: ${org.name}
<br/>Id: ${org.id}
<br/>Company: ${org.company}
Expand Down
2 changes: 1 addition & 1 deletion example/readme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Future<void> main() async {
readmeDiv = querySelector('#readme');
var repo = RepositorySlug('SpinlockLabs', 'github.dart');
final readme = await github.repositories.getReadme(repo);
String markdown = readme.content;
var markdown = readme.content;
if (readme.encoding == 'base64') {
markdown = String.fromCharCodes(base64.decode(markdown));
}
Expand Down
2 changes: 1 addition & 1 deletion example/releases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void loadReleases() {
<h1>${release.name}</h1>
</div>
''', treeSanitizer: NodeTreeSanitizer.trusted);
final Element rel = releasesDiv.querySelector('#release-${release.id}');
final rel = releasesDiv.querySelector('#release-${release.id}');
void append(String key, String value) {
if (value == null) {
return;
Expand Down
8 changes: 3 additions & 5 deletions example/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ List<Repository> _reposCache;

void updateRepos(
List<Repository> repos, [
int compare(Repository a, Repository b),
int Function(Repository a, Repository b) compare,
]) {
document.querySelector('#repos').children.clear();
repos.sort(compare);
Expand All @@ -69,7 +69,7 @@ void updateRepos(
}
}

void loadRepos([int compare(Repository a, Repository b)]) {
void loadRepos([int Function(Repository a, Repository b) compare]) {
final title = querySelector('#title');
if (title.text.contains('(')) {
title.replaceWith(HeadingElement.h2()
Expand All @@ -90,9 +90,7 @@ void loadRepos([int compare(Repository a, Repository b)]) {
}
}

if (compare == null) {
compare = (a, b) => a.name.compareTo(b.name);
}
compare ??= (a, b) => a.name.compareTo(b.name);

github.repositories.listUserRepositories(user).toList().then((repos) {
_reposCache = repos;
Expand Down
6 changes: 3 additions & 3 deletions example/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Future<void> main() async {
}

Future<void> search(_) async {
final Stream<CodeSearchResults> resultsStream = github.search.code(
final resultsStream = github.search.code(
val('query'),
language: val('language'),
filename: val('filename'),
Expand All @@ -28,13 +28,13 @@ Future<void> search(_) async {
final DivElement resultsDiv = querySelector('#results');
resultsDiv.innerHtml = '';

int count = 0;
var count = 0;
await for (final results in resultsStream) {
count += results.items.length;
querySelector('#nresults').text =
'${results.totalCount} result${results.totalCount == 1 ? "" : "s"} (showing $count)';

for (final CodeSearchItem item in results.items) {
for (final item in results.items) {
final url = item.htmlUrl;
final path = item.path;
resultsDiv.append(DivElement()
Expand Down
2 changes: 1 addition & 1 deletion example/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void loadUsers() {
github.users.getUser(baseUser.login).then((user) {
final userDiv = DivElement();

for (int i = 1; i <= 2; i++) {
for (var i = 1; i <= 2; i++) {
userDiv.append(BRElement());
}

Expand Down
2 changes: 1 addition & 1 deletion example/zen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import 'common.dart';

Future<void> main() async {
await initViewSourceButton('zen.dart');
final String msg = await github.misc.getZen();
final msg = await github.misc.getZen();
querySelector('#zen').text = msg;
}
4 changes: 2 additions & 2 deletions lib/browser_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import 'package:github/src/common.dart';
/// [selector] is the selector to use to find markdown elements.
/// [indent] is the indent that needs to be stripped out.
void renderMarkdown(GitHub github, String selector, {int indent = 4}) {
final ElementList elements = document.querySelectorAll(selector);
final elements = document.querySelectorAll(selector);

elements.removeWhere((Element it) => it.attributes.containsKey('rendered'));

for (final Element e in elements) {
for (final e in elements) {
final txt = e.text;

final md = txt.split('\n').map((it) {
Expand Down
4 changes: 1 addition & 3 deletions lib/src/browser/xplat_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import 'package:github/src/common/xplat_common.dart'
Authentication findAuthenticationFromEnvironment() {
// search the query string parameters first
var auth = findAuthenticationInMap(_parseQuery(window.location.href));
if (auth == null) {
auth = findAuthenticationInMap(window.sessionStorage);
}
auth ??= findAuthenticationInMap(window.sessionStorage);
return auth ?? Authentication.anonymous();
}

Expand Down
20 changes: 8 additions & 12 deletions lib/src/common/activity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ class EventPoller {
_controller = StreamController<Event>();

void handleEvent(http.Response response) {
if (interval == null) {
interval = int.parse(response.headers['x-poll-interval']);
}
interval ??= int.parse(response.headers['x-poll-interval']);

if (response.statusCode == 304) {
return;
Expand Down Expand Up @@ -374,17 +372,15 @@ class EventPoller {
}
}

if (_timer == null) {
_timer = Timer.periodic(Duration(seconds: interval), (timer) {
final headers = <String, String>{};
_timer ??= Timer.periodic(Duration(seconds: interval), (timer) {
final headers = <String, String>{};

if (_lastFetched != null) {
headers['If-None-Match'] = _lastFetched;
}
if (_lastFetched != null) {
headers['If-None-Match'] = _lastFetched;
}

github.request('GET', path, headers: headers).then(handleEvent);
});
}
github.request('GET', path, headers: headers).then(handleEvent);
});
}

final headers = <String, String>{};
Expand Down
4 changes: 2 additions & 2 deletions lib/src/common/git_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GitService extends Service {
///
/// API docs: https://developer.github.com/v3/git/refs/#get-all-references
Stream<GitReference> listReferences(RepositorySlug slug, {String type}) {
String path = '/repos/${slug.fullName}/git/refs';
var path = '/repos/${slug.fullName}/git/refs';
if (type != null) {
path += '/$type';
}
Expand Down Expand Up @@ -93,7 +93,7 @@ class GitService extends Service {
String sha, {
bool force = false,
}) {
final String body = jsonEncode({'sha': sha, 'force': force});
final body = jsonEncode({'sha': sha, 'force': force});
// Somehow the reference updates PATCH request needs a valid content-length.
final headers = {'content-length': body.length.toString()};

Expand Down
72 changes: 18 additions & 54 deletions lib/src/common/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,101 +80,65 @@ class GitHub {

/// Service for activity related methods of the GitHub API.
ActivityService get activity {
if (_activity == null) {
_activity = ActivityService(this);
}
return _activity;
return _activity ??= ActivityService(this);
}

/// Service for autorizations related methods of the GitHub API.
///
/// Note: You can only access this API via Basic Authentication using your
/// username and password, not tokens.
AuthorizationsService get authorizations {
if (_authorizations == null) {
_authorizations = AuthorizationsService(this);
}
return _authorizations;
return _authorizations ??= AuthorizationsService(this);
}

/// Service for gist related methods of the GitHub API.
GistsService get gists {
if (_gists == null) {
_gists = GistsService(this);
}
return _gists;
return _gists ??= GistsService(this);
}

/// Service for git data related methods of the GitHub API.
GitService get git {
if (_git == null) {
_git = GitService(this);
}
return _git;
return _git ??= GitService(this);
}

/// Service for issues related methods of the GitHub API.
IssuesService get issues {
if (_issues == null) {
_issues = IssuesService(this);
}
return _issues;
return _issues ??= IssuesService(this);
}

/// Service for misc related methods of the GitHub API.
MiscService get misc {
if (_misc == null) {
_misc = MiscService(this);
}
return _misc;
return _misc ??= MiscService(this);
}

/// Service for organization related methods of the GitHub API.
OrganizationsService get organizations {
if (_organizations == null) {
_organizations = OrganizationsService(this);
}
return _organizations;
return _organizations ??= OrganizationsService(this);
}

/// Service for pull requests related methods of the GitHub API.
PullRequestsService get pullRequests {
if (_pullRequests == null) {
_pullRequests = PullRequestsService(this);
}
return _pullRequests;
return _pullRequests ??= PullRequestsService(this);
}

/// Service for repository related methods of the GitHub API.
RepositoriesService get repositories {
if (_repositories == null) {
_repositories = RepositoriesService(this);
}
return _repositories;
return _repositories ??= RepositoriesService(this);
}

/// Service for search related methods of the GitHub API.
SearchService get search {
if (_search == null) {
_search = SearchService(this);
}
return _search;
return _search ??= SearchService(this);
}

/// Service to provide a handy method to access GitHub's url shortener.
UrlShortenerService get urlShortener {
if (_urlShortener == null) {
_urlShortener = UrlShortenerService(this);
}
return _urlShortener;
return _urlShortener ??= UrlShortenerService(this);
}

/// Service for user related methods of the GitHub API.
UsersService get users {
if (_users == null) {
_users = UsersService(this);
}
return _users;
return _users ??= UsersService(this);
}

/// Handles Get Requests that respond with JSON
Expand All @@ -192,7 +156,7 @@ class GitHub {
/// The default [convert] function returns the input object.
Future<T> getJSON<S, T>(String path,
{int statusCode,
void fail(http.Response response),
void Function(http.Response response) fail,
Map<String, String> headers,
Map<String, String> params,
JSONConverter<S, T> convert,
Expand Down Expand Up @@ -228,7 +192,7 @@ class GitHub {
Future<T> postJSON<S, T>(
String path, {
int statusCode,
void fail(http.Response response),
void Function(http.Response response) fail,
Map<String, String> headers,
Map<String, String> params,
JSONConverter<S, T> convert,
Expand All @@ -251,7 +215,7 @@ class GitHub {
String method,
String path, {
int statusCode,
void fail(http.Response response),
void Function(http.Response response) fail,
Map<String, String> headers,
Map<String, String> params,
JSONConverter<S, T> convert,
Expand Down Expand Up @@ -304,7 +268,7 @@ class GitHub {
Map<String, dynamic> params,
dynamic body,
int statusCode,
void fail(http.Response response),
void Function(http.Response response) fail,
String preview,
}) async {
if (rateLimitRemaining != null && rateLimitRemaining <= 0) {
Expand All @@ -314,7 +278,7 @@ class GitHub {
await Future.delayed(waitTime);
}

if (headers == null) headers = {};
headers ??= {};

if (preview != null) {
headers['Accept'] = preview;
Expand Down Expand Up @@ -412,7 +376,7 @@ class GitHub {
buff.writeln(' Message: $message');
if (errors != null) {
buff.writeln(' Errors:');
for (final Map<String, String> error in errors) {
for (final error in errors) {
final resource = error['resource'];
final field = error['field'];
final code = error['code'];
Expand Down
Loading