Skip to content

Remove unused exports & dead code (using Knip) - #56817

Merged
Jake Bailey (jakebailey) merged 30 commits into
microsoft:mainfrom
webpro:remove-unused-exports
Jun 27, 2024
Merged

Jake Bailey (jakebailey) merged 30 commits into
microsoft:mainfrom
webpro:remove-unused-exports

Conversation

@webpro

@webpro Lars Kappert (webpro) commented Dec 17, 2023 •

Copy link
Copy Markdown
Contributor

Fixes #56818

When running Knip with a bit of config (see knip.jsonc) I get these results:

$ npx knip
Unused files (1)
scripts/failed-tests.d.cts
Unused devDependencies (1)
@types/microsoft__typescript-etw  package.json
Unresolved imports (1)
./cancellationToken  src/tsserver/nodeServer.ts:360:33
Unused exports (13)
cleanTestDirs                 function  scripts/build/tests.mjs:177:23                  
writeTestConfigFile           function  scripts/build/tests.mjs:195:17                  
coverageDir                   unknown   scripts/build/tests.mjs:23:14                   
ROOT_DIR                      unknown   scripts/eslint/tests/support/RuleTester.cjs:4:16
FILENAME                      unknown   scripts/eslint/tests/support/RuleTester.cjs:5:16
enableDeprecationWarnings     unknown   src/deprecatedCompat/deprecate.ts:10:12         
setEnableDeprecationWarnings  function  src/deprecatedCompat/deprecate.ts:12:17         
createDeprecation             function  src/deprecatedCompat/deprecate.ts:48:17         
sanitizeLog                   function  src/harness/tsserverLogger.ts:111:17            
sanitizeLibFileText           function  src/harness/tsserverLogger.ts:141:17            
createLoggerWritingToConsole  function  src/harness/tsserverLogger.ts:96:17             
serializeMultiMap             function  src/harness/watchUtils.ts:157:17                
server                        unknown   src/typingsInstaller/_namespaces/ts.ts:7:9
Unused exports in namespaces (1)
server  unknown  src/typescript/_namespaces/ts.ts:8:9
Unused exported types (3)
Logger           interface  src/harness/tsserverLogger.ts:30:18
TestFileWatcher  interface  src/harness/watchUtils.ts:15:18    
TestFsWatcher    interface  src/harness/watchUtils.ts:20:18
Duplicate exports (2)
local, default                            Herebyfile.mjs       
getJSDocTagCompletionDetails, getJSDo...  src/services/jsDoc.ts

There are a few false positives, but I think the results are still quite useful.

Then I ran npx knip --fix to remove the export keywords for unused exports, and then I went into the file to check it and remove the remaining dead code. Running the tests does not give issues.

Let me know if I should remove Knip + config itself again, I totally understand you might not be eager to introduce new dependencies. Alternatively, I'm happy to extend the work until it reports no issues and then you can keep using this (in CI) it to prevent future regressions.

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug Housekeeping Housekeeping PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unused exports & dead code (using Knip)

5 participants