AUTOSAR Checker
Real-time AUTOSAR compliance checker for C/C++ code in Visual Studio Code. This extension helps you maintain AUTOSAR coding standards by flagging violations as you write code, similar to a spell checker.
Features
- Real-time Diagnostics: Get instant feedback on AUTOSAR violations as you type
- Checker Numbers: Each warning displays the specific AUTOSAR rule code (e.g., A1-1-1, M0-1-1)
- Quick Fixes: Suppress warnings with one click using code actions
- C/C++ Support: Works with
.c, .cpp, .h, .hpp files
- Non-intrusive: Similar to spell checking - fix now or suppress later
Supported AUTOSAR Rules
Complete Coverage: This extension now supports ALL 400+ AUTOSAR C++14 rules across all categories!
📘 See AUTOSAR_RULES_COMPLETE_REFERENCE.md for the complete rules catalog.
Rule Categories (26 Total)
- Category 0: Language Independent Issues (18 rules) - Unused code, dead code, unreachable code
- Category 1: General (1 rule) - C++14 Standard conformance
- Category 2: Lexical Conventions (24 rules) - Character sets, comments, literals, identifiers
- Category 3: Basic Concepts (23 rules) - ODR, linkage, types, file structure
- Category 4: Standard Conversions (9 rules) - Type conversions, nullptr usage
- Category 5: Expressions (60+ rules) - Operators, casts, lambdas, pointer arithmetic
- Category 6: Statements (22 rules) - Control flow, loops, switch statements
- Category 7: Declarations (24 rules) - const/constexpr, enums, namespaces
- Category 8: Declarators (25+ rules) - Function parameters, initialization, smart pointers
- Categories 9-12: Classes (40+ rules) - Inheritance, virtual functions, special members
- Category 13: Overloading (12 rules) - Operator overloading, conversions
- Category 14: Templates (8 rules) - Template specialization, constraints
- Category 15: Exception Handling (30+ rules) - Exception safety, noexcept, catch handlers
- Category 16: Preprocessing (17 rules) - Include guards, macros, #include directives
- Categories 17-26: Library Rules (70+ rules) - STL usage, memory management, containers
Implementation Status
- ✅ ~150 rules: Implemented with pattern-based detection
- 🔄 ~100 rules: Implemented (requires enhanced analysis)
- 📋 ~150 rules: Documented (requires compiler/AST integration)
Quick Rule Reference
Common rules checked:
- A0-1-1 through A0-1-6: Unused variables, parameters, types
- A1-1-1: ISO C++14 conformance, no deprecated features
- A2-3-1: Basic source character set only
- A2-10-1: No identifier hiding (variable shadowing)
- A2-11-1: No volatile keyword
- A2-13-4: String literals assigned to const char* only
- A3-1-1: Header files must have include guards
- A3-9-1: Use fixed-width integer types from
- A4-10-1: Use nullptr (not NULL or 0)
- A5-0-3: Maximum two levels of pointer indirection
- A5-1-1: No magic numbers (use named constants)
- A5-2-2: No C-style casts
- A5-2-3: No const_cast removing const
- A5-2-4: No reinterpret_cast
- A6-6-1: No goto statements
- A7-1-1: Use const/constexpr for immutable data
- A7-2-3: Enumerations shall be scoped enum classes
- A13-2-1: Assignment operator must return *this
- A15-1-1: Only throw std::exception derived types
- A18-1-1: No C-style arrays (use std::array/std::vector)
- A18-5-2: No explicit new/delete (use smart pointers)
- M0-1-1: No unreachable code
- M0-1-3: No unused variables
- And 380+ more...
Usage
Real-time Checking
- Open any C/C++ file
- The extension automatically analyzes your code
- Violations appear as warnings/errors with squiggly underlines
- Hover over warnings to see the AUTOSAR rule code and description
Suppressing Warnings
When you see a warning, click the lightbulb icon or press Ctrl+. (Windows/Linux) or Cmd+. (Mac) to see quick fixes:
- Suppress on this line: Adds
// autosar-disable-line <rule-code> at the end of the line
- Suppress on next line: Adds
// autosar-disable-next-line <rule-code> above the line
Example:
// autosar-disable-next-line A1-1-1
goto error_handler; // This warning is suppressed
int value = 42; // autosar-disable-line A5-1-1 - Magic number suppressed
Manual Check
Run the command AUTOSAR: Check Current File from the Command Palette (Ctrl+Shift+P).
Installation
From Source
- Clone this repository
- Run
npm install to install dependencies
- Run
npm run compile to build the extension
- Press
F5 to open a new VS Code window with the extension loaded
Package as VSIX
npm install -g @vscode/vsce
vsce package
Then install the .vsix file in VS Code.
Configuration
Currently, all AUTOSAR rules are enabled by default. Future versions will support:
- Rule-level configuration
- Custom severity levels
- Project-specific rule sets
Extension Development
Prerequisites
- Node.js (v16 or higher)
- Visual Studio Code
- npm
Setup
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch mode for development
npm run watch
Testing
# Run tests
npm test
# Compile tests
npm run compile-tests
Debugging
- Open this project in VS Code
- Press
F5 to start debugging
- A new VS Code window will open with the extension loaded
- Open a C/C++ file to test the extension
Project Structure
.
├── src/
│ ├── extension.ts # Extension entry point
│ ├── diagnosticProvider.ts # Real-time AUTOSAR checking
│ ├── codeActionProvider.ts # Quick fix actions
│ └── autosarRules.ts # AUTOSAR rule definitions
├── dist/ # Compiled output
├── package.json # Extension manifest
└── tsconfig.json # TypeScript configuration
How It Works
- Diagnostic Provider: Monitors document changes and analyzes code against AUTOSAR rules using regex patterns
- Code Action Provider: Offers quick fixes to suppress warnings when requested
- Rule Definitions: Each AUTOSAR rule has a pattern, severity, and message
- Suppression: Comments with specific format are recognized to ignore violations
Extending the Extension
Adding New AUTOSAR Rules
Edit src/autosarRules.ts and add new rules to the autosarRules array:
{
code: 'A1-2-3',
message: 'Your rule description',
severity: 'warning', // 'error', 'warning', or 'info'
pattern: /your-regex-pattern/,
description: 'Detailed explanation'
}
Customizing Severity
Change the severity field in the rule definition to 'error', 'warning', or 'info'.
Limitations
- Pattern-based detection (not full AST analysis)
- Limited to regex-matchable violations
- May have false positives for complex code patterns
- Does not perform deep semantic analysis
Future Enhancements
- [ ] Integration with external AUTOSAR checkers
- [ ] AST-based analysis for better accuracy
- [ ] Configurable rule sets per project
- [ ] Custom rule definitions
- [ ] Batch checking for entire projects
- [ ] Export violation reports
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
MIT
Support
For issues, questions, or suggestions, please open an issue on the GitHub repository.
Note: This extension provides basic AUTOSAR compliance checking. For comprehensive analysis, consider using dedicated static analysis tools like Axivion, LDRA, or Parasoft C/C++test in conjunction with this extension.