Files
compiler-explorer/docs/AddingAFormatter.md
T
Mats Larsen e7b9cbda91 Respect tab width and tabs/spaces settings for format APIs (#2957)
Site settings for tab width and tabs vs spaces are now being used when sent to the /api/format APIs.

This patch also includes some tiny internal refactoring on the bits related to the formatting API.
2021-09-26 23:56:39 +02:00

1.3 KiB

Adding a new formatter

  • Add a etc/config/compiler-explorer.local.properties file

    • Add a new formatter under the formatters key
    • The new formatter can have the following keys: name, exe, styles, type, version (argument to get version info), versionRe (regex to filter out the right version info)
    • Add a lib/formatters/<formatter>.js file using the template below, replacing Type and type as appropriate
      import { BaseFormatter } from '../base-formatter';
      
      export class TypeFormatter extends BaseFormatter {
          static get key() { return 'type'; }
      }
      
    • The value returned by key above corresponds to the type property you set in the compiler-explorer properties configuration file.
    • Tweak format(source, options) and isValidStyle(style) as necessary. See the JSDoc for format and the implementations for other formatters to get a further understanding of how to implement format(source, options).
  • Add your TypeFormatter to lib/formatters/_all.js in alphabetical order

  • You can check the output of http://localhost:10240/api/formats to be sure your formatter is there.

  • Make an installer in the infra repository. An example patch for adding an installer can be found here