-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprettier.js
53 lines (45 loc) · 1.22 KB
/
prettier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// @ts-check
const path = require('path');
const editorConfigToPrettier = require('editorconfig-to-prettier');
const { json, install, getStyleForFile } = require('mrm-core');
const packages = {
prettier: '>=2',
};
const defaultPrettierOptions = {
printWidth: 100,
tabWidth: 4,
useTabs: true,
semi: false,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'avoid',
};
// Remove options that have the same values as Prettier defaults
function removeDefaultOptions(options) {
const newOptions = { ...options };
for (const option in newOptions) {
if (newOptions[option] === defaultPrettierOptions[option]) {
delete newOptions[option];
}
}
return newOptions;
}
module.exports.task = function () {
// Try to read options from EditorConfig
const testJsFile = path.join(process.cwd(), 'test.js');
const editorconfigOptions = editorConfigToPrettier(
getStyleForFile(testJsFile)
);
// .prettierrc
const prettierrc = json('.prettierrc');
// Update options and save
prettierrc
.merge(Object.assign({}, defaultPrettierOptions, editorconfigOptions))
.save();
// Dependencies
install(packages);
};
module.exports.description = 'Adds Prettier';