Skip to content

Commit 27360ff

Browse files
Merge pull request #19036 from opf/code-maintenance/text-formatting-rubocop
Freeze string literals, other Rubocop fixes for `OpenProject::TextFormatting` module
2 parents 8e467f4 + 3c37eef commit 27360ff

40 files changed

+110
-34
lines changed

lib/open_project/text_formatting/filters/attachment_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/autolink_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/bem_css_filter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -82,7 +84,7 @@ def add_css_class(element, css_class)
8284
if element["class"].present?
8385
# Avoid using element['class'].include?(css_class) as css_class can be a substring
8486
# of an existing class
85-
element["class"] += " #{css_class}" unless element["class"].split.any? { |existing_class| existing_class == css_class }
87+
element["class"] += " #{css_class}" unless element["class"].split.any?(css_class)
8688
else
8789
element["class"] = css_class
8890
end

lib/open_project/text_formatting/filters/figure_wrapped_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/link_attribute_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/macro_filter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -37,7 +39,7 @@ def self.register(*macros)
3739
macros.each { |macro| registered << macro }
3840
end
3941

40-
def call
42+
def call # rubocop:disable Metrics/AbcSize
4143
doc.search("macro").each do |macro|
4244
registered.each do |macro_class|
4345
next unless macro_applies?(macro_class, macro)
@@ -81,7 +83,7 @@ def macro_placeholder(macro_class)
8183
end
8284

8385
def macro_applies?(macro_class, element)
84-
((element["class"] || "").split & Array(macro_class.identifier)).any?
86+
(element["class"] || "").split.intersect?(Array(macro_class.identifier))
8587
end
8688
end
8789
end

lib/open_project/text_formatting/filters/macros/child_pages.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -28,7 +30,7 @@
2830

2931
module OpenProject::TextFormatting::Filters::Macros
3032
module ChildPages
31-
HTML_CLASS = "child_pages".freeze
33+
HTML_CLASS = "child_pages"
3234

3335
module_function
3436

lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/macros/create_work_package_link.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -32,7 +34,7 @@ class << self
3234
include OpenProject::StaticRouting::UrlHelpers
3335
end
3436

35-
HTML_CLASS = "create_work_package_link".freeze
37+
HTML_CLASS = "create_work_package_link"
3638

3739
module_function
3840

@@ -44,7 +46,7 @@ def apply(macro, result:, context:)
4446
macro.replace work_package_link(macro, context)
4547
end
4648

47-
def work_package_link(macro, context)
49+
def work_package_link(macro, context) # rubocop:disable Metrics/AbcSize
4850
project = context[:project]
4951
raise I18n.t("macros.create_work_package_link.errors.no_project_context") if project.nil?
5052

lib/open_project/text_formatting/filters/macros/embedded_table.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -28,8 +30,8 @@
2830

2931
module OpenProject::TextFormatting::Filters::Macros
3032
module EmbeddedTable
31-
CUSTOM_ELEMENT = "opce-macro-embedded-table".freeze
32-
HTML_CLASS = "embedded-table".freeze
33+
CUSTOM_ELEMENT = "opce-macro-embedded-table"
34+
HTML_CLASS = "embedded-table"
3335

3436
module_function
3537

lib/open_project/text_formatting/filters/macros/github_pull_request.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -28,8 +30,8 @@
2830

2931
module OpenProject::TextFormatting::Filters::Macros
3032
module GithubPullRequest
31-
CUSTOM_ELEMENT = "opce-github-pull-request".freeze
32-
HTML_CLASS = "github_pull_request".freeze
33+
CUSTOM_ELEMENT = "opce-github-pull-request"
34+
HTML_CLASS = "github_pull_request"
3335

3436
module_function
3537

lib/open_project/text_formatting/filters/macros/include_wiki_page.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -28,7 +30,7 @@
2830

2931
module OpenProject::TextFormatting::Filters::Macros
3032
module IncludeWikiPage
31-
HTML_CLASS = "include_wiki_page".freeze
33+
HTML_CLASS = "include_wiki_page"
3234

3335
module_function
3436

lib/open_project/text_formatting/filters/macros/toc.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -28,7 +30,7 @@
2830

2931
module OpenProject::TextFormatting::Filters::Macros
3032
module Toc
31-
HTML_CLASS = "toc".freeze
33+
HTML_CLASS = "toc"
3234

3335
module_function
3436

lib/open_project/text_formatting/filters/markdown_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/mention_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/pattern_matcher_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/plain_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/relative_link_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/syntax_highlight_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/filters/table_of_contents_filter.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -66,7 +68,7 @@ def get_unique_id(text)
6668
# that prefix is used if it matches the calculated number.
6769
def process_item(node, number)
6870
text = node.text
69-
return "".html_safe unless text.present?
71+
return "".html_safe if text.blank?
7072

7173
id = get_unique_id(text)
7274
add_header_link_class_and_id(node, id)
@@ -80,13 +82,13 @@ def get_heading_number(parent_number, num_in_level)
8082
parent_number == "" ? num_in_level.to_s : "#{parent_number}.#{num_in_level}"
8183
end
8284

83-
def render_nested(level = 0, parent_number = "")
85+
def render_nested(level = 0, parent_number = "") # rubocop:disable Metrics/AbcSize
8486
result = "".html_safe
8587
num_in_level = 0
8688

87-
while headings.length > 0
89+
while !headings.empty?
8890
node = headings.first
89-
node_level = node.name[1,].to_i
91+
node_level = node.name[1].to_i
9092

9193
if level == node_level
9294
# We will render this node

lib/open_project/text_formatting/filters/task_list_filter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -56,7 +58,7 @@ def render_item_checkbox(item)
5658
# Modifications apply to the parsed document directly.
5759
#
5860
# Returns nothing.
59-
def filter!
61+
def filter! # rubocop:disable Metrics/AbcSize
6062
list_items(doc).reverse_each do |li|
6163
next if list_items(li.parent).empty?
6264

lib/open_project/text_formatting/formats.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/base_format.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/base_formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/markdown/format.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/markdown/formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/markdown/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/plain/format.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/plain/formatter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/formats/plain/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/helpers/link_rewriter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/matchers/attribute_macros.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH

lib/open_project/text_formatting/matchers/link_handlers/base.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -55,9 +57,7 @@ def self.allowed_prefixes
5557
[]
5658
end
5759

58-
def allowed_prefixes
59-
self.class.allowed_prefixes
60-
end
60+
delegate :allowed_prefixes, to: :class
6161

6262
##
6363
# Test whether we should try to resolve the given link
@@ -74,9 +74,7 @@ def call
7474
end
7575

7676
def oid
77-
unless identifier.nil?
78-
identifier.to_i
79-
end
77+
identifier&.to_i
8078
end
8179

8280
delegate :identifier, to: :matcher

lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
#-- copyright
24
# OpenProject is an open source project management software.
35
# Copyright (C) the OpenProject GmbH
@@ -87,7 +89,7 @@ def render_version
8789
end
8890
end
8991

90-
def render_commit
92+
def render_commit # rubocop:disable Metrics/AbcSize
9193
if project&.repository &&
9294
(changeset = Changeset.where(["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{oid}%"]).first)
9395
link_to h("#{matcher.project_prefix}#{matcher.identifier}"),
@@ -98,7 +100,7 @@ def render_commit
98100
end
99101
end
100102

101-
def render_source
103+
def render_source # rubocop:disable Metrics/AbcSize
102104
if project&.repository
103105
matcher.identifier =~ %r{\A[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?\z}
104106
path = $1
@@ -164,7 +166,7 @@ def render_meeting
164166
.where(["LOWER(title) = :s", { s: oid.downcase }])
165167
.first
166168

167-
if meeting && meeting.visible?(User.current)
169+
if meeting&.visible?(User.current)
168170
link_to meeting.title,
169171
{ only_path: context[:only_path], controller: "/meetings", action: "show", id: meeting.id },
170172
class: "meeting"

0 commit comments

Comments
 (0)