scalafmt

1.1.0-beta.5 • Public • Published

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)
// }

Readme

Keywords

none

Package Sidebar

Install

npm i scalafmt

Weekly Downloads

8

Version

1.1.0-beta.5

License

Apache-2.0

Last publish

Collaborators

  • tanishiking
  • olafurpg
  • xeno-by
  • gabro
  • ckipp01