| name | code-formatting-after-ai-generation |
| description | Use when AI generates code and code cleanup/formatting is needed - removes unused imports, sorts imports alphabetically, removes unused methods, and adds missing Javadoc comments |
Code Formatting After AI Generation
Overview
This skill automatically formats and cleans up code after AI generates it. It ensures code quality by removing unused imports, sorting imports, removing unused methods, and adding missing documentation comments.
When to Use
- Immediately after AI generates any code
- When reviewing code before committing
- When code has inconsistent import organization
Core Actions
1. Remove Unused Imports
Detect and remove imports that are not used in the code.
Java: Use IDE or tools like google-java-format, SpotBugs
JavaScript/TypeScript: Use ESLint with no-unused-imports rule
Python: Use isort combined with IDE unused import detection
2. Sort Imports Alphabetically
Organize imports in alphabetical order.
Java:
import android.xxx;
import com.xxx;
import org.xxx;
JavaScript/TypeScript:
import React from 'react';
import { Button } from 'antd';
import lodash from 'lodash';
import { utils } from './utils';
import { config } from '@/config';
Python:
import os
import sys
import numpy as np
import pandas as pd
from . import models
from .utils import helper
3. Remove Unused Methods
Identify and remove private methods that are never called.
Detection approach:
- Use IDE warnings (IntelliJ IDEA, VSCode)
- Use static analysis tools
- Review code manually if tools unavailable
Important: Only remove methods that are:
private (not part of public API)
- Not used within the same class
- Not overriding any interface/base class method
4. Add Missing Comments
Add Javadoc-style comments to classes and methods that lack documentation.
Required for:
- All public classes
- All public/protected methods
- All methods with complex logic
Comment format:
public PageResult<MenuVO> getMenuList(Query query, PageRequest pageRequest) {
}
For classes:
public class MenuService {
}
For simple getters/setters: No comment needed
For constructors:
public MenuService(Long id) {
}
Quick Reference
| Language | Unused Import Tool | Import Sort Tool |
|---|
| Java | IDE / SpotBugs | google-java-format |
| JavaScript | ESLint | eslint-plugin-import |
| TypeScript | ESLint | eslint-plugin-import |
| Python | flake8 / isort | isort |
| Go | goimports | goimports |
Common Mistakes
- Removing used imports - Always verify usage before removal
- Removing public methods - Only remove private unused methods
- Over-commenting - Don't add comments to simple getters/setters
- Wrong sort order - Some languages require specific grouping before alphabetical
File Patterns to Skip
Do not format auto-generated files:
*_generated*.java
*.gen.ts
__pycache__/*
node_modules/*
- Build output directories