styleguide icon indicating copy to clipboard operation
styleguide copied to clipboard

Parser intellij-java-google-style.xml to .editorconfig file

Open pedrro opened this issue 6 years ago • 5 comments

Hi, I'd like to use an .editorconfig file with the same configuration of intellij-java-google-style.xml

I'd like to know if this .editorconfig configured with this style already exist, or if not, could we do this translation from xml to .editorconfig?

pedrro avatar Feb 19 '19 18:02 pedrro

If you have IntelliJ it looks like you can export configuration via "File->Settings->Editor->Code Style" (see https://stackoverflow.com/questions/35915970/how-to-export-all-my-intellij-code-styles-to-a-editorconfig-file)

I'm in the process of trying to get an .editorconfig for the C++ style guide by using CLion to import eclipse-cpp-google-style.xml and then export again 🤞

jacobq avatar Aug 13 '19 12:08 jacobq

@jacobq It is unavailable in CLion 2020.2 image image

:cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:

spencercjh avatar Sep 17 '20 14:09 spencercjh

@jacobq It is unavailable in CLion 2020.2

I can't remember if I even got it to work before or not (see https://github.com/google/styleguide/issues/411), but in any case support for importing from an Eclipse style file is an open issue filed a long time ago (please consider voting for it): https://youtrack.jetbrains.com/issue/CPP-368 It would be nice if there were also a intellij-cpp-google-style.xml file here, but my guess is that no one is assigned to this task nor has anyone cared enough to volunteer. I suppose one of us could start by taking the "Google" presets that CLion ships with then exporting the resulting XML and submitting a PR.

See also:

  • https://youtrack.jetbrains.com/issue/CPP-9177
  • https://youtrack.jetbrains.com/issue/CPP-15439

jacobq avatar Sep 17 '20 15:09 jacobq

I just use Intellij IDEA to write protobuf files and need cpp code style. I think user shoud not write cpp by Intellj IDEA but use CLion with nice full supports.

I try to do something else to go around this issue and solve my problem of code format consistency.

  • Add .editorconfig to simulate Google cpp code style on .proto.
  • Add .clang-format used by an Intellij IDEA plugin described below to config ClangFormat.
  • Install ClangFormat to your PC. In Ubuntu, just sudo apt install clang-format.
  • In Intellij IDEA, a plugin named ClangFormatIJ need to be installed. This plugin use clang-format in the PATH and .clang-format config file in the root directory of project.
  • Use Reformat Code with clang-format to every file you edit. There is no default keymap of the command. You can bind one or just use Search Everywhere, type clang and get it in the Action part.
  • Deselect the Reformat code in the commit config from unexpected code formatting.
  • Run the following shell before committing your code: git diff -U0 --no-color HEAD^ | clang-format-diff -style Google -i -p1.I strongly suggest you execute both steps to ensure there is no diff about format.

spencercjh avatar Sep 17 '20 16:09 spencercjh

If you have IntelliJ it looks like you can export configuration via "File->Settings->Editor->Code Style" (see https://stackoverflow.com/questions/35915970/how-to-export-all-my-intellij-code-styles-to-a-editorconfig-file)

I'm in the process of trying to get an .editorconfig for the C++ style guide by using CLion to import eclipse-cpp-google-style.xml and then export again crossed_fingers

While it works, it does generate a bunch of things that look like IntelliJ specific config which might not work with other editors

ij_continuation_indent_size = 4
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false

robbie-cahill avatar Sep 01 '22 00:09 robbie-cahill