Create official PhpStorm code style

Created on 14 September 2022, about 2 years ago
Updated 4 May 2023, over 1 year ago

Problem/Motivation

PhpStorm includes a Drupal "code style scheme" to provide validation and auto-completion in the IDE, but it's highly incorrect and incomplete. I filed an issue at to get it updated, and they expressed willingness to accept updated settings from us.

Steps to reproduce

  1. Clone any Drupal codebase--core or contrib--and open it in PhpStorm.
  2. Set up Drupal support.
  3. ...including applying the pre-configured Drupal code style.
  4. Inspect the settings in the application preferences.

Proposed resolution

Provide updated settings, obviously. :) I (@TravisCarden) can provide a pretty good baseline for PHP code, but I'd like review. And I'm not competent to provide more than the most basic settings for CSS, JavaScript, and Twig, for example, so I'd like help with those.

Remaining tasks

  • Get review on the various sections:
    1. [ ] PHP
    2. [ ] Style Sheets (CSS/Sass/SCSS)
    3. [ ] HTML
    4. [ ] JavaScript
    5. [ ] JSON
    6. [ ] Markdown
    7. [ ] Shell Script (we do have a few)
    8. [ ] Twig
    9. [ ] XML
    10. [ ] YAML
    11. [ ] Other Types
  • Provide the approved settings to JetBrains: WI-68784.

Steps to review

  1. Clone any Drupal codebase--core or contrib--and open it in PhpStorm.
  2. Set up Drupal support.
  3. Instead of applying the pre-configured Drupal code style, import the latest settings file attached to this issue per these instructions.
  4. Inspect the new settings in the application preferences.
  5. Make any necessary changes and export the result. Attach it to the issue for the next reviewer ( interdiffs β†’ will be helpful since there's no codebase to create MRs for) and update the remaining tasks above according to your degree of confidence.

The meaning of the various settings can be found here. (Note the sub-pages for each language in the left nav.)

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States traviscarden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States traviscarden

    The current PR seems to be working for people, so I'm going to go ahead and merge it in lieu of further feedback. Obviously, we can follow-up issues as needed. Thanks, all. πŸ™‚οΈ

  • πŸ‡ΊπŸ‡¦Ukraine lobodacyril

    It seems you need to remove for JSON. It adds trailing commas when I save composer.json and it's wrong.

  • πŸ‡ΊπŸ‡ΈUnited States traviscarden

    Thanks for the feedback, @lobodacyril! Are you sure that behavior is coming from here? It looks like the setting for trailing commas in JSON is this:

      <JSON>
        <option name="KEEP_TRAILING_COMMA" value="true" />
      </JSON>
    

    But that's absent from the JSON settings in the current Drupal.xml:

      <codeStyleSettings language="JSON">
        <option name="WRAP_LONG_LINES" value="true" />
        <indentOptions>
          <option name="CONTINUATION_INDENT_SIZE" value="2" />
          <option name="TAB_SIZE" value="2" />
        </indentOptions>
      </codeStyleSettings>
    

    I'll bet it's from your local preferences. You can see you those by exporting your active configuration and comparing them.

Production build 0.71.5 2024