Skip to content

Commit

Permalink
merge: pull request #116 from Solvro/feat/linter
Browse files Browse the repository at this point in the history
Feat/add linter
  • Loading branch information
simon-the-shark authored Jul 26, 2024
2 parents 7b01009 + 8db8bd6 commit 9592d1a
Show file tree
Hide file tree
Showing 192 changed files with 2,040 additions and 1,820 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/lint_and_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lint & formatting

on:
push:
branches: ["**"]
pull_request:
branches: ["**"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.22.3"
channel: "stable"
- run: flutter --version

- name: Install dependencies
run: dart pub get

- name: Example .env
run: cp example.env .env

- name: generate files
run: dart run build_runner build --delete-conflicting-outputs

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
run: flutter analyze --fatal-infos
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ app.*.symbols


#Env setup
*.env
.env
*.env.dev
.env.dev
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ fvm flutter run
3. Api helper module instructions: https://github.com/Solvro/topwr-mobile/tree/main/lib/api_base
4. We use `flutter_gen` for generating asset paths: https://pub.dev/packages/flutter_gen

# Before you push a commit
- run the linter
```bash
flutter analyze
```
- if you have any problems listed, try to autofix with
```bash
dart fix --apply
```
- run `analyze` again, if problems still persist, correct them manually. If you disagree with some of the rules, we can still discuss and adjust them. Hit me up @simon-the-shark or open an issue.
- run formatter
```bash
dart format .
```
## Github workflow
Don't worry if you've forgotten about the steps, automatic gh action will run the checks for you and notify if somthing's wrong.


## Working with git

Expand Down
33 changes: 16 additions & 17 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
include: package:total_lints/app.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
prefer_relative_imports: true
avoid_relative_lib_imports: true
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
prefer_single_quotes: false
prefer_double_quotes: true # I hate single quotes
use_setters_to_change_properties: false
lines_longer_than_80_chars: false # I'd love to be able to set here some other number, but 80 is too low
sort_pub_dependencies: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.mocks.dart"
- "**/*.gform.dart"
- "**/*.tailor.dart"
- "**/*.gen.dart"
- "**/*.graphql.dart"
- "**/*.icons.dart"
3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
API_URL="https://<...>"
ASSETS_URL="https://<...>"
IPARKING_URL="https://<...>"
2 changes: 1 addition & 1 deletion lib/api_base/directus_assets_url.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../config/api_base_config.dart';
import "../config/api_base_config.dart";

extension DirectusAssetsUrl on String {
String get directusUrl {
Expand Down
8 changes: 4 additions & 4 deletions lib/api_base/gql_client_provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:graphql/client.dart';
import "package:flutter/foundation.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:graphql/client.dart";

import '../config/api_base_config.dart';
import "../config/api_base_config.dart";

final _hiveCacheBoxProvider = Provider((ref) async {
if (kIsWeb) return GraphQLCache(); // Normal in memory cache
Expand Down
8 changes: 4 additions & 4 deletions lib/api_base/hive_init.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:graphql/client.dart';
import 'package:path_provider/path_provider.dart';
import "package:flutter/foundation.dart";
import "package:flutter/widgets.dart";
import "package:graphql/client.dart";
import "package:path_provider/path_provider.dart";

Future<void> initHiveForGraphqlCache() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down
16 changes: 8 additions & 8 deletions lib/api_base/ttl/local_timestamp_repository.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:graphql/client.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import "package:graphql/client.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";
import "package:shared_preferences/shared_preferences.dart";

import '../../config/api_base_config.dart';
import '../../config/ttl_config.dart';
import '../../utils/timestamp.dart';
import 'ttl_timestamp.dart';
import "../../config/api_base_config.dart";
import "../../config/ttl_config.dart";
import "../../utils/timestamp.dart";
import "ttl_timestamp.dart";

part "local_timestamp_repository.g.dart";

Expand All @@ -32,7 +32,7 @@ class LocalTimestampRepo {

@Riverpod(keepAlive: true)
Future<SharedPreferences> _prefs(_PrefsRef ref) async {
return await SharedPreferences.getInstance();
return SharedPreferences.getInstance();
}

@riverpod
Expand Down
15 changes: 8 additions & 7 deletions lib/api_base/ttl/ttl_service.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'dart:async';
import "dart:async";

import 'package:graphql/client.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import "package:graphql/client.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import 'local_timestamp_repository.dart';
import '../../config/ttl_config.dart';
import "../../config/ttl_config.dart";
import "local_timestamp_repository.dart";

part 'ttl_service.g.dart';
part "ttl_service.g.dart";

@riverpod
class TtlService extends _$TtlService {
Expand All @@ -24,7 +24,8 @@ class TtlService extends _$TtlService {
ref.watch(localTimestampRepoProvider.call(key).future);

Future<QueryResult<T>> interceptAndSaveTimestamps<T>(
QueryResult<T> event) async {
QueryResult<T> event,
) async {
if (event.source == QueryResultSource.network) {
final repo = await repository;
await repo.saveTimestamp(event);
Expand Down
9 changes: 4 additions & 5 deletions lib/api_base/ttl/ttl_timestamp.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import '../../utils/timestamp.dart';
import '../../config/ttl_config.dart';
import "../../config/ttl_config.dart";
import "../../utils/timestamp.dart";

class TimestampTtl extends Timestamp {
TimestampTtl.nil(this.key) : super.nil();
TimestampTtl.from(DateTime? ts, this.key) : super.from(ts);
TimestampTtl.tryParse(String? formattedString, this.key)
: super.tryParse(formattedString);
TimestampTtl.from(super.ts, this.key) : super.from();
TimestampTtl.tryParse(super.formattedString, this.key) : super.tryParse();

final TtlKey key;

Expand Down
14 changes: 8 additions & 6 deletions lib/api_base/watch_query_adapter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:graphql/client.dart';
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:graphql/client.dart";

import 'gql_client_provider.dart';
import '../config/ttl_config.dart';
import 'ttl/ttl_service.dart';
import "../config/ttl_config.dart";
import "gql_client_provider.dart";
import "ttl/ttl_service.dart";

class GqlOfflineException implements Exception {
const GqlOfflineException(this.ttlKey);
Expand Down Expand Up @@ -41,7 +41,9 @@ extension _WatchQueryStreamAdapter<T> on Ref {

extension TTLWatchQueryAdapter on AutoDisposeStreamProviderRef {
Stream<T?> watchQueryWithCache<T>(
WatchQueryOptions<T> watchQueryOptions, TtlKey ttlKey) async* {
WatchQueryOptions<T> watchQueryOptions,
TtlKey ttlKey,
) async* {
final apiClient = await watch(gqlClientProvider);
final ttlService = ttlServiceProvider.call(ttlKey);
final ttlFetchPolicy = await watch(ttlService.future);
Expand Down
6 changes: 3 additions & 3 deletions lib/config/api_base_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:envied/envied.dart';
import "package:envied/envied.dart";

part 'api_base_config.g.dart';
part "api_base_config.g.dart";

abstract class ApiBaseConfig {
static const hiveCacheBoxName = "hiveCacheBoxForDirectusGraphQL";
Expand All @@ -9,7 +9,7 @@ abstract class ApiBaseConfig {
}

@Envied(
path: '.env',
path: ".env",
obfuscate: true,
useConstantCase: true,
requireEnvFile: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/config/map_view_config.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import "package:flutter/material.dart";
import "package:google_maps_flutter/google_maps_flutter.dart";

typedef MapSheetSize = ({
double recomendedSheetHeight,
Expand Down
10 changes: 5 additions & 5 deletions lib/config/nav_bar_config.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:enum_map/enum_map.dart';
import 'package:flutter/material.dart';
import "package:enum_map/enum_map.dart";
import "package:flutter/material.dart";

import '../features/iparking/widgets/i_parking_icons_icons.dart';
import '../features/bottom_nav_bar/bottom_nav_bar_icon_icons.dart';
import "../features/bottom_nav_bar/bottom_nav_bar_icon_icons.icons.dart";
import "../features/iparking/widgets/i_parking_icons_icons.icons.dart";

part 'nav_bar_config.g.dart';
part "nav_bar_config.g.dart";

@unmodifiableEnumMap
enum NavBarEnum {
Expand Down
15 changes: 7 additions & 8 deletions lib/config/navigator_config.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import '../features/buildings_map/buildings_view.dart';
import '../features/departments_tab/departments_tab.dart';
import '../features/guide/guide_view_template.dart';
import '../features/home_view/home_view.dart';
import '../features/iparking/parking_view.dart';
import '../features/student_research_group_tab/scientific_circles_tab.dart';
import 'nav_bar_config.dart';
import "../features/buildings_map/buildings_view.dart";
import "../features/departments_tab/departments_tab.dart";
import "../features/guide/guide_view_template.dart";
import "../features/home_view/home_view.dart";
import "../features/iparking/parking_view.dart";
import "../features/student_research_group_tab/scientific_circles_tab.dart";
import "nav_bar_config.dart";

abstract class NavigatorConfig {
static const initialTab = NavBarEnum.home;
}


abstract class TabsConfig {
static const tabs = UnmodifiableNavBarEnumMap(
home: HomeView(),
Expand Down
8 changes: 4 additions & 4 deletions lib/config/routes.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
abstract class AppRoutes {
AppRoutes._();

static const root = '/';
static const studyCircleDetails = 'study-circle-details';
static const aboutUsDetail = 'about-us-detail';
static const departmentDetails = 'department-details';
static const root = "/";
static const studyCircleDetails = "study-circle-details";
static const aboutUsDetail = "about-us-detail";
static const departmentDetails = "department-details";
}
10 changes: 5 additions & 5 deletions lib/config/ttl_config.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:enum_map/enum_map.dart';
import 'package:flutter/foundation.dart';
import "package:enum_map/enum_map.dart";
import "package:flutter/foundation.dart";

part 'ttl_config.g.dart';
part "ttl_config.g.dart";

@unmodifiableEnumMap
enum TtlKey {
Expand All @@ -25,7 +25,7 @@ abstract class TtlStrategy {
static const thirtyDays = kDebugMode ? Duration.zero : Duration(days: 30);

static const _ttlDurations = UnmodifiableTtlKeyMap(
// TODO: specific values are yet ment to be accordingly adjusted
// TODO(simon-the-shark): specific values are yet ment to be accordingly adjusted.
infosPreviewRepository: day,
academicCalendarRepository: day,
sciCirclesPreviewRepository: thirtyDays,
Expand All @@ -34,7 +34,7 @@ abstract class TtlStrategy {
mapBuildingsRepository: thirtyDays,
departmentsRepository: thirtyDays,
aboutUsRepository: thirtyDays,
departmentsDetailsRepository: thirtyDays
departmentsDetailsRepository: thirtyDays,
);

static Duration get(TtlKey key) {
Expand Down
Loading

0 comments on commit 9592d1a

Please sign in to comment.