From b5eef9e3981383babdfdddbee7e9e2b206eb7502 Mon Sep 17 00:00:00 2001 From: digitalMoksha Date: Sun, 19 Jun 2022 10:03:21 -0500 Subject: [PATCH] Update gems and RubyMotion, add rubocop --- .gitignore | 2 + .rubocop.yml | 3 + .rubocop_todo.yml | 66 +++++++++++++++++++++ .ruby-version | 1 + Gemfile | 18 +++--- Gemfile.lock | 121 +++++++++++++++++---------------------- Rakefile | 14 +++-- app/app_delegate.rb | 4 +- app/destination_view.rb | 50 ++++++++-------- app/main_controller.rb | 10 ++-- app/main_layout.rb | 13 +++-- app/menu.rb | 9 ++- app/window_controller.rb | 4 +- app/window_layout.rb | 6 +- spec/main_spec.rb | 4 +- vendor/Podfile.lock | 3 - 16 files changed, 198 insertions(+), 130 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml create mode 100644 .ruby-version delete mode 100644 vendor/Podfile.lock diff --git a/.gitignore b/.gitignore index ad3e387..a8a475b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .repl_history build +build-log tags app/pixate_code.rb resources/*.nib @@ -12,6 +13,7 @@ nbproject #*# *~ *.sw[po] +.bundle .eprj .sass-cache .idea diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4c0486b --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,3 @@ +inherit_from: .rubocop_todo.yml + +require: rubocop-performance diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..165fb2d --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,66 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-06-19 15:04:54 UTC using RuboCop version 1.30.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 +# Configuration parameters: AllowComments, AllowNil. +Lint/SuppressedException: + Exclude: + - 'Rakefile' + +# Offense count: 3 +Lint/UselessAssignment: + Exclude: + - 'app/destination_view.rb' + +# Offense count: 4 +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 83 + +# Offense count: 3 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +Metrics/MethodLength: + Max: 74 + +# Offense count: 14 +# Configuration parameters: EnforcedStyle, AllowedPatterns, IgnoredPatterns. +# SupportedStyles: snake_case, camelCase +Naming/MethodName: + Exclude: + - 'app/app_delegate.rb' + - 'app/destination_view.rb' + - 'app/main_controller.rb' + - 'app/menu.rb' + +# Offense count: 7 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'app/destination_view.rb' + - 'app/menu.rb' + +# Offense count: 24 +# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - 'app/destination_view.rb' + - 'app/menu.rb' + +# Offense count: 5 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'app/main_controller.rb' + - 'app/main_layout.rb' + - 'app/menu.rb' + - 'app/window_controller.rb' + - 'app/window_layout.rb' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..a603bb5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.5 diff --git a/Gemfile b/Gemfile index ce18606..abcefaf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,19 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'rake' -# Add your dependencies here: -gem 'motion_print', '~> 1.2.0' -gem 'motion-cocoapods', '~> 1.8' -gem 'bubble-wrap', '~> 1.9' -gem 'sugarcube', '~> 3.4' gem 'motion-kit', '~> 1.1' +gem 'motion_print', '~> 1.2.0' +gem 'sugarcube', '~> 4.0' + +gem 'pry-byebug', '~> 3.9.0', platform: :mri +gem 'rubocop' +gem 'rubocop-performance' +gem 'rubocop-rake' +gem 'rubocop-rspec' group :spec do - gem 'bacon-expect' + gem 'bacon-expect', git: 'https://github.com/eamonn-webster/bacon-expect' end - diff --git a/Gemfile.lock b/Gemfile.lock index 04d087b..8698be7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,88 +1,69 @@ +GIT + remote: https://github.com/eamonn-webster/bacon-expect + revision: a54805ca2b8cdbcbb81a298fc3c1d4dff38d2a80 + specs: + bacon-expect (1.0.3) + GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.5) - activesupport (4.2.9) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - bacon-expect (1.0.3) - bubble-wrap (1.9.6) - claide (1.0.2) - cocoapods (1.3.1) - activesupport (>= 4.0.2, < 5) - claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.3.1) - cocoapods-deintegrate (>= 1.0.1, < 2.0) - cocoapods-downloader (>= 1.1.3, < 2.0) - cocoapods-plugins (>= 1.0.0, < 2.0) - cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.2.0, < 2.0) - cocoapods-try (>= 1.1.0, < 2.0) - colored2 (~> 3.1) - escape (~> 0.0.4) - fourflusher (~> 2.0.1) - gh_inspector (~> 1.0) - molinillo (~> 0.5.7) - nap (~> 1.0) - ruby-macho (~> 1.1) - xcodeproj (>= 1.5.1, < 2.0) - cocoapods-core (1.3.1) - activesupport (>= 4.0.2, < 6) - fuzzy_match (~> 2.0.4) - nap (~> 1.0) - cocoapods-deintegrate (1.0.1) - cocoapods-downloader (1.1.3) - cocoapods-plugins (1.0.0) - nap - cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.2.0) - nap (>= 0.8, < 2.0) - netrc (= 0.7.8) - cocoapods-try (1.1.0) - colored2 (3.1.2) + ast (2.4.2) + byebug (11.1.3) + coderay (1.1.3) dbt (1.2.0) - escape (0.0.4) - fourflusher (2.0.1) - fuzzy_match (2.0.4) - gh_inspector (1.0.3) - i18n (0.8.6) - minitest (5.10.3) - molinillo (0.5.7) - motion-cocoapods (1.9.0) - cocoapods (>= 1.0.0) + method_source (1.0.0) motion-kit (1.1.1) dbt (~> 1.1, >= 1.1.5) motion_print (1.2.0) - nanaimo (0.2.3) - nap (1.1.0) - netrc (0.7.8) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + rainbow (3.1.1) rake (12.0.0) - ruby-macho (1.1.0) - sugarcube (3.4.0) - thread_safe (0.3.6) - tzinfo (1.2.3) - thread_safe (~> 0.1) - xcodeproj (1.5.1) - CFPropertyList (~> 2.3.3) - claide (>= 1.0.2, < 2.0) - colored2 (~> 3.1) - nanaimo (~> 0.2.3) + regexp_parser (2.5.0) + rexml (3.2.5) + rubocop (1.30.1) + parallel (~> 1.10) + parser (>= 3.1.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.18.0) + parser (>= 3.1.1.0) + rubocop-performance (1.14.2) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) + ruby-progressbar (1.11.0) + sugarcube (4.0.0) + unicode-display_width (2.1.0) PLATFORMS ruby DEPENDENCIES - bacon-expect - bubble-wrap (~> 1.9) - motion-cocoapods (~> 1.8) + bacon-expect! motion-kit (~> 1.1) motion_print (~> 1.2.0) + pry-byebug (~> 3.9.0) rake - sugarcube (~> 3.4) + rubocop + rubocop-performance + rubocop-rake + rubocop-rspec + sugarcube (~> 4.0) BUNDLED WITH - 1.14.6 + 2.3.6 diff --git a/Rakefile b/Rakefile index 10db7b1..f1e9539 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,12 @@ -# -*- coding: utf-8 -*- -$:.unshift("/Library/RubyMotion/lib") +# frozen_string_literal: true + +$LOAD_PATH.unshift('/Library/RubyMotion/lib') +$LOAD_PATH.unshift('~/.rubymotion/rubymotion-templates') require 'motion/project/template/osx' begin require 'bundler' - Bundler.require + ARGV.join(' ').include?('spec') ? Bundler.require(:default, :spec) : Bundler.require rescue LoadError end @@ -15,8 +17,8 @@ Motion::Project::App.setup do |app| app.name = 'dragdrop-tester' app.identifier = 'com.digitalmoksha.dragdrop-tester' app.copyright = "Copyright © 2017 digitalMoksha LLC\nAll Rights Reserved" - app.short_version = '0.1' # CFBundleShortVersionString + app.short_version = '0.1' # CFBundleShortVersionString app.version = `git rev-list --all | wc -l`.strip.to_i.to_s # the build number - app.sdk_version = '10.12' - app.deployment_target = '10.10' + app.sdk_version = '12.3' + app.deployment_target = '10.14' end diff --git a/app/app_delegate.rb b/app/app_delegate.rb index 2c1756b..8cdc67a 100644 --- a/app/app_delegate.rb +++ b/app/app_delegate.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # App for testing different drag/drop scenarios and the information available. #------------------------------------------------------------------------------ class AppDelegate #------------------------------------------------------------------------------ - def applicationDidFinishLaunching(notification) + def applicationDidFinishLaunching(_notification) buildMenu buildWindow end diff --git a/app/destination_view.rb b/app/destination_view.rb index 50f2015..846f115 100644 --- a/app/destination_view.rb +++ b/app/destination_view.rb @@ -1,49 +1,51 @@ -# Parts based on the tutorial +# frozen_string_literal: true + +# Parts based on the tutorial # https://www.raywenderlich.com/136272/drag-and-drop-tutorial-for-macos #------------------------------------------------------------------------------ class DestinationView < NSView - attr_accessor :delegate - + #------------------------------------------------------------------------------ def initialize_dragging registerForDraggedTypes([KUTTypeItem]) - @isReceivingDrag = false + @isReceivingDrag = false end #------------------------------------------------------------------------------ - def shouldAllowDrag(draggingInfo) # NSDraggingInfo + # NSDraggingInfo + def shouldAllowDrag(draggingInfo) canAccept = false pasteBoard = draggingInfo.draggingPasteboard # if pasteBoard.canReadObjectForClasses([NSURL], options: {}) - canAccept = true + true # end - return canAccept end - + #------------------------------------------------------------------------------ - def draggingEntered(sender) # NSDraggingInfo -> NSDragOperation + # NSDraggingInfo -> NSDragOperation + def draggingEntered(sender) allow = shouldAllowDrag(sender) @isReceivingDrag = allow self.needsDisplay = true - return allow ? NSDragOperationGeneric : NSDragOperationNone + allow ? NSDragOperationGeneric : NSDragOperationNone end - + #------------------------------------------------------------------------------ - def draggingExited(sender) + def draggingExited(_sender) @isReceivingDrag = false self.needsDisplay = true end #------------------------------------------------------------------------------ - def draggingEnded(sender) + def draggingEnded(_sender) @isReceivingDrag = false self.needsDisplay = true end #------------------------------------------------------------------------------ def prepareForDragOperation(draggingInfo) - return shouldAllowDrag(draggingInfo) + shouldAllowDrag(draggingInfo) end #------------------------------------------------------------------------------ @@ -51,28 +53,28 @@ def performDragOperation(draggingInfo) @isReceivingDrag = false point = convertPoint(draggingInfo.draggingLocation, fromView: nil) - pasteboard = draggingInfo.draggingPasteboard + pasteboard = draggingInfo.draggingPasteboard - urls = pasteboard.readObjectsForClasses([NSURL, ], options: {}) - urls.each {|x| @delegate.log_msg x.isFileReferenceURL ? x.path : x.absoluteString} + urls = pasteboard.readObjectsForClasses([NSURL], options: {}) + urls.each { |x| @delegate.log_msg x.isFileReferenceURL ? x.path : x.absoluteString } pasteboard.types.each do |type| @delegate.log_msg " PB type: #{type}" @delegate.log_msg " properties: #{pasteboard.propertyListForType(type)}" end - @delegate.log_msg "------------------------------------------------------" - return true + @delegate.log_msg '------------------------------------------------------' + true end #------------------------------------------------------------------------------ - def concludeDragOperation(draggingInfo) - end + def concludeDragOperation(draggingInfo); end #------------------------------------------------------------------------------ - def drawRect(dirtyRect) # NSRect + # NSRect + def drawRect(_dirtyRect) @isReceivingDrag ? NSColor.selectedControlColor.set : NSColor.secondaryLabelColor.set - path = NSBezierPath.bezierPathWithRect(self.bounds) + path = NSBezierPath.bezierPathWithRect(bounds) path.lineWidth = 1 path.stroke end -end \ No newline at end of file +end diff --git a/app/main_controller.rb b/app/main_controller.rb index 5f15315..3bdef14 100644 --- a/app/main_controller.rb +++ b/app/main_controller.rb @@ -1,5 +1,6 @@ -class MainController < NSViewController +# frozen_string_literal: true +class MainController < NSViewController #------------------------------------------------------------------------------ def loadView @layout = MainLayout.new @@ -9,14 +10,13 @@ def loadView @destination_view.delegate = self @destination_view.initialize_dragging - @log_field = @layout.get(:log_field) + @log_field = @layout.get(:log_field) end #------------------------------------------------------------------------------ def log_msg(msg) @log_field.setSelectedRange(NSMakeRange(@log_field.string.length, 0)) @log_field.insertText("#{msg}\n") - @log_field.setSelectedRange(NSMakeRange(@log_field.string.length, 0)) + @log_field.setSelectedRange(NSMakeRange(@log_field.string.length, 0)) end - -end \ No newline at end of file +end diff --git a/app/main_layout.rb b/app/main_layout.rb index c452b1e..3f59093 100644 --- a/app/main_layout.rb +++ b/app/main_layout.rb @@ -1,5 +1,6 @@ -class MainLayout < MotionKit::Layout +# frozen_string_literal: true +class MainLayout < MotionKit::Layout VERTICAL_SPACE_BETWEEN_ITEMS = 25 SPACE_BETWEEN_LABEL_CONTROL = 10 MARGIN_LEFT = 25 @@ -17,7 +18,7 @@ def layout end end end - + #------------------------------------------------------------------------------ def root_style self.translatesAutoresizingMaskIntoConstraints = true @@ -66,11 +67,11 @@ def log_field_style # sets the left/right indent. This is better than the textContainerInset # because in this case the indent responds to the mouse drags - self.textContainer.lineFragmentPadding = 10 + textContainer.lineFragmentPadding = 10 self.textContainerInset = [0, TEXT_INSET] - self.enabledTextCheckingTypes = NSTextCheckingAllCustomTypes | NSTextCheckingTypeDate #NSTextCheckingTypeDash - self.font = NSFont.fontWithName('Source Code Pro', size: 13) || NSFont.userFixedPitchFontOfSize(13) + self.enabledTextCheckingTypes = NSTextCheckingAllCustomTypes | NSTextCheckingTypeDate # NSTextCheckingTypeDash + self.font = NSFont.fontWithName('Source Code Pro', + size: 13) || NSFont.userFixedPitchFontOfSize(13) end - end diff --git a/app/menu.rb b/app/menu.rb index d2ba968..8e696ee 100644 --- a/app/menu.rb +++ b/app/menu.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AppDelegate def buildMenu @mainMenu = NSMenu.new @@ -18,7 +20,8 @@ def buildMenu addItem(NSMenuItem.separatorItem) addItemWithTitle('Check Spelling While Typing', action: 'toggleContinuousSpellChecking:', keyEquivalent: '') addItemWithTitle('Check Grammar With Spelling', action: 'toggleGrammarChecking:', keyEquivalent: '') - addItemWithTitle('Correct Spelling Automatically', action: 'toggleAutomaticSpellingCorrection:', keyEquivalent: '') + addItemWithTitle('Correct Spelling Automatically', action: 'toggleAutomaticSpellingCorrection:', + keyEquivalent: '') end substitutions_menu = createMenu('Substitutions') do @@ -50,7 +53,7 @@ def buildMenu addItem(NSMenuItem.separatorItem) addItemWithTitle("Hide #{appName}", action: 'hide:', keyEquivalent: 'h') item = addItemWithTitle('Hide Others', action: 'hideOtherApplications:', keyEquivalent: 'H') - item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask + item.keyEquivalentModifierMask = NSCommandKeyMask | NSAlternateKeyMask addItemWithTitle('Show All', action: 'unhideAllApplications:', keyEquivalent: '') addItem(NSMenuItem.separatorItem) addItemWithTitle("Quit #{appName}", action: 'terminate:', keyEquivalent: 'q') @@ -64,7 +67,7 @@ def buildMenu addItemWithTitle('Copy', action: 'copy:', keyEquivalent: 'c') addItemWithTitle('Paste', action: 'paste:', keyEquivalent: 'v') item = addItemWithTitle('Paste and Match Style', action: 'pasteAsPlainText:', keyEquivalent: 'V') - item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask + item.keyEquivalentModifierMask = NSCommandKeyMask | NSAlternateKeyMask addItemWithTitle('Delete', action: 'delete:', keyEquivalent: '') addItemWithTitle('Select All', action: 'selectAll:', keyEquivalent: 'a') addItem(NSMenuItem.separatorItem) diff --git a/app/window_controller.rb b/app/window_controller.rb index 02ab0b8..cc465f4 100644 --- a/app/window_controller.rb +++ b/app/window_controller.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class WindowController < NSWindowController attr_accessor :main_controller - + #------------------------------------------------------------------------------ def init super.tap do diff --git a/app/window_layout.rb b/app/window_layout.rb index 9c412d5..0352aab 100644 --- a/app/window_layout.rb +++ b/app/window_layout.rb @@ -1,13 +1,13 @@ -class WindowLayout < MotionKit::WindowLayout +# frozen_string_literal: true +class WindowLayout < MotionKit::WindowLayout #------------------------------------------------------------------------------ def layout frame [[240, 180], [1000, 600]] - styleMask NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | + styleMask NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSFullSizeContentViewWindowMask self.movableByWindowBackground = true self.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary end - end diff --git a/spec/main_spec.rb b/spec/main_spec.rb index a8463eb..9b09f76 100644 --- a/spec/main_spec.rb +++ b/spec/main_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + describe "Application 'dragdrop-tester'" do before do @app = NSApplication.sharedApplication end - it "has one window" do + it 'has one window' do @app.windows.size.should == 1 end end diff --git a/vendor/Podfile.lock b/vendor/Podfile.lock deleted file mode 100644 index a7e5006..0000000 --- a/vendor/Podfile.lock +++ /dev/null @@ -1,3 +0,0 @@ -PODFILE CHECKSUM: f827fab77bf9b9d16d131a8d2d9b985e61144159 - -COCOAPODS: 1.3.1