From e3eee22e01e448a21844ae861791ef3f652a9e8d Mon Sep 17 00:00:00 2001 From: David Jennes Date: Thu, 24 Aug 2017 14:35:41 +0200 Subject: [PATCH 1/8] memoize the result of `version_select`, and allow us to change it from the Rakefile using a MIN_XCODE_VERSION constant --- common/rakelib/utils.rake | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index a3a3573..fdff59b 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -1,8 +1,9 @@ # Used constants: -# none +# - MIN_XCODE_VERSION require 'json' require 'octokit' +require 'pathname' class Utils COLUMN_WIDTH = 30 @@ -17,7 +18,7 @@ class Utils # run a command using xcrun and xcpretty if applicable def self.run(cmd, task, subtask = '', xcrun: false, formatter: :raw) commands = xcrun ? [*cmd].map { |cmd| - "#{version_select} xcrun #{cmd}" + "#{@@version_select} xcrun #{cmd}" } : [*cmd] case formatter @@ -122,18 +123,29 @@ class Utils # select the xcode version we want/support def self.version_select - version = '8.*' - xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '#{version}'"`.chomp.split("\n") - if xcodes.empty? - raise "\n[!!!] SwiftGen requires Xcode #{version}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" - end - - # Order by version and get the latest one - vers = lambda { |path| `mdls -name kMDItemVersion -raw "#{path}"` } - latest_xcode_version = xcodes.sort { |p1, p2| vers.call(p1) <=> vers.call(p2) }.last - %Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer") + @@version_select ||= compute_developer_dir(MIN_XCODE_VERSION) end private_class_method :version_select + + def self.compute_developer_dir(min_version) + # if current Xcode already fulfills min version don't force DEVELOPER_DIR=… + current_xcode = Pathname.new(`xcode-select -p`).parent.parent + current_xcode_version = `mdls -name kMDItemVersion -raw #{current_xcode}`.chomp + return "" if current_xcode_version.to_f >= min_version + + # Get all available Xcodes, order by version, get the latest one + xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"`.chomp.split("\n") + versions = xcodes.map { |path| { :vers => `mdls -name kMDItemVersion -raw "#{path}"`, :path => path } } + latest_xcode = versions.sort { |p1, p2| p1[:vers] <=> p2[:vers] }.last + + # Check if it's at least the right version + unless latest_xcode[:vers].to_f >= min_version + raise "\n[!!!] SwiftGen requires Xcode #{MIN_XCODE_VERSION}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" + end + + return %Q(DEVELOPER_DIR="#{latest_xcode[:path]}/Contents/Developer") + end + private_class_method :compute_developer_dir end class String From a2e321df700a59246dd0be1474638e2dc4260358 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Thu, 24 Aug 2017 15:59:03 +0200 Subject: [PATCH 2/8] rubocop --autocorrect --- common/rakelib/changelog.rake | 23 +++++----- common/rakelib/lint.rake | 32 +++++++------- common/rakelib/pod.rake | 2 +- common/rakelib/spm.rake | 2 +- common/rakelib/utils.rake | 83 +++++++++++++++++------------------ common/rakelib/xcode.rake | 4 +- 6 files changed, 74 insertions(+), 72 deletions(-) diff --git a/common/rakelib/changelog.rake b/common/rakelib/changelog.rake index 305dcaa..a4c1cc2 100644 --- a/common/rakelib/changelog.rake +++ b/common/rakelib/changelog.rake @@ -3,7 +3,7 @@ namespace :changelog do desc 'Add the empty CHANGELOG entries after a new release' - task :reset do |task| + task :reset do changelog = File.read('CHANGELOG.md') abort('A Master entry already exists') if changelog =~ /^##\s*Master$/ changelog.sub!(/^##[^#]/, "#{header}\\0") @@ -11,7 +11,7 @@ namespace :changelog do end def header - return <<-HEADER.gsub(/^\s*\|/,'') + <<-HEADER.gsub(/^\s*\|/, '') |## Master | |### Bug Fixes @@ -34,19 +34,22 @@ namespace :changelog do end desc 'Check if links to issues and PRs use matching numbers between text & link' - task :check do |task| + task :check do current_repo = File.basename(`git remote get-url origin`.chomp, '.git').freeze slug_re = '([a-zA-Z]*/[a-zA-Z]*)' links = %r{\[#{slug_re}?\#([0-9]+)\]\(https://github.com/#{slug_re}/(issues|pull)/([0-9]+)\)} all_wrong_links = [] File.readlines('CHANGELOG.md').each_with_index do |line, idx| wrong_links = line.scan(links) - .reject do |m| - (slug, num, url_slug, url_num) = [m[0] || "SwiftGen/#{current_repo}", m[1], m[2], m[4]] - (slug == url_slug) && (num == url_num) - end.map do |m| - " - Line #{idx+1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}" - end + .reject do |m| + slug = m[0] || "SwiftGen/#{current_repo}" + num = m[1] + url_slug = m[2] + url_num = m[4] + (slug == url_slug) && (num == url_num) + end.map do |m| + " - Line #{idx + 1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}" + end all_wrong_links.concat(wrong_links) end if all_wrong_links.empty? @@ -65,6 +68,6 @@ namespace :changelog do body = Utils.top_changelog_entry repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze - client.create_release("SwiftGen/#{repo_name}", tag, :body => body) + client.create_release("SwiftGen/#{repo_name}", tag, body: body) end end diff --git a/common/rakelib/lint.rake b/common/rakelib/lint.rake index 38bed21..bfca7d1 100644 --- a/common/rakelib/lint.rake +++ b/common/rakelib/lint.rake @@ -2,13 +2,13 @@ # - WORKSPACE namespace :lint do - SWIFTLINT_VERSION = '0.19.0' + SWIFTLINT_VERSION = '0.19.0'.freeze desc 'Install swiftlint' task :install do |task| - next if check_version() + next if check_version - if not system('tty >/dev/null') + unless system('tty >/dev/null') puts "warning: Unable to install SwiftLint #{SWIFTLINT_VERSION} without a terminal. Please run 'bundle exec rake lint:install' from a terminal." next end @@ -17,39 +17,39 @@ namespace :lint do tmppath = '/tmp/SwiftLint.pkg' Utils.run([ - "curl -Lo #{tmppath} #{url}", - "sudo installer -pkg #{tmppath} -target /" - ], task) + "curl -Lo #{tmppath} #{url}", + "sudo installer -pkg #{tmppath} -target /" + ], task) end - + if File.directory?('Sources') desc 'Lint the code' task :code => :install do |task| Utils.print_header 'Linting the code' - Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task) + Utils.run(%(swiftlint lint --no-cache --strict --path Sources), task) end end - + desc 'Lint the tests' task :tests => :install do |task| Utils.print_header 'Linting the unit test code' - Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/#{WORKSPACE}Tests"), task) + Utils.run(%(swiftlint lint --no-cache --strict --path "Tests/#{WORKSPACE}Tests"), task) end - + if File.directory?('Tests/Expected') desc 'Lint the output' task :output => :install do |task| Utils.print_header 'Linting the template output code' - Utils.run(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task) + Utils.run(%(swiftlint lint --no-cache --strict --path Tests/Expected), task) end end def check_version - return false if not system('which swiftlint > /dev/null') + return false unless system('which swiftlint > /dev/null') - current = `swiftlint version`.chomp.split('.').map { |e| e.to_i } - required = SWIFTLINT_VERSION.chomp.split('.').map { |e| e.to_i } + current = `swiftlint version`.chomp.split('.').map(&:to_i) + required = SWIFTLINT_VERSION.chomp.split('.').map(&:to_i) - return (current <=> required) >= 0 + (current <=> required) >= 0 end end diff --git a/common/rakelib/pod.rake b/common/rakelib/pod.rake index 9a9ecac..55c82b2 100644 --- a/common/rakelib/pod.rake +++ b/common/rakelib/pod.rake @@ -6,7 +6,7 @@ if defined?(POD_NAME) && File.file?("#{POD_NAME}.podspec") desc 'Lint the Pod' task :lint do |task| Utils.print_header 'Linting the pod spec' - Utils.run(%Q(bundle exec pod lib lint "#{POD_NAME}.podspec" --quick), task) + Utils.run(%(bundle exec pod lib lint "#{POD_NAME}.podspec" --quick), task) end end end diff --git a/common/rakelib/spm.rake b/common/rakelib/spm.rake index 1282cea..1462836 100644 --- a/common/rakelib/spm.rake +++ b/common/rakelib/spm.rake @@ -2,7 +2,7 @@ # none if File.file?('Package.swift') - namespace :spm do + namespace :spm do desc 'Build using SPM' task :build do |task| Utils.print_header 'Compile using SPM' diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index fdff59b..f017ac9 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -11,15 +11,15 @@ class Utils ## [ Run commands ] ######################################################### # formatter types - :xcpretty # pass through xcpretty and store in artifacts - :raw # store in artifacts - :to_string # run using backticks and return output + # :xcpretty : through xcpretty and store in artifacts + # :raw : store in artifacts + # :to_string : run using backticks and return output # run a command using xcrun and xcpretty if applicable def self.run(cmd, task, subtask = '', xcrun: false, formatter: :raw) - commands = xcrun ? [*cmd].map { |cmd| + commands = xcrun ? [*cmd].map do |cmd| "#{@@version_select} xcrun #{cmd}" - } : [*cmd] + end : [*cmd] case formatter when :xcpretty then xcpretty(commands, task, subtask) @@ -32,7 +32,7 @@ class Utils ## [ Convenience Helpers ] ################################################## def self.podspec_version(file = '*') - JSON.parse(`bundle exec pod ipc spec #{file}.podspec`)["version"] + JSON.parse(`bundle exec pod ipc spec #{file}.podspec`)['version'] end def self.podfile_lock_version(pod) @@ -46,7 +46,7 @@ class Utils token = File.exist?('.apitoken') && File.read('.apitoken') token ||= File.exist?('../.apitoken') && File.read('../.apitoken') Utils.print_error('No .apitoken file found') unless token - Octokit::Client.new(:access_token => token) + Octokit::Client.new(access_token: token) end def self.top_changelog_version(changelog_file = 'CHANGELOG.md') @@ -54,8 +54,8 @@ class Utils end def self.top_changelog_entry(changelog_file = 'CHANGELOG.md') - tag = self.top_changelog_version - `sed -n /'^## #{tag}$'/,/'^## '/p "#{changelog_file}"`.gsub(/^## .*$/,'').strip + tag = top_changelog_version + `sed -n /'^## #{tag}$'/,/'^## '/p "#{changelog_file}"`.gsub(/^## .*$/, '').strip end ## [ Print info/errors ] #################################################### @@ -90,12 +90,11 @@ class Utils result end - ## [ Private helper functions ] ################################################## # run a command, pipe output through 'xcpretty' and store the output in CI artifacts def self.xcpretty(cmd, task, subtask) - name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") + name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, '_') command = [*cmd].join(' && ') if ENV['CI'] @@ -110,7 +109,7 @@ class Utils # run a command and store the output in CI artifacts def self.plain(cmd, task, subtask) - name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") + name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, '_') command = [*cmd].join(' && ') if ENV['CI'] @@ -128,22 +127,22 @@ class Utils private_class_method :version_select def self.compute_developer_dir(min_version) - # if current Xcode already fulfills min version don't force DEVELOPER_DIR=… + # if current Xcode already fulfills min version don't force DEVELOPER_DIR=... current_xcode = Pathname.new(`xcode-select -p`).parent.parent current_xcode_version = `mdls -name kMDItemVersion -raw #{current_xcode}`.chomp - return "" if current_xcode_version.to_f >= min_version - + return '' if current_xcode_version.to_f >= min_version + # Get all available Xcodes, order by version, get the latest one xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"`.chomp.split("\n") - versions = xcodes.map { |path| { :vers => `mdls -name kMDItemVersion -raw "#{path}"`, :path => path } } - latest_xcode = versions.sort { |p1, p2| p1[:vers] <=> p2[:vers] }.last + versions = xcodes.map { |path| { vers: `mdls -name kMDItemVersion -raw "#{path}"`, path: path } } + latest_xcode = versions.sort_by { |a| a[:vers] }.last # Check if it's at least the right version unless latest_xcode[:vers].to_f >= min_version raise "\n[!!!] SwiftGen requires Xcode #{MIN_XCODE_VERSION}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" end - return %Q(DEVELOPER_DIR="#{latest_xcode[:path]}/Contents/Developer") + %(DEVELOPER_DIR="#{latest_xcode[:path]}/Contents/Developer") end private_class_method :compute_developer_dir end @@ -152,37 +151,37 @@ class String # colorization FORMATTING = { # text styling - :bold => 1, - :faint => 2, - :italic => 3, - :underline => 4, + bold: 1, + faint: 2, + italic: 3, + underline: 4, # foreground colors - :black => 30, - :red => 31, - :green => 32, - :yellow => 33, - :blue => 34, - :magenta => 35, - :cyan => 36, - :white => 37, + black: 30, + red: 31, + green: 32, + yellow: 33, + blue: 34, + magenta: 35, + cyan: 36, + white: 37, # background colors - :bg_black => 40, - :bg_red => 41, - :bg_green => 42, - :bg_yellow => 43, - :bg_blue => 44, - :bg_magenta => 45, - :bg_cyan => 46, - :bg_white => 47 - } + bg_black: 40, + bg_red: 41, + bg_green: 42, + bg_yellow: 43, + bg_blue: 44, + bg_magenta: 45, + bg_cyan: 46, + bg_white: 47 + }.freeze # only enable formatting if terminal supports it if `tput colors`.chomp.to_i >= 8 - def format(*styles) - styles.reduce("") { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m" + def format(*styles) + styles.reduce('') { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m" end else - def format(*styles) + def format(*_styles) self end end diff --git a/common/rakelib/xcode.rake b/common/rakelib/xcode.rake index c66f4c1..5ff7245 100644 --- a/common/rakelib/xcode.rake +++ b/common/rakelib/xcode.rake @@ -7,12 +7,12 @@ namespace :xcode do desc 'Build using Xcode' task :build do |task| Utils.print_header 'Compile using Xcode' - Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, formatter: :xcpretty) + Utils.run(%(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, formatter: :xcpretty) end desc 'Run Xcode Unit Tests' task :test => :build do |task| Utils.print_header 'Run the unit tests using Xcode' - Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty) + Utils.run(%(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty) end end From b5e71de37d5aba698f3254c8b13b9956db798204 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 11:43:36 +0200 Subject: [PATCH 3/8] Fix Rakefile: quoting Xcode path --- common/rakelib/changelog.rake | 5 +---- common/rakelib/utils.rake | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/common/rakelib/changelog.rake b/common/rakelib/changelog.rake index a4c1cc2..f12d615 100644 --- a/common/rakelib/changelog.rake +++ b/common/rakelib/changelog.rake @@ -43,10 +43,7 @@ namespace :changelog do wrong_links = line.scan(links) .reject do |m| slug = m[0] || "SwiftGen/#{current_repo}" - num = m[1] - url_slug = m[2] - url_num = m[4] - (slug == url_slug) && (num == url_num) + (slug == m[2]) && (m[1] == m[4]) end.map do |m| " - Line #{idx + 1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}" end diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index f017ac9..f1bd6a0 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -129,7 +129,7 @@ class Utils def self.compute_developer_dir(min_version) # if current Xcode already fulfills min version don't force DEVELOPER_DIR=... current_xcode = Pathname.new(`xcode-select -p`).parent.parent - current_xcode_version = `mdls -name kMDItemVersion -raw #{current_xcode}`.chomp + current_xcode_version = `mdls -name kMDItemVersion -raw "#{current_xcode}"`.chomp return '' if current_xcode_version.to_f >= min_version # Get all available Xcodes, order by version, get the latest one From d9da312503715bcaacb3b6957b49939458de6f6d Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 12:14:51 +0200 Subject: [PATCH 4/8] Add rubocop in Gemfile + initial .rubocop.yml, then autocorrect --- .rubocop.yml | 130 +++++++++++++++++++++++++++++++++++++++++++ Gemfile | 6 +- Gemfile.lock | 17 ++++++ Rakefile | 54 +++++++++--------- common/Gemfile | 5 +- rakelib/labels.rake | 18 +++--- rakelib/subrepo.rake | 12 ++-- rakelib/sync.rake | 12 ++-- rakelib/utils.rake | 18 +++--- 9 files changed, 211 insertions(+), 61 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4208f5f --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,130 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-08-27 12:06:39 +0200 using RuboCop version 0.49.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/DeprecatedClassMethods: + Exclude: + - 'Rakefile' + +# Offense count: 5 +Lint/ScriptPermission: + Exclude: + - 'StencilSwiftKit/Rakefile' + - 'SwiftGen/Resources/Rakefile' + - 'SwiftGenKit/Rakefile' + - 'SwiftGenKit/Tests/Resources/Rakefile' + - 'templates/Rakefile' + +# Offense count: 7 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'StencilSwiftKit/rakelib/utils.rake' + - 'SwiftGen/Resources/rakelib/utils.rake' + - 'SwiftGen/rakelib/utils.rake' + - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' + - 'SwiftGenKit/rakelib/utils.rake' + - 'common/rakelib/utils.rake' + - 'templates/rakelib/utils.rake' + +# Offense count: 6 +Lint/Void: + Exclude: + - 'SwiftGen/Resources/rakelib/utils.rake' + - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' + +# Offense count: 10 +Metrics/AbcSize: + Max: 24 + +# Offense count: 25 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 105 + +# Offense count: 1 +Metrics/CyclomaticComplexity: + Max: 7 + +# Offense count: 239 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 236 + +# Offense count: 4 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 26 + +# Offense count: 3 +Metrics/PerceivedComplexity: + Max: 8 + +# Offense count: 12 +# Cop supports --auto-correct. +Performance/RedundantMatch: + Exclude: + - 'SwiftGen/Resources/Rakefile' + - 'SwiftGenKit/Tests/Resources/Rakefile' + - 'templates/Rakefile' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: + Exclude: + - 'rakelib/labels.rake' + +# Offense count: 5 +Style/ClassVars: + Exclude: + - 'StencilSwiftKit/rakelib/utils.rake' + - 'SwiftGen/rakelib/utils.rake' + - 'SwiftGenKit/rakelib/utils.rake' + - 'common/rakelib/utils.rake' + - 'templates/rakelib/utils.rake' + + +# Offense count: 16 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'StencilSwiftKit/rakelib/utils.rake' + - 'SwiftGen/Resources/rakelib/utils.rake' + - 'SwiftGen/rakelib/utils.rake' + - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' + - 'SwiftGenKit/rakelib/utils.rake' + - 'common/rakelib/utils.rake' + - 'rakelib/utils.rake' + - 'templates/rakelib/utils.rake' + +# Offense count: 40 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'Rakefile' + - 'common/rakelib/lint.rake' + - 'common/rakelib/spm.rake' + - 'common/rakelib/xcode.rake' + - 'rakelib/labels.rake' + - 'rakelib/sync.rake' + - 'rakelib/utils.rake' diff --git a/Gemfile b/Gemfile index a823565..b6832b2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,10 @@ # frozen_string_literal: true + source 'https://rubygems.org' gem 'cocoapods', '1.3.1' -gem 'xcpretty' -gem 'rake' gem 'octokit', '~> 4.7' gem 'plist', '~> 3.2' +gem 'rake' +gem 'rubocop' +gem 'xcpretty' diff --git a/Gemfile.lock b/Gemfile.lock index 318417c..4276933 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ GEM tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) + ast (2.3.0) claide (1.0.2) cocoapods (1.3.1) activesupport (>= 4.0.2, < 5) @@ -59,17 +60,32 @@ GEM netrc (0.7.8) octokit (4.7.0) sawyer (~> 0.8.0, >= 0.5.3) + parallel (1.11.2) + parser (2.4.0.0) + ast (~> 2.2) plist (3.3.0) + powerpack (0.1.1) public_suffix (2.0.5) + rainbow (2.2.2) + rake rake (12.0.0) rouge (2.0.7) + rubocop (0.49.1) + parallel (~> 1.10) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) ruby-macho (1.1.0) + ruby-progressbar (1.8.1) sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) faraday (~> 0.8, < 1.0) thread_safe (0.3.6) tzinfo (1.2.3) thread_safe (~> 0.1) + unicode-display_width (1.2.1) xcodeproj (1.5.1) CFPropertyList (~> 2.3.3) claide (>= 1.0.2, < 2.0) @@ -86,6 +102,7 @@ DEPENDENCIES octokit (~> 4.7) plist (~> 3.2) rake + rubocop xcpretty BUNDLED WITH diff --git a/Rakefile b/Rakefile index cca67e5..686ff17 100755 --- a/Rakefile +++ b/Rakefile @@ -6,15 +6,15 @@ require 'uri' require 'plist' namespace :repos do - REPOS = [:StencilSwiftKit, :SwiftGenKit, :SwiftGen, :templates].freeze + REPOS = %i[StencilSwiftKit SwiftGenKit SwiftGen templates].freeze desc 'Bootstrap this repository for development' task :bootstrap do REPOS.each do |repository| - next if Dir.exists? "#{repository}" + next if Dir.exists? repository.to_s sh "git clone git@github.com:SwiftGen/#{repository}.git --recursive" - Dir.chdir("#{repository}") do - sh "git submodule update --init --recursive" + Dir.chdir(repository.to_s) do + sh 'git submodule update --init --recursive' end end end @@ -46,7 +46,7 @@ end namespace :submodules do def submodules(cmd) - [:SwiftGenKit, :SwiftGen].each do |repository| + %i[SwiftGenKit SwiftGen].each do |repository| Utils.print_header repository.to_s Dir.chdir(repository.to_s) do sh(cmd) @@ -62,8 +62,8 @@ namespace :submodules do desc 'Show status for submodules of each repo' task :status do Utils.print_header "Current 'templates' commit" - Dir.chdir('templates') { sh "git describe --all && git describe --always" } - submodules("git submodule status") + Dir.chdir('templates') { sh 'git describe --all && git describe --always' } + submodules('git submodule status') end end @@ -79,7 +79,7 @@ namespace :release do # Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early) `which bundler` - results << Utils.table_result( $?.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.') + results << Utils.table_result($CHILD_STATUS.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.') # Extract version from SwiftGen.podspec version = Utils.podspec_version('SwiftGen') @@ -89,32 +89,32 @@ namespace :release do check_dep_versions = lambda do |pod| lock_version = Utils.podfile_lock_version(pod) pod_version = Utils.podspec_version(pod) - results << Utils.table_result(lock_version == pod_version, "#{pod.ljust(Utils::COLUMN_WIDTH-10)} (#{pod_version})", "Please update #{pod} to latest version in your Podfile") + results << Utils.table_result(lock_version == pod_version, "#{pod.ljust(Utils::COLUMN_WIDTH - 10)} (#{pod_version})", "Please update #{pod} to latest version in your Podfile") end check_dep_versions.call('SwiftGenKit') check_dep_versions.call('StencilSwiftKit') # Check if version matches the Info.plist - results << Utils.table_result(version == Utils.plist_version, "Info.plist version matches", "Please update the version numbers in the Info.plist file") + results << Utils.table_result(version == Utils.plist_version, 'Info.plist version matches', 'Please update the version numbers in the Info.plist file') # Check if submodule is aligned submodule_aligned = Dir.chdir('SwiftGen/Resources') do - sh "git fetch origin >/dev/null" + sh 'git fetch origin >/dev/null' `git rev-parse origin/master`.chomp == `git rev-parse HEAD`.chomp end - results << Utils.table_result(submodule_aligned, "Submodule on origin/master", "Please align the submodule to master") + results << Utils.table_result(submodule_aligned, 'Submodule on origin/master', 'Please align the submodule to master') # Check if entry present in CHANGELOG - changelog_entry = system(%Q{grep -q '^## #{Regexp.quote(version)}$' SwiftGen/CHANGELOG.md}) - results << Utils.table_result(changelog_entry, "CHANGELOG, Entry added", "Please add an entry for #{version} in CHANGELOG.md") + changelog_entry = system("grep -q '^## #{Regexp.quote(version)}$' SwiftGen/CHANGELOG.md") + results << Utils.table_result(changelog_entry, 'CHANGELOG, Entry added', "Please add an entry for #{version} in CHANGELOG.md") - changelog_master = system(%q{grep -qi '^## Master' SwiftGen/CHANGELOG.md}) - results << Utils.table_result(!changelog_master, "CHANGELOG, No master", 'Please remove entry for master in CHANGELOG') + changelog_master = system("grep -qi '^## Master' SwiftGen/CHANGELOG.md") + results << Utils.table_result(!changelog_master, 'CHANGELOG, No master', 'Please remove entry for master in CHANGELOG') exit 1 unless results.all? print "Release version #{version} [Y/n]? " - exit 2 unless (STDIN.gets.chomp == 'Y') + exit 2 unless STDIN.gets.chomp == 'Y' end desc 'Create a zip containing all the prebuilt binaries' @@ -125,7 +125,7 @@ namespace :release do def post(url, content_type) uri = URI.parse(url) - req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => content_type}) + req = Net::HTTP::Post.new(uri, initheader = { 'Content-Type' => content_type }) yield req if block_given? req.basic_auth 'AliSoftware', File.read('.apitoken').chomp @@ -144,7 +144,7 @@ namespace :release do task :github => :zip do v = Utils.podspec_version - changelog = `sed -n /'^## #{v}$'/,/'^## '/p SwiftGen/CHANGELOG.md`.gsub(/^## .*$/,'').strip + changelog = `sed -n /'^## #{v}$'/,/'^## '/p SwiftGen/CHANGELOG.md`.gsub(/^## .*$/, '').strip Utils.print_header "Releasing version #{v} on GitHub" puts changelog @@ -152,7 +152,7 @@ namespace :release do req.body = { :tag_name => v, :name => v, :body => changelog, :draft => false, :prerelease => false }.to_json end - upload_url = json['upload_url'].gsub(/\{.*\}/,"?name=swiftgen-#{v}.zip") + upload_url = json['upload_url'].gsub(/\{.*\}/, "?name=swiftgen-#{v}.zip") zipfile = "SwiftGen/build/swiftgen-#{v}.zip" zipsize = File.size(zipfile) @@ -166,7 +166,7 @@ namespace :release do desc 'pod trunk push SwiftGen to CocoaPods' task :cocoapods do - Utils.print_header "Pushing pod to CocoaPods Trunk" + Utils.print_header 'Pushing pod to CocoaPods Trunk' Dir.chdir('SwiftGen') do sh 'bundle exec pod trunk push SwiftGen.podspec' end @@ -174,7 +174,7 @@ namespace :release do desc 'Release a new version on Homebrew and prepare a PR' task :homebrew do - Utils.print_header "Updating Homebrew Formula" + Utils.print_header 'Updating Homebrew Formula' tag = Utils.podspec_version revision = Dir.chdir('SwiftGen') { `git rev-list -1 #{tag}`.chomp } formulas_dir = Bundler.with_clean_env { `brew --repository homebrew/core`.chomp } @@ -187,17 +187,17 @@ namespace :release do formula = File.read(formula_file) new_formula = formula - .gsub(%r(:tag => ".*"), %Q(:tag => "#{tag}")) - .gsub(%r(:revision => ".*"), %Q(:revision => "#{revision}")) + .gsub(/:tag => ".*"/, %Q(:tag => "#{tag}")) + .gsub(/:revision => ".*"/, %Q(:revision => "#{revision}")) File.write(formula_file, new_formula) - Utils.print_header "Checking Homebrew formula..." + Utils.print_header 'Checking Homebrew formula...' Bundler.with_clean_env do sh 'brew audit --strict --online swiftgen' sh 'brew upgrade swiftgen' sh 'brew test swiftgen' end - Utils.print_header "Pushing to Homebrew" + Utils.print_header 'Pushing to Homebrew' sh "git add #{formula_file}" sh "git commit -m 'swiftgen #{tag}'" sh "git push -u AliSoftware swiftgen-#{tag}" @@ -206,4 +206,4 @@ namespace :release do end end -task :default => "release:new" +task :default => 'release:new' diff --git a/common/Gemfile b/common/Gemfile index 13d8ba2..14033cb 100644 --- a/common/Gemfile +++ b/common/Gemfile @@ -1,7 +1,8 @@ # frozen_string_literal: true + source 'https://rubygems.org' gem 'cocoapods', '1.3.1' -gem 'xcpretty' -gem 'rake' gem 'octokit', '~> 4.7' +gem 'rake' +gem 'xcpretty' diff --git a/rakelib/labels.rake b/rakelib/labels.rake index e6acbdb..119973e 100644 --- a/rakelib/labels.rake +++ b/rakelib/labels.rake @@ -2,18 +2,18 @@ require 'octokit' namespace :sync do desc 'Synchronize the github issue labels for all repositories' - task :labels, [:repo_slug, :dry_run] do |task, args| + task :labels, %i[repo_slug dry_run] do |_task, args| args.with_defaults(:dry_run => 'false') repo_slug = args[:repo_slug] dry_run = args[:dry_run].to_bool unless repo_slug - puts "[!] A repo slug is required" - puts "Usage: rake labels:sync[User/RepoName,true|false]" + puts '[!] A repo slug is required' + puts 'Usage: rake labels:sync[User/RepoName,true|false]' exit 2 end - + begin token = File.read('github_access_token') rescue @@ -38,13 +38,13 @@ namespace :sync do 'type: enhancement' => '84b6eb', 'type: internal' => 'f9d0c4', 'type: question' => 'cc317c', - 'change: breaking' => 'b60205', + 'change: breaking' => 'b60205' }.freeze missing_labels = LABELS.keys.dup extra_labels = [] - puts "Retrieving existing labels…" + puts 'Retrieving existing labels…' labels = client.labels(repo_slug) # Update existing labels @@ -69,12 +69,12 @@ namespace :sync do client.add_label(repo_slug, label_name, LABELS[label_name]) unless dry_run end - puts "Done." + puts 'Done.' # List unexpected labels unless extra_labels.empty? - puts "Extra labels found:" + puts 'Extra labels found:' puts extra_labels.map { |label| " - #{label.name}" }.join("\n") end end -end \ No newline at end of file +end diff --git a/rakelib/subrepo.rake b/rakelib/subrepo.rake index d5b8427..aeb8f55 100644 --- a/rakelib/subrepo.rake +++ b/rakelib/subrepo.rake @@ -1,22 +1,22 @@ namespace :swiftgen do desc 'Run tests on SwiftGen repo' task :tests do - Dir.chdir("SwiftGen") do - sh "rake xcode:test" + Dir.chdir('SwiftGen') do + sh 'rake xcode:test' end end desc 'Clean the build on SwiftGen repo' task :clean do - Dir.chdir("SwiftGen") do - sh "rake cli:clean" + Dir.chdir('SwiftGen') do + sh 'rake cli:clean' end end desc 'Run the install task SwiftGen repo' task :install do - Dir.chdir("SwiftGen") do - sh "rake cli:install" + Dir.chdir('SwiftGen') do + sh 'rake cli:install' end end end diff --git a/rakelib/sync.rake b/rakelib/sync.rake index d1a59a2..c4201c8 100644 --- a/rakelib/sync.rake +++ b/rakelib/sync.rake @@ -1,30 +1,30 @@ namespace :sync do - REPOSITORIES = [:StencilSwiftKit, :SwiftGenKit, :SwiftGen, :templates] + REPOSITORIES = %i[StencilSwiftKit SwiftGenKit SwiftGen templates].freeze desc 'Synchronize all files across repositories' - task :all_files => [:rakelib, :gitignore, :license] + task :all_files => %i[rakelib gitignore license] - task :gems do |task| + task :gems do |_task| REPOSITORIES.each do |repository| FileUtils.cp('common/Gemfile', "#{repository}/") FileUtils.cp('common/Gemfile.lock', "#{repository}/") end end - task :rakelib => :gems do |task| + task :rakelib => :gems do |_task| REPOSITORIES.each do |repository| FileUtils.rm_rf("#{repository}/rakelib") FileUtils.cp_r('common/rakelib', "#{repository}/") end end - task :gitignore do |task| + task :gitignore do |_task| REPOSITORIES.each do |repository| FileUtils.cp('common/gitignore', "#{repository}/.gitignore") end end - task :license do |task| + task :license do |_task| REPOSITORIES.each do |repository| FileUtils.cp('LICENSE', "#{repository}/") end diff --git a/rakelib/utils.rake b/rakelib/utils.rake index b2c2e2a..1aee3eb 100644 --- a/rakelib/utils.rake +++ b/rakelib/utils.rake @@ -4,7 +4,7 @@ class Utils COLUMN_WIDTH = 30 def self.podspec_version(pod = 'SwiftGen') - JSON.parse(`bundle exec pod ipc spec #{pod}/#{pod}.podspec`)["version"] + JSON.parse(`bundle exec pod ipc spec #{pod}/#{pod}.podspec`)['version'] end def self.podfile_lock_version(pod) @@ -15,7 +15,7 @@ class Utils end def self.plist_version - Plist::parse_xml('SwiftGen/Sources/Info.plist')['CFBundleVersion'] + Plist.parse_xml('SwiftGen/Sources/Info.plist')['CFBundleVersion'] end # print a header @@ -51,9 +51,9 @@ end class String def to_bool - return true if self =~ (/^(true|t|yes|y|1)$/i) - return false if self.empty? || self =~ (/^(false|f|no|n|0)$/i) - raise ArgumentError.new "invalid value: #{self}" + return true if self =~ /^(true|t|yes|y|1)$/i + return false if empty? || self =~ /^(false|f|no|n|0)$/i + raise ArgumentError, "invalid value: #{self}" end # colorization @@ -81,15 +81,15 @@ class String :bg_magenta => 45, :bg_cyan => 46, :bg_white => 47 - } + }.freeze # only enable formatting if terminal supports it if `tput colors`.chomp.to_i >= 8 - def format(*styles) - styles.reduce("") { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m" + def format(*styles) + styles.reduce('') { |r, s| r << "\e[#{FORMATTING[s]}m" } << "#{self}\e[0m" end else - def format(*styles) + def format(*_styles) self end end From f77d5c95df7fe265f30355264f9b4516620f43a6 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 13:56:17 +0200 Subject: [PATCH 5/8] Fixing more rubocop violations --- .rubocop.yml | 86 +++-------------------------------- Rakefile | 8 ++-- common/rakelib/changelog.rake | 11 ++--- common/rakelib/utils.rake | 17 ++++--- rakelib/labels.rake | 2 +- rakelib/utils.rake | 4 ++ 6 files changed, 31 insertions(+), 97 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4208f5f..1d243fa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,38 +6,12 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Cop supports --auto-correct. -Lint/DeprecatedClassMethods: - Exclude: - - 'Rakefile' - -# Offense count: 5 -Lint/ScriptPermission: - Exclude: - - 'StencilSwiftKit/Rakefile' - - 'SwiftGen/Resources/Rakefile' - - 'SwiftGenKit/Rakefile' - - 'SwiftGenKit/Tests/Resources/Rakefile' - - 'templates/Rakefile' - -# Offense count: 7 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'StencilSwiftKit/rakelib/utils.rake' - - 'SwiftGen/Resources/rakelib/utils.rake' - - 'SwiftGen/rakelib/utils.rake' - - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' - - 'SwiftGenKit/rakelib/utils.rake' - - 'common/rakelib/utils.rake' - - 'templates/rakelib/utils.rake' - -# Offense count: 6 -Lint/Void: +AllCops: Exclude: - - 'SwiftGen/Resources/rakelib/utils.rake' - - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' + - SwiftGen/**/* + - SwiftGenKit/**/* + - StencilSwiftKit/**/* + - templates/**/* # Offense count: 10 Metrics/AbcSize: @@ -67,64 +41,16 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 8 -# Offense count: 12 -# Cop supports --auto-correct. -Performance/RedundantMatch: - Exclude: - - 'SwiftGen/Resources/Rakefile' - - 'SwiftGenKit/Tests/Resources/Rakefile' - - 'templates/Rakefile' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Exclude: - - 'Rakefile' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'rakelib/labels.rake' - -# Offense count: 5 -Style/ClassVars: - Exclude: - - 'StencilSwiftKit/rakelib/utils.rake' - - 'SwiftGen/rakelib/utils.rake' - - 'SwiftGenKit/rakelib/utils.rake' - - 'common/rakelib/utils.rake' - - 'templates/rakelib/utils.rake' - # Offense count: 16 Style/Documentation: Exclude: - 'spec/**/*' - 'test/**/*' - - 'StencilSwiftKit/rakelib/utils.rake' - - 'SwiftGen/Resources/rakelib/utils.rake' - - 'SwiftGen/rakelib/utils.rake' - - 'SwiftGenKit/Tests/Resources/rakelib/utils.rake' - - 'SwiftGenKit/rakelib/utils.rake' - - 'common/rakelib/utils.rake' - - 'rakelib/utils.rake' - - 'templates/rakelib/utils.rake' # Offense count: 40 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: - Exclude: - - 'Rakefile' - - 'common/rakelib/lint.rake' - - 'common/rakelib/spm.rake' - - 'common/rakelib/xcode.rake' - - 'rakelib/labels.rake' - - 'rakelib/sync.rake' - - 'rakelib/utils.rake' + Enabled: false diff --git a/Rakefile b/Rakefile index 686ff17..b1d87b8 100755 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ namespace :repos do desc 'Bootstrap this repository for development' task :bootstrap do REPOS.each do |repository| - next if Dir.exists? repository.to_s + next if Dir.exist? repository.to_s sh "git clone git@github.com:SwiftGen/#{repository}.git --recursive" Dir.chdir(repository.to_s) do @@ -125,7 +125,7 @@ namespace :release do def post(url, content_type) uri = URI.parse(url) - req = Net::HTTP::Post.new(uri, initheader = { 'Content-Type' => content_type }) + req = Net::HTTP::Post.new(uri, initheader: { 'Content-Type' => content_type }) yield req if block_given? req.basic_auth 'AliSoftware', File.read('.apitoken').chomp @@ -187,8 +187,8 @@ namespace :release do formula = File.read(formula_file) new_formula = formula - .gsub(/:tag => ".*"/, %Q(:tag => "#{tag}")) - .gsub(/:revision => ".*"/, %Q(:revision => "#{revision}")) + .gsub(/:tag => ".*"/, %(:tag => "#{tag}")) + .gsub(/:revision => ".*"/, %(:revision => "#{revision}")) File.write(formula_file, new_formula) Utils.print_header 'Checking Homebrew formula...' Bundler.with_clean_env do diff --git a/common/rakelib/changelog.rake b/common/rakelib/changelog.rake index f12d615..356d7ee 100644 --- a/common/rakelib/changelog.rake +++ b/common/rakelib/changelog.rake @@ -40,14 +40,13 @@ namespace :changelog do links = %r{\[#{slug_re}?\#([0-9]+)\]\(https://github.com/#{slug_re}/(issues|pull)/([0-9]+)\)} all_wrong_links = [] File.readlines('CHANGELOG.md').each_with_index do |line, idx| - wrong_links = line.scan(links) - .reject do |m| - slug = m[0] || "SwiftGen/#{current_repo}" - (slug == m[2]) && (m[1] == m[4]) - end.map do |m| + wrong_links = line.scan(links).reject do |m| + slug = m[0] || "SwiftGen/#{current_repo}" + (slug == m[2]) && (m[1] == m[4]) + end + all_wrong_links.concat wrong_links.map do |m| " - Line #{idx + 1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}" end - all_wrong_links.concat(wrong_links) end if all_wrong_links.empty? puts "\u{2705} All links correct" diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index f1bd6a0..a86ae37 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -5,6 +5,8 @@ require 'json' require 'octokit' require 'pathname' +# Utility functions to run Xcode commands, extract versionning info and logs messages +# class Utils COLUMN_WIDTH = 30 @@ -16,11 +18,12 @@ class Utils # :to_string : run using backticks and return output # run a command using xcrun and xcpretty if applicable - def self.run(cmd, task, subtask = '', xcrun: false, formatter: :raw) - commands = xcrun ? [*cmd].map do |cmd| - "#{@@version_select} xcrun #{cmd}" - end : [*cmd] - + def self.run(command, task, subtask = '', xcrun: false, formatter: :raw) + commands = if xcrun + [*command].map { |cmd| "#{version_select} xcrun #{cmd}" } + else + [*command] + end case formatter when :xcpretty then xcpretty(commands, task, subtask) when :raw then plain(commands, task, subtask) @@ -122,7 +125,7 @@ class Utils # select the xcode version we want/support def self.version_select - @@version_select ||= compute_developer_dir(MIN_XCODE_VERSION) + @@version_select ||= compute_developer_dir(MIN_XCODE_VERSION) # rubocop:disable Style/ClassVars end private_class_method :version_select @@ -147,6 +150,8 @@ class Utils private_class_method :compute_developer_dir end +# Colorization support for Strings +# class String # colorization FORMATTING = { diff --git a/rakelib/labels.rake b/rakelib/labels.rake index 119973e..136d7e2 100644 --- a/rakelib/labels.rake +++ b/rakelib/labels.rake @@ -58,7 +58,7 @@ namespace :sync do puts " 👍 `#{label.name}`" else puts " 🎨 `#{label.name}` (#{label.color} => #{color})" - client.update_label(repo_slug, label.name, { :color => color }) unless dry_run + client.update_label(repo_slug, label.name, :color => color) unless dry_run end end end diff --git a/rakelib/utils.rake b/rakelib/utils.rake index 1aee3eb..faa8ede 100644 --- a/rakelib/utils.rake +++ b/rakelib/utils.rake @@ -1,5 +1,7 @@ require 'json' +# Utility functions to extract versionning info and logs messages +# class Utils COLUMN_WIDTH = 30 @@ -49,6 +51,8 @@ class Utils end end +# Colorization support for Strings +# class String def to_bool return true if self =~ /^(true|t|yes|y|1)$/i From c0ca5f29b4a02c29cc0c87b97d649326708e5d16 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 14:50:38 +0200 Subject: [PATCH 6/8] Fix last rubocop warnings --- .rubocop.yml | 47 +++++---------------------------------- Rakefile | 36 +++++++++++++++++++++++++----- common/rakelib/lint.rake | 3 ++- common/rakelib/utils.rake | 6 +++-- common/rakelib/xcode.rake | 14 ++++++++++-- 5 files changed, 54 insertions(+), 52 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1d243fa..0a8d644 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,3 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2017-08-27 12:06:39 +0200 using RuboCop version 0.49.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - AllCops: Exclude: - SwiftGen/**/* @@ -13,44 +5,17 @@ AllCops: - StencilSwiftKit/**/* - templates/**/* -# Offense count: 10 +Style/HashSyntax: + Enabled: false + Metrics/AbcSize: Max: 24 -# Offense count: 25 -# Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: - Max: 105 - -# Offense count: 1 -Metrics/CyclomaticComplexity: - Max: 7 + Enabled: false -# Offense count: 239 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https Metrics/LineLength: - Max: 236 + Max: 140 -# Offense count: 4 -# Configuration parameters: CountComments. Metrics/MethodLength: - Max: 26 - -# Offense count: 3 -Metrics/PerceivedComplexity: - Max: 8 - - -# Offense count: 16 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - -# Offense count: 40 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Enabled: false + Max: 20 diff --git a/Rakefile b/Rakefile index b1d87b8..d60b8fe 100755 --- a/Rakefile +++ b/Rakefile @@ -79,7 +79,11 @@ namespace :release do # Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early) `which bundler` - results << Utils.table_result($CHILD_STATUS.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.') + results << Utils.table_result( + $CHILD_STATUS.success?, + 'Bundler installed', + 'Please install bundler using `gem install bundler` and run `bundle install` first.' + ) # Extract version from SwiftGen.podspec version = Utils.podspec_version('SwiftGen') @@ -89,27 +93,47 @@ namespace :release do check_dep_versions = lambda do |pod| lock_version = Utils.podfile_lock_version(pod) pod_version = Utils.podspec_version(pod) - results << Utils.table_result(lock_version == pod_version, "#{pod.ljust(Utils::COLUMN_WIDTH - 10)} (#{pod_version})", "Please update #{pod} to latest version in your Podfile") + results << Utils.table_result( + lock_version == pod_version, + "#{pod.ljust(Utils::COLUMN_WIDTH - 10)} (#{pod_version})", + "Please update #{pod} to latest version in your Podfile" + ) end check_dep_versions.call('SwiftGenKit') check_dep_versions.call('StencilSwiftKit') # Check if version matches the Info.plist - results << Utils.table_result(version == Utils.plist_version, 'Info.plist version matches', 'Please update the version numbers in the Info.plist file') + results << Utils.table_result( + version == Utils.plist_version, + 'Info.plist version matches', + 'Please update the version numbers in the Info.plist file' + ) # Check if submodule is aligned submodule_aligned = Dir.chdir('SwiftGen/Resources') do sh 'git fetch origin >/dev/null' `git rev-parse origin/master`.chomp == `git rev-parse HEAD`.chomp end - results << Utils.table_result(submodule_aligned, 'Submodule on origin/master', 'Please align the submodule to master') + results << Utils.table_result( + submodule_aligned, + 'Submodule on origin/master', + 'Please align the submodule to master' + ) # Check if entry present in CHANGELOG changelog_entry = system("grep -q '^## #{Regexp.quote(version)}$' SwiftGen/CHANGELOG.md") - results << Utils.table_result(changelog_entry, 'CHANGELOG, Entry added', "Please add an entry for #{version} in CHANGELOG.md") + results << Utils.table_result( + changelog_entry, + 'CHANGELOG, Entry added', + "Please add an entry for #{version} in CHANGELOG.md" + ) changelog_master = system("grep -qi '^## Master' SwiftGen/CHANGELOG.md") - results << Utils.table_result(!changelog_master, 'CHANGELOG, No master', 'Please remove entry for master in CHANGELOG') + results << Utils.table_result( + !changelog_master, + 'CHANGELOG, No master', + 'Please remove entry for master in CHANGELOG' + ) exit 1 unless results.all? diff --git a/common/rakelib/lint.rake b/common/rakelib/lint.rake index bfca7d1..f12e10d 100644 --- a/common/rakelib/lint.rake +++ b/common/rakelib/lint.rake @@ -9,7 +9,8 @@ namespace :lint do next if check_version unless system('tty >/dev/null') - puts "warning: Unable to install SwiftLint #{SWIFTLINT_VERSION} without a terminal. Please run 'bundle exec rake lint:install' from a terminal." + puts "warning: Unable to install SwiftLint #{SWIFTLINT_VERSION} without a terminal." \ + "Please run 'bundle exec rake lint:install' from a terminal." next end diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index a86ae37..e3a2704 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -101,7 +101,8 @@ class Utils command = [*cmd].join(' && ') if ENV['CI'] - Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | bundle exec xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\"" + Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | " \ + "bundle exec xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\"" elsif system('which xcpretty > /dev/null') Rake.sh "set -o pipefail && (#{command}) | bundle exec xcpretty -c" else @@ -142,7 +143,8 @@ class Utils # Check if it's at least the right version unless latest_xcode[:vers].to_f >= min_version - raise "\n[!!!] SwiftGen requires Xcode #{MIN_XCODE_VERSION}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" + raise "\n[!!!] SwiftGen requires Xcode #{MIN_XCODE_VERSION}, but we were not able to find it. " \ + "If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" end %(DEVELOPER_DIR="#{latest_xcode[:path]}/Contents/Developer") diff --git a/common/rakelib/xcode.rake b/common/rakelib/xcode.rake index 5ff7245..057b46c 100644 --- a/common/rakelib/xcode.rake +++ b/common/rakelib/xcode.rake @@ -7,12 +7,22 @@ namespace :xcode do desc 'Build using Xcode' task :build do |task| Utils.print_header 'Compile using Xcode' - Utils.run(%(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, formatter: :xcpretty) + Utils.run( + %(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), + task, + xcrun: true, + formatter: :xcpretty + ) end desc 'Run Xcode Unit Tests' task :test => :build do |task| Utils.print_header 'Run the unit tests using Xcode' - Utils.run(%(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty) + Utils.run( + %(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}" test-without-building), + task, + xcrun: true, + formatter: :xcpretty + ) end end From 5c9e673d24a08c64dccbd91642d896aeb916a9e1 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 15:33:38 +0200 Subject: [PATCH 7/8] Generalize rubocop.yml to submodules --- .rubocop.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0a8d644..f8eb3b6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,3 @@ -AllCops: - Exclude: - - SwiftGen/**/* - - SwiftGenKit/**/* - - StencilSwiftKit/**/* - - templates/**/* Style/HashSyntax: Enabled: false From 4b016cd8ba2fbc1fc377d51c83d5919717392609 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 27 Aug 2017 18:05:34 +0200 Subject: [PATCH 8/8] Last rubocop warnings --- .rubocop.yml | 5 +++++ common/rakelib/utils.rake | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index f8eb3b6..dc96878 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,8 @@ +AllCops: + TargetRubyVersion: 2.0 + Exclude: + - SwiftGenKit/Tests/Resources/**/* + - SwiftGen/Resources/**/* Style/HashSyntax: Enabled: false diff --git a/common/rakelib/utils.rake b/common/rakelib/utils.rake index e3a2704..ea0161f 100644 --- a/common/rakelib/utils.rake +++ b/common/rakelib/utils.rake @@ -134,7 +134,7 @@ class Utils # if current Xcode already fulfills min version don't force DEVELOPER_DIR=... current_xcode = Pathname.new(`xcode-select -p`).parent.parent current_xcode_version = `mdls -name kMDItemVersion -raw "#{current_xcode}"`.chomp - return '' if current_xcode_version.to_f >= min_version + return '' if current_xcode_version.to_f >= min_version.to_f # Get all available Xcodes, order by version, get the latest one xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"`.chomp.split("\n")