Skip to content
Merged
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
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ module.exports = {
// selector:
// @ 'ExportDefaultDeclaration > Identifier, ExportNamedDeclaration[source=null] > ExportSpecifier',
// message: 'Export in one statement'
// }
// },
...['path', 'fs-extra', 'webpack', 'lodash'].map((m) => ({
selector: `ImportDeclaration[importKind=value]:has(Literal[value=${m}]) > ImportSpecifier[importKind=value]`,
message:
'Default-import this, both for readability and interoperability with ESM',
})),
],
'no-template-curly-in-string': WARNING,
'no-unused-expressions': [WARNING, {allowTaggedTemplates: true}],
Expand Down Expand Up @@ -312,5 +317,11 @@ module.exports = {
'@typescript-eslint/explicit-module-boundary-types': OFF,
},
},
{
files: ['*.test.ts', '*.test.tsx'],
rules: {
'import/no-extraneous-dependencies': OFF,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe this should be disabled with more granularity (if possible)? 🤷‍♂️

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Test files are internal anyways. If they can run, there's nothing to worry about.

},
},
],
};
1 change: 0 additions & 1 deletion __tests__/validate-package-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable import/no-extraneous-dependencies */

import {Globby} from '@docusaurus/utils';
import fs from 'fs-extra';
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-logger/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import logger from '../index';

describe('formatters', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import remark from 'remark';
import mdx from 'remark-mdx';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

import {join} from 'path';
import path from 'path';
import remark from 'remark';
import mdx from 'remark-mdx';
import vfile from 'to-vfile';
import plugin from '..';

const processFixture = async (name) => {
const path = join(__dirname, '__fixtures__', name);
const file = await vfile.read(path);
const processFixture = async (name: string) => {
const file = await vfile.read(path.join(__dirname, '__fixtures__', name));
const result = await remark().use(mdx).use(plugin).process(file);
return result.toString();
};

const processFixtureAST = async (name) => {
const path = join(__dirname, '__fixtures__', name);
const file = await vfile.read(path);
const processFixtureAST = async (name: string) => {
const file = await vfile.read(path.join(__dirname, '__fixtures__', name));
return remark().use(mdx).use(plugin).parse(file);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import {migrateDocusaurusProject} from '../index';
import path from 'path';
import fs from 'fs-extra';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import fs from 'fs-extra';
import {createBlogFeedFiles} from '../feed';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import pluginContentBlog from '../index';
import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import fs from 'fs-extra';
import path from 'path';
import {linkify, type LinkifyParams, getSourceToPermalink} from '../blogUtils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import {cliDocsVersionCommand} from '../cli';
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import {loadContext} from '@docusaurus/core/src/server/index';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import {isMatch} from 'picomatch';
import commander from 'commander';
Expand All @@ -29,7 +30,7 @@ import type {
} from '../sidebars/types';
import {toSidebarsProp} from '../props';

import {validate} from 'webpack';
import webpack from 'webpack';
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
import {DisabledSidebars} from '../sidebars';

Expand Down Expand Up @@ -311,7 +312,7 @@ describe('simple website', () => {
undefined,
content,
);
const errors = validate(config);
const errors = webpack.validate(config);
expect(errors).toBeUndefined();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import fs from 'fs-extra';
import path from 'path';
import shell from 'shelljs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import path from 'path';
import {
getVersionsFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import fs from 'fs-extra';
import path from 'path';
import {linkify} from '../linkify';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import {DefaultSidebarItemsGenerator} from '../generator';
import type {SidebarItemsGenerator} from '../types';
import {DefaultNumberPrefixParser} from '../../numberPrefix';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {jest} from '@jest/globals';
import {processSidebars} from '../processor';
import type {
SidebarItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import React, {
type ComponentProps,
isValidElement,
type ComponentProps,
type ReactElement,
} from 'react';
import Head from '@docusaurus/Head';
Expand Down Expand Up @@ -52,7 +52,7 @@ const MDXComponents: MDXComponentsObject = {
const shouldBeInline = React.Children.toArray(props.children).every(
(el) =>
(typeof el === 'string' && !el.includes('\n')) ||
(React.isValidElement(el) && inlineElements.includes(el.props.mdxType)),
(isValidElement(el) && inlineElements.includes(el.props.mdxType)),
);

return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import React, {
useState,
cloneElement,
Children,
isValidElement,
type ReactElement,
} from 'react';
Expand Down Expand Up @@ -40,7 +39,7 @@ function TabsComponent(props: Props): JSX.Element {
groupId,
className,
} = props;
const children = Children.map(props.children, (child) => {
const children = React.Children.map(props.children, (child) => {
if (isValidElement(child) && isTabItem(child)) {
return child;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import React, {
useEffect,
useRef,
useCallback,
useLayoutEffect,
type RefObject,
type Dispatch,
type SetStateAction,
type ReactNode,
useLayoutEffect,
} from 'react';

const DefaultAnimationEasing = 'ease-in-out';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import React, {
type ComponentProps,
type ReactElement,
useRef,
useState,
type ComponentProps,
type ReactElement,
} from 'react';
import useIsBrowser from '@docusaurus/useIsBrowser';
import clsx from 'clsx';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import React, {
useEffect,
useCallback,
useMemo,
type ReactNode,
useContext,
createContext,
type ReactNode,
} from 'react';
import useIsBrowser from '@docusaurus/useIsBrowser';
import {createStorageSlot} from './storageUtils';
Expand Down Expand Up @@ -96,7 +95,9 @@ const useAnnouncementBarContextValue = (): AnnouncementBarAPI => {
);
};

const AnnouncementBarContext = createContext<AnnouncementBarAPI | null>(null);
const AnnouncementBarContext = React.createContext<AnnouncementBarAPI | null>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not against this change, just wondering why it's necessary?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh, purely stylistic. We have some React.createContext and some createContext. I personally prefer to have the React. prefix except for hooks so we understand what we are talking about

null,
);

export function AnnouncementBarProvider({
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React, {
useEffect,
useContext,
useMemo,
useRef,
type ReactNode,
} from 'react';
import {ReactContextError} from './reactUtils';
Expand Down Expand Up @@ -96,7 +97,7 @@ function useColorModeContextValue(): ColorModeContextValue {
// be reset to dark when exiting print mode, disregarding user settings. When
// the listener fires only because of a print/screen switch, we don't change
// color mode. See https://github.com/facebook/docusaurus/pull/6490
const previousMediaIsPrint = React.useRef(false);
const previousMediaIsPrint = useRef(false);

useEffect(() => {
if (disableSwitch && !respectPrefersColorScheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import React, {
createContext,
type ReactNode,
useContext,
useEffect,
useMemo,
useState,
type ReactNode,
} from 'react';
import {useThemeConfig, type DocsVersionPersistence} from '../useThemeConfig';
import {isDocsPluginEnabled} from '../docsUtils';
Expand Down Expand Up @@ -131,7 +130,9 @@ function useContextValue() {

type DocsPreferredVersionContextValue = ReturnType<typeof useContextValue>;

const Context = createContext<DocsPreferredVersionContextValue | null>(null);
const Context = React.createContext<DocsPreferredVersionContextValue | null>(
null,
);

export function DocsPreferredVersionContextProvider({
children,
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-theme-common/src/utils/docsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {createContext, type ReactNode, useContext} from 'react';
import React, {type ReactNode, useContext} from 'react';
import {
useActivePlugin,
useAllDocsData,
Expand All @@ -29,7 +29,7 @@ export const isDocsPluginEnabled: boolean = !!useAllDocsData;
// Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
const EmptyContextValue: unique symbol = Symbol('EmptyContext');

const DocsVersionContext = createContext<
const DocsVersionContext = React.createContext<
PropVersionMetadata | typeof EmptyContextValue
>(EmptyContextValue);

Expand Down Expand Up @@ -69,7 +69,7 @@ export function useDocById(id: string | undefined): PropVersionDoc | undefined {
return doc;
}

const DocsSidebarContext = createContext<
const DocsSidebarContext = React.createContext<
PropSidebar | null | typeof EmptyContextValue
>(EmptyContextValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

import React, {
useState,
type ReactNode,
useContext,
createContext,
useEffect,
type ComponentType,
useMemo,
type ReactNode,
type ComponentType,
} from 'react';
import {ReactContextError} from './reactUtils';

Expand Down Expand Up @@ -46,7 +45,7 @@ function useContextValue() {

type ContextValue = ReturnType<typeof useContextValue>;

const Context = createContext<ContextValue | null>(null);
const Context = React.createContext<ContextValue | null>(null);

export function MobileSecondaryMenuProvider({
children,
Expand Down
5 changes: 2 additions & 3 deletions packages/docusaurus-theme-common/src/utils/scrollUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/

import React, {
createContext,
type ReactNode,
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useRef,
type ReactNode,
} from 'react';
import {useDynamicCallback, ReactContextError} from './reactUtils';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
Expand Down Expand Up @@ -57,7 +56,7 @@ function useScrollControllerContextValue(): ScrollController {
);
}

const ScrollMonitorContext = createContext<ScrollController | undefined>(
const ScrollMonitorContext = React.createContext<ScrollController | undefined>(
undefined,
);

Expand Down
Loading