upgrade @types/fuzzaldrin-plus to address API changes
See original GitHub issueRecently I had to build a similar fuzzy filtering feature like the one that works in many places of Github Desktop. Since this project is open source I decided to take a peak to see how you guys implemented it and what packages you used.
There I noticed that you are passing the options
to the fuzzaldrin-plus
functions as a fourth parameter:
The documentation of that package is kind-of lacking to say the least, so if you check source code for version 0.6.0 you will notice that the options should be the third parameter instead, so right now the options
object in Desktop’s implementation is being completely ignored and using the defaults! :
score: (string, query, options = {}) ->
return 0 unless string?.length and query?.length
options = parseOptions(options, query)
if options.usePathScoring
Also, the option isPath: boolean
doesn’t exist in that version, so I assume you meant usePathScoring
. These are the default options the package has…
#Setup default values
parseOptions = (options, query) ->
options.allowErrors ?= false
options.usePathScoring ?= true
options.useExtensionBonus ?= false
options.pathSeparator ?= defaultPathSeparator
options.optCharRegEx ?= null
options.wrap ?= null
I debugged Desktop locally just to make sure, and indeed this is the case:
If you do decide to make the fix and apply the options, I would suggest that you test it properly since the options that you are setting will impact the behavior of the algorithm and produce different results than the ones you’ve been seeing so far. allowErrors
for instance, will indeed allow errors and some mismatchs will happen. Also, the pathSeparator
being used so far was either /
or \\
, so I assume that changing it to ‘-’ will have an impact as well. I wonder why you went with these options ?
/cc @damaneice @j-f1
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (16 by maintainers)
Top GitHub Comments
@shiftkey By the way, those behavior changes should’ve been caught by some automated tests somewhere. If none of your tests broke after doing those changes, this would be a good opportunity to add them!
@shiftkey The issues you are seeing are caused because the
options
object is mutated inside each of the functions thatfuzzaldrin-plus
exposes by filling out the properties that were not provided. One of the possible options is apreparedQuery
which is used instead of thestr
when it is present. Although you didn’t provide it, it is added to theoptions
variable and then remains there for all the following calls after the first one.In the mean time, so that you can test out the options, you can mitigate this by destructuring the options object in each call so that a clone is created and the original one it is not mutated.