code-analyzerx v1.0.0
Code Analyzer
A command-line tool to analyze code files and provide detailed statistics such as line count, word count, comment count, and code complexity.
Features
- Line Count: Total lines and non-empty lines in the file.
- Word Count: Total words in the file.
- Character Count: Total characters in the file.
- Comment Count: Number of single-line and multi-line comments.
- Keyword Frequency: Frequency of common keywords (e.g.,
if
,else
,for
,function
). - Function Detection: List of detected functions in the file.
- Code Complexity: Number of conditionals and loops.
- Export Results: Save analysis results to a JSON file.
- Visual Appeal: Colorful console output and formatted tables.
Installation
You can install the package globally using npm:
npm install -g code-analyzer
Usage
Run the tool from the command line by passing the path to the file you want to analyze:
code-analyzer <file-path>
Example
code-analyzer ./src/index.js
Output
Code Analysis Results:
File Path: ./src/index.js
File Type: .js
Total Lines: 120
Non-Empty Lines: 90
Total Words: 500
Total Characters: 3000
Comment Count: 15
Code Complexity (Conditionals/Loops): 8
Keyword Frequency: { if: 5, else: 3, for: 2, while: 1, function: 4, return: 3, const: 10, let: 5, var: 0 }
Functions Detected: 'main', 'calculate', 'render'
Summary:
Most Frequent Keyword: const (10 occurrences) Total Functions Detected: 3 Code Complexity Rating: Medium Analysis completed in 0.45 seconds.
## Options
- `--verbose`: Display additional details, such as the full list of comments.
- `--export-csv`: Export results to a CSV file.
- `--help`: Show usage instructions.
### Example with Options
```bash
code-analyzer ./src/index.js --verbose --export-csv
Development
Installation
Clone the repository:
git clone https://github.com/elyashium/CLI-code_analyser
Navigate to the project directory:
cd code-analyzer
Install dependencies:
npm install
Running Locally
To test the package locally, use npm link:
npm link
Then run the tool:
code-analyzer ./path/to/your/file.js
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
Create a new branch:
git checkout -b feature/your-feature
Commit your changes:
git commit -m "Add your feature"
Push to the branch:
git push origin feature/your-feature
Open a pull request.
Dependencies
- chalk: For colorful console output.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Your Name
GitHub
Support
If you find this tool useful, consider giving it a ⭐️ on GitHub!
4 months ago