knip icon indicating copy to clipboard operation
knip copied to clipboard

🐛 A custom stylelint plugin causes knip crash

Open Ronny-zzl opened this issue 10 months ago • 2 comments

Prerequisites

Reproduction url

https://github.com/Ronny-zzl/knip-stylelint-plugin

Reproduction access

  • [x] I've made sure the reproduction is publicly accessible

Description of the issue

  1. clone the repo and pnpm i
  2. run pnpm knip and the error below will occur TypeError: filePath.includes is not a function

I believe that knip interprets the plugin's path as a string, but in fact the directly imported plugin is not a string, which causes an error.

Ronny-zzl avatar Feb 28 '25 03:02 Ronny-zzl

Thanks for the report, Zhang! The repro url returns a 404, though.

webpro avatar Feb 28 '25 04:02 webpro

@webpro I'm sorry for that. It's public now.

Ronny-zzl avatar Feb 28 '25 05:02 Ronny-zzl

Hello, I may facing same issue. If there is workaround, I want to know it.🙏

tbashiyy avatar Mar 24 '25 01:03 tbashiyy

Looks like we need to check whether the value is a string before using it: https://github.com/webpro-nl/knip/blob/main/packages/knip/src/plugins/stylelint/index.ts#L19

Someone up for a PR maybe? :)

webpro avatar Mar 24 '25 06:03 webpro

I found same we should fix, too. I'm trying to add test now...

tbashiyy avatar Mar 24 '25 10:03 tbashiyy

@webpro I created PR! https://github.com/webpro-nl/knip/pull/1004

tbashiyy avatar Mar 24 '25 11:03 tbashiyy