Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prettier plugin to sort imports in a consistent and automated way #877

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ import { Link } from '@hypothesis/frontend-shared';
### Icons (legacy)

```js
import { profile, share, trash } from '@hypothesis/frontend-shared/lib/icons';

import { registerIcons } from '@hypothesis/frontend-shared';
import { profile, share, trash } from '@hypothesis/frontend-shared/lib/icons';

registerIcons({ profile, shareAnnotation: share, trash });

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-virtual": "^3.0.0",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"autoprefixer": "^10.3.7",
Expand Down Expand Up @@ -75,7 +76,12 @@
},
"prettier": {
"arrowParens": "avoid",
"singleQuote": true
"singleQuote": true,
"importOrder": [
"^.\\/components\\/patterns\\/(.*)Components$",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regular expression ensures the imports for legacy components in the pattern library router are placed in their own group (as they are now), to ease eventual removal.

Once those are removed we can also remove this regexp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding removal of this to the list of small tasks for version 6: #876

"^[./]"
],
"importOrderSeparation": true
},
"files": [
"lib",
Expand Down
2 changes: 1 addition & 1 deletion rollup-tests.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { string } from 'rollup-plugin-string';
import virtual from '@rollup/plugin-virtual';
import { string } from 'rollup-plugin-string';

export default {
input: 'build/scripts/test-inputs.js', // Input file generated by gulp task
Expand Down
1 change: 0 additions & 1 deletion scripts/generate-icons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import * as path from 'node:path';

import { format } from 'prettier';
import { optimize } from 'svgo';

Expand Down
5 changes: 2 additions & 3 deletions scripts/serve-pattern-library.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as path from 'path';
import { fileURLToPath } from 'url';

import express from 'express';
import log from 'fancy-log';
import mustacheExpress from 'mustache-express';
import * as path from 'path';
import { fileURLToPath } from 'url';

export function servePatternLibrary(port = 4001) {
const dirname = path.dirname(fileURLToPath(import.meta.url));
Expand Down
4 changes: 2 additions & 2 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
import checkboxSVG from '../../images/icons/checkbox.svg';
import classnames from 'classnames';

// @ts-ignore
import checkboxSVG from '../../images/icons/checkbox.svg';
import { registerIcon, SvgIcon } from './SvgIcon';

// Register the checkbox icon for use
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';

// @ts-ignore
import cancelSVG from '../../images/icons/cancel.svg';
import { IconButton, LabeledButton } from './buttons';
import { registerIcon, SvgIcon } from './SvgIcon';
import { IconButton, LabeledButton } from './buttons';

// Register the checkbox icon for use
const cancelIcon = registerIcon('cancel', cancelSVG);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import classnames from 'classnames';

// @ts-ignore
import cancelSVG from '../../images/icons/cancel.svg';
import { IconButton } from './buttons';
import { registerIcon, SvgIcon } from './SvgIcon';
import { IconButton } from './buttons';

// Register the cancel icon for use
const cancelIcon = registerIcon('cancel', cancelSVG);
Expand Down
5 changes: 2 additions & 3 deletions src/components/data/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { useArrowKeyNavigation } from '../../hooks/use-arrow-key-navigation';
import { useSyncedRef } from '../../hooks/use-synced-ref';
import type { CompositeProps } from '../../types';
import { downcastRef } from '../../util/typing';

import { SpinnerSpokesIcon } from '../icons';
import ScrollContext from './ScrollContext';
import Table from './Table';
import TableHead from './TableHead';
import TableBody from './TableBody';
import TableRow from './TableRow';
import TableCell from './TableCell';
import TableFoot from './TableFoot';
import TableHead from './TableHead';
import TableRow from './TableRow';

export type TableColumn = {
field: string;
Expand Down
3 changes: 1 addition & 2 deletions src/components/data/Scroll.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import classnames from 'classnames';

import { downcastRef } from '../../util/typing';
import { useSyncedRef } from '../../hooks/use-synced-ref';

import { downcastRef } from '../../util/typing';
import ScrollContext from './ScrollContext';

/**
Expand Down
1 change: 0 additions & 1 deletion src/components/data/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import classnames from 'classnames';

import { useSyncedRef } from '../../hooks/use-synced-ref';
import { downcastRef } from '../../util/typing';

import TableContext from './TableContext';

/**
Expand Down
3 changes: 1 addition & 2 deletions src/components/data/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import classnames from 'classnames';
import { useContext } from 'preact/hooks';

import { downcastRef } from '../../util/typing';

import TableSectionContext from './TableSectionContext';
import TableContext from './TableContext';
import TableSectionContext from './TableSectionContext';

/**
* @typedef {import('../../types').PresentationalProps} CommonProps
Expand Down
1 change: 0 additions & 1 deletion src/components/data/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useContext } from 'preact/hooks';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import TableSectionContext from './TableSectionContext';

export type TableCellProps = PresentationalProps &
Expand Down
1 change: 0 additions & 1 deletion src/components/data/TableFoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { JSX } from 'preact';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import TableSectionContext from './TableSectionContext';
import type { TableSection } from './TableSectionContext';

Expand Down
1 change: 0 additions & 1 deletion src/components/data/TableHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import classnames from 'classnames';
import { useContext } from 'preact/hooks';

import { downcastRef } from '../../util/typing';

import TableContext from './TableContext';
import TableSectionContext from './TableSectionContext';

Expand Down
3 changes: 1 addition & 2 deletions src/components/data/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { useContext } from 'preact/hooks';
import { useSyncedRef } from '../../hooks/use-synced-ref';
import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import TableSectionContext from './TableSectionContext';
import TableContext from './TableContext';
import TableSectionContext from './TableSectionContext';

type ComponentProps = {
selected?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/components/data/Thumbnail.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import classnames from 'classnames';
import { toChildArray } from 'preact';
import { downcastRef } from '../../util/typing';

import AspectRatio from './AspectRatio';
import { EllipsisIcon } from '../icons';
import { downcastRef } from '../../util/typing';
import Spinner from '../feedback/Spinner';
import { EllipsisIcon } from '../icons';
import AspectRatio from './AspectRatio';

/**
* @typedef {import('../../types').CompositeProps} CompositeProps
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/AspectRatio-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testSimpleComponent } from '../../test/common-tests';

import AspectRatio from '../AspectRatio';

const createComponent = (Component, props = {}) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/DataTable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { mount } from 'enzyme';
import { useState } from 'preact/hooks';

import { testCompositeComponent } from '../../test/common-tests';

import DataTable from '../DataTable';
import Scroll from '../Scroll';

Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/Scroll-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testPresentationalComponent } from '../../test/common-tests';

import Scroll from '../Scroll';

describe('Scroll', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/ScrollBox-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testCompositeComponent } from '../../test/common-tests';

import ScrollBox from '../ScrollBox';

const createComponent = (Component, props = {}) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/ScrollContainer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testPresentationalComponent } from '../../test/common-tests';

import ScrollContainer from '../ScrollContainer';

describe('ScrollContainer', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/ScrollContent-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testPresentationalComponent } from '../../test/common-tests';

import ScrollContent from '../ScrollContent';

describe('ScrollContent', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/Table-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testPresentationalComponent } from '../../test/common-tests';

import Table from '../Table';

describe('Table', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/TableBody-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableBody from '../TableBody';
import TableContext from '../TableContext';

Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/TableCell-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableCell from '../TableCell';
import TableSectionContext from '../TableSectionContext';

Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/TableFoot-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableFoot from '../TableFoot';

describe('TableFoot', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/data/test/TableHead-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableHead from '../TableHead';
import TableContext from '../TableContext';
import TableHead from '../TableHead';

describe('TableHead', () => {
let tableContextValue;
Expand Down
3 changes: 1 addition & 2 deletions src/components/data/test/TableRow-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { mount } from 'enzyme';

import { testPresentationalComponent } from '../../test/common-tests';

import TableRow from '../TableRow';
import TableContext from '../TableContext';
import TableRow from '../TableRow';
import TableSectionContext from '../TableSectionContext';

describe('TableRow', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/data/test/Thumbnail-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testCompositeComponent } from '../../test/common-tests';

import Thumbnail from '../Thumbnail';

const createComponent = (Component, props = {}) => {
Expand Down
2 changes: 0 additions & 2 deletions src/components/feedback/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { useEffect, useLayoutEffect } from 'preact/hooks';
import { useElementShouldClose } from '../../hooks/use-element-should-close';
import { useSyncedRef } from '../../hooks/use-synced-ref';
import { useUniqueId } from '../../hooks/use-unique-id';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import Overlay from '../layout/Overlay';
import Panel from '../layout/Panel';
import type { PanelProps } from '../layout/Panel';
Expand Down
1 change: 0 additions & 1 deletion src/components/feedback/test/Modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { mount } from 'enzyme';
import { createRef } from 'preact';

import { testPresentationalComponent } from '../../test/common-tests';

import Modal from '../Modal';

const createComponent = (Component, props = {}) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/feedback/test/Spinner-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testSimpleComponent } from '../../test/common-tests';

import Spinner from '../Spinner';

describe('Spinner', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/feedback/test/SpinnerOverlay-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { testSimpleComponent } from '../../test/common-tests';

import SpinnerOverlay from '../SpinnerOverlay';

describe('SpinnerOverlay', () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/input/Button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import classnames from 'classnames';

import { downcastRef } from '../../util/typing';

import ButtonBase from './ButtonBase';

/**
Expand Down
1 change: 1 addition & 0 deletions src/components/input/ButtonBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classNames from 'classnames';

import { downcastRef } from '../../util/typing';

/**
Expand Down
1 change: 0 additions & 1 deletion src/components/input/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import classnames from 'classnames';
import { useState } from 'preact/hooks';

import { downcastRef } from '../../util/typing';

import { CheckboxOutlineIcon, CheckboxCheckedIcon } from '../icons';

/**
Expand Down
4 changes: 1 addition & 3 deletions src/components/input/IconButton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import classnames from 'classnames';

import { downcastRef } from '../../util/typing';

import { inputGroupStyles } from './InputGroup';

import ButtonBase from './ButtonBase';
import { inputGroupStyles } from './InputGroup';

/**
* @typedef {import('../../types').IconComponent} IconComponent
Expand Down
1 change: 0 additions & 1 deletion src/components/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { JSX } from 'preact';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import InputRoot from './InputRoot';

type ComponentProps = {
Expand Down
1 change: 0 additions & 1 deletion src/components/input/InputRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { JSX } from 'preact';

import type { PresentationalProps } from '../../types';
import { downcastRef } from '../../util/typing';

import { inputGroupStyles } from './InputGroup';

type RootComponentProps = {
Expand Down
1 change: 0 additions & 1 deletion src/components/input/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import classnames from 'classnames';
import type { ComponentChildren, JSX } from 'preact';

import type { PresentationalProps } from '../../types';

import InputRoot from './InputRoot';

type ComponentProps = {
Expand Down
3 changes: 1 addition & 2 deletions src/components/input/test/Button-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { mount } from 'enzyme';

import { CancelIcon } from '../../icons';
import { testPresentationalComponent } from '../../test/common-tests';

import Button from '../Button';
import { CancelIcon } from '../../icons';

describe('Button', () => {
const createComponent = (props = {}) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/input/test/ButtonBase-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mount } from 'enzyme';

import { testBaseComponent } from '../../test/common-tests';

import ButtonBase from '../ButtonBase';

describe('ButtonBase', () => {
Expand Down
Loading