Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SwiftLint feature. #288

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/liftoffrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

test_target_name: UnitTests
configure_git: true
configure_swiftlint: true
warnings_as_errors: true
enable_static_analyzer: true
indentation_level: 4
Expand Down
1 change: 1 addition & 0 deletions lib/liftoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require "liftoff/dependency_managers/carthage"
require "liftoff/dependency_managers/cocoapods"
require "liftoff/dependency_managers/null_dependency_manager"
require 'liftoff/swiftlint_setup'
require 'liftoff/settings_generator'
require 'liftoff/configuration_parser'
require 'liftoff/deprecation_manager'
Expand Down
4 changes: 4 additions & 0 deletions lib/liftoff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def global_options
@options[:configure_git] = configure_git
end

opts.on('--[no-]swiftlint', 'Enable/Disable swiftlint') do |configure_swiftlint|
@options[:configure_swiftlint] = configure_swiftlint
end

opts.on('--no-open', "Don't open Xcode after generation") do
@options[:xcode_command] = false
end
Expand Down
12 changes: 12 additions & 0 deletions lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def perform_project_actions
perform_extra_config
save_project
generate_git
generate_swiftlint
end

def setup_dependency_managers
Expand All @@ -71,6 +72,13 @@ def generate_git
GitSetup.new(@config).setup
end

def generate_swiftlint
if @config.configure_swiftlint
swiftlint.setup
xcode_helper.add_script_phases(swiftlint.run_script_phases)
end
end

def set_indentation_level
xcode_helper.set_indentation_level(@config.indentation_level, @config.use_tabs)
end
Expand Down Expand Up @@ -118,6 +126,10 @@ def file_manager
@file_manager ||= FileManager.new
end

def swiftlint
@swiftlint ||= SwiftLintSetup.new(@config)
end

def dependency_manager_coordinator
@dependency_manager_coordinator ||=
DependencyManagerCoordinator.new(dependency_managers)
Expand Down
1 change: 1 addition & 0 deletions lib/liftoff/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ProjectConfiguration
:prefix,
:test_target_name,
:configure_git,
:configure_swiftlint,
:enable_settings,
:warnings_as_errors,
:enable_static_analyzer,
Expand Down
40 changes: 40 additions & 0 deletions lib/liftoff/swiftlint_setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Liftoff
class SwiftLintSetup
def initialize(config)
@config = config
end

def setup
if @config.configure_swiftlint
if swiftlint_installed?
generate_files
else
puts 'Please install Swiftlint or disable from liftoff'
end
end
end

def run_script_phases
[
{
"file" => "swiftlint.sh",
"name" => "Execute SwiftLint",
}
]
end

private

def generate_files
file_manager.generate('swiftlint', '.swiftlint.yml', @config)
end

def swiftlint_installed?
system('which swiftlint > /dev/null')
end

def file_manager
@file_manager ||= FileManager.new
end
end
end
5 changes: 5 additions & 0 deletions man/liftoff.1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.Op Fl -dependency-managers Ar NAMES
.Op Fl -[no-]cocoapods
.Op Fl -[no-]git
.Op Fl -[no-]swiftlint
.Op Fl -no-open
.Op Fl -[no-]settings
.Op Fl -template Ar TEMPLATE_NAME
Expand Down Expand Up @@ -52,6 +53,10 @@ enable or disable CocoaPods support
enable or disable
.Xr git 1
configuration
.It Fl -[no-]swiftlint
enable or disable
.Xr SwiftLint
configuration
.It Fl -no-open
Don't open Xcode after project generation
.It Fl -[no-]settings
Expand Down
13 changes: 13 additions & 0 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ Create
.Ic .gitignore ,
.Ic .gitattributes ,
and initialize git repo if needed.
.It Ic configure_swiftlint
type: boolean
.br
default:
.Ic true
.Pp
Imports the default template of swiftlint
and add script phases to perform the lint command
on build.
.It Ic warnings_as_errors
type: boolean
.br
Expand Down Expand Up @@ -484,6 +493,10 @@ meaning.
.Ic liftoff
installs a number of templates by default:
.Bl -tag -width 10
.It Pa swiftlint
This template is installed to
.Pa .swiftlint.yml
and contains a default lint rules to use with SwiftLint.
.It Pa travis.yml
This template is installed to
.Pa .travis.yml ,
Expand Down
18 changes: 18 additions & 0 deletions templates/swiftlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
disabled_rules: # rule identifiers to exclude from running
- line_length
- todo
- trailing_whitespace
- variable_name
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods

force_cast: warning # implicitly
force_try:
severity: warning # explicitly
variable_name:
min_length: # only min_length
warning: 3 # only warning
excluded: # excluded via string array
- id
- URL
5 changes: 5 additions & 0 deletions templates/swiftlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi