From ea253b694877b882f541dc0ac0174b1ad6a0fdfb Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Tue, 27 Aug 2024 11:58:36 -0300 Subject: [PATCH] Fix ameba warnings and other fixable stuff due to new fixes on GICrystal. --- src/application_window.cr | 4 ++-- src/code_commenter.cr | 2 +- src/config.cr | 6 +++--- src/document_view.cr | 6 +++--- src/find_replace.cr | 4 ++-- src/git_branch_model.cr | 2 +- src/lame_regex_crystal_code_model.cr | 1 - src/lsp/server_capabilities.cr | 2 +- src/macros/license.cr | 6 +++--- src/project.cr | 2 +- src/text_view.cr | 14 +++++++------- src/view.cr | 2 +- src/view_manager.cr | 2 +- src/view_manager_split_node.cr | 1 + src/view_manager_view_node.cr | 2 +- src/welcome_widget.cr | 2 +- 16 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/application_window.cr b/src/application_window.cr index 44afa52..f13d765 100644 --- a/src/application_window.cr +++ b/src/application_window.cr @@ -270,7 +270,7 @@ class ApplicationWindow < Adw::ApplicationWindow if view.resource.nil? save_current_view_as - elsif !view.readonly? && view.modified + elsif !view.readonly? && view.modified? view.save else Log.info { "Skipping save for readonly and/or unmodified documents" } @@ -333,7 +333,7 @@ class ApplicationWindow < Adw::ApplicationWindow def show_open_file_dialog dialog = Gtk::FileDialog.new(initial_folder: Gio::File.new_for_path(@project.root.dirname)) - dialog.open(self, nil) do |obj, result| + dialog.open(self, nil) do |_, result| path = dialog.open_finish(result).try(&.path) open(path) if path rescue e : Gtk::DialogError::Dismissed diff --git a/src/code_commenter.cr b/src/code_commenter.cr index cd07841..fa0edff 100644 --- a/src/code_commenter.cr +++ b/src/code_commenter.cr @@ -56,7 +56,7 @@ module CodeCommenter private def uncomment_lines(iter : Gtk::TextIter, count : Int32) line_comment = language.line_comment - indent = find_text_indent(iter.copy, count) + find_text_indent(iter.copy, count) buffer.user_action do count.times do diff --git a/src/config.cr b/src/config.cr index 6309df7..548a2db 100644 --- a/src/config.cr +++ b/src/config.cr @@ -43,11 +43,11 @@ class Config # editor getter editor_font_size : Int32 - getter editor_insert_spaces_instead_of_tabs : Bool + getter? editor_insert_spaces_instead_of_tabs : Bool getter editor_tab_width : Int32 - getter editor_show_right_margin : Bool + getter? editor_show_right_margin : Bool getter editor_right_margin_position : Int32 - getter editor_highlight_current_line : Bool + getter? editor_highlight_current_line : Bool def self.instance @@instance ||= begin diff --git a/src/document_view.cr b/src/document_view.cr index dc1cf72..68bb388 100644 --- a/src/document_view.cr +++ b/src/document_view.cr @@ -5,11 +5,11 @@ abstract class DocumentView < View property project : Project? property? readonly = false @[GObject::Property] - property modified = false + property? modified = false @[GObject::Property] - property externally_modified = false + property? externally_modified = false @[GObject::Property] - property deleted = false + property? deleted = false @@untitled_count = 0 @resource_actions = [] of Gio::SimpleAction diff --git a/src/find_replace.cr b/src/find_replace.cr index f9595a2..d84d6b1 100644 --- a/src/find_replace.cr +++ b/src/find_replace.cr @@ -15,7 +15,7 @@ class FindReplace < Gtk::Box @offset_when_show : Int32 = 0 @[GObject::Property] - property active : Bool = false + property? active : Bool = false def initialize(@editor : CodeEditor) super() @@ -46,7 +46,7 @@ class FindReplace < Gtk::Box def find_prev @search_context.highlight = true - start, end_ = @buffer.selection_bounds + start, _ = @buffer.selection_bounds found, start, end_, _wrap = @search_context.backward(start) return unless found diff --git a/src/git_branch_model.cr b/src/git_branch_model.cr index 51cab9f..42cf326 100644 --- a/src/git_branch_model.cr +++ b/src/git_branch_model.cr @@ -27,7 +27,7 @@ class GitBranchModel < GObject::Object def menu_model=(menu_model : Gio::Menu) @menu_model = menu_model menu_model.remove_all - local_branches.each.with_index do |branch_name, index| + local_branches.each do |branch_name| variant = GLib::Variant.new(branch_name) menu_model.append(branch_name, "win.change_git_branch(#{variant})") end diff --git a/src/lame_regex_crystal_code_model.cr b/src/lame_regex_crystal_code_model.cr index 24dccd6..2497173 100644 --- a/src/lame_regex_crystal_code_model.cr +++ b/src/lame_regex_crystal_code_model.cr @@ -28,7 +28,6 @@ class LameRegexCrystalCodeModel < CodeModel private def scan_symbols(source : Path) : Array(CodeSymbol) symbols = [] of CodeSymbol line_number = -1 - is_spec = source =~ /_spec\...\z/ File.open(source).each_line do |line| line_number += 1 diff --git a/src/lsp/server_capabilities.cr b/src/lsp/server_capabilities.cr index 246d4ec..7eb4014 100644 --- a/src/lsp/server_capabilities.cr +++ b/src/lsp/server_capabilities.cr @@ -21,7 +21,7 @@ module LSP @[JSON::Field(key: "willSave")] getter? will_save : Bool = false @[JSON::Field(key: "willSaveWaitUntil")] - getter will_save_wait_until : Bool = false + getter? will_save_wait_until : Bool = false getter save : SaveOptions | Bool = false end diff --git a/src/macros/license.cr b/src/macros/license.cr index 3be30df..53c3762 100644 --- a/src/macros/license.cr +++ b/src/macros/license.cr @@ -9,15 +9,15 @@ def render_license(io : IO, title : String, license_file : Path | String) io << "\n\n" end -license = String.build do |s| +license = String.build do |str| if File.exists?("./LICENSE") title = Dir.current.split("/").last.capitalize - render_license(s, title, "./LICENSE") + render_license(str, title, "./LICENSE") end Dir.glob("./lib/*/LICENSE", "./lib/*/license").each do |path| title = path.match(/^\.\/lib\/([^\/]+)\//).try(&.[1]).to_s.capitalize - render_license(s, title, path) + render_license(str, title, path) end end diff --git a/src/project.cr b/src/project.cr index 7dde6d8..89bc55f 100644 --- a/src/project.cr +++ b/src/project.cr @@ -120,7 +120,7 @@ class Project < GObject::Object files.each do |file| @files.add?(file) end - directories.each { |f| @directories.add(f) } + directories.each { |directory| @directories.add(directory) } end end diff --git a/src/text_view.cr b/src/text_view.cr index 1397a56..bdcd627 100644 --- a/src/text_view.cr +++ b/src/text_view.cr @@ -91,10 +91,10 @@ class TextView < DocumentView @editor.wrap_mode = config.wrap_mode @editor.tab_width = is_make_file ? 4 : config.editor_tab_width - @editor.insert_spaces_instead_of_tabs = is_make_file ? false : config.editor_insert_spaces_instead_of_tabs - @editor.show_right_margin = config.editor_show_right_margin + @editor.insert_spaces_instead_of_tabs = is_make_file ? false : config.editor_insert_spaces_instead_of_tabs? + @editor.show_right_margin = config.editor_show_right_margin? @editor.right_margin_position = config.editor_right_margin_position - @editor.highlight_current_line = config.editor_highlight_current_line + @editor.highlight_current_line = config.editor_highlight_current_line? end # Line and col starts at zero in code, but at 1 in UI @@ -125,8 +125,8 @@ class TextView < DocumentView buffer.remove_trailing_spaces! saver = GtkSource::FileSaver.new(buffer: buffer, file: @source_file, flags: :ignore_modification_time) - saver.save_async(:default) do |obj, result| - v = saver.save_finish(result) + saver.save_async(:default) do |_, result| + saver.save_finish(result) buffer.modified = false self.externally_modified = false rescue ex @@ -141,8 +141,8 @@ class TextView < DocumentView saver = GtkSource::FileSaver.new_with_target(buffer: buffer, file: @source_file, target_location: Gio::File.new_for_path(resource.to_s)) saver.flags = :ignore_modification_time - saver.save_async(:default) do |obj, result| - v = saver.save_finish(result) + saver.save_async(:default) do |_, result| + saver.save_finish(result) buffer.modified = false self.externally_modified = false rescue ex diff --git a/src/view.cr b/src/view.cr index 5ef9f1f..75d03a5 100644 --- a/src/view.cr +++ b/src/view.cr @@ -39,7 +39,7 @@ abstract class View < Gtk::Box @[GObject::Virtual] def grab_focus : Bool - @contents.grab_focus + @contents.grab_focus end private def key_pressed(key_val : UInt32, key_code : UInt32, modifier : Gdk::ModifierType) : Bool diff --git a/src/view_manager.cr b/src/view_manager.cr index a00f60c..2a36930 100644 --- a/src/view_manager.cr +++ b/src/view_manager.cr @@ -330,7 +330,7 @@ class ViewManager < Gtk::Widget root.each_view_node do |node| @ordered_view_nodes << node end - @ordered_view_nodes.sort! { |a, b| b.last_used <=> a.last_used } + @ordered_view_nodes.sort! { |view_a, view_b| view_b.last_used <=> view_a.last_used } items_changed(0, old_size, @ordered_view_nodes.size) end diff --git a/src/view_manager_split_node.cr b/src/view_manager_split_node.cr index 8fe30b6..fb8d5e5 100644 --- a/src/view_manager_split_node.cr +++ b/src/view_manager_split_node.cr @@ -7,6 +7,7 @@ class ViewManagerSplitNode < ViewManagerNode end delegate index, to: @children + delegate index!, to: @children def child_count : Int32 @children.size diff --git a/src/view_manager_view_node.cr b/src/view_manager_view_node.cr index 4458f39..5be4a45 100644 --- a/src/view_manager_view_node.cr +++ b/src/view_manager_view_node.cr @@ -50,7 +50,7 @@ class ViewManagerViewNode < ViewManagerNode moved_view = remove_visible_view if old_parent && old_parent.orientation == orientation - idx = old_parent.index(self).not_nil! + idx = old_parent.index!(self) idx += 1 if position.end? new_node = ViewManagerViewNode.new(moved_view) old_parent.add_child(idx, new_node) diff --git a/src/welcome_widget.cr b/src/welcome_widget.cr index 8ebda4a..0a0ec06 100644 --- a/src/welcome_widget.cr +++ b/src/welcome_widget.cr @@ -181,7 +181,7 @@ class WelcomeWidget < Gtk::Box message = "Tijolo is meant to be used with git projects but no git projects were found under " \ "#{Path.home}. " \ "Create a git project somewhere and ask Tijolo to rescan projects." - dialog = Gtk::MessageDialog.ok(message_type: :info, + Gtk::MessageDialog.ok(message_type: :info, text: "No Git projects were found", secondary_text: message, secondary_use_markup: true, transient_for: ApplicationWindow.cast(root.not_nil!)) do end