Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Autocorrect Rubocop offenses in TextFormatting module

Alexander Brandon Coles98a369f99a91
diff --git a/lib/open_project/text_formatting/filters/bem_css_filter.rb b/lib/open_project/text_formatting/filters/bem_css_filter.rb
index 182faad7159..63181fa3545 100644
--- a/lib/open_project/text_formatting/filters/bem_css_filter.rb
+++ b/lib/open_project/text_formatting/filters/bem_css_filter.rb
@@ -84,7 +84,7 @@ module OpenProject::TextFormatting
if element["class"].present?
# Avoid using element['class'].include?(css_class) as css_class can be a substring
# of an existing class
- element["class"] += " #{css_class}" unless element["class"].split.any? { |existing_class| existing_class == css_class }
+ element["class"] += " #{css_class}" unless element["class"].split.any?(css_class)
else
element["class"] = css_class
end
diff --git a/lib/open_project/text_formatting/filters/macro_filter.rb b/lib/open_project/text_formatting/filters/macro_filter.rb
index 445e05d45be..3bb328145ff 100644
--- a/lib/open_project/text_formatting/filters/macro_filter.rb
+++ b/lib/open_project/text_formatting/filters/macro_filter.rb
@@ -83,7 +83,7 @@ module OpenProject::TextFormatting
end
def macro_applies?(macro_class, element)
- ((element["class"] || "").split & Array(macro_class.identifier)).any?
+ (element["class"] || "").split.intersect?(Array(macro_class.identifier))
end
end
end
diff --git a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb b/lib/open_project/text_formatting/filters/table_of_contents_filter.rb
index bbb3a253de5..3b53636bc47 100644
--- a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb
+++ b/lib/open_project/text_formatting/filters/table_of_contents_filter.rb
@@ -68,7 +68,7 @@ module OpenProject::TextFormatting
# that prefix is used if it matches the calculated number.
def process_item(node, number)
text = node.text
- return "".html_safe unless text.present?
+ return "".html_safe if text.blank?
id = get_unique_id(text)
add_header_link_class_and_id(node, id)
@@ -86,9 +86,9 @@ module OpenProject::TextFormatting
result = "".html_safe
num_in_level = 0
- while headings.length > 0
+ while !headings.empty?
node = headings.first
- node_level = node.name[1,].to_i
+ node_level = node.name[1].to_i
if level == node_level
# We will render this node
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/base.rb b/lib/open_project/text_formatting/matchers/link_handlers/base.rb
index f32dd15b345..40178cbd16b 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/base.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/base.rb
@@ -57,9 +57,7 @@ module OpenProject::TextFormatting::Matchers
[]
end
- def allowed_prefixes
- self.class.allowed_prefixes
- end
+ delegate :allowed_prefixes, to: :class
##
# Test whether we should try to resolve the given link
@@ -76,9 +74,7 @@ module OpenProject::TextFormatting::Matchers
end
def oid
- unless identifier.nil?
- identifier.to_i
- end
+ identifier&.to_i
end
delegate :identifier, to: :matcher
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
index 569a3bcf36a..30616eec585 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
@@ -166,7 +166,7 @@ module OpenProject::TextFormatting::Matchers
.where(["LOWER(title) = :s", { s: oid.downcase }])
.first
- if meeting && meeting.visible?(User.current)
+ if meeting&.visible?(User.current)
link_to meeting.title,
{ only_path: context[:only_path], controller: "/meetings", action: "show", id: meeting.id },
class: "meeting"
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
index 482f79605fe..03f12f6ae13 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
@@ -68,7 +68,7 @@ module OpenProject::TextFormatting::Matchers
end
def render_document
- if document = Document.visible.find_by_id(oid)
+ if document = Document.visible.find_by(id: oid)
link_to document.title,
{ only_path: context[:only_path],
controller: "/documents",
@@ -79,7 +79,7 @@ module OpenProject::TextFormatting::Matchers
end
def render_meeting
- meeting = Meeting.find_by_id(oid)
+ meeting = Meeting.find_by(id: oid)
if meeting&.visible?(User.current)
link_to meeting.title,
{ only_path: context[:only_path],
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb b/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb
index a4b507dcfb6..8148c6e74c4 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb
@@ -45,7 +45,7 @@ module OpenProject::TextFormatting::Matchers
# r11, r13
def call
# don't handle link unless repository exists
- return nil unless project && project.repository
+ return nil unless project&.repository
changeset = project.repository.find_changeset_by_name(matcher.identifier)
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/work_packages.rb b/lib/open_project/text_formatting/matchers/link_handlers/work_packages.rb
index 8d43b9e03c0..9002b457956 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/work_packages.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/work_packages.rb
@@ -50,7 +50,7 @@ module OpenProject::TextFormatting::Matchers
# prohibits links to things like #0123
return if wp_id.to_s != matcher.identifier
- if matcher.sep == "##" || matcher.sep == "###"
+ if ["##", "###"].include?(matcher.sep)
render_work_package_macro(wp_id, detailed: (matcher.sep === "###"))
else
render_work_package_link(wp_id)
diff --git a/lib/open_project/text_formatting/matchers/regex_matcher.rb b/lib/open_project/text_formatting/matchers/regex_matcher.rb
index 0058559aad8..a2cc6dea7ef 100644
--- a/lib/open_project/text_formatting/matchers/regex_matcher.rb
+++ b/lib/open_project/text_formatting/matchers/regex_matcher.rb
@@ -52,7 +52,7 @@ module OpenProject::TextFormatting
##
# Process the node's html and possibly, replace it
def self.process_node!(content, context)
- return nil unless content.present?
+ return nil if content.blank?
content.gsub!(regexp) do |matched_string|
matchdata = Regexp.last_match
diff --git a/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb b/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb
index fbd75c835f5..799e2594a18 100644
--- a/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb
+++ b/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb
@@ -150,7 +150,7 @@ module OpenProject::TextFormatting
link_to h(wiki_title),
url,
- class: ("wiki-page" + (wiki_page ? "" : " new"))
+ class: "wiki-page#{wiki_page ? '' : ' new'}"
end
end
end