From db9ddd2446092a2a3a94c2e539ac018c3e7ac40f Mon Sep 17 00:00:00 2001 From: David Jennes Date: Thu, 29 Mar 2018 13:43:32 +0200 Subject: [PATCH] Unify the lint steps from xcode and rake into a bash script --- Scripts/SwiftLint.sh | 28 ++++++++++++++++++++++++++++ SwiftGen.xcodeproj/project.pbxproj | 12 ++++++------ rakelib/lint.rake | 16 +++++++--------- 3 files changed, 41 insertions(+), 15 deletions(-) create mode 100755 Scripts/SwiftLint.sh diff --git a/Scripts/SwiftLint.sh b/Scripts/SwiftLint.sh new file mode 100755 index 000000000..824cc6fd8 --- /dev/null +++ b/Scripts/SwiftLint.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +SWIFTLINT="$(PWD)/Pods/SwiftLint/swiftlint" +CONFIG="$(PWD)/.swiftlint.yml" + +# possible paths +paths_swiftgen_sources="Sources/SwiftGen" +paths_swiftgen_tests="Tests/SwiftGenTests" +paths_swiftgenkit_sources="Sources/SwiftGenKit" +paths_swiftgenkit_tests="Tests/SwiftGenKitTests" +paths_templates_tests="Tests/TemplatesTests" +paths_templates_generated="Tests/Fixtures/Generated" + +# load selected group +if [ $# -gt 0 ]; then + key="$1" +else + echo "error: need group to lint." + exit 1 +fi + +selected_path=`eval echo '$'paths_$key` +if [ -z "$selected_path" ]; then + echo "error: need a valid group to lint." + exit 1 +fi + +"$SWIFTLINT" lint --strict --config "$CONFIG" --path "${PWD}/${selected_path}" diff --git a/SwiftGen.xcodeproj/project.pbxproj b/SwiftGen.xcodeproj/project.pbxproj index da75739ca..d522c5817 100644 --- a/SwiftGen.xcodeproj/project.pbxproj +++ b/SwiftGen.xcodeproj/project.pbxproj @@ -886,7 +886,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Sources/SwiftGen\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"swiftgen_sources\"\nfi"; }; 2C9D66D627FB898D3DA8D22E /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; @@ -1136,7 +1136,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Sources/SwiftGenKit\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"swiftgenkit_sources\"\nfi"; }; DD9F4766206ADC4C006B0DCA /* ⚠️ SwiftLint */ = { isa = PBXShellScriptBuildPhase; @@ -1150,7 +1150,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Tests/SwiftGenTests\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"swiftgen_tests\"\nfi"; }; DD9F4767206ADCB4006B0DCA /* ⚠️ SwiftLint */ = { isa = PBXShellScriptBuildPhase; @@ -1164,7 +1164,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Tests/SwiftGenKitTests\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"swiftgenkit_tests\"\nfi"; }; DD9F4768206ADCD0006B0DCA /* ⚠️ SwiftLint */ = { isa = PBXShellScriptBuildPhase; @@ -1178,7 +1178,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Tests/TemplatesTests\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"templates_tests\"\nfi"; }; DD9F4769206ADCD4006B0DCA /* ⚠️ SwiftLint (generated output) */ = { isa = PBXShellScriptBuildPhase; @@ -1192,7 +1192,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$PODS_ROOT/SwiftLint/swiftlint\" lint --strict --config \"${SRCROOT}/.swiftlint.yml\" --path \"${SRCROOT}/Tests/Fixtures/Generated\"\nfi"; + shellScript = "if [[ ! $CI && ! $NO_CODE_LINT ]]; then\n \"$SRCROOT/Scripts/SwiftLint.sh\" \"templates_generated\"\nfi"; }; FBB073641159892604C35D32 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/rakelib/lint.rake b/rakelib/lint.rake index f3542b008..88e87af17 100644 --- a/rakelib/lint.rake +++ b/rakelib/lint.rake @@ -2,30 +2,28 @@ # none namespace :lint do - SWIFTLINT = 'Pods/SwiftLint/swiftlint' + SWIFTLINT = 'Scripts/SwiftLint.sh' desc 'Lint the code' task :code do |task| Utils.print_header 'Linting the code' - config = Pathname.getwd + '.swiftlint.yml' - Utils.run(%(#{SWIFTLINT} lint --strict --path Sources --config "#{config}"), task) + Utils.run(%(#{SWIFTLINT} swiftgen_sources), task) + Utils.run(%(#{SWIFTLINT} swiftgenkit_sources), task) end desc 'Lint the tests' task :tests do |task| Utils.print_header 'Linting the unit test code' - config = Pathname.getwd + '.swiftlint.yml' - Dir.glob("Tests/*Tests").each { |folder| - Utils.run(%(#{SWIFTLINT} lint --strict --path "#{folder}" --config "#{config}"), task) - } + Utils.run(%(#{SWIFTLINT} swiftgen_tests), task) + Utils.run(%(#{SWIFTLINT} swiftgenkit_tests), task) + Utils.run(%(#{SWIFTLINT} templates_tests), task) end if File.directory?('Tests/Fixtures/Generated') desc 'Lint the output' task :output do |task| Utils.print_header 'Linting the template output code' - config = Pathname.getwd + '.swiftlint.yml' - Utils.run(%(#{SWIFTLINT} lint --strict --path Tests/Fixtures/Generated --config "#{config}"), task) + Utils.run(%(#{SWIFTLINT} templates_generated), task) end end end