-
Notifications
You must be signed in to change notification settings - Fork 296
/
Copy pathprettier.config.cjs
56 lines (50 loc) · 1.94 KB
/
prettier.config.cjs
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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
// Note: there are 2 versions of prettiers:
// - Local prettier. Affects `yarn run prettier`, and editors like `nvim`.
// - Monorepo prettier. Affects `arc lint`, and the internal VSCode.
// Thoroughly test when making changes.
const config = {
arrowParens: 'avoid',
bracketSpacing: false,
bracketSameLine: true,
useTabs: false,
singleQuote: true,
tabWidth: 2,
printWidth: 100,
trailingComma: 'all',
overrides: [
{
files: ['**/*.{ts,tsx}'],
options: {
parser: 'typescript',
},
},
],
};
// `arc lint` runs the monorepo prettier, with cwd == monorepo root
// related code path: tools/arcanist/lint/external/prettier_linter.js
const isArcLint = process.env.ARC2_COMMAND != null; // could be: 'lint', 'linttool', 'f'
if (isArcLint) {
// Use prettier2's "plugin search" to discover and load the plugin.
// (see "externalAutoLoadPluginInfos" in tools/third-party/prettier/node_modules/prettier/index.js)
// Need a different approach for prettier3 (https://github.com/prettier/prettier/pull/14759).
config.pluginSearchDirs = ['.'];
} else {
// Explicitly set the plugin.
// Does not work with the monorepo prettier (arc lint).
// - `prettier-plugin-organize-imports` cannot be imported from monorepo root.
// - `require('prettier-plugin-organize-imports')` does not work either
// because its dependency (ex. `typescript`) cannot be imported from
// monorepo root.
// Normally, you'd just use 'prettier-plugin-organize-imports',
// but it incorrectly looks for this relative to the monorepo prettier,
// but we want it to find it in our workspace's node_modules.
config.plugins = [path.join(__dirname, 'node_modules/prettier-plugin-organize-imports')];
}
module.exports = config;