Comments (10)
I think that I have found the problem. Can you please help to verify whether the solution is working as I do not have a Windows computer?
The problem seems to be restricted to files in which not lint violations is found that can be autocorrected. In such files the line endings were indeed changed from CRLF to LF. In files in which a lint violation is found, and which could also be autocorrected, the line endings were not changed.
Please run Ktlint CLI latest snapshot build or ktlint-cli-1.4.0-20240723.140247-11-all.jar on your project to check that line endings are no longer changed.
*edited: update direct link to jar to refer to fat jar
from ktlint.
I can't figure out how I can run
ktlint-cli-1.4.0-20240723.140247-11.jar
, since it is compiled without-include-runtime
. Could you please help me with this? I usually use kotlinter.
Sorry, I should have pointed you to the fat jar and to the run instructions for Windows.
from ktlint.
Okay… Now there are a few problems:
- Without specifying
end_of_line
in.editorconfig
, files are still formatted inlf
if ktlint decides to modify them; - When
end_of_line
is specified in.editorconfig
, files are not formatted if they contain another endings, but there are no other problems.
from ktlint.
Although I've already added a workaround for these problems using .gitattributes
, I still think it's a bug and worth fixing.
I understand that this behavior was introduced quite a while ago, but I don't think anyone is going to be frustrated by the fact that their files are no longer randomly switching from crlf to cr. The second issue you didn't mention is also an obvious bug.
from ktlint.
As I understand from the description of this pull request, ktlint will still change the ending to lf in case of finding problems in the file. If this is indeed the case, this will cause confusion in file endings, they will not be standardised under default settings in projects developed on Windows machines. What are your thoughts on this?
I'm ready to test this version of the formatter if you explain whether crlf would change to cr in case the file requires formatting, but the .editorconfig doesn't specify the corresponding rule.
from ktlint.
My expectation is that the problem only occurred in files where no Ktlint violations were autocorrected. In that case the end of line separator was not determined whilst still updating the end of line separator with the default value.
For files in which a violation was found, the behavior was not changed in Ktlint 1.3. So in this case the end of line separator was, and still is, correctly determined.
from ktlint.
Good to know.
I can't figure out how I can run ktlint-cli-1.4.0-20240723.140247-11.jar
, since it is compiled without -include-runtime
. Could you please help me with this? I usually use kotlinter.
from ktlint.
- Without specifying
end_of_line
in.editorconfig
, files are still formatted inlf
if ktlint decides to modify them;
This behavior was changed in #1831 (ktlint version 0.49.0
). I missed the impact of the change by setting the default value to lf
when the value was not set in the .editorconfig
. At this moment, I cannot revert this behavior to the old situation as too many new versions have been released since then. Especially as you are the first one who identified this as an issue.
from ktlint.
Faced the same issue while upgrading ktlint from 1.2.1 to 1.3.1. I do format all the code, but see no changes, only different line-endings.
@paul-dingemans I can confirm that 1.4.0-SNAPSHOT solves the problem.
So, waiting for 1.4.0 (or 1.3.2) to upgrade to the latest ktlint 😎
But as @mxkmn has noted, the line endings of auto-fixed files get indeed transformed from CRLF to LF even without explicit end_of_line
specified in .editorconfig
I cannot revert this behavior to the old situation as too many new versions have been released since then.
I don't think anyone is going to be frustrated by the fact that their files are no longer randomly switching from crlf to cr
I am not aware of any potential harm of changing line endings of Kotlin source code, so I tend to agree that most probably nobody will be frustrated if ktlint will stop converting from CRLF to LF on auto-formatting for Windows users.
It's also interesting, that if you generate a project on Windows either with gradle init
of simply with Intellij's "New project..." menu, the line ending of generated sample code will be LF anyway. But as soon as you create a new file in Intellij with Alt+Insert, it will be CRLF, so Intellij it also a bit inconsistent while generating a new project.
from ktlint.
Related Issues (20)
- Properties that start with `_` should be suppressed by `PropertyName` HOT 1
- Cannot apply default formatting Kotest\StringSpec when migrate from 1.0.1 -> 1.3.0 HOT 5
- Documentation unclear/inconsistent about rule names HOT 4
- Enable installing a specific version of ktlint via brew HOT 1
- Format was not able to resolve all violations which (theoretically) can be autocorrected
- Some rules in https://pinterest.github.io/ktlint/latest/rules/standard/ missing "Suppress or disable rule" HOT 1
- Allow single-line `try`/`catch` statements HOT 2
- Inconsistent starting position of chain method continuation HOT 1
- `function-literal` rule conflict with maximum line length HOT 2
- multiline class arguments HOT 1
- `backing-property-naming` rule shouldn't be applied to fields that have the `override` modifier
- class-signature rule incorrectly forces removal of primary no-argument constructor HOT 2
- ktlint --stdin takes too long and only supports a single file HOT 9
- Abstract classes after a long previous line are multilined regardless of the ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than setting HOT 1
- I get an "Enable default patterns" message when I try to format a Kotlin file in Vim with ALE and Ktlint HOT 2
- blank-line-between-when-conditions has incorrect id in docs
- Conflict between `binary-expression-wrapping` and `ktlint_standard_range-spacing` HOT 5
- False positive Unnecessary semicolon (standard:no-semi) HOT 2
- Reconsider allowing standard:no-consecutive-comments if there are empty lines, and allow automatic fix HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktlint.