Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Closes #1430: Add linting support (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored Oct 17, 2018
1 parent f9fd5ad commit 25417b8
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
68 changes: 68 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
disabled_rules: # rule identifiers to exclude from running
- missing_docs
- valid_docs
- cyclomatic_complexity
- type_body_length
- function_parameter_count
- file_length
- mark
- unused_closure_parameter
- empty_parentheses_with_trailing_closure
- redundant_string_enum_value
- large_tuple
- class_delegate_protocol
- syntactic_sugar
- implicit_getter
- weak_delegate
- shorthand_operator
- unused_optional_binding
- empty_enum_arguments
- discarded_notification_center_observer
- block_based_kvo
- nesting
- is_disjoint
- multiple_closures_with_trailing_closure
- fallthrough
- switch_case_alignment
- legacy_cggeometry_functions
- closure_parameter_position
opt_in_rules: # some rules are only opt-in
- closing_brace
- opening_brace
- return_arrow_whitespace
- trailing_semicolon
- statement_position
- explicit_init
- shorthand_operator
- file_header
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- XCUITests/
- ClientTests/
- ScreenshotTests/
- Search/
- Client/Assets/Search/get_supported_locales.swift

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
trailing_semicolon: error
empty_count: error
closing_brace: error
opening_brace: error
return_arrow_whitespace: error
statement_position: error
colon: error
comma: error
force_try: warning
force_cast: warning


file_header:
required_string: "/* This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/. */"
line_length: 1000

reporter: "json" # reporter type (xcode, json, csv, checkstyle)
37 changes: 37 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# for debugging uncomment out these 2 lines
# require 'pry'
# binding.pry

# Run swiftlint
swiftlint.lint_files

# Localized Strings check
changedFiles = (git.added_files + git.modified_files).select{|file| file.end_with?(".swift")}
changedFiles.select{|file| file != "Blockzilla/UIConstants.swift" }.each do |changed_file|
addedLines = git.diff_for_file(changed_file).patch.lines.select{ |line| line.start_with?("+") }
if addedLines.select{ |line| line.include?("NSLocalizedString") }.count != 0
warn("NSLocalizedString should only be added to Strings.swift")
break # We only need to show the warning once
end
end

# Add a friendly reminder for Sentry
changedFiles.each do |changed_file|
addedLines = git.diff_for_file(changed_file).patch.lines.select{ |line| line.start_with?("+") }
if addedLines.select{ |line| line.include?("Sentry.shared.send") }.count != 0
markdown("### Sentry check list")
markdown("- [ ] I understand that only .fatal events will be reported on release")
markdown("- [ ] The message param contains a string that will not create multiple events")
break
end
end

# Warn if diff contains !try or as!
changedFiles.each do |changed_file|
# filter out only the lines that were added
addedLines = git.diff_for_file(changed_file).patch.lines.select{ |line| line.start_with?("+") }
warn("No new force try! or as!") if addedLines.select{ |line| (line.include?("as!") || line.include?("try!")) }.count != 0
end

# TODO: Limit the number of new lines added to BVC to less than 10
9 changes: 5 additions & 4 deletions buddybuild_prebuild.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bash

# Run linting
chruby 2.3.1
bundle install
bundle exec danger --fail-on-errors=false

#
# Add our Adjust keys to the build depending on the scheme. We use the sandbox for beta so
# that we have some insight in beta usage.
Expand Down Expand Up @@ -35,7 +40,3 @@ fi

# Set the build number to match the Buddybuild number
agvtool new-version -all "$BUDDYBUILD_BUILD_NUMBER"


# Set the build number to match the Buddybuild number
agvtool new-version -all "$BUDDYBUILD_BUILD_NUMBER"

0 comments on commit 25417b8

Please sign in to comment.