Skip to content

Conversation

@taronsung
Copy link
Contributor

Summary

Fix for linting error when opening files via virtual filesystems (WebDAV, kio-fuse, etc.).

Closes #1370

Problem

When using editors like Kate on KDE Plasma with WebDAV-mounted files, the document URI uses a non-file: scheme (e.g., kio-fuse://...). The linter would throw:

TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

This occurred because fileURLToPath() from Node.js only accepts file: URIs.

Solution

Added a safeFileURLToPath helper function that:

  1. Checks if the URI uses the file: protocol
  2. Returns the file path for valid file: URIs
  3. Returns null for non-file: URIs or invalid URIs

When the document path cannot be determined, linting proceeds without adding the document's directory to the source paths. This means ShellCheck's --source-path will only include explicitly configured paths, but linting will still work for the document content itself.

Testing

Added a test case to verify that non-file: URI schemes are handled gracefully without throwing errors.

Notes

  • Linting still works for non-file: URIs - it just won't include the document's directory in the source search path
  • Users with such setups can explicitly configure sourcePaths in their LSP client settings if needed

When opening files via virtual filesystems (WebDAV, kio-fuse, etc.),
the document URI may not use the file: scheme. Previously, calling
fileURLToPath() on such URIs would throw ERR_INVALID_URL_SCHEME.

This change adds a safeFileURLToPath helper that:
- Returns the file path for valid file: URIs
- Returns null for non-file URIs or invalid URIs
- Allows linting to proceed without the document directory in source paths

Closes bash-lsp#1370
@skovhus
Copy link
Collaborator

skovhus commented Jan 29, 2026

Thanks, can you just run pnpm lint to apply formatting?

@skovhus skovhus enabled auto-merge January 29, 2026 12:43
@skovhus skovhus merged commit c6b9bda into bash-lsp:main Jan 29, 2026
3 checks passed
@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.59%. Comparing base (13a26c2) to head (84ec668).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
server/src/shellcheck/index.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1371      +/-   ##
==========================================
+ Coverage   80.55%   80.59%   +0.03%     
==========================================
  Files          29       29              
  Lines        1502     1510       +8     
  Branches      371      373       +2     
==========================================
+ Hits         1210     1217       +7     
- Misses        234      235       +1     
  Partials       58       58              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error while linting: TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file

2 participants