Skip to content

[Bug]: cspell fails when have a directory with name constructor in it #7194

Closed

Description

@AlexeyDmitriev

Kind of Issue

Crash / Error

Tool or Library

cspell

Version

8.19.0 [8.17.5 already fails, 8.12.1 is fine, I didn't bisect further]

Supporting Library

Not sure / None

OS

Linux

OS Version

ubuntu 20.04

Description

Running cspell with a path that contains directory called constructor in it fails with Linter error inside picomatch (expected string to call .startsWith("./") on it, but [Function: Object] is given (Even before opening files))

Steps to Reproduce

  1. Go to any directory (it may or may not have a directory called constructor in it)
  2. Run ➜ ~ /path/to/cspell constructor
  3. See result:
TypeError: output.startsWith is not a function
    at exports.removePrefix (/home/alexeyd/node_modules/picomatch/lib/utils.js:48:14)
    at parse (/home/alexeyd/node_modules/picomatch/lib/parse.js:130:17)
    at picomatch.makeRe (/home/alexeyd/node_modules/picomatch/lib/picomatch.js:298:14)
    at micromatch.makeRe (/home/alexeyd/node_modules/micromatch/index.js:392:44)
    at file:///home/alexeyd/node_modules/cspell-glob/dist/GlobMatcher.js:98:24
    at Array.map (<anonymous>)
    at buildMatcherFn (file:///home/alexeyd/node_modules/cspell-glob/dist/GlobMatcher.js:94:10)
    at new GlobMatcher (file:///home/alexeyd/node_modules/cspell-glob/dist/GlobMatcher.js:58:24)
    at buildGlobMatcher (file:///home/alexeyd/node_modules/cspell/dist/esm/util/glob.js:83:12)
    at normalizeGlobsToRoot (file:///home/alexeyd/node_modules/cspell/dist/esm/util/glob.js:91:43)
  1. Run ➜ ~ /path/to/cspell example/of/path/with/constructor/in/it
  2. See result:
Linter Error: output.startsWith is not a function
-------------------------------------------
CSpell: Files checked: 0, Issues found: 0 in 0 files with 1 error.

Expected Behavior

File is checked for correctness (if it doesn't exists then something else)

Additional Information

That happens with empty cspell.json as well as with no cspell.json at all (not sure it's read by this point)

cspell.json

{}

cspell.config.yaml

Example Repository

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. Jason3S commented on Apr 17, 2025

    @Jason3S
    Collaborator

    @AlexeyDmitriev,

    Thank you. I'll follow up with picomatch.

  2. Jason3S commented on Apr 17, 2025

    @Jason3S
    Collaborator

    There seem to be an old PR: micromatch/picomatch#132

  3. Jason3S commented on Apr 18, 2025

    @Jason3S
    Collaborator

    I have opened a PR: micromatch/picomatch#144

  4. Jason3S commented on Apr 18, 2025

    @Jason3S
    Collaborator

    @AlexeyDmitriev,

    This is a bug, but there isn't a lot I can do about it until picomatch is fixed.

    But there are workarounds: Do you globs actually have constructor in them? Or are the trying to spell check a filename?

    The --file option allows you to specify file names instead of globs.

    cspell --file path/to/file/with/constructor/in/the/path/file.txt

    If you must have constructor in the glob, consider using: {}

    cspell "**/{c,c}onstructor/**" 
    cspell "**/{constructor,constructor}/**" 
    

    Look at cspell lint --help for more options.

  5. AlexeyDmitriev commented on Apr 19, 2025

    @AlexeyDmitriev
    Author

    I only ever pass list of file generated automatically (and some of them happen to have constructor in it). I'll try to workaround with --file

  6. Jason3S commented on Apr 19, 2025

    @Jason3S
    Collaborator

    @AlexeyDmitriev,

    In that case, I suggest using --file or --file-list:

      --file-list <path or stdin>  Specify a list of files to be spell checked. The
                                   list is filtered against the glob file patterns.
                                   Note: the format is 1 file path per line.
      --file [file...]             Specify files to spell check. They are filtered
                                   by the [globs...].
    
  7. AlexeyDmitriev commented on Apr 24, 2025

    @AlexeyDmitriev
    Author

    that helped indeed, thank you

  8. github-actions commented on May 25, 2025

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  9. locked as resolved and limited conversation to collaborators on May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions