Path Checker
A VS Code extension that validates file paths in your code and highlights paths that don't exist in the workspace.
Features
🔍 Automatic Path Detection: Detects file paths in various formats:
- Import/require statements:
import './file', require('./file')
- Quoted paths:
"./path/to/file", '../path/to/file'
- Relative paths:
./file, ../folder/file
- Absolute paths:
/absolute/path/to/file
⚠️ Visual Feedback: Invalid paths are highlighted with:
- Red wavy underline
- Hover tooltip showing "Path not found in workspace"
- Subtle background highlight
⚙️ Configurable: Customize the extension behavior:
- Enable/disable path checking
- Specify file extensions to check
- Customize decoration color
🚀 Smart Resolution: Automatically resolves paths:
- Relative to current file
- Relative to workspace root
- With common file extensions (.js, .ts, .jsx, .tsx, etc.)
- Index files (index.js, index.ts, etc.)
Installation
From Source
- Clone this repository
- Run
npm install to install dependencies
- Run
npm run compile to build the extension
- Press F5 in VS Code to launch the Extension Development Host
From VSIX (when published)
- Download the
.vsix file
- In VS Code, go to Extensions view
- Click "..." menu → "Install from VSIX..."
- Select the downloaded file
Usage
Once installed, the extension automatically activates when you open a file. It will:
- Scan the file for path references
- Validate each path against your workspace
- Highlight invalid paths with a red wavy underline
- Show a tooltip when you hover over invalid paths
Example
// Valid path - no highlight
import { Component } from './components/MyComponent';
// Invalid path - highlighted in red
import { Utils } from './utils/nonexistent';
// Also works with require
const config = require('./config.json'); // Valid
const missing = require('./missing.js'); // Invalid
Extension Settings
This extension contributes the following settings:
pathChecker.enabled: Enable/disable path checking (default: true)
pathChecker.fileExtensions: Array of file extensions to check (default: ["js", "ts", "jsx", "tsx", "vue", "py", "java", "go", "rs", "cpp", "c", "h", "md", "html", "css", "json", "xml", "svg", "yaml", "yml", "toml"])
pathChecker.decorationColor: Color for invalid path decorations (default: "#ff0000")
Configuration Example
{
"pathChecker.enabled": true,
"pathChecker.fileExtensions": ["js", "ts", "jsx", "tsx"],
"pathChecker.decorationColor": "#ff6b6b"
}
How It Works
- Detection: The extension uses regular expressions to detect various path patterns in your code
- Validation: Each detected path is resolved relative to:
- The current file's directory
- The workspace root
- File System Check: The extension checks if the resolved path exists on the file system
- Smart Extensions: If a path has no extension, the extension tries common extensions (.js, .ts, etc.) and index files
- Decoration: Invalid paths are decorated with a red wavy underline and hover tooltip
Known Limitations
- Only checks paths in text files (not in binary files)
- May not detect all path formats (e.g., dynamic paths constructed at runtime)
- Performance may be affected in very large files with many paths
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
MIT
Release Notes
0.0.1
Initial release of Path Checker:
- Path detection for imports, requires, and file references
- Visual highlighting of invalid paths
- Configurable settings
- Support for multiple file types
| |