New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

codeinsights

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codeinsights

Concise code quality analysis CLI tool

latest
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Code Analysis Tools

A suite of tools for analyzing and improving codebase quality.

Features

  • Import Analysis: Find unused imports in JavaScript and TypeScript files
  • Codebase Analysis: Analyze code structure, documentation quality, and identify redundant patterns
  • Complexity Analysis: Identify complex code and suggest refactoring opportunities

Directory Structure

scripts/
  ├── config/              # Shared configuration
  │   └── analysis_config.js   # Configuration management
  │
  ├── utils/               # Shared utilities
  │   ├── file_utils.js        # File finding utilities
  │   ├── code_analysis.js     # Code pattern analysis utilities
  │   ├── code_preprocessor.js # Code preprocessing utilities
  │   ├── report_generator.js  # Report generation utilities
  │   └── index.js             # Entry point for all utilities
  │
  ├── analyze_all.js       # Main entry point for running all analyses
  ├── analyze_codebase.js  # Codebase structure analysis
  ├── check_imports.js     # Import usage analysis
  └── refactor_complexity.js # Code complexity analysis and refactoring suggestions

Usage

Installation

npm install

Running Analysis

Run comprehensive analysis:

npm run analyze

Or run individual checks:

# Check for unused imports
npm run check-imports

# Analyze codebase structure
npm run analyze-codebase

# Analyze code complexity
npm run analyze-complexity

Command Line Options

All scripts support the following options:

  • --exclude-dirs: Comma-separated list of directories to exclude (default: node_modules,.git)
  • --extensions: Comma-separated list of file extensions to analyze (default: .js,.ts,.jsx,.tsx)
  • --reports-dir: Directory to save reports (default: reports)

Complexity analysis also supports:

  • --complexity-threshold: Cyclomatic complexity threshold (default: 10)
  • --max-function-length: Maximum function length in statements (default: 30)

Reports

All reports are saved to the reports directory as JSON files:

  • unused_imports_report.json: List of unused imports
  • codebase_analysis_report.json: Codebase structure analysis
  • refactoring_suggestions.json: Complexity analysis and refactoring suggestions

Architecture

The codebase follows these architectural principles:

  • Modularity: All functionality is split into small, focused modules
  • DRY (Don't Repeat Yourself): Common functionality is extracted into shared utilities
  • Configuration Management: Centralized configuration with sensible defaults
  • Standardized Reporting: Consistent report generation and formatting

CodeStats

A concise code analysis CLI tool that helps you improve your codebase by analyzing:

  • Code Complexity: Find complex functions and code patterns
  • Documentation: Check JSDoc completeness
  • Redundant Patterns: Identify duplicated code
  • Unused Imports: Find unused imports in your code

Installation

# Global installation 
npm install -g codestats

# Or run with npx
npx codestats

Usage

# Analyze the current project directory
codestats

# Analyze a specific directory
codestats -d ./my-project

# Specify extensions to analyze
codestats -e .js,.ts,.jsx,.tsx

# Exclude specific directories
codestats -x node_modules,.git,dist,build

# Quiet mode (minimal output)
codestats -q

# Help
codestats --help

Features

Comprehensive CLI Output

  • Color-coded summary for quick assessment
  • Detailed analysis showing specific issues
  • Actionable recommendations based on findings
  • No external reports - everything happens in your terminal
  • Fast analysis with minimal dependencies

Comprehensive Analysis

  • Function complexity scoring
  • Documentation completeness checking
  • Redundant code pattern detection
  • Unused import identification

Example Output

═════════════════════════════════════
📊 CODEBASE ANALYSIS SUMMARY
═════════════════════════════════════
Files Analyzed: 42
Average Complexity: 5.3
Complex Functions: 8/127
Documentation: 62.5%
Undocumented Functions: 24
Redundant Patterns: 6
Potential LOC Savings: 83
Unused Imports: 12
═════════════════════════════════════

🔥 MOST COMPLEX FUNCTIONS:
1. processData in main.js:127 [18]
2. renderComponent in component.js:48 [16]
3. calculateTotals in utils.js:92 [14]
4. validateInput in validators.js:35 [13]
5. parseConfig in config.js:65 [12]

📁 MOST COMPLEX FILES:
1. main.js - 12.5 avg complexity (8 functions)
2. validators.js - 9.3 avg complexity (5 functions)
3. utils.js - 7.8 avg complexity (12 functions)

📝 UNDOCUMENTED FUNCTIONS:
1. formatData in formatter.js:25
2. validateInput in validator.js:42
3. parseConfig in config.js:18
  ... and 21 more

🔄 REDUNDANT CODE PATTERNS:
1. utility pattern appears 5 times (41 lines savable)
   Snippet: function formatDate(date) { return date.toISOString().split('T')[0]; }
   Appears in:
   - utils.js:45
   - helpers.js:23
   - formatter.js:12

2. operation pattern appears 3 times (24 lines savable)
   Snippet: data.filter(item => item.active).map(item => item.value).reduce((a, b) => a + b, 0)
   Appears in:
   - main.js:89
   - reports.js:56
   - dashboard.js:102

📦 UNUSED IMPORTS:
main.js:
  - fs (line 3)
  - path (line 4)
utils.js:
  - moment (line 2)
  ... and 9 more

💡 RECOMMENDATIONS:
• Refactor complex functions to improve maintainability
• Improve documentation coverage with JSDoc comments
• Extract repeated patterns into shared utilities
• Remove unused imports to clean up code

Project Structure

bin/
  └── index.js           # CLI entry point
lib/
  ├── analyzer.js        # Main analysis orchestration
  ├── core.js            # Core analysis functions
  └── utils/             # Utility functions
      ├── complexity.js  # Complexity calculation
      └── parser.js      # Code parsing utilities

License

MIT

Keywords

code-analysis

FAQs

Package last updated on 17 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts