chore(v2): fix code style

This commit is contained in:
Alexey Pyltsyn 2020-04-05 17:27:03 +03:00
parent b07507c9cc
commit 6965a668cd
143 changed files with 458 additions and 457 deletions

View file

@ -47,7 +47,7 @@ test('site with wrong sidebar file', async () => {
});
return plugin
.loadContent()
.catch((e) =>
.catch(e =>
expect(e).toMatchInlineSnapshot(
`[Error: Improper sidebars file, document with id 'goku' not found.]`,
),
@ -110,7 +110,7 @@ describe('simple website', () => {
test('getPathToWatch', () => {
const pathToWatch = plugin.getPathsToWatch();
const matchPattern = pathToWatch.map((filepath) =>
const matchPattern = pathToWatch.map(filepath =>
posixPath(path.relative(siteDir, filepath)),
);
expect(matchPattern).not.toEqual([]);
@ -235,7 +235,7 @@ describe('versioned website', () => {
test('getPathToWatch', () => {
const pathToWatch = plugin.getPathsToWatch();
const matchPattern = pathToWatch.map((filepath) =>
const matchPattern = pathToWatch.map(filepath =>
posixPath(path.relative(siteDir, filepath)),
);
expect(matchPattern).not.toEqual([]);

View file

@ -183,7 +183,7 @@ describe('simple site', () => {
context,
options,
env,
}).catch((e) =>
}).catch(e =>
expect(e).toMatchInlineSnapshot(
`[Error: Document id cannot include "/".]`,
),

View file

@ -26,7 +26,7 @@ export function getVersionsJSONFile(siteDir: string) {
return path.join(siteDir, VERSIONS_JSON_FILE);
}
export default function (siteDir: string): Env {
export default function(siteDir: string): Env {
const versioning: VersioningEnv = {
enabled: false,
versions: [],

View file

@ -81,7 +81,7 @@ export default function pluginContentDocs(
docsDir: versionedDir,
sidebarsDir: versionedSidebarsDir,
} = versioning;
const versionsNames = versions.map((version) => `version-${version}`);
const versionsNames = versions.map(version => `version-${version}`);
return {
name: 'docusaurus-plugin-content-docs',
@ -91,7 +91,7 @@ export default function pluginContentDocs(
.command('docs:version')
.arguments('<version>')
.description('Tag a new version for docs')
.action((version) => {
.action(version => {
docsVersion(version, siteDir, {
path: options.path,
sidebarPath: options.sidebarPath,
@ -101,18 +101,17 @@ export default function pluginContentDocs(
getPathsToWatch() {
const {include} = options;
let globPattern = include.map((pattern) => `${docsDir}/${pattern}`);
let globPattern = include.map(pattern => `${docsDir}/${pattern}`);
if (versioning.enabled) {
const docsGlob = include
.map((pattern) =>
.map(pattern =>
versionsNames.map(
(versionName) => `${versionedDir}/${versionName}/${pattern}`,
versionName => `${versionedDir}/${versionName}/${pattern}`,
),
)
.reduce((a, b) => a.concat(b), []);
const sidebarsGlob = versionsNames.map(
(versionName) =>
`${versionedSidebarsDir}/${versionName}-sidebars.json`,
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
);
globPattern = [...globPattern, ...sidebarsGlob, ...docsGlob];
}
@ -137,7 +136,7 @@ export default function pluginContentDocs(
});
docsPromises.push(
Promise.all(
docsFiles.map(async (source) => {
docsFiles.map(async source => {
const metadata: MetadataRaw = await processMetadata({
source,
refDir: docsDir,
@ -153,8 +152,8 @@ export default function pluginContentDocs(
// Metadata for versioned docs.
if (versioning.enabled) {
const versionedGlob = include
.map((pattern) =>
versionsNames.map((versionName) => `${versionName}/${pattern}`),
.map(pattern =>
versionsNames.map(versionName => `${versionName}/${pattern}`),
)
.reduce((a, b) => a.concat(b), []);
const versionedFiles = await globby(versionedGlob, {
@ -162,7 +161,7 @@ export default function pluginContentDocs(
});
docsPromises.push(
Promise.all(
versionedFiles.map(async (source) => {
versionedFiles.map(async source => {
const metadata = await processMetadata({
source,
refDir: versionedDir,
@ -180,8 +179,7 @@ export default function pluginContentDocs(
const sidebarPaths = [
sidebarPath,
...versionsNames.map(
(versionName) =>
`${versionedSidebarsDir}/${versionName}-sidebars.json`,
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
),
];
const loadedSidebars: Sidebar = loadSidebars(sidebarPaths);
@ -193,7 +191,7 @@ export default function pluginContentDocs(
const docsMetadata: DocsMetadata = {};
const permalinkToSidebar: PermalinkToSidebar = {};
const versionToSidebars: VersionToSidebars = {};
Object.keys(docsMetadataRaw).forEach((currentID) => {
Object.keys(docsMetadataRaw).forEach(currentID => {
const {next: nextID, previous: previousID, sidebar} =
order[currentID] || {};
const previous = previousID
@ -293,7 +291,7 @@ export default function pluginContentDocs(
metadataItems: Metadata[],
): Promise<RouteConfig[]> => {
const routes = await Promise.all(
metadataItems.map(async (metadataItem) => {
metadataItems.map(async metadataItem => {
await createData(
// Note that this created data path must be in sync with
// metadataPath provided to mdx-loader.
@ -347,7 +345,7 @@ export default function pluginContentDocs(
'version',
);
await Promise.all(
Object.keys(docsMetadataByVersion).map(async (version) => {
Object.keys(docsMetadataByVersion).map(async version => {
const routes: RouteConfig[] = await genRoutes(
docsMetadataByVersion[version],
);
@ -366,9 +364,8 @@ export default function pluginContentDocs(
content.docsSidebars,
Array.from(neededSidebars),
),
permalinkToSidebar: pickBy(
content.permalinkToSidebar,
(sidebar) => neededSidebars.has(sidebar),
permalinkToSidebar: pickBy(content.permalinkToSidebar, sidebar =>
neededSidebars.has(sidebar),
),
version,
};

View file

@ -24,7 +24,7 @@ const sourceToPermalink: SourceToPermalink = {
'/docs/1.0.0/subdir/doc1',
};
const transform = (filepath) => {
const transform = filepath => {
const content = fs.readFileSync(filepath, 'utf-8');
const transformedContent = linkify(
content,

View file

@ -9,7 +9,7 @@ import {getOptions} from 'loader-utils';
import {loader} from 'webpack';
import linkify from './linkify';
export = function (fileString: string) {
export = function(fileString: string) {
const callback = this.async();
const {docsDir, siteDir, versionedDir, sourceToPermalink} = getOptions(this);
return (

View file

@ -10,7 +10,7 @@ import {resolve} from 'url';
import {getSubFolder} from '@docusaurus/utils';
import {SourceToPermalink} from '../types';
export default function (
export default function(
fileString: string,
filePath: string,
docsDir: string,
@ -36,7 +36,7 @@ export default function (
// Replace internal markdown linking (except in fenced blocks).
if (sourceDir) {
let fencedBlock = false;
const lines = content.split('\n').map((line) => {
const lines = content.split('\n').map(line => {
if (line.trim().startsWith('```')) {
fencedBlock = !fencedBlock;
}

View file

@ -11,12 +11,12 @@ import {Sidebar, SidebarItem, Order} from './types';
export default function createOrder(allSidebars: Sidebar = {}): Order {
const order: Order = {};
Object.keys(allSidebars).forEach((sidebarId) => {
Object.keys(allSidebars).forEach(sidebarId => {
const sidebar = allSidebars[sidebarId];
const ids: string[] = [];
const indexItems = ({items}: {items: SidebarItem[]}) => {
items.forEach((item) => {
items.forEach(item => {
switch (item.type) {
case 'category':
indexItems({

View file

@ -43,7 +43,7 @@ function normalizeCategoryShorthand(
*/
function assertItem(item: Object, keys: string[]): void {
const unknownKeys = Object.keys(item).filter(
(key) => !keys.includes(key) && key !== 'type',
key => !keys.includes(key) && key !== 'type',
);
if (unknownKeys.length) {
@ -150,7 +150,7 @@ export default function loadSidebars(sidebarPaths?: string[]): Sidebar {
return {} as Sidebar;
}
sidebarPaths.map((sidebarPath) => {
sidebarPaths.map(sidebarPath => {
if (sidebarPath && fs.existsSync(sidebarPath)) {
const sidebar = importFresh(sidebarPath) as SidebarRaw;
Object.assign(allSidebars, sidebar);