feat: unused declarations diagnostics#2245
Draft
hongjr03 wants to merge 52 commits intoMyriad-Dreamin:mainfrom
Draft
feat: unused declarations diagnostics#2245hongjr03 wants to merge 52 commits intoMyriad-Dreamin:mainfrom
hongjr03 wants to merge 52 commits intoMyriad-Dreamin:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.