jq icon indicating copy to clipboard operation
jq copied to clipboard

feature: For `is not defined` error message, prompt for similar names

Open A4-Tacks opened this issue 10 months ago • 1 comments

Current outputs:

    $ jq -n 'to_string'
jq: error: to_string/0 is not defined at <top-level>, line 1:
to_string
jq: 1 compile error
    $ jq -n '1 as $X | $x'
jq: error: $x is not defined at <top-level>, line 1:
1 as $X | $x
jq: 1 compile error

Expect outputs like:

    $ jq -n 'to_string'
jq: error: to_string/0 is not defined at <top-level>, line 1:
to_string
jq: Did you mean: tostring/0?
jq: 1 compile error
    $ jq -n '1 as $X | $x'
jq: error: $x is not defined at <top-level>, line 1:
1 as $X | $x
jq: Did you mean: $X?
jq: 1 compile error

Similar python:

    $ python
Python 3.12.7 (main, Oct 11 2024, 10:50:28) [GCC 14.1.1 20240507] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> X=2
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined. Did you mean: 'X'?
>>> priny
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'priny' is not defined. Did you mean: 'print'?

A4-Tacks avatar Feb 18 '25 13:02 A4-Tacks

Levenshtein distance? Yes, apparently that's how Python does. https://github.com/python/cpython/blob/v3.13.0/Python/suggestions.c#L164-L166

itchyny avatar Feb 21 '25 08:02 itchyny