Skip to content

Commit

Permalink
Unify the lint steps from xcode and rake into a bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed Apr 9, 2018
1 parent 8946de5 commit db9ddd2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
28 changes: 28 additions & 0 deletions 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}"
12 changes: 6 additions & 6 deletions SwiftGen.xcodeproj/project.pbxproj
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 7 additions & 9 deletions rakelib/lint.rake
Expand Up @@ -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

0 comments on commit db9ddd2

Please sign in to comment.