A prettier plugin that aligns properties of object literals.
Align by 'colon': Algn by 'value':
a = { a = {
name : 'foo', name: 'foo',
width : 100, width: 100,
height : 20, height: 20,
}; };
.
For Prettier v2:
npm install -D prettier@^2 @yikes2000/prettier-plugin-preserve-line
For Prettier v3:[^1]
npm install -D prettier @yikes2000/prettier-plugin-preserve-line
.
JSON example:
{
"plugins": ["@yikes2000/prettier-plugin-align-object-properties"]
}
JS example (CommonJS module):
module.exports = {
plugins: ['@yikes2000/prettier-plugin-align-object-properties'],
alignObjectProperties: 'colon',
};
JS example (ES module):
export default {
plugins: ['@yikes2000/prettier-plugin-align-object-properties'],
alignObjectProperties: 'value',
};
.
Align properties of object literals.
Properties are grouped by consecutive lines properties and inline comments:
const a = {
be : true,
cat : 123,
door : "knob",
// inline comment, continues group
extra : true,
east : 123,
foo : [
// multi-line, breaks group
1, 2, 3,
],
g : "new group",
h : "hi",
}
Alignment options: 'colon' (default), 'value', 'none'
Align by 'colon': Algn by 'value':
a = { a = {
name : 'foo', name: 'foo',
width : 100, width: 100,
height : 20, height: 20,
}; };
Default | CLI Override | API Override |
---|---|---|
colon |
--align-object-propertiens=none |
alignObjectProperties: <string> |
.
Single property is not aligned by default.
const a = {
// force multi-line
bar: true,
}
Default | CLI Override | API Override |
---|---|---|
false |
--align-single-property |
alignSingleProperty: <boolean> |
.
See prettier-plugin-merge-preserve and prettier-plugin-merge.
.
Language | Supported | Notes |
---|---|---|
Javascript | Yes | |
Typescript | Yes |
Implemented using RegExp, which has limitations. Please kindly report issues for evaluation. .
This plugin was templated from Hyeonjong's prettier-plugin-brace-style.