From 1d0ef7631467ca7af4106bcd6383f786cbe2e325 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 1 Apr 2020 12:55:03 +0300 Subject: [PATCH 1/2] create code-quality-reports folder for cpd and unused; check if cpd is installed; run cpd for all targets --- xcode/build_phases/Unused.rb | 3 ++- xcode/build_phases/copy_paste_detection.sh | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/xcode/build_phases/Unused.rb b/xcode/build_phases/Unused.rb index 478a8d2..73c5db4 100644 --- a/xcode/build_phases/Unused.rb +++ b/xcode/build_phases/Unused.rb @@ -90,7 +90,8 @@ class Unused puts "Unused Code Warning!: warning: Total Count #{unused_warnings.length}" puts "#{unused_warnings.map { |e| e.to_xcode}.join("\n")}" # write log - File.open("UnusedLog.txt", "w") do |file| + Dir.mkdir(directory_name) unless File.exists?("code-quality-reports") + File.open("code-quality-reports/UnusedLog.txt", "w") do |file| file.write("Unused code warnings count: #{unused_warnings.length}\n\n") file.write("#{unused_warnings.map { |e| e.serialize }.join("\n")}") end diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index e647710..01398a7 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -1,6 +1,16 @@ -# running CPD -SOURCES_DIR=${1:-${EXECUTABLE_NAME}} # first argument or EXECUTABLE_NAME -pmd cpd --files ${SOURCES_DIR} --exclude ${EXECUTABLE_NAME}/Generated --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > cpd-output.xml --failOnViolation true +if which pmd >/dev/null; then + # running CPD + readonly SOURCES_DIR=${1:-${PROJECT_DIR}} # first argument or PROJECT_DIR + readonly REPORTS_DIR=${PROJECT_DIR}/code-quality-reports + readonly FILES_TO_EXCLUDE=`find ${SOURCES_DIR} -type d -name Localization -or -name Generated -or -name Pods | paste -sd " " -` -# running script -php ./build-scripts/xcode/aux_scripts/cpd_script.php -cpd-xml cpd-output.xml + mkdir ${REPORTS_DIR} + + pmd cpd --files ${SOURCES_DIR} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > ${REPORTS_DIR}/cpd-output.xml --failOnViolation true + + # running script + php ./build-scripts/xcode/aux_scripts/cpd_script.php -cpd-xml ${REPORTS_DIR}/cpd-output.xml | tee ${REPORTS_DIR}/CPDLog.txt +else + echo "warning: pmd not installed, install using 'brew install pmd'" + exit 1 +fi From 097dd43301561e307d3fb8287a6f4eff9128c265 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 1 Apr 2020 13:02:32 +0300 Subject: [PATCH 2/2] update line_length rule, so it ignores long urls --- xcode/.swiftlint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index 4cf4b27..0cddb78 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -75,7 +75,9 @@ excluded: - Generated - Localization -line_length: 128 +line_length: + warning: 128 + ignores_urls: true cyclomatic_complexity: ignores_case_statements: true