Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line tool to modify XML in .idea folder in JetBrains projects

I use WebStorm and other JetBrains projects.

I am looking for a command line tool that can modify the settings for a new project so that I don't have to do it manually.

For example, I never want spellcheck to be active, and I believe this is the XML that controls spellcheck:

<component name="InspectionProjectProfileManager">
  <profile version="1.0">
    <option name="myName" value="Project Default" />
    <inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="false">
      <option name="processCode" value="true" />
      <option name="processLiterals" value="true" />
      <option name="processComments" value="true" />
    </inspection_tool>
  </profile>
</component>

Does anyone know of a JetBrains tool that can do this, or should I write something myself?

The right way to do this will be for each user to modify the Default Settings of JetBrains products themselves.

https://www.jetbrains.com/help/webstorm/accessing-default-settings.html

However, I am still curious if there is a good way to use/create a command line to tool to change per project settings.

like image 479
Alexander Mills Avatar asked Dec 07 '25 06:12

Alexander Mills


2 Answers

If you know XPath, another option is to use xmlstarlet. Specifically, the ed (edit) command.

Example command line...

xmlstarlet ed -u "//inspection_tool[@class='SpellCheckingInspection']/@enabled" -v "false" some_settings_file.xml

results...

<component name="InspectionProjectProfileManager">
  <profile version="1.0">
    <option name="myName" value="Project Default"/>
    <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
      <option name="processCode" value="true"/>
      <option name="processLiterals" value="true"/>
      <option name="processComments" value="true"/>
    </inspection_tool>
  </profile>
</component>

You can also edit the file in-place by adding -L (xmlstarlet ed -L ...).

like image 130
Daniel Haley Avatar answered Dec 10 '25 01:12

Daniel Haley


Does it really have to be a command-line tool? Why don't you just use IDEA's on-board means?

Solution A: Ex-/import inspections directly

Enter the inspections dialog in the settings. Then export, import, duplicate (with special name like "MyCompany default") all inspection settings to/from XML.

Inspections settings ex-/import

Solution B: Ex-/import project defaults

Select "File" - "Other settings" - "Default settings", then deactivate the spelling inspection (similar to screenshot above) and save.

Now just export all (or your own subset of) default settings into an importable JAR file via "File" - "Export settings". This has the advantage that you can bundle a package of default settings, e.g. code style, colors, toolbar buttons, file templates and many more. The minimum your need to export are "Default project" and "Inspection profiles (schemes)".

Project settings ex-/import

like image 20
kriegaex Avatar answered Dec 10 '25 02:12

kriegaex