-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.prettierrc-base.js
67 lines (59 loc) · 1.91 KB
/
.prettierrc-base.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
function toPosixPath(input) {
return input.replace(/\\/g, '/').replace(/^\w+:/, '');
}
const posixDirname = path.posix.dirname(toPosixPath(__dirname));
function findClosestNodeModulesPath(dirPath = __dirname) {
const currentAttempt = path.join(dirPath, 'node_modules');
if (fs.existsSync(currentAttempt)) {
return currentAttempt;
} else if (dirPath === '/') {
throw new Error(`Could not find node_modules directory.`);
} else {
return findClosestNodeModulesPath(path.dirname(dirPath));
}
}
const nodeModules = toPosixPath(findClosestNodeModulesPath());
const plugins = [
'prettier-plugin-toml',
'prettier-plugin-sort-json',
'prettier-plugin-packagejson',
'prettier-plugin-multiline-arrays',
'prettier-plugin-organize-imports',
'prettier-plugin-jsdoc',
].map((pluginName) => {
// account for installations where node_modules is flattened and installations where it's nested
const flattenedPath = path.posix.join(nodeModules, pluginName);
const nestedPath = path.posix.join(
nodeModules,
'celestial-alignment',
'node_modules',
pluginName,
);
if (fs.existsSync(flattenedPath)) {
return path.posix.resolve(posixDirname, flattenedPath);
} else {
return path.posix.resolve(posixDirname, nestedPath);
}
});
/**
* @typedef {import('prettier-plugin-multiline-arrays').MultilineArrayOptions} MultilineOptions
*
* @typedef {import('prettier').Options} PrettierOptions
* @type {PrettierOptions & MultilineOptions}
*/
const prettierConfig = {
arrowParens: 'always',
bracketSpacing: false,
endOfLine: 'lf',
htmlWhitespaceSensitivity: 'ignore',
jsonRecursiveSort: true,
bracketSameLine: false,
plugins,
printWidth: 100,
singleQuote: true,
tabWidth: 4,
trailingComma: 'all',
};
module.exports = prettierConfig;