Code formatting, linting rules, and coding conventions for Ora Browser development
Ora Browser maintains strict code quality standards through automated formatting and linting. All code must adhere to these standards before being merged.
func example() { let value = 42 if value > 0 { print(value) }}
2
Line Length
Maximum line width is 120 characters
// Good - within 120 character limitfunc processUserData(userId: UUID, name: String, email: String) { }// Bad - exceeds limit, should be wrappedfunc processUserDataWithVeryLongParameterNamesAndMultipleArgumentsThatMakeTheLineTooLongToRead(userId: UUID, userName: String) { }
3
Semicolons
Never use semicolons (they’re optional in Swift)
// Goodlet x = 10let y = 20// Badlet x = 10;let y = 20;
4
Self References
Remove explicit self unless required for disambiguation
class Example { var name: String // Good - self removed where not needed func updateName(_ newName: String) { name = newName } // Good - self required in closure func delayedUpdate(_ newName: String) { DispatchQueue.main.async { self.name = newName } }}
The project enables additional opt-in rules for stricter code quality:
Safety Rules
Best Practices
opt_in_rules: - force_unwrapping # Warn on force unwraps (!) - implicitly_unwrapped_optional # Warn on implicitly unwrapped optionals
These rules help prevent runtime crashes:
// Warning - force unwrappinglet value = optionalValue!// Preferred - safe unwrappingguard let value = optionalValue else { return }// Warning - implicitly unwrapped optionalvar unsafeValue: String!// Preferred - explicit optional handlingvar safeValue: String?
opt_in_rules: - empty_count # Use isEmpty instead of count == 0 - weak_delegate # Delegates should be weak
Examples:
// Good - use isEmptyif tabs.isEmpty { showEmptyState()}// Bad - comparing count to zeroif tabs.count == 0 { showEmptyState()}// Good - weak delegateweak var delegate: TabDelegate?// Bad - strong delegate (potential retain cycle)var delegate: TabDelegate?
The project defines custom rules for specific requirements:
custom_rules: no_print_statements: name: "No Print Statements" regex: "print\\(" message: "Use logger instead of print statements" severity: warning
Example from Tab.swift:224:
// Bad - using printprint("Tab title changed: \(title)")// Good - structured loggingdelegate.onTitleChange = { [weak self] title in DispatchQueue.main.async { if let title, !title.isEmpty { self?.title = title } }}
Prefer modern Swift and SwiftUI APIs when possible:
// Good - modern async/awaitTask { @MainActor in await downloadManager.startDownload(url: url)}// Avoid - older completion handler style (when async alternative exists)downloadManager.startDownload(url: url) { result in DispatchQueue.main.async { // handle result }}// Good - SwiftUI state management@Published var isLoading: Bool = false// Good - modern collection operationslet activeTabs = tabs.filter { $0.type == .normal }
if #available(macOS 15.0, *) { // Use macOS 15+ features window.backgroundColor = .systemBackground} else { // Fallback for older versions window.backgroundColor = .windowBackgroundColor}// Or for declarations@available(macOS 15.0, *)func useNewFeature() { // Implementation using macOS 15+ APIs}
Before raising minimum version: Open an issue to discuss the trade-offs. Backward compatibility should be preserved unless there’s a compelling reason to require a newer OS version.