mirror of
https://github.com/flutter/samples.git
synced 2026-05-09 16:37:30 +00:00
[linting_tool] Add lint rules list (#856)
This commit is contained in:
committed by
GitHub
parent
3b65403631
commit
6bac1b9694
26
experimental/linting_tool/lib/repository/api_provider.dart
Normal file
26
experimental/linting_tool/lib/repository/api_provider.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:linting_tool/model/rule.dart';
|
||||
|
||||
class APIProvider {
|
||||
final _baseURL = 'https://dart-lang.github.io/linter';
|
||||
Future<List<Rule>> getRulesList() async {
|
||||
http.Response response =
|
||||
await http.get(Uri.parse('$_baseURL//lints/machine/rules.json'));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<Rule> rulesList = [];
|
||||
final data = json.decode(response.body) as List;
|
||||
for (var item in data) {
|
||||
rulesList.add(Rule.fromJson(item as Map<String, dynamic>));
|
||||
}
|
||||
return rulesList;
|
||||
} else {
|
||||
throw Exception('Failed to load rules');
|
||||
}
|
||||
}
|
||||
}
|
||||
12
experimental/linting_tool/lib/repository/repository.dart
Normal file
12
experimental/linting_tool/lib/repository/repository.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:linting_tool/model/rule.dart';
|
||||
import 'package:linting_tool/repository/api_provider.dart';
|
||||
|
||||
class Repository {
|
||||
final _apiProvider = APIProvider();
|
||||
|
||||
Future<List<Rule>> getRulesList() => _apiProvider.getRulesList();
|
||||
}
|
||||
Reference in New Issue
Block a user