Skip to content
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

Don't autoformat imports if the import list contains top-level comments #441

Merged
merged 1 commit into from
May 30, 2019

Conversation

shashachu
Copy link
Contributor

Fixes #408

Refusing to auto-import seemed much easier than trying to figure out which imports the comments were attached to.

@@ -23,10 +25,17 @@ class ImportOrderingRule : Rule("import-ordering") {
val children = node.getChildren(null)
if (children.isNotEmpty()) {
val imports = children.filter { it.elementType == IMPORT_DIRECTIVE }
val hasComments = children.find { it.elementType == BLOCK_COMMENT || it.elementType == EOL_COMMENT } != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a broad brush. should we check for the suppression message? though perhaps unlikely to be a problem in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppression message causes a real problem, but it would also seem annoying if you had comments (for some reason?) in an import list that they'd get blown away by the autoformatter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. sounds good.

@@ -23,10 +25,17 @@ class ImportOrderingRule : Rule("import-ordering") {
val children = node.getChildren(null)
if (children.isNotEmpty()) {
val imports = children.filter { it.elementType == IMPORT_DIRECTIVE }
val hasComments = children.find { it.elementType == BLOCK_COMMENT || it.elementType == EOL_COMMENT } != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. sounds good.

@shashachu shashachu merged commit 3d18cfd into pinterest:master May 30, 2019
@shashachu shashachu deleted the import-ordering branch May 30, 2019 23:45
@shashachu shashachu added this to the 0.33.1 milestone May 31, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 9, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 9, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 9, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this pull request Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ktlint-disable removed from imports after auto-formatting
2 participants