1.1.0-beta.5 • Published 7 years ago

scalafmt v1.1.0-beta.5

Weekly downloads
1
License
Apache-2.0
Repository
-
Last release
7 years ago

scalafmt

A JS API for scalafmt.

It exposes a single function:

  • format(code: string, configString?: string, ranges?: Range[]): string: formats the given code

where:

  • code is the entire source code you want to format
  • configString optional is the Scalafmt configuration (as documented here). If not provided, the default one is used.
  • ranges optional is an array of ranges. If not provided, the entire document is formatted. Each range is an object with two properties:
    • start: the start line of the range
    • end: the end line of the range (not inclusive)

Example:

const { format } = require('scalafmt');

const input = `
object Main {
  case class Foo(
    a: String,
      b: Boolean,
        c: Int
  )
val x =  Foo("a", true
  , 2)
}`;
const output = format(input);
console.log(output);

// Output:

// object Main {
//   case class Foo(
//       a: String,
//       b: Boolean,
//       c: Int
//   )
//   val x = Foo("a", true, 2)
// }