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