addons/prettier.config.cjsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318const path = require('path');
b69ab319
b69ab3110// Note: there are 2 versions of prettiers:
b69ab3111// - Local prettier. Affects `yarn run prettier`, and editors like `nvim`.
b69ab3112// - Monorepo prettier. Affects `arc lint`, and the internal VSCode.
b69ab3113// Thoroughly test when making changes.
b69ab3114
b69ab3115const config = {
b69ab3116 arrowParens: 'avoid',
b69ab3117 bracketSpacing: false,
b69ab3118 bracketSameLine: true,
b69ab3119 useTabs: false,
b69ab3120 singleQuote: true,
b69ab3121 tabWidth: 2,
b69ab3122 printWidth: 100,
b69ab3123 trailingComma: 'all',
b69ab3124 overrides: [
b69ab3125 {
b69ab3126 files: ['**/*.{ts,tsx}'],
b69ab3127 options: {
b69ab3128 parser: 'typescript',
b69ab3129 },
b69ab3130 },
b69ab3131 ],
b69ab3132};
b69ab3133
b69ab3134// `arc lint` runs the monorepo prettier, with cwd == monorepo root
b69ab3135// related code path: tools/arcanist/lint/external/prettier_linter.js
b69ab3136const isArcLint = process.env.ARC2_COMMAND != null; // could be: 'lint', 'linttool', 'f'
b69ab3137if (isArcLint) {
b69ab3138 // Use prettier2's "plugin search" to discover and load the plugin.
b69ab3139 // (see "externalAutoLoadPluginInfos" in tools/third-party/prettier/node_modules/prettier/index.js)
b69ab3140 // Need a different approach for prettier3 (https://github.com/prettier/prettier/pull/14759).
b69ab3141 config.pluginSearchDirs = ['.'];
b69ab3142} else {
b69ab3143 // Explicitly set the plugin.
b69ab3144 // Does not work with the monorepo prettier (arc lint).
b69ab3145 // - `prettier-plugin-organize-imports` cannot be imported from monorepo root.
b69ab3146 // - `require('prettier-plugin-organize-imports')` does not work either
b69ab3147 // because its dependency (ex. `typescript`) cannot be imported from
b69ab3148 // monorepo root.
b69ab3149
b69ab3150 // Normally, you'd just use 'prettier-plugin-organize-imports',
b69ab3151 // but it incorrectly looks for this relative to the monorepo prettier,
b69ab3152 // but we want it to find it in our workspace's node_modules.
b69ab3153 config.plugins = [path.join(__dirname, 'node_modules/prettier-plugin-organize-imports/index.js')];
b69ab3154}
b69ab3155
b69ab3156module.exports = config;