Eslint-plugin-sonarjs must have @types/functional-red-black-tree in its dependencies

Otherwise TypeScript with skipLibCheck: false errors with this:

node_modules/eslint-plugin-sonarjs/lib/helpers/regex/simplified-regex-character-class.d.ts:3:24 - error TS7016: Could not find a declaration file for module 'functional-red-black-tree'. '/.../node_modules/functional-red-black-tree/rbtree.js' implicitly has an 'any' type.
   Try `npm i --save-dev @types/functional-red-black-tree` if it exists or add a new declaration (.d.ts) file containing `declare module 'functional-red-black-tree';`
 
 3 import createTree from 'functional-red-black-tree';
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ideally it should be a peer dependency, but it’s probably okay to ship it as a regular dependency, as it’s a pretty niche package.

Hi @alecmev,

is it possible for you to share a minimum reproducer for this? We have in our CI a sample Typescript project that works correctly with the new version.

Thanks!
Victor

Hi Victor, sure! This reproduces it: Comparing SonarSource:master...alecmev:repro-121216 · SonarSource/SonarJS · GitHub

@alecmev , there are two different topics here.

The first one is the reason why the TypeScript compiler emits an error: our plugin API wrongly exposes our internal helpers as public, which is not what we intended. We are going to remove then from v2.0.2, which will also solve your issue.

The second one is about skipLibCheck. What TypeScript compiler says when you set skipLibCheck to false is that you must install @types/functional-red-black-tree if you want to use our API. There is nothing wrong with that and it is not something that needs to be fixed on our side: to fix the issue, you just have to install the dependency requested by the TypeScript compiler. Well, I say there is no nothing to fix on our side, but this is not totally true: we should fix the documentation of the plugin API to explain that it requires @types/functional-red-black-tree to be installed if skipLibCheck is set to false

The good news for us is that, since we will remove the helpers, there is no requirement for this package to be installed anymore in order to compile a project that depends on the plugin API, with skipLibCheck set to false.

You can follow the progress on the removal of the helpers there:

https://sonarsource.atlassian.net/browse/ESLINTJS-51

Hi Eric,

I agree that not exposing something that’s not public in the first place is the best fix.

Even though I understand that it doesn’t matter for this particular problem anymore, I just want to mention that if it’s accessible via an “importable” .d.ts - it’s public API. In this case there was export * from './helpers'; in index.d.ts, so anybody using this plugin could in theory import SimplifiedRegexCharacterClass with partially broken types.

Regardless, thanks for fixing this!