| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | const path = require('path'); |
| 9 | |
| 10 | // Note: there are 2 versions of prettiers: |
| 11 | // - Local prettier. Affects `yarn run prettier`, and editors like `nvim`. |
| 12 | // - Monorepo prettier. Affects `arc lint`, and the internal VSCode. |
| 13 | // Thoroughly test when making changes. |
| 14 | |
| 15 | const config = { |
| 16 | arrowParens: 'avoid', |
| 17 | bracketSpacing: false, |
| 18 | bracketSameLine: true, |
| 19 | useTabs: false, |
| 20 | singleQuote: true, |
| 21 | tabWidth: 2, |
| 22 | printWidth: 100, |
| 23 | trailingComma: 'all', |
| 24 | overrides: [ |
| 25 | { |
| 26 | files: ['**/*.{ts,tsx}'], |
| 27 | options: { |
| 28 | parser: 'typescript', |
| 29 | }, |
| 30 | }, |
| 31 | ], |
| 32 | }; |
| 33 | |
| 34 | // `arc lint` runs the monorepo prettier, with cwd == monorepo root |
| 35 | // related code path: tools/arcanist/lint/external/prettier_linter.js |
| 36 | const isArcLint = process.env.ARC2_COMMAND != null; // could be: 'lint', 'linttool', 'f' |
| 37 | if (isArcLint) { |
| 38 | // Use prettier2's "plugin search" to discover and load the plugin. |
| 39 | // (see "externalAutoLoadPluginInfos" in tools/third-party/prettier/node_modules/prettier/index.js) |
| 40 | // Need a different approach for prettier3 (https://github.com/prettier/prettier/pull/14759). |
| 41 | config.pluginSearchDirs = ['.']; |
| 42 | } else { |
| 43 | // Explicitly set the plugin. |
| 44 | // Does not work with the monorepo prettier (arc lint). |
| 45 | // - `prettier-plugin-organize-imports` cannot be imported from monorepo root. |
| 46 | // - `require('prettier-plugin-organize-imports')` does not work either |
| 47 | // because its dependency (ex. `typescript`) cannot be imported from |
| 48 | // monorepo root. |
| 49 | |
| 50 | // Normally, you'd just use 'prettier-plugin-organize-imports', |
| 51 | // but it incorrectly looks for this relative to the monorepo prettier, |
| 52 | // but we want it to find it in our workspace's node_modules. |
| 53 | config.plugins = [path.join(__dirname, 'node_modules/prettier-plugin-organize-imports/index.js')]; |
| 54 | } |
| 55 | |
| 56 | module.exports = config; |
| 57 | |