Skip to content

Commit

Permalink
Fix ameba offences
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed May 15, 2024
1 parent d87d76a commit 4f0305a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
13 changes: 13 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
Documentation/DocumentationAdmonition:
Enabled: false

Naming/RescuedExceptionsVariableName:
Excluded:
- spec/examples_spec.cr

Metrics/CyclomaticComplexity:
Enabled: false

Lint/NotNil:
Enabled: false

Lint/Typos:
Enabled: false

Lint/UselessAssign:
ExcludeTypeDeclarations: true
2 changes: 1 addition & 1 deletion spec/examples_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Dir
rescue item : Mint::Error
fail item.to_terminal.to_s
rescue item
fail item.to_s + '\n' + item.backtrace.join('\n')
fail "#{item}\n#{item.backtrace.join('\n')}"
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ ENV["SPEC"] = "TRUE"
MINT_ENV["TEST"] = "TRUE"

def diff(a, b)
file1 = File.tempfile do |f|
f.puts a.strip
f.flush
file1 = File.tempfile do |io|
io.puts a.strip
io.flush
end
file2 = File.tempfile do |f|
f.puts b
f.flush
file2 = File.tempfile do |io|
io.puts b
io.flush
end

io = IO::Memory.new
Expand Down
4 changes: 2 additions & 2 deletions src/ast/node.cr
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ module Mint
def self.compute_location(file : Parser::File, from, to)
# TODO: avoid creating this array for every (initial) call to `Node#location`
lines = [0]
file.contents.each_char_with_index do |ch, i|
lines << i + 1 if ch == '\n'
file.contents.each_char_with_index do |char, i|
lines << i + 1 if char == '\n'
end

Location.new(
Expand Down
4 changes: 2 additions & 2 deletions src/builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module Mint
workspace.watch
end

def get_service_worker_utils
def service_worker_utils
Assets.read("sw-utils.js")
end

Expand All @@ -214,7 +214,7 @@ module Mint

def service_worker(artifacts, relative, optimize)
worker = ServiceWorker.new(artifacts, relative, optimize)
"#{get_service_worker_utils}#{worker}"
"#{service_worker_utils}#{worker}"
end
end
end
8 changes: 3 additions & 5 deletions src/utils/service_worker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ module Mint
files
.reduce(OpenSSL::Digest.new("SHA256")) do |digest, file|
digest.file(file)
end.final.hexstring
end.hexfinal
end

def get_routes : String
def build_routes : String
routes = Mint::Compiler
.new(TypeChecker.check(@artifacts.ast))
.compile_service_worker(@artifacts.ast.routes)
.map do |node|
"...#{node}"
end
.map { |node| "...#{node}" }

@js.const("routes", "[#{routes.join(", ")}]")
end
Expand Down
2 changes: 1 addition & 1 deletion src/utils/service_worker.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const CACHE = '<%= calculate_hash %>'
const PRECACHE_URLS = [
<%= precache_urls.indent(2) %>
]
<%= get_routes %>
<%= build_routes %>

// On install precache all static resources
self.addEventListener('install', event => {
Expand Down

0 comments on commit 4f0305a

Please sign in to comment.