Fix issue with interpolation of strings vs charlists. Fixes #729. #733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #729. This was a fun one to track down. When we pass code into
:elixir_tokenizer
to identify the token locations, we first convert the string to a charlist:credo/lib/credo/code.ex
Lines 132 to 134 in d77eab6
This results in column numbers consistent with the charlist indexes of the characters. For the unicode character in question (🇿🇼), it translates to two values:
This means that when the
:elixir_tokenizer
identifies the#
token in this string:it identifies it at the 5th column in the output, which is correct because it is the 5th item in the charlist:
The problem is that our code to split and replace that interpolation uses
String.slice
, which uses theString
indexes, notcharlist
indexes, so when it grabs the 5th character, it is off by one and starts the replacement at the{
instead of the#
. The resulting code has an unexpected/unparsable#
:The fix was simply to convert the strings to charlists and use
Enum.slice
instead ofString.slice
to replace the values, as the numbers we are working with are the charlist indexes, not the string indexes.