asljs-sfmt
v0.1.11
Published
A command line tool for formatting JavaScript and TypeScript according to the Alexandrite Software Library style guide.
Maintainers
Readme
sfmt
Part of Alexandrite Software Library - a set of high-quality, performant JavaScript libraries for everyday use.
Below are some examples of how the code is formatted with this tool. For more details, see the FORMATTING.md file. The source code of this project is formatted with the tool itself, therefore for complete example of the formatting rules, see the source code of this project.
Highlights
Import
- one declaration per line
- aligned with first declaration
- from is on a new line, indented
import { format,
rules }
from 'sfmt';Assignments
- newline after
=if the value is complex - applied to assignment, new varaible declaration
let code =
getCode(
declaration);Function
- parameters - double-indented
- closing parenthesis - on a new line, indented
- return type - after the closing parenthesis
- body opening brace - on a new line, aligned with
function
function getIndentation(
sourceCode: SourceCode,
node: AST.Token
): string
{
...
}If
- criteria - indented (if complex)
if (
nodeLocation === undefined
|| nodeLocation === null
) {
return '';
}For
- each part of the for statement is on a new line, indented
for (
let index = 0;
index < node.arguments.length;
index++
) {
...
}Objects and Arrays
- first property/array item - on the same line as opening brace
- subsequent properties/array items - on a new line, aligned with the first
{ first: 'a',
second:
{ a: 1,
b: 2 },
third:
[ 'one',
'two' ] };