Skip to content

Adds a script for removing unused diagnostics - #44324

Merged
Orta Therox (orta) merged 3 commits into
microsoft:mainfrom
orta:remove_unused_diags
Aug 24, 2021
Merged

Adds a script for removing unused diagnostics#44324
Orta Therox (orta) merged 3 commits into
microsoft:mainfrom
orta:remove_unused_diags

Conversation

@orta

Copy link
Copy Markdown
Contributor

This adds a script which only runs on linux boxes, that searches the codebase for every diagnostic and lets you know if nothing is found.

TODO: Add to CI.

@orta

Copy link
Copy Markdown
Contributor Author

Screen Shot 2021-06-03 at 4 43 32 PM

I can use findstr to check

const diagName = line.split(":")[0].trim();

try {
execSync(`grep -rnw 'src' -e 'Diagnostics.${diagName}'`).toString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's probably a platform-independent package on npm that does recursive file string search, although feature-detecting grep vs findstr would work too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wes thinks ripgrep ( https://www.npmjs.com/package/vscode-ripgrep ) should be a reasonable tradeoff here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the offensive huge cost of this you could just grep all lines that include Diagnostics., print them to a temp file, then search through this file. Also, even if the names are well behaved, it would be better to add -F. Also, -n is redundant AFAICT.

(And doing it with a grep library seems like an overkill too...)

"category": "Message",
"code": 95001
},
"Convert function '{0}' to class": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm almost certain this message and the ones that follow are used in codefixes. I wonder why our fourslash tests don't fail with them gone.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well...early in a release's development is the best time to try something like this.

Orta Therox (@orta) you want to try merging this early on Monday to see whether it breaks anything?

(I think Eli Barzilay (@elibarzilay) 's right about grep -- almost all the team can run this script in an environment with grep if they need to.)

@orta

Copy link
Copy Markdown
Contributor Author

Yeah, lets do it

@orta
Orta Therox (orta) merged commit 41dcad0 into microsoft:main Aug 24, 2021
Cassandra Choi (BobobUnicorn) pushed a commit to BobobUnicorn/TypeScript that referenced this pull request Oct 24, 2021
* Adds a script for removing unused diagnostics

* Accidentally deleted the wrong one
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants