Right now prettier is giving me this:
function _project(x, k, dim: number = -1, eps: Float = -1.0) {
if (eps < 0) {
if (x.dtype == torch.float32) {
eps = 4e-3
} else {
eps = 1e-5
}
}
maxnorm = (1 - eps) / sabs(k) ** 0.5
maxnorm = torch.where(k.lt(0), maxnorm, k.newFull([], 1e15))
norm = x.norm({ dim: dim, keepdim: true, p: 2 }).clampMin(1e-15)
cond = norm > maxnorm
projected = (x / norm) * maxnorm
return torch.where(cond, projected, x)
}
function lambdaX(
x: TorchTensor,
k: TorchTensor,
keepdim = false,
dim = -1,
) {
return _lambdaX(x, k, { keepdim: keepdim, dim: dim })
}
function _lambdaX(
x: TorchTensor,
k: TorchTensor,
keepdim: Bool = false,
dim: number = -1,
) {
return (
2 /
(1 + k * x.pow(2).sum({ dim: dim, keepdim: keepdim })).clampMin(
1e-15,
)
)
}
function inner(
x: TorchTensor,
u: TorchTensor,
v: TorchTensor,
k,
keepdim = false,
dim = -1,
) {
Is there a way to configure either prettier or eslint to put a space after some of the blocks, so it is more like this:
function _project(x, k, dim: number = -1, eps: Float = -1.0) {
if (eps < 0) {
if (x.dtype == torch.float32) {
eps = 4e-3
} else {
eps = 1e-5
}
}
maxnorm = (1 - eps) / sabs(k) ** 0.5
maxnorm = torch.where(k.lt(0), maxnorm, k.newFull([], 1e15))
norm = x.norm({ dim: dim, keepdim: true, p: 2 }).clampMin(1e-15)
cond = norm > maxnorm
projected = (x / norm) * maxnorm
return torch.where(cond, projected, x)
}
function lambdaX(
x: TorchTensor,
k: TorchTensor,
keepdim = false,
dim = -1,
) {
return _lambdaX(x, k, { keepdim: keepdim, dim: dim })
}
function _lambdaX(
x: TorchTensor,
k: TorchTensor,
keepdim: Bool = false,
dim: number = -1,
) {
return (
2 /
(1 + k * x.pow(2).sum({ dim: dim, keepdim: keepdim })).clampMin(
1e-15,
)
)
}
function inner(
x: TorchTensor,
u: TorchTensor,
v: TorchTensor,
k,
keepdim = false,
dim = -1,
) {
My prettier config currently is:
{
semi: false,
parser: 'typescript',
trailingComma: 'all',
singleQuote: true,
printWidth: 72,
tabWidth: 2,
useTabs: false,
arrowParens: 'avoid',
quoteProps: 'as-needed',
bracketSpacing: true,
proseWrap: 'always',
endOfLine: 'lf',
singleAttributePerLine: true,
importOrder: [
'^\w(.*)$',
'^@(.*)$',
'~(.*)$',
'\..(.*)$',
'\.(.*)$',
],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
}
And I am programmatically running it like this:
const prettier = require('prettier')
function pretty(string) {
return prettier.format(string, config)
}
What is as close as you can get to this “space between blocks” style?