diff options
author | Jeff King <peff@peff.net> | 2022-10-05 13:57:28 +0300 |
---|---|---|
committer | Jeff King <peff@peff.net> | 2022-10-05 16:28:15 +0300 |
commit | c5e8c4d0cd77b301c0a45100ea7b9f94a7c64bfa (patch) | |
tree | abceb721807e6580c81d982bef1a36b088cf465f | |
parent | a378a4eaaf63e86c699b66c1f7dd10b185b831cb (diff) |
appease rubocop Lint/AssignmentInCondition
These cases were all fine. In a few I just added parentheses, but in
general it makes things more readable to just split the assignment and
conditional to two lines.
-rw-r--r-- | app/controllers/books_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/site_controller.rb | 4 | ||||
-rw-r--r-- | app/models/doc_file.rb | 3 | ||||
-rw-r--r-- | app/models/section.rb | 12 | ||||
-rw-r--r-- | lib/tasks/book2.rake | 9 | ||||
-rw-r--r-- | lib/tasks/index.rake | 6 |
6 files changed, 26 insertions, 17 deletions
diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 1d61a8d9..5476f5f9 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -5,7 +5,8 @@ class BooksController < ApplicationController def show lang = params[:lang] || "en" - if edition = params[:edition] + edition = params[:edition] + if edition @book = Book.where(code: lang, edition: edition).first else @book = Book.where(code: lang).order("percent_complete DESC, edition DESC").first @@ -30,7 +31,8 @@ class BooksController < ApplicationController @content = @book.sections.where(slug: params[:slug]).first if !@content @book = Book.where(code: @book.code, edition: 2).first - if @content = @book.sections.where(slug: params[:slug]).first + @content = @book.sections.where(slug: params[:slug]).first + if @content return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{params[:slug]}" else return redirect_to "/book/#{@book.code}" @@ -57,7 +59,8 @@ class BooksController < ApplicationController end def book_resource - if edition = params[:edition] + edition = params[:edition] + if edition @book ||= Book.where(code: (params[:lang] || "en"), edition: edition).first else @no_edition = true diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 30407a57..968300a1 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -41,11 +41,11 @@ class SiteController < ApplicationController results: [] } - if results = Doc.search(sname) + if (results = Doc.search(sname)) data[:results] << results end - if results = Section.search(sname, lang: "en") + if (results = Section.search(sname, lang: "en")) data[:results] << results end diff --git a/app/models/doc_file.rb b/app/models/doc_file.rb index 52c158c1..c8448b77 100644 --- a/app/models/doc_file.rb +++ b/app/models/doc_file.rb @@ -48,7 +48,8 @@ class DocFile < ApplicationRecord changes = [] doc_versions = self.doc_versions.includes(:version).version_changes.limit(limit_size).to_a doc_versions.each_with_index do |doc_version, i| - next unless previous_doc_version = doc_versions[i + 1] + previous_doc_version = doc_versions[i + 1] + next unless previous_doc_version sha2 = doc_version.doc.blob_sha sha1 = previous_doc_version.doc.blob_sha diff --git a/app/models/section.rb b/app/models/section.rb index 29d9ecc1..e10e0da4 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -34,11 +34,11 @@ class Section < ApplicationRecord def prev_slug lang = book.code prev_number = number - 1 - if section = sections.find_by(number: prev_number) + if (section = sections.find_by(number: prev_number)) return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}" - elsif ch = chapter.prev + elsif (ch = chapter.prev) # find previous chapter - if section = ch.last_section + if (section = ch.last_section) return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}" end end @@ -49,10 +49,10 @@ class Section < ApplicationRecord def next_slug lang = book.code next_number = number + 1 - if section = sections.find_by(number: next_number) + if (section = sections.find_by(number: next_number)) return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}" - elsif ch = chapter.next - if section = ch.first_section + elsif (ch = chapter.next) + if (section = ch.first_section) return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}" end # find next chapter diff --git a/lib/tasks/book2.rake b/lib/tasks/book2.rake index 0551f1c5..83d85d26 100644 --- a/lib/tasks/book2.rake +++ b/lib/tasks/book2.rake @@ -136,7 +136,8 @@ def genbook(code, &get_content) html.gsub!("<h5", "<h4") html.gsub!(/\/h5>/, "/h4>") - if xlink = html.scan(/href="1-.*?\.html\#(.*?)"/) + xlink = html.scan(/href="1-.*?\.html\#(.*?)"/) + if xlink xlink.each do |link| xref = link.first begin @@ -147,7 +148,8 @@ def genbook(code, &get_content) end end - if xlink = html.scan(/href="\#(.*?)"/) + xlink = html.scan(/href="\#(.*?)"/) + if xlink xlink.each do |link| xref = link.first begin @@ -158,7 +160,8 @@ def genbook(code, &get_content) end end - if subsec = html.scan(/<img src="(.*?)"/) + subsec = html.scan(/<img src="(.*?)"/) + if subsec subsec.each do |sub| sub = sub.first begin diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake index b438075d..258002b7 100644 --- a/lib/tasks/index.rake +++ b/lib/tasks/index.rake @@ -198,11 +198,13 @@ def index_doc(filter_tags, doc_list, get_content) end generated = cmd_list.keys.inject({}) do |list, category| links = cmd_list[category].map do |cmd, attr| - next unless cmd_file = tag_files.detect { |ent| ent.first == "Documentation/#{cmd}.txt" } + cmd_file = tag_files.detect { |ent| ent.first == "Documentation/#{cmd}.txt" } + next unless cmd_file content = get_content.call(cmd_file.second) section = content.match(/^git.*\(([1-9])\)/)[1] - if match = content.match(/NAME\n----\n\S+ - (.*)$/) + match = content.match(/NAME\n----\n\S+ - (.*)$/) + if match "linkgit:#{cmd}[#{section}]::\n\t#{attr == 'deprecated' ? '(deprecated) ' : ''}#{match[1]}\n" end end |