Script Editor: Basic Code Formatter Plugin – Arma Reforger

From Bohemia Interactive Community
Revision as of 16:26, 13 February 2024 by Lou Montana (talk | contribs) (Page creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Basic Code Formatter is a plugin that helps formatting code to Bohemia Interactive standards as well as warns for bad practice.

It features:

  • General space formatting
  • Line end trimming
  • Indentation fix from spaces to tabs
  • Method separator fix
  • Auto line end at the end of the file
  • Scripting prefix check
  • Batch processing (all addon scripts at once)
  • The option to only formats modified lines (if using SVN/Git)
  • Bad practice warnings
  • A demo mode to practice in read-only.


Usage

It is triggered by Ctrl + ⇧ Shift + K; depending on the selected options, it will either process the current file or the selected addon's files.

Ctrl + Alt + ⇧ Shift + K can be used to force formatting of all the current file's lines.


Example

Before After
class abc:Managed // must warn for non-prefixed class + must space around ':' { [Attribute()]; // must remove the semicolon protected ScriptInvokerVoid Event_OnSomething; protected static string m_sValue3; // must fix the separator (below) //--- protected void Method() { // must replace 5 spaces by one tab if(true ) return; // must reformat the if and warn about one-liner // must warn about two empty lines (below) // must remove trailing empty space (below) } // must remove the final semicolon below }; // must add a line return (below)
class abc : Managed // must warn for non-prefixed class + must space around ':' { [Attribute()] // must remove the semicolon protected ScriptInvokerVoid Event_OnSomething; protected static string m_sValue; // must fix the separator (below) //------------------------------------------------------------------------------------------------ protected void Method() { // must replace 5 spaces by one tab if (true) return; // must reformat the if and warn about one-liner // must warn about two empty lines (below) // must remove trailing empty space (below) } // must remove the final semicolon below } // must add a line return (below)
Changelog
SCRIPT       : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SCRIPT       : SCR_BasicCodeFormatterPluginExample.c - 7 lines changed, 1× line trimming, 1× indent fix(es) at line(s) 11, 5 formattings, 1 end spaces trimming, 1 4-spaces indent -> tabs replaced, 1 space(s) in indentation removed, 1 method separators fixed, added final newline (read: 3 ms, format: 83 ms, diff: 81 ms - total: 167 ms)
SCRIPT       : Checking all 20 lines (100% of the file)
SCRIPT       : 1× multiple consecutive empty lines found at line(s) 14 - leave only one
SCRIPT       : 2× badly-named variables found at line(s) 5-6 - use proper prefixes: m_s for ResourceName/string, m_v for vectors, NO m_p, CASED_CONSTS, etc
SCRIPT       : 1× non-prefixed class/enum found at line(s) 1 - classes and enums should be prefixed; see the settings to setup accepted prefixes (current SCR_)