Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code problemMatcher-friendly reporter #438

Open
danvk opened this issue Jan 9, 2024 · 4 comments
Open

VS Code problemMatcher-friendly reporter #438

danvk opened this issue Jan 9, 2024 · 4 comments
Labels
feature request Feature request

Comments

@danvk
Copy link

danvk commented Jan 9, 2024

I'd like to have a VS Code Task for knip that has a problemMatcher. The output format of knip isn't the best for parsing. Here's an example of what I see:

$ pnpm lint:knip
Analyzing workspace ....
Unused devDependencies (1)
ts-node  package.json
Unused exports (3)
runFile        function  src/main.ts:10:23
runPrompt      function  src/main.ts:15:23
tokenToString  function  src/token.ts:10:17

Here's a problemMatcher that I've written that at least matches the "Unused exports" bit:

{
	"type": "npm",
	"script": "lint:knip",
	"label": "npm: lint:knip",
	"detail": "knip",
	"problemMatcher": {
		"owner": "tsc",
		"fileLocation": ["relative", "${workspaceFolder}"],
		"pattern": [
			{
				"regexp": "^([^\\s].*) \\(\\d+\\)$",
				"message": 1
			},
			{
				"regexp": "([^ ]+) +([^ ]+) +([^:]+):(\\d+):(\\d+)",
				"file": 3,
				"line": 4,
				"column": 5,
				"loop": true
			}
		]
	}
}

This works pretty well:

image

But it's a bit of a bummer that I had to write these regexes and that there aren't line numbers for the unused devDependencies.

So call this a feature request for a new reporter that's compatible with one of VS Code's built-in problem matchers, for example "tsc" or "eslint".

@danvk danvk added the feature request Feature request label Jan 9, 2024
@webpro
Copy link
Owner

webpro commented Jan 9, 2024

The output format of knip isn't the best for parsing.

Did you see the JSON reporter? https://knip.dev/features/reporters#json

This works pretty well:

Nice! Great to see Knip used like this.

there aren't line numbers for the unused devDependencies

That's a good RFC.

So call this a feature request for a new reporter that's compatible with one of VS Code's built-in problem matchers, for example "tsc" or "eslint".

What would be the best way to go about this? Use the JSON reporter as a basis, or implement a new reporter for VS Code? Either way, I'll try to read up on the topic a bit more when I can, I'm not familiar with this part of VS Code at all.

Anybody reading this, definitely feel free to pick this up, might be a fun task.

@danvk
Copy link
Author

danvk commented Jan 9, 2024

The output format of knip isn't the best for parsing.

Did you see the JSON reporter? https://knip.dev/features/reporters#json

Yes! You'd think JSON output would be perfect for consuming from another tool, but so far as I can tell VS Code problemMatchers really want line-based output.

This works pretty well:

Nice! Great to see Knip used like this.

there aren't line numbers for the unused devDependencies

That's a good RFC.

Want me to file an issue for this?

So call this a feature request for a new reporter that's compatible with one of VS Code's built-in problem matchers, for example "tsc" or "eslint".

What would be the best way to go about this? Use the JSON reporter as a basis, or implement a new reporter for VS Code? Either way, I'll try to read up on the topic a bit more when I can, I'm not familiar with this part of VS Code at all.

Anybody reading this, definitely feel free to pick this up, might be a fun task.

I'd suggest implementing a new reporter that outputs in the exact same format as eslint, tsc or some other tool that VS Code has a built-in matcher for.

@beaussan
Copy link
Contributor

Yes! You'd think JSON output would be perfect for consuming from another tool, but so far as I can tell VS Code problemMatchers really want line-based output.

Did you try creating a custom reporter that is vscode problemMatchers friendly ?

@danvk
Copy link
Author

danvk commented Jan 12, 2024

Did you try creating a custom reporter that is vscode problemMatchers friendly ?

That's what this issue is proposing :) I haven't taken a crack at it myself yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

3 participants