Skip to content

Conversation

@klortiz13
Copy link
Contributor

Summary

Defined a standard for the dart formatting of the campus app.
Draft of the rules: https://excalidraw.com/#room=97b1f775d13c07c1d598,CDZR10Dmdirwt6QdZsBivQ

Files changed (the rest are just format changes):

  • .editorconfig (layer 0)
    • Has IDE enforce some of these rules automatically when saving your files.
  • .pre-commit-config.yml (layer 1)
    • Runs auto_fix_all.sh to automatically fix formatting issues based on our rules from the link above.
  • .github/workflows/pre_commit_check.yml (layer 2)
    • Workflow file that runs the pre-commit hook and auto_check_all.sh to comment on the PR if there are any remaining violations. It fails if pre-commit fails.
  • scripts/auto_fix_all.sh
    • Checks for violations that can be made automatically and fixes them for you.
  • scripts/auto_check_all.sh
    • Checks for violations that can't be made automatically.
  • scripts/cleanup_backups.sh
    • Removes .bak files generated when running these scripts.

Scripts inside the styling directory are used by auto_fix_all.sh

  • scripts/styling/one_line_function_fix.sh
  • scripts/styling/add_date_to_todo_comment.sh
  • scripts/styling/add_space_after_comment_slashes.sh
  • scripts/styling/one_line_if_statement_fix.sh

Scripts inside the checking directory are used by auto_check_all.sh

  • scripts/checking/check_very_long_conditions.sh
  • scripts/checking/check_var_func_lower_camel_case.sh
  • scripts/checking/check_static_const_upper_snake_case.sh
  • scripts/checking/check_package_imports.sh
  • scripts/checking/check_files_directories_have_snake_case.sh
  • scripts/checking/check_classes_have_upper_camel_case.sh

Changelog

[General] [Add] - Added scripts to consistently format the campus app to several rules defined below:

Organizational Style

  • Files and Directories have to be snake_cased
    • app_provider.dart or student_id
  • Imports have to contain the full path
    • import 'package:campus_mobile_experimental/core/providers/map.dart';
  • Comments have to have a space after the slashes
    • // This is okay, however -> //This is not okay
  • "TODO" comments have to have two slashes and have a date (month and year) when it was made
    • // TODO: Remove old TODOs - November 2025

Coding Style

  • No more than 120 characters per line.
  • Variables/Functions have to be lowerCamelCase.
  • STATIC CONSTANTS can be FULL_UPPER_SNAKE_CASE.
  • Classes have to be UpperCamelCase
  • One-line if statements shouldn't have curly braces (i.e. if(condition) action;)
  • One-line functions have to use lambda (i.e. int oneLineFunction(int a, int b) ()=> return a+b;)
  • If statements with super long conditions have to have their values calculated beforehand to facilitate reading.

Test Plan

  1. Checkout local-remote-formatting-klortiz13
  2. Temporarily modify a file, commit and push.
  3. File should be automatically reformatted if it violates the 120-character line rule.
  4. Revert your changes

@klortiz13 klortiz13 self-assigned this Dec 4, 2025
@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as duplicate.

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

Code Style Violations Found

  • Static Constants (UPPER_SNAKE_CASE): 91 violations
  • File/Directory Naming (snake_case): 1 violations
  • Variable Naming (lowerCamelCase): 13 violations
  • Very Long If Statement Conditions: 62 violations

Total Violations: 167
Total Categories Failed: 4/6

Here are the formatting rules to follow:

  • Static Constants have to use UPPER_SNAKE_CASE (e.g., MAX_RETRY_COUNT)
  • Classes have to use UpperCamelCase (e.g., UserProfile)
  • Variables/Functions have to use lowerCamelCase (e.g., userName)
  • Files/Directories have to use snake_case (e.g., user_profile.dart)
  • Imports have to use full package paths (e.g., package:app_name/path/file.dart)
  • If Conditions have to split long/complex conditions into variables for readability

Example of a long if condition violation:

if (userDataProvider.isLoggedIn &&
    (userDataProvider.userProfileModel.classifications?.staff ?? false)) {
  // action
}
// GOOD: split condition into variables for readability
var isLoggedIn = userDataProvider.isLoggedIn;
var isStaff = userDataProvider.userProfileModel.classifications?.staff ?? false;
if (isLoggedIn && isStaff) {
  // action
}

To see more details and fix these violations:

  1. Run ./scripts/auto_check_all.sh locally.
  2. Apply the suggested corrections.
  3. Re-run the script to verify fixes.
  4. Commit your changes.

This comment will continue to appear until all violations are resolved.

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

Code Style Violations Found

  • Very Long If Statement Conditions: 63 violations

Total Violations: 63
Total Categories Failed: 1/6

Here are the formatting rules to follow:

  • Static Constants have to use UPPER_SNAKE_CASE (e.g., MAX_RETRY_COUNT)
  • Classes have to use UpperCamelCase (e.g., UserProfile)
  • Variables/Functions have to use lowerCamelCase (e.g., userName)
  • Files/Directories have to use snake_case (e.g., user_profile.dart)
  • Imports have to use full package paths (e.g., package:app_name/path/file.dart)
  • If Conditions have to split long/complex conditions into variables for readability

Example of a long if condition violation:

if (userDataProvider.isLoggedIn &&
    (userDataProvider.userProfileModel.classifications?.staff ?? false)) {
  // action
}
// GOOD: split condition into variables for readability
var isLoggedIn = userDataProvider.isLoggedIn;
var isStaff = userDataProvider.userProfileModel.classifications?.staff ?? false;
if (isLoggedIn && isStaff) {
  // action
}

To see more details and fix these violations:

  1. Run ./scripts/auto_check_all.sh locally.
  2. Apply the suggested corrections.
  3. Re-run the script to verify fixes.
  4. Commit your changes.

This comment will continue to appear until all violations are resolved.

@klortiz13 klortiz13 added the Enhancement New feature or request label Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants