Skip to content

Use idiomatic .empty? instead of == "" / != "" for empty-string checks #1340

@hahwul

Description

@hahwul

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:45if path == "/" || path == ""
  • src/output_builder/powershell.cr:36if baked[:body] != ""
  • src/minilexers/golang.cr:31,37if @buffer != ""
  • src/config_initializer.cr:61if 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.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions