Skip to content

Commit

Permalink
sort-imports: switch to prettier-plugin-organize-imports
Browse files Browse the repository at this point in the history
Summary:
This has better compatibility with vim / emacs, since prettier is the code
formatter and there is no need to execute the "code fix" provided by eslint.

I first tried `prettier-plugin-sort-imports`. but it has a serious bug
prettier/prettier-vscode#3578 - incorrectly
drops type parameters, and breaks type checking.
This issue might be fixable by upgrading prettier, but we also use the monorepo
prettier and upgrading that requires rewriting all javascript files in the
monorepo, which I'd like to avoid for now.

There are 2 prettiers in use:
- Local prettier. Affects `yarn run prettier`, and editors like `nvim`.
- Monorepo prettier. Affects `arc lint`, and the internal VSCode.
Right now they have the same version. The monorepo prettier sets cwd to
fbsource root, which requires extra logic to load plugins.

To support both, check `prettier.config.mjs`.

Reviewed By: muirdm, evangrayk

Differential Revision: D69540547

fbshipit-source-id: 9fe5b4f213be8bd9630d6f256a12c52d99cb15ff
  • Loading branch information
quark-zju authored and facebook-github-bot committed Feb 12, 2025
1 parent 4c21a25 commit f6d1f75
Show file tree
Hide file tree
Showing 320 changed files with 1,286 additions and 1,259 deletions.
15 changes: 3 additions & 12 deletions addons/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
'@typescript-eslint',
// enforce rules of hooks and hook dependencies
'react-hooks',
// Sorting imports is hard...
// Sorting imports is maintained by prettier-plugin-organize-imports
'import',
// Allow locally defined custom rules
'rulesdir',
Expand Down Expand Up @@ -63,17 +63,8 @@ module.exports = {
curly: 'error',
'dot-notation': 'error',
'import/no-duplicates': 'error',
'import/order': [
'error',
{
groups: ['type'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],
// Sorting imports is maintained by prettier-plugin-organize-imports
'import/order': 'off',
'no-await-in-loop': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
Expand Down
10 changes: 0 additions & 10 deletions addons/.prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion addons/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type {ReactNode} from 'react';
import type {ReactProps} from './utils';

import * as stylex from '@stylexjs/stylex';

Expand Down
2 changes: 1 addition & 1 deletion addons/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import type {ReactNode} from 'react';

import {Tooltip} from './Tooltip';
import * as stylex from '@stylexjs/stylex';
import {Tooltip} from './Tooltip';

import './Banner.css';

Expand Down
6 changes: 3 additions & 3 deletions addons/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ForwardedRef} from 'react';
import type {ExclusiveOr} from './Types';
import type {ReactProps} from './utils';
import type {ForwardedRef} from 'react';

import {layout} from './theme/layout';
import {colors} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {forwardRef, type ReactNode} from 'react';
import {layout} from './theme/layout';
import {colors} from './theme/tokens.stylex';

/**
* StyleX tries to evaluate CSS variables and store them separately.
Expand Down
2 changes: 1 addition & 1 deletion addons/components/ButtonDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import type {ReactNode} from 'react';

import * as stylex from '@stylexjs/stylex';
import {Button, buttonStyles} from './Button';
import {Icon} from './Icon';
import {colors, spacing} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
container: {
Expand Down
2 changes: 1 addition & 1 deletion addons/components/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import {colors} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import React from 'react';
import {colors} from './theme/tokens.stylex';

const styles = stylex.create({
group: {
Expand Down
6 changes: 3 additions & 3 deletions addons/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type react from 'react';
import type {ReactProps} from './utils';

import {layout} from './theme/layout';
import {spacing} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {useEffect, useId, useRef} from 'react';
import {layout} from './theme/layout';
import {spacing} from './theme/tokens.stylex';

const cssVarFocusWithinBorder = '--checkbox-focus-within-color';
const styles = stylex.create({
Expand Down
2 changes: 1 addition & 1 deletion addons/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type {ReactNode} from 'react';
import type {ReactProps} from './utils';

import * as stylex from '@stylexjs/stylex';
import {useId} from 'react';
Expand Down
2 changes: 1 addition & 1 deletion addons/components/ErrorNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import type {ReactNode} from 'react';

import React, {Component, useState} from 'react';
import {Icon} from './Icon';
import {Tooltip} from './Tooltip';
import React, {useState, Component} from 'react';

import './error-notice.css';

Expand Down
2 changes: 1 addition & 1 deletion addons/components/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import type {ReactProps} from './utils';

import {spacing} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {spacing} from './theme/tokens.stylex';

type ContainerProps = ReactProps<HTMLDivElement> & {xstyle?: stylex.StyleXStyles};

Expand Down
4 changes: 2 additions & 2 deletions addons/components/HorizontallyGrowingTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type {ForwardedRef} from 'react';
import type {ReactProps} from './utils';

import {textFieldStyles} from './TextField';
import * as stylex from '@stylexjs/stylex';
import {forwardRef} from 'react';
import {textFieldStyles} from './TextField';

const styles = stylex.create({
horizontalGrowContainer: {
Expand Down
2 changes: 1 addition & 1 deletion addons/components/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import type {ReactNode} from 'react';

import {colors, font} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {colors, font} from './theme/tokens.stylex';

const styles = stylex.create({
linkButton: {
Expand Down
4 changes: 2 additions & 2 deletions addons/components/Panels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ColumnAlignmentProps} from './Flex';
import type {ReactNode} from 'react';
import type {ColumnAlignmentProps} from './Flex';

import * as stylex from '@stylexjs/stylex';
import {Column, Row} from './Flex';
import {spacing} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';

const styles = stylex.create({
tabList: {
Expand Down
4 changes: 2 additions & 2 deletions addons/components/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import type react from 'react';

import * as stylex from '@stylexjs/stylex';
import {useId} from 'react';
import {Column} from './Flex';
import {Tooltip} from './Tooltip';
import {layout} from './theme/layout';
import {spacing} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {useId} from 'react';

// stylex doesn't support :checked and :before simultaneously very well
import './Radio.css';
Expand Down
2 changes: 1 addition & 1 deletion addons/components/Subtle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {stylexPropsWithClassName} from './utils';
import * as stylex from '@stylexjs/stylex';
import {stylexPropsWithClassName} from './utils';

const styles = stylex.create({
subtle: {
Expand Down
2 changes: 1 addition & 1 deletion addons/components/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type {ReactNode} from 'react';
import type {ReactProps} from './utils';

import * as stylex from '@stylexjs/stylex';

Expand Down
2 changes: 1 addition & 1 deletion addons/components/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import type {ForwardedRef, ReactNode} from 'react';

import {Column} from './Flex';
import * as stylex from '@stylexjs/stylex';
import {forwardRef, useId} from 'react';
import {Column} from './Flex';

const styles = stylex.create({
root: {
Expand Down
4 changes: 2 additions & 2 deletions addons/components/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ReactProps} from './utils';
import type {ForwardedRef, ReactNode} from 'react';
import type {ReactProps} from './utils';

import {Column} from './Flex';
import * as stylex from '@stylexjs/stylex';
import {forwardRef, useId} from 'react';
import {Column} from './Flex';

export const textFieldStyles = stylex.create({
root: {
Expand Down
2 changes: 1 addition & 1 deletion addons/components/ThemedComponentsRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import type {ReactNode} from 'react';

import {light} from './theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {light} from './theme/tokens.stylex';

type Writable<T> = {-readonly [P in keyof T]: T[P]};
export function ThemedComponentsRoot({
Expand Down
4 changes: 2 additions & 2 deletions addons/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

import type {ExclusiveOr} from './Types';
import type {MouseEvent, ReactNode} from 'react';
import type {ExclusiveOr} from './Types';

import React, {useEffect, useLayoutEffect, useRef, useState} from 'react';
import {ViewportOverlay} from './ViewportOverlay';
import {findParentWithClassName} from './utils';
import {getZoomLevel} from './zoom';
import React, {useLayoutEffect, useEffect, useRef, useState} from 'react';

import './Tooltip.css';

Expand Down
2 changes: 1 addition & 1 deletion addons/components/Typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import type {TypeaheadResult} from './Types';
import type {ReactProps} from './utils';

import {useEffect, useRef, useState} from 'react';
import {Icon} from './Icon';
import {Subtle} from './Subtle';
import {TextField} from './TextField';
import {extractTokens, TokensList, tokensToString} from './Tokens';
import {useRef, useEffect, useState} from 'react';

export function Typeahead({
tokenString,
Expand Down
4 changes: 2 additions & 2 deletions addons/components/__tests__/KeyboardShortcuts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @jest-environment jsdom
*/

import {makeCommandDispatcher, KeyCode, Modifier} from '../KeyboardShortcuts';
import {render, screen, act} from '@testing-library/react';
import '@testing-library/jest-dom';
import {act, render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {useCallback, useState} from 'react';
import {KeyCode, makeCommandDispatcher, Modifier} from '../KeyboardShortcuts';

/* eslint-disable no-bitwise */

Expand Down
3 changes: 1 addition & 2 deletions addons/components/__tests__/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import {render, screen} from '@testing-library/react';
import {ThemedComponentsRoot} from '../ThemedComponentsRoot';
import {ViewportOverlayRoot} from '../ViewportOverlay';
import ComponentExplorer from '../explorer/ComponentExplorer';
import {render, screen} from '@testing-library/react';
import React from 'react';

describe('component library', () => {
it('renders component explorer', () => {
Expand Down
4 changes: 2 additions & 2 deletions addons/components/explorer/ComponentExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import type {StyleXVar} from '@stylexjs/stylex/lib/StyleXTypes';

import * as stylex from '@stylexjs/stylex';
import {useState, type ReactNode} from 'react';
import {Badge} from '../Badge';
import {Banner, BannerKind} from '../Banner';
import {Button} from '../Button';
Expand All @@ -30,8 +32,6 @@ import {Tooltip} from '../Tooltip';
import {Typeahead} from '../Typeahead';
import {layout} from '../theme/layout';
import {colors, font, radius, spacing} from '../theme/tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {useState, type ReactNode} from 'react';

/* eslint-disable no-console */

Expand Down
4 changes: 2 additions & 2 deletions addons/components/explorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import 'react';
import ReactDOM from 'react-dom/client';
import {ThemedComponentsRoot} from '../ThemedComponentsRoot';
import {ViewportOverlayRoot} from '../ViewportOverlay';
import ComponentExplorer from './ComponentExplorer';
import 'react';
import ReactDOM from 'react-dom/client';

import './index.css';

Expand Down
2 changes: 1 addition & 1 deletion addons/components/theme/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {spacing} from './tokens.stylex';
import * as stylex from '@stylexjs/stylex';
import {spacing} from './tokens.stylex';

export const layout = stylex.create({
flexRow: {
Expand Down
2 changes: 1 addition & 1 deletion addons/isl-server/proxy/__tests__/rmtree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import rmtree from '../rmtree';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {exists} from 'shared/fs';
import rmtree from '../rmtree';

describe('rmtree', () => {
let tmp: string;
Expand Down
4 changes: 2 additions & 2 deletions addons/isl-server/proxy/__tests__/run-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import * as util from 'node:util';
import {readExistingServerFile} from '../existingServerStateFiles';
import * as startServer from '../server';
import * as lifecycle from '../serverLifecycle';
import {runProxyMain, parseArgs} from '../startServer';
import * as util from 'node:util';
import {parseArgs, runProxyMain} from '../startServer';

/* eslint-disable require-await */

Expand Down
2 changes: 1 addition & 1 deletion addons/isl-server/proxy/existingServerStateFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import rmtree from './rmtree';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {nullthrows} from 'shared/utils';
import rmtree from './rmtree';

export type ExistingServerInfo = {
sensitiveToken: string;
Expand Down
Loading

0 comments on commit f6d1f75

Please sign in to comment.