Command Line Tools
analyze code
analyze code
Section titled “analyze code”Analyzes code quality in your Wheels application, checking for best practices, potential issues, and code standards compliance.
Synopsis
Section titled “Synopsis”wheels analyze code [--path=<path>] [--fix] [--format=<format>] [--severity=<severity>] [--report] [--verbose]CommandBox Parameter Syntax
Section titled “CommandBox Parameter Syntax”This command supports multiple parameter formats:
- Named parameters:
name=value(e.g.,path=app/controllers,format=json) - Flag parameters:
--flagequalsflag=true(e.g.,--fixequalsfix=true) - Flag with value:
--flag=valueequalsflag=value(e.g.,--path=app/models)
Parameter Mixing Rules:
ALLOWED:
- All flags:
wheels analyze code --fix --report --verbose - Flags with values:
wheels analyze code --path=app/models --format=json - Named + flags:
path=app/controllers format=json --fix
NOT ALLOWED:
- Positional parameters: This command does not support positional parameters
Recommendation: Use flag syntax for consistency: wheels analyze code --path=app/models --fix --format=json
Parameters
Section titled “Parameters”| Parameter | Description | Default |
|---|---|---|
--path | Path to analyze (directory or file) | app |
--fix | Attempt to fix issues automatically | false |
--format | Output format: console, json, junit | console |
--severity | Minimum severity level: info, warning, error | warning |
--report | Generate HTML report | false |
--verbose | Show detailed progress during analysis | false |
Description
Section titled “Description”The analyze code command performs comprehensive code quality analysis on your Wheels application. It automatically excludes framework files and focuses only on your application code.
What It Checks
Section titled “What It Checks”- Code Complexity: Cyclomatic complexity and function length metrics
- Code Style: Line length, indentation, trailing spaces, tabs vs spaces
- Security Issues: SQL injection risks, hardcoded credentials, evaluate() usage
- Performance: N+1 queries, missing query caching, SELECT * usage
- Best Practices: Variable scoping, output attributes, code organization
- Wheels Conventions: Controller/Model naming, validations, filters
- Code Smells: Long parameter lists, nested loops, TODO comments
- Duplicate Code: Detection of similar code blocks (30+ lines by default)
- Deprecated Functions: Outdated Wheels function usage
Grading System
Section titled “Grading System”The analyzer assigns a health score (0-100) and letter grade (A-F) based on:
- A (90-100): Excellent code quality
- B (80-89): Good code quality with minor issues
- C (70-79): Acceptable code quality, needs improvement
- D (60-69): Poor code quality, significant refactoring needed
- F (0-59): Critical issues, immediate attention required
Examples
Section titled “Examples”Basic code analysis
Section titled “Basic code analysis”Analyzes all code in the app/ directory by default:
wheels analyze codeAnalyze specific directory
Section titled “Analyze specific directory”# Flag syntax (recommended)wheels analyze code --path=app/controllers
# OR namedwheels analyze code path=app/controllersAnalyze specific file
Section titled “Analyze specific file”# Flag syntax (recommended)wheels analyze code --path=app/models/User.cfc
# OR namedwheels analyze code path=app/models/User.cfcAuto-fix issues
Section titled “Auto-fix issues”Automatically fixes issues like trailing spaces, tabs, and missing var scoping:
wheels analyze code --fixGenerate HTML report
Section titled “Generate HTML report”Creates a detailed HTML report with visualizations:
wheels analyze code --reportReports are saved to reports/code-analysis-[timestamp].html
Analyze with JSON output for CI/CD
Section titled “Analyze with JSON output for CI/CD”wheels analyze code --format=jsonJUnit format for CI integration
Section titled “JUnit format for CI integration”wheels analyze code --format=junitCheck only errors (skip warnings and info)
Section titled “Check only errors (skip warnings and info)”wheels analyze code --severity=errorVerbose mode with progress indicators
Section titled “Verbose mode with progress indicators”wheels analyze code --verboseComprehensive analysis with all options
Section titled “Comprehensive analysis with all options”wheels analyze code --path=app/models --fix --report --verboseOutput Format
Section titled “Output Format”Console Output (Default)
Section titled “Console Output (Default)”Analyzing code quality with report and verbose output...
Configuration: Path: C:\Users\Hp\db_app\app\models\ Severity filter: warning Fix mode: enabled Output format: console Report generation: enabled
Scanning for files... + C:\Users\Hp\db_app\app\models\Model.cfcFound 1 files to analyzeAnalyzing file 1/1: C:\Users\Hp\db_app\app\models\Model.cfc File has 7 lines Running code style checks... Running security checks... Running performance checks... Running best practice checks... Running complexity analysis... Checking naming conventions... Detecting code smells... Checking for deprecated functions... Checking Wheels conventions... Found 0 issues total, 0 after severity filterAnalyzing: [==================================================] 100% Complete!Starting duplicate code detection...Detecting duplicate code... Found 0 duplicate blocks
Applying automatic fixes...Fixed 0 issues automatically
Re-analyzing after fixes with verbose output...Scanning for files... + C:\Users\Hp\db_app\app\models\Model.cfcFound 1 files to analyzeAnalyzing file 1/1: C:\Users\Hp\db_app\app\models\Model.cfc File has 7 lines Running code style checks... Running security checks... Running performance checks... Running best practice checks... Running complexity analysis... Checking naming conventions... Detecting code smells... Checking for deprecated functions... Checking Wheels conventions... Found 0 issues total, 0 after severity filterAnalyzing: [==================================================] 100% Complete!Starting duplicate code detection...Detecting duplicate code... Found 0 duplicate blocks
Scanning for files... Found 51 files to analyzeAnalyzing: [==================================================] 100% Complete!Detecting duplicate code... Found 0 duplicate blocks
================================================== CODE QUALITY REPORT==================================================
Excellent code quality==================================================
Code Metrics--------------------------------------------------Files Analyzed: 51Total Lines: 1184Functions: 51Avg Complexity: 0Duplicate Blocks: 0Code Smells: 0Deprecated Calls: 0
Grade: A (100/100)Excellent! No issues found. Your code is pristine!Generating HTML report...HTML report generated: C:\Users\Hp\db_app\reports\code-analysis .....htmlJSON Output
Section titled “JSON Output”Structured JSON with all metrics, issues, and file details for programmatic processing.
JUnit Output
Section titled “JUnit Output”XML format compatible with CI/CD tools like Jenkins, GitLab CI, and GitHub Actions.
Configuration
Section titled “Configuration”Create a .wheelscheck file in your project root to customize rules:
{ "rules": { "max-line-length": 120, "indent-size": 4, "max-function-length": 50, "max-function-complexity": 10, "max-file-length": 500, "duplicate-threshold": 30, "naming-convention": "camelCase" }, "features": { "duplicateDetection": true, "complexityAnalysis": true, "wheelsConventions": true, "codeSmells": true }, "exclude": [ "custom/path/to/exclude/", "generated/" ]}Excluded Directories
Section titled “Excluded Directories”The analyzer automatically excludes:
- Wheels framework files (
vendor/wheels/,wheels/) - Third-party dependencies (
vendor/,node_modules/) - Test frameworks (
testbox/,tests/) - Build artifacts (
build/,dist/) - Version control (
.git/,.svn/) - System directories (
WEB-INF/,CFIDE/) - Generated files (
*.min.js,*.min.css)
Auto-fixable Issues
Section titled “Auto-fixable Issues”The following issues can be automatically fixed with the --fix flag:
- Trailing whitespace
- Tab characters (converted to spaces)
- Missing var scoping in functions
- Missing output attribute on components
Integration with CI/CD
Section titled “Integration with CI/CD”GitHub Actions
Section titled “GitHub Actions”- name: Code Analysis run: | wheels analyze code --format=junit --severity=errorGitLab CI
Section titled “GitLab CI”code_quality: script: - wheels analyze code --format=json > code-quality.json artifacts: reports: codequality: code-quality.jsonJenkins
Section titled “Jenkins”stage('Code Analysis') { steps { sh 'wheels analyze code --format=junit' junit 'code-analysis-results.xml' }}Performance Considerations
Section titled “Performance Considerations”- Small projects (< 100 files): Analysis completes in seconds
- Medium projects (100-500 files): 30-60 seconds typical
- Large projects (500+ files): Several minutes, use
--verboseto track progress - HTML report generation adds 5-30 seconds depending on project size
- Run analysis regularly during development to catch issues early
- Use
--fixfor quick cleanup before commits - Include analysis in pre-commit hooks or CI pipelines
- Start with
--severity=errorand gradually include warnings - Review the HTML report for visual insights into code quality
- Use the grade as a benchmark to track improvement over time
- Focus on fixing high-complexity functions first for maximum impact
Troubleshooting
Section titled “Troubleshooting”No files found to analyze
Section titled “No files found to analyze”- Ensure you’re in a Wheels application root directory
- Check that the
app/directory exists - Verify path permissions
Analysis taking too long
Section titled “Analysis taking too long”- Use
--pathto analyze specific directories - Add frequently changing directories to exclude list
- Consider splitting analysis across multiple runs
Fix not working
Section titled “Fix not working”- Some issues require manual intervention
- Check file permissions for write access
- Review the specific fix recommendations in the output