Giter Site home page Giter Site logo

gitter-badger / prettier-plugin-apex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dangmai/prettier-plugin-apex

0.0 0.0 0.0 28.33 MB

Code formatter for the Apex Programming Language

License: MIT License

JavaScript 74.09% TeX 0.79% Apex 25.12%

prettier-plugin-apex's Introduction

Prettier Apex Build Status npm

Prettier Banner

This is a code formatter for the Apex Programming Language, used on the Salesforce development platform.

It uses the excellent Prettier engine for formatting, and the jorje compiler from Salesforce for parsing.

Status

This project is actively being worked on, and has been tested on production code.

  • Formatting still needs work.
  • Some defaults might be changed in the future, e.g. default number of spaces, continuation indent, etc.

Usage

Requirements

  • Node >= 8
  • Java Runtime Engine >= 1.8.0

How to use

First, install the library:

# Install locally
npm install --save-dev prettier prettier-plugin-apex

# Or install globally
npm install --global prettier prettier-plugin-apex

If you install globally, run:

prettier --write "/path/to/project/**/*.{trigger,cls}"

If you install locally, you can add prettier as a script in package.json:

{
  "scripts": {
    "prettier": "prettier"
  }
}

Then in order to run it:

npm run prettier -- --write "/path/to/project/**/*.{trigger,cls}"

Configuration

This library follows the same configuration format as Prettier, which is documented here.

The amount of configuration is very limited, because this is intended to be a very opinionated formatter. Here is the default configuration that can be overriden:

{
  "tabWidth": 2,
  "printWidth": 80,
  "useTab": false
}

Which means that by default, the formatted code will use 2 spaces for indentation, and will try to format every line to contain under 80 characters.

Performance Tips/3rd party integration

By default, this library invokes a CLI application to get the AST of the Apex code. However, since this CLI application is written in Java, there is a heavy start up cost associated with it. In order to alleviate this issue, we also have an optional Nailgun server that makes sure the start up is invoked exactly once. This is especially useful if this library is integrated in a 3rd party application.

In order to use this server, you have to evoke it out of band before running Prettier, as well as specifying a special flag when running Prettier:

# Start the server (if installed globally)
start-apex-server
# Or if installed locally
node /path/to/libary/bin/start-apex-server.js

# In a separate console
prettier --use-standalone-server --write "/path/to/project/**/*.{trigger,cls}"

# After you are done, stop the server (if installed globally)
stop-apex-server
# Or if installed locally
node /path/to/libary/bin/stop-apex-server.js

License

MIT

prettier-plugin-apex's People

Contributors

dangmai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.