Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Differences in formatting between ktlint and Android Studio #685

Closed
PPetka opened this issue Jan 17, 2020 · 7 comments
Closed

Differences in formatting between ktlint and Android Studio #685

PPetka opened this issue Jan 17, 2020 · 7 comments

Comments

@PPetka
Copy link

PPetka commented Jan 17, 2020

Hi, I am having trouble with setting Android Studio so it exactly follows formatting applied by ktlint.
The style is set to official kotlin one.
Screenshot 2020-01-17 at 16 10 36

I've done everything as described in your readme file (try to apply settings via --apply-to-idea-project Option1 , and also Option 2 and 3https://github.com/pinterest/ktlint#option-3

I guess the problem could be probably solved by applying some settings into .editorconfig file,
but I am not sure what property can cause it.
I had the same inconsistency with max line lenght property. Adding max_line_length=100 did solved the issue.

Screenshots before formatting
Screenshot 2020-01-17 at 16 08 01

after formatting via Android Studio:
Screenshot 2020-01-17 at 16 08 11

Any suggestions?

ktlint version: 0.32.0

@shashachu
Copy link
Contributor

Hm.. I kind of surprised that AS formats it without that extra indent. What version of AS are you using?

@PPetka
Copy link
Author

PPetka commented Jan 20, 2020

The newest one:

Android Studio 3.5.3
Build #AI-191.8026.42.35.6010548, built on November 15, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6

But In older versions, it was exactly the same. Just didn't have time to take care of that.

@PPetka
Copy link
Author

PPetka commented Jan 22, 2020

@shashachu I am posting my Code style settings imported from AS
I took it from Preferences -> Editor -> Code Style
Then there is a Scheme: where I can export settings.

I removed all languages but Kotlin, and left other settings that may be important.

Can you please check the diff with yours? Or at least post your configuration so I can manually spot the differences?

Thanks

kotlin-official-code-style.codestyle.json

{
  "schemeName": "kotlin-official-code-style",
  "version": "1.0",
  "codeStyle": {
    "all": {
      "formatter_off_tag": "@formatter:off",
      "formatter_on_tag": "@formatter:on",
      "formatter_tags_accept_regexp": false,
      "formatter_tags_enabled": false,
      "max_line_length": 100,
      "wrap_on_typing": false
    },
    "editorconfig": {
      "align_group_field_declarations": false,
      "space_after_colon": false,
      "space_after_comma": true,
      "space_before_colon": false,
      "space_before_comma": false,
      "spaces_around_assignment_operators": true
    },
    "kotlin": {
      "align_in_columns_case_branch": false,
      "align_multiline_binary_operation": false,
      "align_multiline_extends_list": false,
      "align_multiline_method_brackets": false,
      "align_multiline_parameters": false,
      "align_multiline_parameters_in_calls": false,
      "assignment_wrap": "normal",
      "blank_lines_after_class_header": 0,
      "blank_lines_around_block_when_branches": 0,
      "block_comment_at_first_column": true,
      "call_parameters_new_line_after_left_paren": true,
      "call_parameters_right_paren_on_new_line": true,
      "call_parameters_wrap": "on_every_item",
      "catch_on_new_line": false,
      "class_annotation_wrap": "split_into_lines",
      "code_style_defaults": "KOTLIN_OFFICIAL",
      "continuation_indent_for_chained_calls": false,
      "continuation_indent_for_expression_bodies": false,
      "continuation_indent_in_argument_lists": false,
      "continuation_indent_in_elvis": false,
      "continuation_indent_in_if_conditions": false,
      "continuation_indent_in_parameter_lists": false,
      "continuation_indent_in_supertype_lists": false,
      "continuation_indent_size": 4,
      "else_on_new_line": false,
      "enum_constants_wrap": "off",
      "extends_list_wrap": "normal",
      "field_annotation_wrap": "split_into_lines",
      "finally_on_new_line": false,
      "if_rparen_on_new_line": true,
      "import_nested_classes": false,
      "indent_size": 4,
      "indent_style": "space",
      "insert_whitespaces_in_simple_one_line_method": true,
      "keep_blank_lines_before_right_brace": 0,
      "keep_blank_lines_in_code": 1,
      "keep_blank_lines_in_declarations": 1,
      "keep_first_column_comment": true,
      "keep_indents_on_empty_lines": false,
      "keep_line_breaks": true,
      "lbrace_on_next_line": false,
      "line_comment_add_space": true,
      "line_comment_at_first_column": false,
      "method_annotation_wrap": "split_into_lines",
      "method_call_chain_wrap": "normal",
      "method_parameters_new_line_after_left_paren": true,
      "method_parameters_right_paren_on_new_line": true,
      "method_parameters_wrap": "on_every_item",
      "name_count_to_use_star_import": 2147483647,
      "name_count_to_use_star_import_for_members": 2147483647,
      "parameter_annotation_wrap": "off",
      "smart_tabs": false,
      "space_after_comma": true,
      "space_after_extend_colon": true,
      "space_after_type_colon": true,
      "space_before_catch_parentheses": true,
      "space_before_comma": false,
      "space_before_extend_colon": true,
      "space_before_for_parentheses": true,
      "space_before_if_parentheses": true,
      "space_before_lambda_arrow": true,
      "space_before_type_colon": false,
      "space_before_when_parentheses": true,
      "space_before_while_parentheses": true,
      "spaces_around_additive_operators": true,
      "spaces_around_assignment_operators": true,
      "spaces_around_equality_operators": true,
      "spaces_around_function_type_arrow": true,
      "spaces_around_logical_operators": true,
      "spaces_around_multiplicative_operators": true,
      "spaces_around_range": false,
      "spaces_around_relational_operators": true,
      "spaces_around_unary_operator": false,
      "spaces_around_when_arrow": true,
      "tab_width": 4,
      "variable_annotation_wrap": "off",
      "while_on_new_line": false,
      "wrap_elvis_expressions": 1,
      "wrap_expression_body_functions": 1,
      "wrap_first_method_in_call_chain": false
    },
    "properties": {
      "align_group_field_declarations": false
    }
  }
}

@PPetka PPetka changed the title Differences in formatting by ktlint vs Android Studio Differences in formatting between ktlint and Android Studio Jan 23, 2020
@xserxses
Copy link

xserxses commented Feb 6, 2020

I'm facing similar problem. :(

@romtsn
Copy link
Collaborator

romtsn commented May 29, 2020

I have a feeling that it was fixed in the recent versions, could you try it out with 0.36.0 @PPetka ?

@romtsn
Copy link
Collaborator

romtsn commented Jun 15, 2020

Closing this for now. If the issue is still existing in the latest version, please provide a reproducible code snippet.

@romtsn romtsn closed this as completed Jun 15, 2020
@PPetka
Copy link
Author

PPetka commented Jun 23, 2020

@romtsn I've done some testing and It feels like the problem was solved indeed!! Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants