Skip to content

Move normalizeSlug() to a shared utility to remove duplication #92

Description

@sametcelikbicak

Summary

The function normalizeSlug(slug) is defined identically in 3 separate files. It should be moved to a shared utility and imported where needed.

Current Locations

  • src/commands/remove.js (lines 5-7)
  • src/commands/update.js (lines 8-10)
  • src/utils/installer.js (lines 6-8)

All three define: function normalizeSlug(slug) { return slug.replace(/\//g, "-") }

How to Fix

  1. Add normalizeSlug to src/utils/lockfile.js (or a new src/utils/helpers.js) and export it
  2. Import it in remove.js, update.js, and installer.js instead of defining it locally
  3. Remove the local definitions
  4. Run npm test to verify

Why This Matters

Duplicated code means if the logic ever needs to change, it has to be updated in 3 places. A single source of truth is easier to maintain.

Difficulty

Easy — pure refactor, no behavior change.

Files

  • src/commands/remove.js
  • src/commands/update.js
  • src/utils/installer.js
  • src/utils/lockfile.js (or new file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions