Skip to content

🎨 Add emoji support to commit messages #71

@ryota-murakami

Description

@ryota-murakami

Problem

Currently, the sanitizeCommitMessage() function removes all emojis from commit messages. There's a TODO comment indicating this is a known limitation.

Location: utils/sanitizeCommitMessage.js:1

// TODO should allow emojis
export function sanitizeCommitMessage(message) {
  // Unicode regex: Allow only all characters (including Japanese and Traditional Chinese), numbers, spaces, and symbols.
  return message.replace(/[^\p{L}\p{N}\s.:@<>\/-]/gu, '')
}

Current behavior:

sanitizeCommitMessage('fix: bug πŸ›πŸ”₯πŸ’₯')
// Result: 'fix: bug ' (emojis removed)

Test expectation (tests/utils/sanitizeCommitMessage.test.js:47-49):

it('should remove emojis and unsupported unicode', () => {
  expect(sanitizeCommitMessage('fix: bug πŸ›πŸ”₯πŸ’₯')).toBe('fix: bug ')
})

User Request

Many developers use emojis in commit messages for visual clarity:

  • πŸ› for bug fixes
  • ✨ for new features
  • πŸ”₯ for removing code/files
  • πŸ“ for documentation
  • ♻️ for refactoring
  • πŸš€ for deployment
  • βœ… for tests

Popular projects like gitmoji encourage this practice.

Proposed Solution

Option 1: Allow All Emojis (Simple)

/**
 * Sanitizes commit message by removing dangerous characters
 * Allows: letters, numbers, spaces, common symbols, and emojis
 * @param {string} message - Raw commit message
 * @returns {string} Sanitized commit message
 */
export function sanitizeCommitMessage(message) {
  // Allow all characters except potentially dangerous ones
  // \p{L} = letters, \p{N} = numbers, \p{Emoji} = emojis
  return message.replace(/[^\p{L}\p{N}\p{Emoji}\s.:@<>\/-]/gu, '')
}

Test update:

it('should allow emojis in commit messages', () => {
  expect(sanitizeCommitMessage('fix: bug πŸ›πŸ”₯πŸ’₯')).toBe('fix: bug πŸ›πŸ”₯πŸ’₯')
})

Option 2: Allow Specific Emoji Categories

/**
 * Sanitizes commit message
 * Allows common emojis but blocks potentially problematic ones
 */
export function sanitizeCommitMessage(message) {
  // Allow: letters, numbers, emojis, and safe symbols
  // Block: control characters, private use area, format characters
  return message.replace(
    /[^\p{L}\p{N}\p{Emoji_Presentation}\s.:@<>\/-]/gu, 
    ''
  )
}

Option 3: Configurable Emoji Support

// Add to config
{
  "model": "gpt-5-mini",
  "language": "English",
  "prefixEnabled": true,
  "allowEmojis": true  // ← New option
}

// In sanitizeCommitMessage
export function sanitizeCommitMessage(message, allowEmojis = true) {
  if (allowEmojis) {
    return message.replace(/[^\p{L}\p{N}\p{Emoji}\s.:@<>\/-]/gu, '')
  }
  // Original behavior (no emojis)
  return message.replace(/[^\p{L}\p{N}\s.:@<>\/-]/gu, '')
}

// Add CLI command
program
  .command('emoji')
  .description('Toggle emoji support in commit messages')
  .action(async () => {
    const response = await prompts({
      type: 'select',
      name: 'value',
      message: 'Allow emojis in commit messages?',
      choices: [
        { title: 'Enable emojis πŸŽ‰', value: true },
        { title: 'Disable emojis', value: false },
      ],
      initial: config.allowEmojis ? 0 : 1,
    })
    
    saveConfig({ allowEmojis: response.value })
    console.log(`Emojis ${response.value ? 'enabled' : 'disabled'}`)
  })

Considerations

Pros

  • βœ… Better visual clarity in commit history
  • βœ… Aligns with popular practices (gitmoji)
  • βœ… OpenAI may generate emoji-enhanced messages
  • βœ… No functional impact (emojis are valid in git)

Cons

  • ⚠️ Some terminal/font configurations don't display emojis well
  • ⚠️ Can look unprofessional in some corporate environments
  • ⚠️ May complicate commit message parsing

Git Compatibility

Emojis work perfectly in git commit messages:

$ git commit -m "✨ Add new feature"
$ git log
commit abc123...
    ✨ Add new feature

Recommendation

Option 3 (Configurable) is the most flexible:

  • Default: Enabled (modern practice)
  • Users who don't want emojis can disable
  • Backward compatible

Implementation Plan

  1. Update sanitizeCommitMessage() to accept allowEmojis parameter
  2. Add emoji configuration option to config file
  3. Add git gpt emoji command to toggle
  4. Update tests to verify emoji support
  5. Update documentation
  6. Consider asking OpenAI to suggest appropriate emojis

Acceptance Criteria

  • sanitizeCommitMessage() preserves emojis when enabled
  • Add allowEmojis config option (default: true)
  • Add git gpt emoji command
  • Update tests for emoji support
  • Update README with emoji examples
  • Add integration test with emoji commit

Priority

Low - Feature request, not a blocker

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions