Why Grammar Checkers Shouldn't Touch Your Code
A rant about AI tools that "helpfully" rename variables, break SQL queries, and generally make developers' lives harder. Plus: what to look for in code-aware tools.
I have a simple test for any AI writing tool that claims to work with code:
Does it change your variable names?
If the answer is yes, throw it out. Here’s why.
The Variable Name Problem
You write this JavaScript:
const u = users.find(u => u.id === id);
A grammar checker “helpfully” rewrites it to:
const user = users.find(user => user.id === id);
Seems fine, right? Until you remember that u is referenced in seventeen other files in your codebase. Now you have a bug to track down.
Or maybe you have:
SELECT u.id, u.name FROM users u WHERE u.active = 1;
Some AI says “this is hard to read” and rewrites it as:
SELECT users.id, users.name FROM users WHERE users.active = 1;
Now your query is ambiguous (which users table if there are joins?) and slower (full table names vs aliases).
The Real Issue
These tools don’t understand that code is not prose. In prose, clarity means longer, more descriptive words. In code, clarity often means shorter, more established patterns.
Consider:
// Prose: "The user object contains their personal information"
// Code: const u = getUser(id);
The short form is clearer in context. The variable name u carries implicit meaning: it’s a user, it’s local, it’s being defined now.
Variable names in code serve a different purpose than words in prose. AI tools that treat code as text will break your code.
The right approach: extract comment blocks and docstrings before sending them to any grammar tool. Our API is designed for exactly this — it accepts comment text, not full source files, and returns a structured diff you can apply back into your codebase.
What a Code-Aware Tool Actually Returns
A tool that’s actually aware of code will:
- Only modify comments and documentation — Never touch function names, variable names, or logic
- Preserve formatting — Keep indentation, line breaks, and spacing
- Understand syntax — Know that
//starts a comment and/* */is a different syntax - Respect domain conventions — Keep
ias a loop counter,erras an error variable
Here’s what our Code Comment & Documentation Fixer API returns when you send it a messy JSDoc block:
const response = await fetch('https://code-comment-doc-fixer-api-grammar-for-developers.p.rapidapi.com/api/analyze', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY_HERE',
'X-RapidAPI-Host': 'code-comment-doc-fixer-api-grammar-for-developers.p.rapidapi.com'
},
body: JSON.stringify({
text: `/**
* Retreives the curent user from the databse.
* @param {string} userId - the user id to look up
* @returns {Promise<User>} - a promiss that resolvs
*/`,
options: {
language: 'javascript',
doc_style: 'jsdoc',
preserve_terms: ['userId', 'Promise', 'User']
}
})
})
const data = await response.json()
The response is structured JSON — not rewritten prose:
{
"corrected_text": "/**\n * Retrieves the current user from the database.\n * @param {string} userId - The user ID to look up.\n * @returns {Promise<User>} - A promise that resolves.\n */",
"changes_made": [
{ "original": "Retreives", "corrected": "Retrieves", "type": "spelling", "line_reference": "line 2" },
{ "original": "curent", "corrected": "current", "type": "spelling", "line_reference": "line 2" },
{ "original": "databse", "corrected": "database", "type": "spelling", "line_reference": "line 2" }
],
"technical_terms_preserved": ["userId", "Promise", "User"],
"readability_score_before": 42,
"readability_score_after": 91,
"errors_fixed_count": 3
}
Notice: userId, Promise, and User are preserved exactly. The function signature was never touched — because the API only processes the comment text you send it.
The Checklist
Before using any “AI for code” tool, ask:
- Does it preserve variable names, type hints, and technical identifiers?
- Does it return structured JSON diffs (not just rewritten text)?
- Does it provide line references so you can apply changes programmatically?
- Does it let you declare custom terms that must never be altered?
- Does it support your language’s doc conventions (JSDoc, NumPy, Sphinx, Google)?
If the answer to any of these is “no” or “I don’t know,” find a different tool.
The Bottom Line
Code is not prose. Writing tools that don’t understand this will cause bugs. Your AI writing assistant should enhance your documentation without touching your logic.
The Code Comment & Documentation Fixer API is built for this exact distinction — it processes only the documentation you send it, preserves every technical term, and returns a structured diff with line references you can pipe straight into CI/CD.
This post is a simplified version of a longer rant I almost published called “In Defense of Single-Letter Variables.” Maybe next time.