forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prettierx] -- align-object-properties option
feature ported from prettier-miscellaneous (arijs#7 & arijs#8) with adaptations by @brodybits (Christopher J. Brody <[email protected]>), including: * JavaScript tests in es test subdirectory * not applied with any of the JSON parsers, as verified by json test (not applied in case parser matches /json/ pattern) * --align-object-properties option config & docs adapted (copy-pasted) into newer prettier/prettierx project structure * const shouldBreak hack updated (and reformatted), can now deal with an object that is partially but not completely defined on the first line, as verified by an additional test object * extra comment(s) & spacing * additional testing to ensure that it does not get unwanted padding in case an object is on a single line * hack with fix for object partially but not completely defined on the first line, with additional test to verify * test coverage on babel, flow, and typescript parsers * test with shorthand object member * tests_integration updates * some other added tests * lint fixes Co-authored-by: Christopher J. Brody <[email protected]> Co-authored-by: Joseph Frazier <[email protected]> Co-authored-by: Rafael Hengles <[email protected]> Co-authored-by: Ika <[email protected]> Co-authored-by: Lucas Azzola <[email protected]>
- Loading branch information
1 parent
af67abe
commit 1674f7f
Showing
15 changed files
with
467 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
tests/align-object-properties/es/__snapshots__/jsfmt.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`o.js 1`] = ` | ||
====================================options===================================== | ||
alignObjectProperties: true | ||
parsers: ["babel", "flow", "typescript"] | ||
printWidth: 80 | ||
| printWidth | ||
=====================================input====================================== | ||
o = { | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
keyasdf:3 | ||
} | ||
o = { | ||
[namelonglonglong]: 'value', | ||
2:3, | ||
"k-2":2, | ||
keyasdf:3 | ||
} | ||
// with shorthand member: | ||
o = { | ||
shorthand, | ||
[namelonglonglong]: 'value', | ||
2:3, | ||
"k-2":2, | ||
keyasdf:3 | ||
} | ||
// with extra-long shorthand member: | ||
o = { | ||
extraLongShorthand, | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
keyasdf:3 | ||
} | ||
// Ensure this object does not get extra padding: | ||
o = { [name]: 'value', 2:3, "k-2":2, keyasdf:3 } | ||
// Ensure this also does not get extra padding: | ||
o = { [name]: 'value', 2:3, "k-2":2, | ||
keyasdf:3 | ||
} | ||
// Ensure this one *does* get the padding: | ||
o = { // with a comment here | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
keyasdf:3 | ||
} | ||
// with multiple entries on a single line in the input: | ||
o = { | ||
[namelonglonglong]: 'value', | ||
2:3, "k-2":2, keyasdf:3 | ||
} | ||
// longer object on a single line: | ||
o = { [namelonglonglong]: 'value', 2:3, "k-2":2, keyasdf:3 } | ||
// with nested object member: | ||
o = { | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
nested: { | ||
a:1, | ||
next:2 | ||
}, | ||
keyasdf:3 | ||
} | ||
// with nested object member on a single line | ||
// (which should not get extra padding): | ||
o = { | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
nested: { a:1, next:2 }, | ||
keyasdf:3 | ||
} | ||
// with nested object member which is reformatted onto single line | ||
// (which should not get extra padding): | ||
o = { | ||
[name]: 'value', | ||
2:3, | ||
"k-2":2, | ||
nested: {a:1, | ||
next:2}, | ||
keyasdf:3 | ||
} | ||
=====================================output===================================== | ||
o = { | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
o = { | ||
[namelonglonglong] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
// with shorthand member: | ||
o = { | ||
shorthand, | ||
[namelonglonglong] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
// with extra-long shorthand member: | ||
o = { | ||
extraLongShorthand, | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
// Ensure this object does not get extra padding: | ||
o = { [name]: "value", 2: 3, "k-2": 2, keyasdf: 3 }; | ||
// Ensure this also does not get extra padding: | ||
o = { [name]: "value", 2: 3, "k-2": 2, keyasdf: 3 }; | ||
// Ensure this one *does* get the padding: | ||
o = { | ||
// with a comment here | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
// with multiple entries on a single line in the input: | ||
o = { | ||
[namelonglonglong] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
keyasdf : 3 | ||
}; | ||
// longer object on a single line: | ||
o = { [namelonglonglong]: "value", 2: 3, "k-2": 2, keyasdf: 3 }; | ||
// with nested object member: | ||
o = { | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
nested : { | ||
a : 1, | ||
next : 2 | ||
}, | ||
keyasdf : 3 | ||
}; | ||
// with nested object member on a single line | ||
// (which should not get extra padding): | ||
o = { | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
nested : { a: 1, next: 2 }, | ||
keyasdf : 3 | ||
}; | ||
// with nested object member which is reformatted onto single line | ||
// (which should not get extra padding): | ||
o = { | ||
[name] : "value", | ||
2 : 3, | ||
"k-2" : 2, | ||
nested : { a: 1, next: 2 }, | ||
keyasdf : 3 | ||
}; | ||
================================================================================ | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run_spec(__dirname, ["babel", "flow", "typescript"], { | ||
alignObjectProperties: true | ||
}); |
Oops, something went wrong.