-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't report Tab character(s) in multiline string #575
Comments
In the past this repo used tabs instead of 4 spaces for .kt files. Ktlint doesn't convert tabs in multiline strings to spaces. Please take a look at the following issue. pinterest/ktlint#575 Therefore, the following command has been used for conversion. find ./ -iname '*.kt' -type f -exec bash -c 'expand -t 4 "$0" | sponge "$0"' {} \; * ./ is recursively searching the given directory * -iname is a case insensitive match .kt files * type -f finds only regular files (no directories, binaries or symlinks) * -exec bash -c executes the following commands in a subshell for each file * expand -t 4 expands all tabs to 4 spaces * sponge soaks up standard input (from expand) and writes it to the same file Source: https://stackoverflow.com/a/43523362
In the past this repo used tabs instead of 4 spaces for .kt files. Ktlint doesn't convert tabs in multiline strings to spaces. Please take a look at the following issue. pinterest/ktlint#575 Therefore, the following command has been used for conversion. find ./ -iname '*.kt' -type f -exec bash -c 'expand -t 4 "$0" | sponge "$0"' {} \; * ./ is recursively searching the given directory * -iname is a case insensitive match .kt files * type -f finds only regular files (no directories, binaries or symlinks) * -exec bash -c executes the following commands in a subshell for each file * expand -t 4 expands all tabs to 4 spaces * sponge soaks up standard input (from expand) and writes it to the same file Source: https://stackoverflow.com/a/43523362
In the past this repo used tabs instead of 4 spaces for .kt files. Ktlint doesn't convert tabs in multiline strings to spaces. Please take a look at the following issue. pinterest/ktlint#575 Therefore, the following command has been used for conversion. find ./ -iname '*.kt' -type f -exec bash -c 'expand -t 4 "$0" | sponge "$0"' {} \; * ./ is recursively searching the given directory * -iname is a case insensitive match .kt files * type -f finds only regular files (no directories, binaries or symlinks) * -exec bash -c executes the following commands in a subshell for each file * expand -t 4 expands all tabs to 4 spaces * sponge soaks up standard input (from expand) and writes it to the same file Source: https://stackoverflow.com/a/43523362
In the past this repo used tabs instead of 4 spaces for .kt files. Ktlint doesn't convert tabs in multiline strings to spaces. Please take a look at the following issue. pinterest/ktlint#575 Therefore, the following command has been used for conversion. find ./ -iname '*.kt' -type f -exec bash -c 'expand -t 4 "$0" | sponge "$0"' {} \; * ./ is recursively searching the given directory * -iname is a case insensitive match .kt files * type -f finds only regular files (no directories, binaries or symlinks) * -exec bash -c executes the following commands in a subshell for each file * expand -t 4 expands all tabs to 4 spaces * sponge soaks up standard input (from expand) and writes it to the same file Source: https://stackoverflow.com/a/43523362
I don't think that the initial example given should report an error:
This multiline string is not suffixed with Also no error should be reported in case the tab character is found on the right hand side of the margin like in example below:
Only in case the tab character is found on the left hand side of the margin the error should be reported:
Can you agree with above? I have not yet prepared the PR because the calculation of the position of the unexpected tab needs to be determined. Before I do that, I would like to have confirmation about this approach. |
Thanks for the clarification. I understand the reasons behind this.
I didn't know that. Thanks for the hint. |
Yeah, I agree that we shouldn't touch the contents of raw strings if they are not using But it would be beneficial to detect those in the beginning of the line and where |
Ok, I am already working on a fix. It will be ready early 2021. |
* Tabs after indentation margin are not reported as unexpected * If all lines of the multiline string are indented with tabs only then replace the tabs with spaces * Report multiline strings for which the indentations contain both tabs and spaces as this can not autocorrected with certainty * Indent multiline strings when used as property value 'format-raw-string-trim-indent.kt.spec' * Replicate some tests cases as separate unit test for ease of testing * Fixed error as code was not valid kotlin * Add indentation errors
As discussed in above PR, the indent rule will never change the indentation inside a raw string literal. Although it can be very useful to fix indentation inside string literals (appended with trimIndent), it is expected that such behaviour is not well expected in the entire community. Therefore this behaviour will not be added to the indent rule which is contained inside the standard ruleset. I am working on a publicly available custom ruleset in which such a rule will be provided. Either this rule will be provided via a separate repository or it might be included in the experimental ruleset of ktlint. For more info see issue #1229 and PR #1230. |
Yeah, @schalkms sorry, but we aren't going to support indentation within string templates for now |
Please take a look at the following multiline string example.
The tabs in the multiline string don't get reported by ktlint 0.34.2.
The text was updated successfully, but these errors were encountered: