LINE 推出的 ts-remove-unused,移除掉沒有用到的程式碼

出國前看到的東西,LINEGitHub 上發表了整理 TypeScript 程式碼的套件:「Show HN: ts-remove-unused – Remove unused code from your TypeScript project (github.com/line)」,專案在「line/ts-remove-unused」這邊:

Remove unused code from your TypeScript project

不過 Hacker News 上的反應其實頗差,其中一個原因是預設值不太友善,沒有好的 ignore path 設定,test case 這種從 entry point 不會接觸到的就會被誤判了:

It deleted 100s of files, most of which were Jest test files, and potentially all of which were a mistake. I restored them all with `git restore $(git ls-files -d)`.

另外改出來的東西是爛的:

I then ran `tsc` on the remaining _modified_ files and `Found 3920 errors in 511 files.`

另外有不少人抱怨預設不是 dry run mode,被砍了一堆東西:

You should switch the default to not delete any files and modify/remove the files only with some flag (--dry-run=false, --rm, --delete, etc). I just deleted all files accidentally in a monorepo :D Luckily I didn't had any uncommitted changes and could recover using git

反倒是有人提了另外一個已經在停止發展,但運作的很好的 project:

I've been using ts-prune[1] for years at this point. The project is in maintenance mode but works fine so I've kept using it. I've been looking into Knip[2] which is recommended by the authors of ts-prune though it's been slow mostly because there's little incentive with the current tool working fine.

[1]: https://github.com/nadeesha/ts-prune

[2]: https://github.com/webpro-nl/knip

這邊反而值得看看...

Node.js 實驗性支援 type 的語法 (但不會檢查)

Hacker News 上看到「Node.js adds experimental support for TypeScript (github.com/nodejs)」這個,標題有點誤導就是了,GitHub 上面的標題比較正確:「module: add --experimental-strip-types」。

從說明可以看到 --experimental-strip-types 參數只是接受 type 語法,但不會檢查:

It is possible to execute TypeScript files by setting the experimental flag --experimental-strip-types.

Node.js will transpile TypeScript source code into JavaScript source code.

During the transpilation process, no type checking is performed, and types are discarded.

目前的版本離跑 TypeScript 還有段距離,不過算是個有趣的開頭:

At least initially in this PR no trasformation is performed, meaning that using Enum, namespaces etc... will not be possible.

不確定官方打算要支援 TypeScript,還是只是個人作個實驗看看?

vim-polyglot 把預設的 tabstop 改成 2

發現 VimMakefile 類的檔案 (包括 GNUmakefile) 的 tab 都變成 2 格,交叉測了一下發現是 vim-polyglot 造成的:「Polyglot is wrongly setting tabstop to 2 on several file types #648」。

目前先用作者提到的方式 let g:polyglot_disabled = ["autoindent"] 解 (在首頁也有提到這個)。

目前看起來正常一些了...