Skip to content

Commit

Permalink
chore: update SwiftLint rules, remove SwftLint warnings, remove dead …
Browse files Browse the repository at this point in the history
…code (#143) (#195)

Closes #143

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Oct 14, 2024
1 parent 77e437d commit 4a3369f
Show file tree
Hide file tree
Showing 103 changed files with 614 additions and 322 deletions.
8 changes: 8 additions & 0 deletions .github/DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* [About release note](#about-release-note)
* [About changelog](#about-changelog)
- [Use of Gitleaks](#use-of-gitleaks)
- [Linter](#linter)
- [CI/CD](#cicd)

## Technical preconditions
Expand Down Expand Up @@ -463,6 +464,13 @@ Note that we face some issues about the use of _Gitleaks GitHub Action_ and _Git

Remember _Gitleaks_ is also used in GitHub project side thanks to the [dedicated GitHub Action](https://github.com/marketplace/actions/gitleaks) but these controls are done online once commits have left the local environment.

## Linter

We use _SwiftLint_ in this project so as to be sure the source code follows defined guidelines for the syntax and other points.
You must run _SwiftLint_ in CLI or using _Xcode_ to be sure you don't keep and submit warnings.
In most of cases you **must** fiw warnigns, but it could happen some of them should be disabled, mainly for tests cases.
Explain why in yout commtis and pull request comments you choose to disable them.

## CI/CD

We use GitLab CI for CI/CD with our own runners so as to keep private our sensitive files likes certificates and provisioning profiles.
Expand Down
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ _Note: Please transform `- [ ]` into `- (NA)` in the description when things are
#### Development

- [ ] My change follows the [developer guide](https://github.com/Orange-OpenSource/ouds-ios/blob/develop/.github/DEVELOP.md)
- [ ] I checked my changes do not add new SwiftLint warnings
- [ ] <!-- OPTIONAL --> I have added unit tests to cover my changes _(optional)_

#### Documentation
Expand Down
124 changes: 85 additions & 39 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#

# More details at https://realm.github.io/SwiftLint
# Online validator at https://www.yamllint.com/ (beware of data you copy/paste)


# ========
# Included
Expand All @@ -27,6 +27,7 @@ included:
# ========

excluded:
- Showcase/Showcase/Info.plist
- Showcase/Showcase/Resources
- Showcase/Pods
- Showcase/DerivedData
Expand All @@ -38,14 +39,23 @@ strict: true
# ==============

disabled_rules:
- attributes
- conditional_returns_on_newline
- explicit_enum_raw_value
- explicit_type_interface
- extension_access_modifier
- identifier_name
- file_name
- file_types_order
- multiline_arguments_brackets
- multiline_parameters_brackets
- opening_brace
- override_in_extension
- strong_iboutlet
- todo
- type_name
- type_contents_order
- valid_ibinspectable
- vertical_whitespace_between_cases
- vertical_whitespace_opening_braces

# =====================================
# Opt-in rules (not enabled by default)
Expand All @@ -56,32 +66,27 @@ opt_in_rules:
- accessibility_trait_for_button
- anyobject_protocol
- array_init
- attributes
- closure_body_length
- closure_end_indentation
- closure_spacing
- collection_alignment
- conditional_returns_on_newline
- contains_over_first_not_nil
- convenience_type:
severity: error
- convenience_type
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- empty_count
- empty_string
- empty_xctest_method
- explicit_enum_raw_value
- explicit_init
- explicit_self
- fallthrough
- fatal_error_message
- file_name
- file_types_order
- first_where
- force_unwrapping
- function_default_parameter_at_end
- identical_operands
- identifier_name
- implicit_return
- implicitly_unwrapped_optional
- joined_default_parameter
Expand All @@ -92,14 +97,10 @@ opt_in_rules:
- literal_expression_end_indentation
- missing_docs
- modifier_order
- multiline_arguments:
severity: error
- multiline_arguments_brackets
- multiline_function_chains:
severity: error
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- nimble_operator
- no_extension_access_modifier
- no_grouping_extension
Expand All @@ -110,8 +111,7 @@ opt_in_rules:
- operator_usage_whitespace
- overridden_super_call
- override_in_extension
- pattern_matching_keywords:
severity: error
- pattern_matching_keywords
- prefixed_toplevel_constant
- private_action
- prohibited_super_call
Expand All @@ -125,42 +125,40 @@ opt_in_rules:
- sorted_first_last
- sorted_imports
- static_operator
- strict_fileprivate:
severity: error
- strict_fileprivate
- strong_iboutlet
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar:
severity: error
- syntactic_sugar
- toggle_bool
- trailing_closure:
only_single_muted_parameter: true
- trailing_newline:
severity: error
- trailing_closure
- trailing_newline
- trailing_whitespace
- type_body_length
- type_contents_order
- type_name
- unavailable_function
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_import
- unused_optional_binding
- vertical_parameter_alignment:
severity: error
- vertical_parameter_alignment_on_call:
severity: error
- vertical_whitespace_between_cases
- vertical_parameter_alignment
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- weak_delegate:
severity: error
- weak_delegate
- yoda_condition

# ================================
# Other rules (enabled by default)
# ================================
# =============
# Rules details
# =============

closure_body_length:
warning: 50
error: 80

convenience_type:
severity: error

control_statement:
severity: error

Expand All @@ -187,15 +185,63 @@ function_parameter_count:
implicit_getter:
severity: error

identifier_name:
max_length:
warning: 60
error: 80
min_length:
warning: 1
allowed_symbols:
- _

large_tuple:
warning: 3
error: 4

line_length:
warning: 180
error: 200

multiline_arguments:
severity: error

multiline_function_chains:
severity: error

pattern_matching_keywords:
severity: error

strict_fileprivate:
severity: error

syntactic_sugar:
severity: error

trailing_comma:
mandatory_comma: true
mandatory_comma: true

trailing_closure:
only_single_muted_parameter: true

trailing_newline:
severity: error

type_body_length: 250

type_name:
max_length:
warning: 60
error: 80
min_length:
warning: 1
allowed_symbols:
- _

vertical_parameter_alignment:
severity: error

vertical_parameter_alignment_on_call:
severity: error

weak_delegate:
severity: error
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [Library/DemoApp] Updates SwiftLint rules, fix linter warnings ([#143](https://github.com/Orange-OpenSource/ouds-ios/issues/143))
- [Tool] Update the templates for GitHub issues
- [Tool] Improve script for documentation generation ([#168](https://github.com/Orange-OpenSource/ouds-ios/issues/168))
- [Library] Rename raw brand-specific color tokens in Orange theme (no use of "brand" word) ([#179](https://github.com/Orange-OpenSource/ouds-ios/issues/179))
Expand Down
3 changes: 1 addition & 2 deletions OUDS/Core/Components/Sources/Extensions/View+Shadows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ extension View {
/// - Parameter elevation: The token to give for the shadow / elevation effect
/// - Returns `View`: The current `View` with the shadow / elevation effect
public func shadow(elevation: ElevationCompositeRawToken) -> some View {
return self
.shadow(color: elevation.color.color,
self.shadow(color: elevation.color.color,
radius: elevation.radius,
x: CGFloat(elevation.x),
y: CGFloat(elevation.y))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import OUDSTokensComponent
import OUDSTokensRaw
import OUDSTokensSemantic

// TODO: Check if we can get rid of alias colors tokens which are optional
// swiftlint:disable force_unwrapping

/// Defines for `OUDSButton` the basic configuration which can be overriden in subthemes / subclasses of this theme.
/// **Warning: These are random and dumb values**
extension OUDSTheme: ButtonsComponentTokens {
Expand All @@ -35,3 +38,5 @@ extension OUDSTheme: ButtonsComponentTokens {

@objc open var buttonTypography: MultipleTypographyTokens { typeDisplayMedium }
}

// swiftlint:enable force_unwrapping

This file was deleted.

2 changes: 2 additions & 0 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ open class OUDSTheme {
self.customFontFamily = customFontFamily
}

deinit { }

// Please refer to extensions for properties, it will be more clear
}
3 changes: 2 additions & 1 deletion OUDS/Core/OUDS/Sources/OUDSTheme/OUDSThemeableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import SwiftUI

private struct ThemeContractEnvironmentKey: EnvironmentKey {

static let defaultValue: OUDSTheme = OUDSTheme()
static let defaultValue = OUDSTheme()
}

extension EnvironmentValues {

/// The `OUDSTheme` instance exposed as en environment values across the library
public var theme: OUDSTheme {
get {
self[ThemeContractEnvironmentKey.self]
Expand Down
22 changes: 11 additions & 11 deletions OUDS/Core/OUDS/Sources/_OUDS.docc/Themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ class OrangeCustomTheme: OrangeTheme { }

extension OrangeCustomTheme { // For FormsTextInputComponentTokens, used in component FormsTextInputComponent

public override var ftiTitleFontWeight: TypographyFontWeightSemanticToken { fontWeightLabelStrong }
public override var ftiTitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelXLarge }
public override var ftiTitleColor: ColorSemanticToken { ColorRawTokens.colorFunctionalDodgerBlue500 }
override public var ftiTitleFontWeight: TypographyFontWeightSemanticToken { fontWeightLabelStrong }
override public var ftiTitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelXLarge }
override public var ftiTitleColor: ColorSemanticToken { ColorRawTokens.colorFunctionalDodgerBlue500 }

public override var ftiSubtitleFontWeight: TypographyFontWeightSemanticToken { fontWeightBodyDefault }
public override var ftiSubtitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelMedium }
public override var ftiSubtitleColor: ColorSemanticToken { ColorRawTokens.colorFunctionalMalachite500 }
override public var ftiSubtitleFontWeight: TypographyFontWeightSemanticToken { fontWeightBodyDefault }
override public var ftiSubtitleFontSize: TypographyFontSizeSemanticToken { fontSizeLabelMedium }
override public var ftiSubtitleColor: ColorSemanticToken { ColorRawTokens.colorFunctionalMalachite500 }

public override var ftiBackgroundColorLight: ColorSemanticToken { colorBackgroundDefaultPrimaryLight }
public override var ftiBackgroundColorDark: ColorSemanticToken { colorBackgroundDefaultPrimaryDark }
override public var ftiBackgroundColorLight: ColorSemanticToken { colorBackgroundDefaultPrimaryLight }
override public var ftiBackgroundColorDark: ColorSemanticToken { colorBackgroundDefaultPrimaryDark }

public override var ftiBorderColor: ColorSemanticToken { colorBorderEmphasizedDark ?? MyThemeColorRawTokens.someAwesomeThemeExclusiveColor }
override public var ftiBorderColor: ColorSemanticToken { colorBorderEmphasizedDark ?? MyThemeColorRawTokens.someAwesomeThemeExclusiveColor }

public override var ftiBorderStyle: BorderStyleSemanticToken { borderStyleDrag }
override public var ftiBorderStyle: BorderStyleSemanticToken { borderStyleDrag }

public override var ftiBorderWidth: BorderWidthSemanticToken { borderWidthThick }
override public var ftiBorderWidth: BorderWidthSemanticToken { borderWidthThick }
}

extension OrangeCustomTheme { // For ColorSemanticTokens using anywhere
Expand Down
Loading

0 comments on commit 4a3369f

Please sign in to comment.