Skip to content

Commit

Permalink
Integrate custom lints (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras authored May 29, 2024
2 parents 6c9f889 + eb76819 commit 02cd6d2
Show file tree
Hide file tree
Showing 41 changed files with 192 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
with:
commit_message: "Bump app version [no ci]"

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: "zulu"
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/format_lint_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Clone repository
uses: actions/checkout@v4

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: zulu
Expand All @@ -49,7 +49,11 @@ jobs:
flutter-version-file: uni/pubspec.yaml
cache: true

- run: flutter analyze .
- run: flutter pub get

- run: |
flutter analyze .
dart run custom_lint
test:
name: Test
Expand All @@ -60,7 +64,7 @@ jobs:
working-directory: ./uni
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: zulu
Expand Down
2 changes: 2 additions & 0 deletions uni/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ analyzer:
- "**.g.dart"
- "**.mocks.dart"
- "**generated/**"
plugins:
- custom_lint
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ Future<void> workerStartCallback() async {
});
return true;
}
//try to keep the usage of this function BELOW +-30 seconds
//to not be punished by the scheduler in future runs.
// try to keep the usage of this function BELOW +-30 seconds
// to not be punished by the scheduler in future runs.
await taskMap[taskName]!.item1();
} catch (err, stackTrace) {
} catch (err, st) {
Logger().e(
'Error while running $taskName job:',
error: err,
stackTrace: stackTrace,
stackTrace: st,
);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions uni/lib/controller/background_workers/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class NotificationManager {
const initializationSettingsAndroid =
AndroidInitializationSettings('ic_notification');

//request for notifications immediatly on iOS
// request for notifications immediatly on iOS
const darwinInitializationSettings = DarwinInitializationSettings(
requestCriticalPermission: true,
);
Expand Down Expand Up @@ -157,7 +157,7 @@ class NotificationManager {
if (Platform.isAndroid) {
await Workmanager().cancelByUniqueName(
'pt.up.fe.ni.uni.notificationworker',
); //stop task if it's already running
); // stop task if it's already running
await Workmanager().registerPeriodicTask(
'pt.up.fe.ni.uni.notificationworker',
'pt.up.fe.ni.uni.notificationworker',
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/controller/cleanup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Future<void> cleanDirectory(Directory directory, DateTime threshold) async {
try {
final fileDate = file.lastModifiedSync();
return fileDate.isBefore(threshold) && path.extension(file.path) != '.db';
} catch (e) {
} catch (err) {
return false;
}
});
Expand Down
6 changes: 3 additions & 3 deletions uni/lib/controller/fetchers/departures_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ class DeparturesFetcher {
callParam.lastIndexOf("'"),
);
return csrfToken;
} catch (e, stackTrace) {
} catch (err, st) {
unawaited(
Sentry.captureEvent(
SentryEvent(
throwable: e,
throwable: err,
request: SentryRequest(
url: url,
data: response.body,
),
),
stackTrace: stackTrace,
stackTrace: st,
),
);
rethrow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CalendarDatabase extends AppDatabase {
});
}

//Returns a list with all calendar events stored in the database
// Returns a list with all calendar events stored in the database
Future<List<CalendarEvent>> calendar() async {
final db = await getDatabase();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ class RestaurantDatabase extends AppDatabase {
whereArgs.add(toString(day));
}

//Get restaurant meals
// Get restaurant meals
final List<Map<String, dynamic>> mealsMaps =
await txn.query('meals', where: whereQuery, whereArgs: whereArgs);

//Retrieve data from query
// Retrieve data from query
final meals = mealsMaps.map((map) {
final day = parseDayOfWeek(map['day'] as String);
final type = map['type'] as String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NotificationTimeoutStorage {
if (!_fileContent.containsKey(uniqueID)) {
return DateTime.fromMicrosecondsSinceEpoch(
0,
); //get 1970 to always trigger notification
); // get 1970 to always trigger notification
}
return DateTime.parse(_fileContent[uniqueID] as String);
}
Expand All @@ -51,7 +51,7 @@ class NotificationTimeoutStorage {
final applicationDirectory =
(await getApplicationDocumentsDirectory()).path;
if (!File('$applicationDirectory/notificationTimeout.json').existsSync()) {
//empty json
// empty json
await File('$applicationDirectory/notificationTimeout.json')
.writeAsString('{}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class PreferencesController {
final encrypter = _createEncrypter();
try {
return encrypter.decrypt64(base64Text, iv: iv);
} catch (e) {
} catch (_) {
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions uni/lib/controller/parsers/parser_library_occupation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Future<LibraryOccupation> parseLibraryOccupationFromSheets(
int max;
try {
floor = (jsonDecoded['table']['rows'][i]['c'][0]['v'] as double).toInt();
} catch (e) {
} catch (err) {
floor = 0;
}
try {
max = (jsonDecoded['table']['rows'][i]['c'][1]['v'] as double).toInt();
} catch (e) {
} catch (err) {
max = 0;
}
occupation.addFloor(FloorOccupation(i + 1, floor, max));
Expand Down
12 changes: 6 additions & 6 deletions uni/lib/controller/parsers/parser_restaurants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:uni/model/utils/day_of_week.dart';
List<Restaurant> getRestaurantsFromHtml(Response response) {
final document = parse(response.body);

//Get restaurant reference number and name
// Get restaurant reference number and name
final restaurantsHtml = document.querySelectorAll('#conteudoinner ul li > a');

final restaurantsTuple = restaurantsHtml.map((restaurantHtml) {
Expand All @@ -23,7 +23,7 @@ List<Restaurant> getRestaurantsFromHtml(Response response) {
return Tuple2(ref ?? '', name);
}).toList();

//Get restaurant meals and create the Restaurant class
// Get restaurant meals and create the Restaurant class
final restaurants = restaurantsTuple.map((restaurantTuple) {
final meals = <Meal>[];

Expand All @@ -35,14 +35,14 @@ List<Restaurant> getRestaurantsFromHtml(Response response) {
while (next != null && next.attributes['name'] == null) {
next = next.nextElementSibling;
if (next!.classes.contains('dados')) {
//It's the menu table
// It's the menu table
final rows = next.querySelectorAll('tr');
//Check if is empty
// Check if is empty
if (rows.length <= 1) {
break;
}

//Read rows, first row is ignored because it's the header
// Read rows, first row is ignored because it's the header
rows.getRange(1, rows.length).forEach((row) {
DayOfWeek? dayOfWeek;
String? type;
Expand All @@ -55,7 +55,7 @@ List<Restaurant> getRestaurantsFromHtml(Response response) {
if (header == 'Data') {
final d = parseDayOfWeek(value);
if (d == null) {
//It's a date
// It's a date
date = format.parseUtc(value);
} else {
dayOfWeek = d;
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/controller/parsers/parser_schedule_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Future<List<Lecture>> getOverlappedClasses(
)
.first,
);
} catch (e) {
} catch (_) {
final lect = Lecture.fromHtml(
subject!,
typeClass!,
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/model/entities/calendar_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CalendarEvent {
try {
return DateFormat('dd MMMM yyyy', 'pt')
.parse('${splitDate[0]} $month ${splitDate.last}');
} catch (e) {
} catch (_) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion uni/lib/model/providers/startup/session_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SessionProvider extends StateProviderNotifier<Session> {
persistentSession: persistentSession,
ignoreCached: true,
);
} catch (e) {
} catch (_) {
throw InternetStatusException(locale);
}

Expand Down
14 changes: 6 additions & 8 deletions uni/lib/model/providers/state_provider_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ abstract class StateProviderNotifier<T> extends ChangeNotifier {

try {
setState(await loadFromStorage(StateProviders.fromContext(context)));
} catch (e, stackTrace) {
await Sentry.captureException(e, stackTrace: stackTrace);
Logger()
.e('Failed to load $runtimeType info from storage: $e\n$stackTrace');
} catch (err, st) {
await Sentry.captureException(err, stackTrace: st);
Logger().e('Failed to load $runtimeType info from storage: $err\n$st');
_updateStatus(RequestStatus.failed);
}

Expand Down Expand Up @@ -135,10 +134,9 @@ abstract class StateProviderNotifier<T> extends ChangeNotifier {
);

_updateStatus(RequestStatus.successful);
} catch (e, stackTrace) {
await Sentry.captureException(e, stackTrace: stackTrace);
Logger()
.e('Failed to load $runtimeType info from remote: $e\n$stackTrace');
} catch (err, st) {
await Sentry.captureException(err, stackTrace: st);
Logger().e('Failed to load $runtimeType info from remote: $err\n$st');
_updateStatus(RequestStatus.failed);
}
}
Expand Down
10 changes: 3 additions & 7 deletions uni/lib/view/academic_path/widgets/course_units_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ class CourseUnitsCard extends GenericCard {
return Column(
children: courseUnits
.map(
(courseUnit) => Column(
children: [
Padding(
padding: const EdgeInsets.all(5),
child: CourseUnitCard(courseUnit),
),
],
(courseUnit) => Padding(
padding: const EdgeInsets.all(5),
child: CourseUnitCard(courseUnit),
),
)
.toList(),
Expand Down
6 changes: 3 additions & 3 deletions uni/lib/view/bug_report/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ class BugReportFormState extends State<BugReportForm> {
toastMsg = s.success;
}
status = true;
} catch (e, stackTrace) {
await Sentry.captureException(e, stackTrace: stackTrace);
Logger().e('Error while posting bug report:$e');
} catch (err, st) {
await Sentry.captureException(err, stackTrace: st);
Logger().e('Error while posting bug report:$err');
if (context.mounted) {
toastMsg = s.sent_error;
}
Expand Down
46 changes: 19 additions & 27 deletions uni/lib/view/bus_stop_next_arrivals/bus_stop_next_arrivals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,14 @@ class BusStopNextArrivalsPageState
color: Theme.of(context).colorScheme.primary,
),
),
Column(
children: [
ElevatedButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BusStopNextArrivalsPage>(
builder: (context) => const BusStopSelectionPage(),
),
),
child: Text(S.of(context).add),
ElevatedButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BusStopNextArrivalsPage>(
builder: (context) => const BusStopSelectionPage(),
),
],
),
child: Text(S.of(context).add),
),
],
),
Expand Down Expand Up @@ -175,22 +171,18 @@ class NextArrivalsState extends State<NextArrivals> {

widget.buses.forEach((stopCode, stopData) {
rows.add(
Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
left: 22,
right: 22,
),
child: BusStopRow(
stopCode: stopCode,
trips: widget.buses[stopCode]?.trips ?? [],
stopCodeShow: false,
),
),
],
Container(
padding: const EdgeInsets.only(
top: 8,
bottom: 8,
left: 22,
right: 22,
),
child: BusStopRow(
stopCode: stopCode,
trips: widget.buses[stopCode]?.trips ?? [],
stopCodeShow: false,
),
),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BusStopSearch extends SearchDelegate<String> {

@override
Widget buildLeading(BuildContext context) {
//Back arrow to go back to menu
// Back arrow to go back to menu

return IconButton(
icon: const Icon(Icons.arrow_back),
Expand Down
Loading

0 comments on commit 02cd6d2

Please sign in to comment.