Skip to content

Commit

Permalink
chore: enable import/order rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 14, 2022
1 parent a4c54ab commit ecd5517
Show file tree
Hide file tree
Showing 300 changed files with 737 additions and 716 deletions.
66 changes: 65 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,71 @@ module.exports = {
],
},
],
'import/order': OFF,
'import/order': [
WARNING,
{
groups: [
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'type',
],
pathGroups: [
{
pattern: '@jest/globals',
group: 'builtin',
position: 'before',
},
{
pattern: 'react',
group: 'builtin',
position: 'before',
},
{
pattern: 'fs-extra',
group: 'builtin',
},
{
pattern: 'lodash',
group: 'external',
position: 'before',
},
{
pattern: '@docusaurus/logger',
group: 'external',
position: 'before',
},
{
pattern: 'clsx',
group: 'external',
position: 'before',
},
{
// 'Bit weird to not use the `import/internal-regex` option, but
// this way, we can make `import type { Props } from "@theme/*"`
// appear before `import styles from "styles.module.css"`, which is
// what we always do. This should be removable once we stop using
// ambient module declarations for theme aliases.
pattern: '@theme/**',
group: 'internal',
},
{
pattern: '@site/**',
group: 'internal',
},
{
pattern: '@theme-init/**',
group: 'internal',
},
{
pattern: '@theme-original/**',
group: 'internal',
},
],
pathGroupsExcludedImportTypes: [],
},
],
'import/prefer-default-export': OFF,

'jest/consistent-test-it': WARNING,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/validate-package-json.test.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 {Globby} from '@docusaurus/utils';
import fs from 'fs-extra';
import {Globby} from '@docusaurus/utils';

type PackageJsonFile = {
file: string;
Expand Down
3 changes: 1 addition & 2 deletions admin/new.docusaurus.io/functions/codesandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Handler} from '@netlify/functions';

import {createPlaygroundResponse} from '../functionUtils/playgroundUtils';
import type {Handler} from '@netlify/functions';

export const handler: Handler = async function handler() {
return createPlaygroundResponse('codesandbox');
Expand Down
3 changes: 1 addition & 2 deletions admin/new.docusaurus.io/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Handler} from '@netlify/functions';

import {
readPlaygroundName,
createPlaygroundResponse,
createPlaygroundDocumentationResponse,
} from '../functionUtils/playgroundUtils';
import type {Handler} from '@netlify/functions';

export const handler: Handler = async (event) => {
const playgroundName = readPlaygroundName(event);
Expand Down
3 changes: 1 addition & 2 deletions admin/new.docusaurus.io/functions/stackblitz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Handler} from '@netlify/functions';

import {createPlaygroundResponse} from '../functionUtils/playgroundUtils';
import type {Handler} from '@netlify/functions';

export const handler: Handler = async function handler() {
return createPlaygroundResponse('stackblitz');
Expand Down
4 changes: 2 additions & 2 deletions admin/scripts/image-resize.mjs
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 sharp from 'sharp';
import fs from 'fs-extra';
import path from 'path';
import imageSize from 'image-size';
import {fileURLToPath} from 'url';
import logger from '@docusaurus/logger';
import sharp from 'sharp';
import imageSize from 'image-size';

const allImages = (
await fs.readdir(new URL('../../website/src/data/showcase', import.meta.url))
Expand Down
6 changes: 3 additions & 3 deletions jest/snapshotPathNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// Forked from https://github.com/tribou/jest-serializer-path/blob/master/lib/index.js
// Added some project-specific handlers

import os from 'os';
import path from 'path';
import fs from 'fs';
import _ from 'lodash';
import {escapePath} from '@docusaurus/utils';
import stripAnsi from 'strip-ansi';
import {version} from '@docusaurus/core/package.json';
import os from 'os';
import path from 'path';
import fs from 'fs';

export function print(
val: unknown,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-docusaurus/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

// @ts-check

import path from 'path';
import {createRequire} from 'module';
import logger from '@docusaurus/logger';
import semver from 'semver';
import path from 'path';
import {program} from 'commander';
import {createRequire} from 'module';

const packageJson = createRequire(import.meta.url)('../package.json');
const requiredVersion = packageJson.engines.node;
Expand Down
6 changes: 3 additions & 3 deletions packages/create-docusaurus/src/index.ts
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 logger from '@docusaurus/logger';
import fs from 'fs-extra';
import {fileURLToPath} from 'url';
import prompts, {type Choice} from 'prompts';
import path from 'path';
import shell from 'shelljs';
import _ from 'lodash';
import logger from '@docusaurus/logger';
import shell from 'shelljs';
import prompts, {type Choice} from 'prompts';
import supportsColor from 'supports-color';

type CLIOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import clsx from 'clsx';
import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css';
import Layout from '@theme/Layout';
import HomepageFeatures from '@site/src/components/HomepageFeatures';

import styles from './index.module.css';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import clsx from 'clsx';
import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css';
import Layout from '@theme/Layout';
import HomepageFeatures from '@site/src/components/HomepageFeatures';

import styles from './index.module.css';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
return (
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-mdx-loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import fs from 'fs-extra';
import {createCompiler} from '@mdx-js/mdx';
import logger from '@docusaurus/logger';
import {createCompiler} from '@mdx-js/mdx';
import emoji from 'remark-emoji';
import {
parseFrontMatter,
Expand All @@ -16,11 +16,13 @@ import {
getFileLoaderUtils,
} from '@docusaurus/utils';
import stringifyObject from 'stringify-object';

import headings from './remark/headings';
import toc from './remark/toc';
import unwrapMdxCodeBlocks from './remark/unwrapMdxCodeBlocks';
import transformImage from './remark/transformImage';
import transformLinks from './remark/transformLinks';

import type {LoaderContext} from 'webpack';
import type {Processor, Plugin} from 'unified';

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-mdx-loader/src/remark/toc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import {parse, type ParserOptions} from '@babel/parser';
import type {Identifier} from '@babel/types';
import traverse from '@babel/traverse';
import stringifyObject from 'stringify-object';
import toString from 'mdast-util-to-string';
import visit from 'unist-util-visit';
import {toValue} from '../utils';

import type {Identifier} from '@babel/types';
import type {TOCItem} from '../..';
import type {Node, Parent} from 'unist';
import type {Heading, Literal} from 'mdast';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import {promisify} from 'util';
import logger from '@docusaurus/logger';
import {
toMessageRelativeFilePath,
posixPath,
Expand All @@ -13,15 +18,10 @@ import {
findAsyncSequential,
} from '@docusaurus/utils';
import visit from 'unist-util-visit';
import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import escapeHtml from 'escape-html';
import sizeOf from 'image-size';
import {promisify} from 'util';
import type {Transformer} from 'unified';
import type {Image, Literal} from 'mdast';
import logger from '@docusaurus/logger';

const {
loaders: {inlineMarkdownImageFileLoader},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import {
toMessageRelativeFilePath,
posixPath,
Expand All @@ -13,9 +16,6 @@ import {
findAsyncSequential,
} from '@docusaurus/utils';
import visit from 'unist-util-visit';
import path from 'path';
import url from 'url';
import fs from 'fs-extra';
import escapeHtml from 'escape-html';
import {stringifyContent} from '../utils';
import type {Transformer} from 'unified';
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-migrate/bin/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

// @ts-check

import path from 'path';
import {createRequire} from 'module';
import logger from '@docusaurus/logger';
import semver from 'semver';
import cli from 'commander';
import path from 'path';
import {createRequire} from 'module';

const moduleRequire = createRequire(import.meta.url);
const requiredVersion = moduleRequire('../package.json').engines.node;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-migrate/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import {jest} from '@jest/globals';
import {migrateDocusaurusProject} from '../index';
import path from 'path';
import fs from 'fs-extra';
import {posixPath} from '@docusaurus/utils';
import {migrateDocusaurusProject} from '../index';

async function testMigration(siteDir: string, newDir: string) {
const writeMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {});
Expand Down
11 changes: 6 additions & 5 deletions packages/docusaurus-migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import fs from 'fs-extra';
import importFresh from 'import-fresh';
import logger from '@docusaurus/logger';
import importFresh from 'import-fresh';
import {Globby} from '@docusaurus/utils';
import Color from 'color';

import extractMetadata, {shouldQuotifyFrontMatter} from './frontMatter';
import migratePage from './transform';
import sanitizeMD from './sanitizeMD';

import type {
SidebarEntry,
SidebarEntries,
VersionOneConfig,
VersionTwoConfig,
} from './types';
import extractMetadata, {shouldQuotifyFrontMatter} from './frontMatter';
import migratePage from './transform';
import sanitizeMD from './sanitizeMD';
import path from 'path';

const DOCUSAURUS_VERSION = (importFresh('../package.json') as {version: string})
.version;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ declare module '@docusaurus/ErrorBoundary' {
}

declare module '@docusaurus/Head' {
import type {HelmetProps} from 'react-helmet-async';
import type {ReactNode} from 'react';
import type {HelmetProps} from 'react-helmet-async';

export type Props = HelmetProps & {children: ReactNode};

Expand Down
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 {PluginContext} from '../types';
import collectRedirects from '../collectRedirects';
import {validateOptions} from '../options';
import {removeTrailingSlash} from '@docusaurus/utils';
import {normalizePluginOptions} from '@docusaurus/utils-validation';
import collectRedirects from '../collectRedirects';
import {validateOptions} from '../options';
import type {Options} from '../options';
import type {PluginContext} from '../types';

function createTestPluginContext(
options?: Options,
Expand Down
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 {validateOptions, DEFAULT_OPTIONS} from '../options';
import {normalizePluginOptions} from '@docusaurus/utils-validation';
import {validateOptions, DEFAULT_OPTIONS} from '../options';
import type {Options} from '../options';

function testValidate(options: Options) {
Expand Down
Loading

0 comments on commit ecd5517

Please sign in to comment.