-
Notifications
You must be signed in to change notification settings - Fork 120
feat: unused declarations diagnostics #2245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is an excellent and comprehensive pull request that introduces dead code detection to the linter. The implementation is well-structured, splitting the logic into collection, analysis, and diagnostics. The handling of cross-file references is a great addition that will prevent many false positives. The quick-fix code actions are also very well thought out and will significantly improve the user experience. I have one minor suggestion to improve code readability.
4443336 to
5624e5f
Compare
…ting compiler/lint diagnostics
…iagnostic management
…mpiler diagnostics and a new `LintHook` for lint-specific diagnostics.
…, replacing individual handlers for diagnostics, linting, preview, and export.
…ector initialization.
…DiagnosticSeverity::HINT`.
- Add `lint.deadCode` settings (checkExported/checkParams/exceptions) - Thread DeadCodeConfig through Analysis and lint caching - Add `lint_file_with_dead_code_config` entrypoint in tinymist-lint
- Treat module-level exported symbols as exported when configured - De-duplicate decl diagnostics across scopes - Replace docstring suppression with a softer hint
- Emit Diagnostic.code for unused diagnostics and avoid message matching - Route dead-code code actions exclusively by Diagnostic.code - Update fixtures and snapshots (incl exported-mode)
Add settings keys and translations for checkExported/checkParams/exceptions.
5624e5f to
9fdf82a
Compare
This depends on and should be merged after #2244, #2250 and #2302.
This PR introduces dead code detection to the Typst linter, adding a dedicated module for collecting definitions, analyzing their usage, and emitting diagnostics for unused variables, functions, parameters, and exports. It integrates this analysis into the main linting pipeline with configurable rules and pattern-based exceptions, and extends the query engine to support cross-file reference resolution so that symbols used across modules are not mistakenly reported as unused. The implementation is backed by a comprehensive suite of fixtures and snapshot tests that cover arrays, destructuring, closures, conditionals, context blocks, cross-module usage, and fully-used scenarios.