Skip to content

Conversation

@hongjr03
Copy link
Contributor

@hongjr03 hongjr03 commented Nov 15, 2025

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.

@hongjr03 hongjr03 marked this pull request as ready for review November 15, 2025 17:46
@hongjr03 hongjr03 marked this pull request as draft November 15, 2025 17:48
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@hongjr03 hongjr03 marked this pull request as ready for review November 16, 2025 11:19
@hongjr03 hongjr03 force-pushed the feat/lint-dead-code branch 6 times, most recently from 4443336 to 5624e5f Compare December 15, 2025 14:09
@hongjr03 hongjr03 changed the title feat: lint dead code feat: unused expressions diagnostics Dec 16, 2025
- 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.
@hongjr03 hongjr03 changed the title feat: unused expressions diagnostics feat: unused declarations diagnostics Dec 16, 2025
@hongjr03 hongjr03 marked this pull request as draft December 17, 2025 09:22
@hongjr03 hongjr03 force-pushed the feat/lint-dead-code branch from 5624e5f to 9fdf82a Compare December 17, 2025 11:13
@hongjr03 hongjr03 marked this pull request as ready for review December 17, 2025 11:56
@hongjr03 hongjr03 marked this pull request as draft December 19, 2025 06:39
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.

1 participant