Skip to content

Commit 532be9c

Browse files
authored
Merge pull request #38 from CiGit/settings-update
Update to prettier 0.21.0
2 parents d039ce4 + fa6e980 commit 532be9c

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
33

44
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
55

6+
## [Unreleased]
7+
- New setting `jsxBracketSameLine`. (prettier 0.17.0)
8+
- Changed `trailingComma` setting `['none', 'es5', 'all']` (prettier 0.19.0)
9+
610
## [0.7.0]
711
- Removed `Prettier` action.
812
- Use vscode actions `Format Document` and `Format Selection`.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ Use the flow parser instead of babylon. **Deprecated** use `parser: 'flow'` inst
4545
#### singleQuote (default: false)
4646
If true, will use single instead of double quotes
4747

48-
#### trailingComma (default: false)
49-
Controls the printing of trailing commas wherever possible
48+
#### trailingComma (default: 'none')
49+
Controls the printing of trailing commas wherever possible. Valid options:
50+
- "none" - No trailing commas
51+
- "es5" - Trailing commas where valid in ES5 (objects, arrays, etc)
52+
- "all" - Trailing commas wherever possible (function arguments)
5053

5154
#### bracketSpacing (default: true)
5255
Controls the printing of spaces inside object literals
5356

57+
#### jsxBracketSameLine (default: false)
58+
If true, puts the `>` of a multi-line jsx element at the end of the last line instead of being alone on the next line
59+
5460
#### parser (default: 'babylon')
5561
Which parser to use. Valid options are 'flow' and 'babylon'
5662

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,24 @@
5555
"description": "If true, will use single instead of double quotes"
5656
},
5757
"prettier.trailingComma": {
58-
"type": "boolean",
59-
"default": false,
58+
"type": "string",
59+
"enum": [
60+
"none",
61+
"es5",
62+
"all"
63+
],
64+
"default": "none",
6065
"description": "Controls the printing of trailing commas wherever possible"
6166
},
6267
"prettier.bracketSpacing": {
6368
"type": "boolean",
6469
"default": true,
65-
"description": "Controls the printing of spaces inside array and objects"
70+
"description": "Controls the printing of spaces inside object literals"
71+
},
72+
"prettier.jsxBracketSameLine": {
73+
"type": "boolean",
74+
"default": false,
75+
"description": "If true, puts the `>` of a multi-line jsx element at the end of the last line instead of being alone on the next line"
6676
},
6777
"prettier.parser": {
6878
"type": "string",
@@ -90,6 +100,6 @@
90100
"@types/mocha": "^2.2.32"
91101
},
92102
"dependencies": {
93-
"prettier": "0.17.0"
103+
"prettier": "0.21.0"
94104
}
95-
}
105+
}

src/PrettierEditProvider.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import {
1111

1212
const prettier = require('prettier');
1313

14+
type ParserOption = 'babylon' | 'flow'
15+
type TrailingCommaOption = 'none' | 'es5' | 'all' | boolean /* deprecated boolean*/
16+
1417
interface PrettierConfig {
1518
printWidth: number,
1619
tabWidth: number,
1720
useFlowParser: boolean, // deprecated
1821
singleQuote: boolean,
19-
trailingComma: boolean,
22+
trailingComma: TrailingCommaOption,
2023
bracketSpacing: boolean,
21-
parser: string
24+
jsxBracketSameLine: boolean,
25+
parser: ParserOption
2226
}
2327

2428
function format(text: string): string {
@@ -30,14 +34,24 @@ function format(text: string): string {
3034
if (!parser) { // unset config
3135
parser = config.useFlowParser ? 'flow' : 'babylon';
3236
}
37+
/*
38+
handle trailingComma changes boolean -> string
39+
*/
40+
let trailingComma = config.trailingComma;
41+
if (trailingComma === true) {
42+
trailingComma = 'es5';
43+
} else if (trailingComma === false) {
44+
trailingComma = 'none';
45+
}
3346
let transformed: string;
3447
try {
3548
return prettier.format(text, {
3649
printWidth: config.printWidth,
3750
tabWidth: config.tabWidth,
3851
singleQuote: config.singleQuote,
39-
trailingComma: config.trailingComma,
52+
trailingComma,
4053
bracketSpacing: config.bracketSpacing,
54+
jsxBracketSameLine: config.jsxBracketSameLine,
4155
parser: parser
4256
});
4357
} catch (e) {
@@ -72,4 +86,4 @@ class PrettierEditProvider implements
7286
}
7387

7488
export default PrettierEditProvider;
75-
export { PrettierConfig }
89+
export { PrettierConfig }

src/extension.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ import EditProvider, { PrettierConfig } from './PrettierEditProvider';
99

1010
const VALID_LANG: DocumentSelector = ['javascript', 'javascriptreact'];
1111

12-
export function activate(context: ExtensionContext) {
12+
function checkConfig() {
1313
const config: PrettierConfig = workspace.getConfiguration('prettier') as any;
14-
const editProvider = new EditProvider()
1514
if (config.useFlowParser) {
16-
window.showWarningMessage("Option 'useFlowParser' has been deprecated. Use 'parser: \"flow\"' instead.")
15+
window.showWarningMessage("Option 'useFlowParser' has been deprecated. Use 'parser: \"flow\"' instead.");
16+
}
17+
if (typeof config.trailingComma === 'boolean') {
18+
window.showWarningMessage("Option 'trailingComma' as a boolean value has been deprecated. Use 'none', 'es5' or 'all' instead.");
1719
}
20+
}
21+
export function activate(context: ExtensionContext) {
22+
const editProvider = new EditProvider();
23+
checkConfig();
24+
1825
context.subscriptions.push(
1926
languages.registerDocumentRangeFormattingEditProvider(VALID_LANG, editProvider)
2027
);

0 commit comments

Comments
 (0)