Skip to content

Conversation

@JarvisInvestInsight
Copy link

@JarvisInvestInsight JarvisInvestInsight commented Feb 2, 2026

Closes #71

Adds an \�llowEmojis\ config option (default: true) with a \git gpt emoji\ command to toggle it.

Changes:

  • Added \�llowEmojis\ to config defaults
  • Created \emoji\ CLI command (mirrors \prefix\ command pattern)
  • Updated \sanitizeCommitMessage()\ to strip emojis when disabled
  • Added tests for emoji stripping behavior

Usage:
\\�ash
git gpt emoji # Toggle emoji support on/off
\\

When disabled, emojis like bug/fire/explosion get stripped from generated commit messages. Enabled by default to match modern conventions (gitmoji, etc).

All 59 tests passing.


Found this helpful? Buy me a coffee

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new emoji command to toggle emoji usage in commit messages on or off
    • Introduced a configuration option to control emoji support in generated commit messages (enabled by default)
  • Tests

    • Added test coverage for emoji handling behavior in commit message sanitization

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

This PR implements configurable emoji support for commit messages. It adds an allowEmojis configuration option (default: true), creates a CLI command to toggle emoji support, threads the setting through the commit generation pipeline, and updates sanitization logic to conditionally preserve or strip emojis based on configuration.

Changes

Cohort / File(s) Summary
CLI Command Infrastructure
src/cli/commands/emoji.js, src/cli/commands/index.js, src/cli/index.js
New emoji CLI command that reads current config, prompts user to enable/disable emojis, and updates config accordingly. Exported from commands index and registered in main CLI setup.
Configuration
src/config/defaults.js
Adds allowEmojis: true as a default configuration option.
Commit Generation Pipeline
src/cli/commands/commit.js, src/core/commitGenerator.js
Threads allowEmojis option through to commit message generation by passing it to sanitizeCommitMessage.
Message Sanitization
src/utils/sanitizeCommitMessage.js
Updates function signature to accept optional allowEmojis parameter (default: true); conditionally strips emoji characters via Unicode-aware regex when allowEmojis is false.
Tests
utils/sanitizeCommitMessage.test.js
Adds test coverage for default emoji allowance behavior, explicit allowEmojis: true, and allowEmojis: false emoji stripping.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Config
    participant CommitGen
    participant Sanitizer
    
    rect rgba(100, 150, 200, 0.5)
    Note over User,Config: User Toggles Emoji Support
    User->>CLI: Run `git gpt emoji`
    CLI->>Config: Read current allowEmojis setting
    Config-->>CLI: Return setting state
    CLI->>User: Show prompt (enable/disable)
    User->>CLI: Select option
    CLI->>Config: Save new allowEmojis value
    Config-->>CLI: Confirm save
    CLI->>User: Log result
    end
    
    rect rgba(150, 200, 100, 0.5)
    Note over User,Sanitizer: Commit Message Generation
    User->>CLI: Run commit command
    CLI->>CommitGen: generateCommitMessage({allowEmojis: true/false, ...})
    CommitGen->>Sanitizer: sanitizeCommitMessage(message, allowEmojis)
    alt allowEmojis is true
        Sanitizer->>Sanitizer: Remove quotes only, preserve emojis
    else allowEmojis is false
        Sanitizer->>Sanitizer: Remove quotes and emoji characters
    end
    Sanitizer-->>CommitGen: Return sanitized message
    CommitGen-->>CLI: Return final message
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With a hop and a skip through the emoji aisle,
We've threaded them through every file with style!
Config to CLI to the sanitizer's care,
Now developers can sprinkle some sparkle with flair! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding configurable emoji support for commit messages, which is the primary objective of this pull request.
Linked Issues check ✅ Passed The PR implements all core coding requirements from issue #71: allowEmojis config option with true default, sanitizeCommitMessage signature updated to accept allowEmojis parameter with emoji stripping logic, git gpt emoji command added, and tests updated for emoji behavior validation.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with issue #71 requirements. The modifications to commit.js, emoji.js, config defaults, sanitizeCommitMessage, commitGenerator, CLI integration, and test coverage all support the stated objective of configurable emoji support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/utils/sanitizeCommitMessage.js`:
- Around line 16-21: The current emoji-strip in sanitizeCommitMessage (the block
using allowEmojis and result.replace) leaves behind zero-width joiners and
variation selectors; update the replacement to remove ZWJ (U+200D) and VS16
(U+FE0F) and to match emoji sequences so no invisible characters remain—i.e.,
refine the regex used in the result.replace call to include \u200D and \uFE0F
handling (or use a pattern that matches Extended_Pictographic sequences
including joiners/variation selectors) so the function fully strips emojis when
allowEmojis is false.
🧹 Nitpick comments (1)
src/cli/commands/emoji.js (1)

9-35: Clean implementation following established patterns.

The command handler follows the dependency injection pattern and properly handles user cancellation via the undefined check. The logic is straightforward and readable.

One minor defensive suggestion: if config.get('allowEmojis') returns undefined (e.g., fresh config before defaults apply), the initial selection would default to "Disable" (index 1), which contradicts the intended default of true. Consider using nullish coalescing for robustness:

🛡️ Optional: Add defensive default for initial selection
 export function createEmojiCommand({ config }) {
   return async function emojiAction() {
-    const currentEnabled = config.get('allowEmojis')
+    const currentEnabled = config.get('allowEmojis') ?? true
 
     console.log(

Comment on lines +16 to +21
// Strip emojis if disabled
if (!allowEmojis) {
result = result.replace(
/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu,
'',
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

git ls-files | grep -E "(sanitize|emoji)" | head -20

Repository: laststance/git-gpt-commit

Length of output: 196


🏁 Script executed:

fd -t f "sanitizeCommitMessage" .

Repository: laststance/git-gpt-commit

Length of output: 176


🏁 Script executed:

cat -n src/utils/sanitizeCommitMessage.js

Repository: laststance/git-gpt-commit

Length of output: 1036


🏁 Script executed:

cat -n utils/sanitizeCommitMessage.js

Repository: laststance/git-gpt-commit

Length of output: 218


🏁 Script executed:

cat -n utils/sanitizeCommitMessage.test.js

Repository: laststance/git-gpt-commit

Length of output: 3257


🏁 Script executed:

# Check Node.js version requirements and package.json
cat package.json | grep -A 5 -B 5 "engines"

Repository: laststance/git-gpt-commit

Length of output: 51


🏁 Script executed:

# Test the emoji regex behavior to understand current vs suggested approach
node << 'EOF'
// Test if Unicode properties work
try {
  const testStr = '🐛🔥💥';
  const current = testStr.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
  console.log('Current regex works:', current === '');
} catch (e) {
  console.log('Current regex error:', e.message);
}

// Test ZWJ sequences (family emoji)
const familyEmoji = '👨‍👩‍👧‍👦'; // Man, ZWJ, Woman, ZWJ, Girl, ZWJ, Boy
console.log('Family emoji:', familyEmoji);
console.log('Family emoji length:', familyEmoji.length);
console.log('Family emoji codepoints:', [...familyEmoji].length);

// Test with variation selector
const emojiWithVS = '❤️'; // Heart with VS16
console.log('Heart with VS16:', emojiWithVS);
console.log('Heart with VS16 length:', emojiWithVS.length);

// Test current regex on complex emoji
try {
  const result = familyEmoji.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
  console.log('Family emoji after current regex:', result);
  console.log('Family emoji after current regex length:', result.length);
  console.log('Invisible characters remain:', result.length > 0);
} catch (e) {
  console.log('Error testing family emoji:', e.message);
}
EOF

Repository: laststance/git-gpt-commit

Length of output: 332


🏁 Script executed:

# Test the suggested fix
node << 'EOF'
// Test suggested regex with additional emoji components
const familyEmoji = '👨‍👩‍👧‍👦'; // Family emoji with ZWJ
const heartWithVS = '❤️'; // Heart with VS16

// Current regex
const currentResult = familyEmoji.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
console.log('Current regex leaves:', currentResult.length, 'chars');

// Suggested regex from review
try {
  const suggestedResult = familyEmoji.replace(
    /(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,
    ''
  );
  console.log('Suggested regex leaves:', suggestedResult.length, 'chars');
} catch (e) {
  console.log('Suggested regex error:', e.message);
}

// Test with more comprehensive emoji patterns
const testCases = [
  { name: 'Basic emoji', text: '🐛' },
  { name: 'ZWJ family', text: '👨‍👩‍👧‍👦' },
  { name: 'Emoji with VS16', text: '❤️' },
  { name: 'Skin tone modifier', text: '👋🏽' },
];

console.log('\n--- Testing current regex ---');
testCases.forEach(({ name, text }) => {
  const result = text.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, '');
  console.log(`${name}: left ${result.length} chars`);
});

console.log('\n--- Testing suggested regex ---');
testCases.forEach(({ name, text }) => {
  try {
    const result = text.replace(
      /(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,
      ''
    );
    console.log(`${name}: left ${result.length} chars`);
  } catch (e) {
    console.log(`${name}: error - ${e.message}`);
  }
});
EOF

Repository: laststance/git-gpt-commit

Length of output: 422


🏁 Script executed:

# Check Node.js version and what Unicode property support is available
node << 'EOF'
console.log('Node.js version:', process.version);

// Check which Unicode properties are supported
const props = [
  'Emoji_Presentation',
  'Extended_Pictographic',
  'Emoji_Modifier',
  'Emoji_Component',
];

props.forEach(prop => {
  try {
    const regex = new RegExp(`\\p{${prop}}`, 'u');
    console.log(`✓ ${prop} supported`);
  } catch (e) {
    console.log(`✗ ${prop} not supported`);
  }
});
EOF

Repository: laststance/git-gpt-commit

Length of output: 213


Remove ZWJ sequences and variation selectors to fully strip emojis.

The current regex leaves invisible characters behind when removing emojis:

  • ZWJ sequences (e.g., family emojis like 👨‍👩‍👧‍👦) leave zero-width joiners (\u200D)
  • Emoji with variation selectors (e.g., ❤️) leave VS16 (\uFE0F)

Apply the suggested regex to handle these components:

✅ Suggested regex refinement
-      /\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu,
+      /(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,

All required Unicode properties are supported in current Node.js versions.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Strip emojis if disabled
if (!allowEmojis) {
result = result.replace(
/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu,
'',
)
// Strip emojis if disabled
if (!allowEmojis) {
result = result.replace(
/(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Component}|\u200D|\uFE0F)/gu,
'',
)
🤖 Prompt for AI Agents
In `@src/utils/sanitizeCommitMessage.js` around lines 16 - 21, The current
emoji-strip in sanitizeCommitMessage (the block using allowEmojis and
result.replace) leaves behind zero-width joiners and variation selectors; update
the replacement to remove ZWJ (U+200D) and VS16 (U+FE0F) and to match emoji
sequences so no invisible characters remain—i.e., refine the regex used in the
result.replace call to include \u200D and \uFE0F handling (or use a pattern that
matches Extended_Pictographic sequences including joiners/variation selectors)
so the function fully strips emojis when allowEmojis is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🎨 Add emoji support to commit messages

1 participant