Description
The codebase uses == "" and != "" in ~91 places across 41 files to check for empty strings, instead of Crystal's idiomatic .empty? / !.empty?.
Note: This is the string-comparison companion to #1121 (which covers .size > 0 / == 0 / != 0 for collections and strings). They overlap conceptually but are syntactically different patterns.
Affected files (sampling — top offenders)
src/noir.cr — 8 instances (e.g. noir_options["url"] != "", noir_options["diff"] != "")
src/optimizer/optimizer.cr — 7 instances (e.g. if tiny_tmp.url != "", if new_value != "")
src/models/noir.cr — 6 instances
src/analyzer/analyzers/javascript/express.cr — 4 instances
src/analyzer/analyzers/crystal/kemal.cr, grip.cr, amber.cr — 4 instances each
src/analyzer/analyzers/ruby/sinatra.cr, rails.cr — 3 instances each
src/output_builder/mermaid.cr:45 — if path == "/" || path == ""
src/output_builder/powershell.cr:36 — if baked[:body] != ""
src/minilexers/golang.cr:31,37 — if @buffer != ""
src/config_initializer.cr:61 — if symbolized_hash[key].to_s == ""
Expected
# Before
if value == ""
if value != ""
# After
if value.empty?
unless value.empty?
# or:
if !value.empty?
Notes
- For
Hash#[] results that may be non-string (noir_options["url"]), call .to_s first or check the original type.
- For mixed conditions like
path == "/" || path == "", only the empty-string side needs the change: path == "/" || path.empty?.
- This can be tackled incrementally per file or per directory.
Description
The codebase uses
== ""and!= ""in ~91 places across 41 files to check for empty strings, instead of Crystal's idiomatic.empty?/!.empty?.Note: This is the string-comparison companion to #1121 (which covers
.size > 0/== 0/!= 0for collections and strings). They overlap conceptually but are syntactically different patterns.Affected files (sampling — top offenders)
src/noir.cr— 8 instances (e.g.noir_options["url"] != "",noir_options["diff"] != "")src/optimizer/optimizer.cr— 7 instances (e.g.if tiny_tmp.url != "",if new_value != "")src/models/noir.cr— 6 instancessrc/analyzer/analyzers/javascript/express.cr— 4 instancessrc/analyzer/analyzers/crystal/kemal.cr,grip.cr,amber.cr— 4 instances eachsrc/analyzer/analyzers/ruby/sinatra.cr,rails.cr— 3 instances eachsrc/output_builder/mermaid.cr:45—if path == "/" || path == ""src/output_builder/powershell.cr:36—if baked[:body] != ""src/minilexers/golang.cr:31,37—if @buffer != ""src/config_initializer.cr:61—if symbolized_hash[key].to_s == ""Expected
Notes
Hash#[]results that may be non-string (noir_options["url"]), call.to_sfirst or check the original type.path == "/" || path == "", only the empty-string side needs the change:path == "/" || path.empty?.