Naming Analyzer

Automate the analysis of naming conventions to ensure consistency and clarity across large-scale software projects

Naming Analyzer is an AI skill that evaluates and suggests improvements for variable names, function names, class names, and other identifiers in source code. It covers naming convention enforcement, semantic clarity analysis, abbreviation detection, consistency checking across codebases, and automated renaming suggestions that improve code readability.

What Is This?

Overview

Naming Analyzer provides systematic evaluation of identifier names in source code to improve readability and maintainability. It handles checking names against language specific conventions such as camelCase or snake_case, detecting vague or misleading names that obscure code intent, identifying inconsistent naming patterns across modules, suggesting descriptive alternatives based on context and usage, and enforcing team naming standards through configurable rule sets.

Who Should Use This

This skill serves code reviewers who want to provide specific naming feedback, development teams establishing or enforcing naming conventions, individual developers refactoring legacy code with poor identifier choices, and technical leads building style guides with concrete naming examples.

Why Use It?

Problems It Solves

Poorly named variables force readers to trace code paths to understand what values represent. Inconsistent naming conventions create confusion about which style to follow. Abbreviations that seem clear to the original author become cryptic to new team members. Generic names like data, temp, and result provide no semantic information.

Core Highlights

Pattern matching detects naming convention violations across entire codebases. Semantic analysis evaluates whether names describe their values accurately based on usage context. Consistency checking identifies style drift between files and modules. Automated suggestions generate alternatives that follow project conventions.

How to Use It?

Basic Usage

import re
import ast

class NamingAnalyzer:
    def __init__(self, convention="snake_case"):
        self.convention = convention
        self.patterns = {
            "snake_case": r"^[a-z][a-z0-9]*(_[a-z0-9]+)*$",
            "camelCase": r"^[a-z][a-zA-Z0-9]*$",
            "PascalCase": r"^[A-Z][a-zA-Z0-9]*$",
        }
        self.vague_names = {
            "data", "temp", "result", "val", "obj",
            "item", "thing", "stuff", "info", "tmp"
        }

    def check_convention(self, name):
        pattern = self.patterns.get(self.convention)
        if not pattern:
            return True
        return bool(re.match(pattern, name))

    def is_vague(self, name):
        base = name.lower().rstrip("0123456789_")
        return base in self.vague_names

    def analyze_function(self, func_name, params):
        issues = []
        if not self.check_convention(func_name):
            issues.append(
                f"Function '{func_name}' violates "
                f"{self.convention} convention"
            )
        for param in params:
            if self.is_vague(param):
                issues.append(
                    f"Parameter '{param}' is too vague, "
                    f"consider a descriptive name"
                )
            if len(param) == 1 and param not in "ijkn":
                issues.append(
                    f"Single letter param '{param}' "
                    f"lacks context"
                )
        return issues

Real-World Examples

class CodebaseNamingAudit {
  constructor(rules) {
    this.rules = rules;
    this.findings = [];
  }

  auditFile(filepath, astNodes) {
    for (const node of astNodes) {
      if (node.type === "VariableDeclaration") {
        for (const decl of node.declarations) {
          this.checkVariable(filepath, decl);
        }
      }
      if (node.type === "FunctionDeclaration") {
        this.checkFunction(filepath, node);
      }
    }
  }

  checkVariable(filepath, declaration) {
    const name = declaration.id.name;
    if (name.length < 3 && !this.isLoopVar(name)) {
      this.findings.push({
        file: filepath,
        name: name,
        issue: "too_short",
        suggestion: this.suggestExpansion(name)
      });
    }
    if (this.hasInconsistentStyle(name)) {
      this.findings.push({
        file: filepath,
        name: name,
        issue: "style_mismatch",
        suggestion: this.convertToProjectStyle(name)
      });
    }
  }

  suggestExpansion(shortName) {
    const expansions = {
      "cb": "callback", "fn": "handler",
      "el": "element", "ev": "event",
      "idx": "index", "btn": "button"
    };
    return expansions[shortName] || `${shortName}_descriptive`;
  }

  isLoopVar(name) {
    return ["i", "j", "k", "n"].includes(name);
  }
}

Advanced Tips

Run naming analysis as part of the CI pipeline to catch convention violations before code review. Create a project dictionary of approved abbreviations so the analyzer does not flag agreed upon domain terms. Prioritize renaming in public API surfaces first, as those names affect external consumers.

When to Use It?

Use Cases

Use Naming Analyzer when refactoring legacy codebases with inconsistent or unclear identifier names, when onboarding a team to a shared naming convention, when reviewing pull requests for naming quality, or when building linters that enforce project specific naming rules.

Related Topics

Code style linters like ESLint and Pylint, refactoring tools with rename support, clean code principles, code review checklists, and API design guidelines all complement naming analysis practices.

Important Notes

Requirements

Access to the source code's abstract syntax tree for accurate identifier extraction. A configured set of naming rules matching project conventions. Language specific parsers, since naming conventions differ across languages.

Usage Recommendations

Do: configure rules to match your team's conventions before running analysis. Focus on public interfaces and frequently read code paths where naming has the highest impact. Treat suggestions as starting points for discussion rather than mandatory changes.

Don't: enforce rigid naming rules on third party code or generated files that follow different conventions. Flag every single letter variable, as loop counters like i and j are universally understood. Apply naming changes across a large codebase in a single commit, making the diff difficult to review.

Limitations

Automated analysis evaluates structural patterns but cannot fully assess whether a name describes its semantic purpose accurately. Domain specific terminology that appears vague to generic analysis may be clear within a specialized codebase. Renaming published API identifiers requires careful versioning to avoid breaking consumers.