ESLint InterlaceESLint Interlace
Plugin: conventionsRules

prefer-code-point

ESLint rule documentation for prefer-code-point

📡 Live from GitHub — This documentation is fetched directly from prefer-code-point.md and cached for 6 hours.

Keywords: codePointAt, charCodeAt, Unicode, emoji, ESLint rule, auto-fix, LLM-optimized

Prefer String.codePointAt() over String.charCodeAt(). This rule is part of eslint-plugin-conventions.

Prefer String.codePointAt() over String.charCodeAt(). This rule is part of eslint-plugin-conventions.

Quick Summary

AspectDetails
SeverityWarning (correctness)
Auto-Fix✅ Yes (converts method)
CategoryQuality
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForUnicode handling, emoji support

Rule Details

charCodeAt() only works for Basic Multilingual Plane characters. codePointAt() handles all Unicode including emoji.

Why This Matters

IssueImpactSolution
😀 Emoji handlingIncorrect code pointscodePointAt()
🌍 Unicode supportAstral characters failFull Unicode support
📏 String lengthSurrogate pairs miscountedCorrect iteration

Examples

❌ Incorrect

const code = string.charCodeAt(0);  // Fails for emoji
'😀'.charCodeAt(0);  // Returns 55357 (wrong!)

✅ Correct

const code = string.codePointAt(0);  // Works for all Unicode
'😀'.codePointAt(0);  // Returns 128512 (correct!)

// Iterate over code points
for (const char of string) {
  const codePoint = char.codePointAt(0);
}

Configuration Examples

Basic Usage

{
  rules: {
    'conventions/prefer-code-point': 'warn'
  }
}

Further Reading

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// ❌ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not tracked

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// ❌ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings