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

chore(v2): Fix a lot of eslint warnings #2972

Merged
merged 1 commit into from
Jun 20, 2020
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
14 changes: 8 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,11 @@ module.exports = {

// TODO re-enable some these as errors
// context: https://github.com/facebook/docusaurus/pull/2949
'@typescript-eslint/no-var-requires': WARNING,
'@typescript-eslint/ban-ts-comment': WARNING,
'@typescript-eslint/ban-types': WARNING,
'import/no-duplicates': WARNING,
'import/prefer-default-export': WARNING,
'import/no-extraneous-dependencies': WARNING,
'prefer-const': WARNING,
'no-useless-escape': WARNING,
'prefer-object-spread': WARNING,
'no-return-await': WARNING,
'prefer-template': WARNING,
'no-shadow': WARNING,
'no-param-reassign': WARNING,
Expand All @@ -113,7 +108,6 @@ module.exports = {
'no-useless-return': WARNING,
'@typescript-eslint/no-empty-function': WARNING,
'global-require': WARNING,
'import/newline-after-import': WARNING,
'prefer-destructuring': WARNING,
yoda: WARNING,
'no-control-regex': WARNING,
Expand All @@ -133,5 +127,13 @@ module.exports = {
'header/header': OFF,
},
},
{
files: ['*.js'],
rules: {
// Make JS code directly runnable in Node.
'@typescript-eslint/no-var-requires': OFF,
'@typescript-eslint/explicit-module-boundary-types': OFF,
},
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createTestPluginContext(
return {
outDir: '/tmp',
baseUrl: 'https://docusaurus.io',
routesPaths: routesPaths,
routesPaths,
options: normalizePluginOptions(options),
};
}
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('collectRedirects', () => {
`/def?queryString=toto`,
];
}
return;
return undefined;
},
},
['/'],
Expand All @@ -210,7 +210,7 @@ describe('collectRedirects', () => {
if (routePath === '/') {
return [[`/fromPath`]] as any;
}
return;
return undefined;
},
},
['/'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ describe('validateRedirect', () => {

expect(() =>
validateRedirect({
from: null as any,
from: (null as unknown) as string,
to: '/toSomePath?queryString=xyz',
}),
).toThrowErrorMatchingSnapshot();

expect(() =>
validateRedirect({
from: ['heyho'] as any,
from: (['heyho'] as unknown) as string,
to: '/toSomePath?queryString=xyz',
}),
).toThrowErrorMatchingSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('toRedirectFilesMetadata', () => {

describe('writeRedirectFiles', () => {
test('write the files', async () => {
const outDir = '/tmp/docusaurus_tests_' + Math.random();
const outDir = `/tmp/docusaurus_tests_${Math.random()}`;

const filesMetadata = [
{
Expand All @@ -94,7 +94,7 @@ describe('writeRedirectFiles', () => {
});

test('avoid overwriting existing files', async () => {
const outDir = '/tmp/docusaurus_tests_' + Math.random();
const outDir = `/tmp/docusaurus_tests_${Math.random()}`;

const filesMetadata = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function createToExtensionsRedirects(
if (extensionFound) {
const routePathWithoutExtension = removeSuffix(path, extensionFound);
return [routePathWithoutExtension].map((from) => ({
from: from,
from,
to: path,
}));
}
Expand All @@ -78,12 +78,11 @@ export function createFromExtensionsRedirects(
const createPathRedirects = (path: string): RedirectMetadata[] => {
if (path === '' || path.endsWith('/') || alreadyEndsWithAnExtension(path)) {
return [];
} else {
return extensions.map((ext) => ({
from: `${path}.${ext}`,
to: path,
}));
}
return extensions.map((ext) => ({
from: `${path}.${ext}`,
to: path,
}));
};

return flatten(paths.map(createPathRedirects));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const DefaultPluginOptions: PluginOptions = {
};

function isRedirectsCreator(
value: any,
value: unknown,
): value is CreateRedirectsFnOption | undefined {
if (value === null || typeof value === 'undefined') {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const RedirectSchema = Yup.object<RedirectMetadata>({
to: PathnameValidator.required(),
});

export function validateRedirect(redirect: RedirectMetadata) {
export function validateRedirect(redirect: RedirectMetadata): void {
try {
RedirectSchema.validateSync(redirect, {
strict: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export function toRedirectFilesMetadata(
return redirects.map(createFileMetadata);
}

export async function writeRedirectFile(file: RedirectFileMetadata) {
export async function writeRedirectFile(
file: RedirectFileMetadata,
): Promise<void> {
try {
// User-friendly security to prevent file overrides
if (await fs.pathExists(file.fileAbsolutePath)) {
Expand All @@ -79,6 +81,6 @@ export async function writeRedirectFile(file: RedirectFileMetadata) {

export default async function writeRedirectFiles(
redirectFiles: RedirectFileMetadata[],
) {
): Promise<void> {
await Promise.all(redirectFiles.map(writeRedirectFile));
}
4 changes: 1 addition & 3 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
"access": "public"
},
"license": "MIT",
"devDependencies": {
"@docusaurus/types": "^2.0.0-alpha.58"
},
"dependencies": {
"@docusaurus/mdx-loader": "^2.0.0-alpha.58",
"@docusaurus/types": "^2.0.0-alpha.58",
"@docusaurus/utils": "^2.0.0-alpha.58",
"feed": "^4.1.0",
"fs-extra": "^8.1.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@docusaurus/utils';
import {LoadContext} from '@docusaurus/types';

export function truncate(fileString: string, truncateMarker: RegExp) {
export function truncate(fileString: string, truncateMarker: RegExp): string {
return fileString.split(truncateMarker, 1).shift()!;
}

Expand All @@ -37,7 +37,7 @@ function toUrl({date, link}: DateLink) {
export async function generateBlogFeed(
context: LoadContext,
options: PluginOptions,
) {
): Promise<Feed | null> {
if (!options.feedOptions) {
throw new Error(
'Invalid options - `feedOptions` is not expected to be null.',
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function generateBlogFeed(
} = post;
feed.addItem({
title,
id: id,
id,
link: normalizeUrl([siteUrl, permalink]),
date,
description,
Expand All @@ -90,7 +90,7 @@ export async function generateBlogPosts(
blogDir: string,
{siteConfig, siteDir}: LoadContext,
options: PluginOptions,
) {
): Promise<BlogPost[]> {
const {
include,
routeBasePath,
Expand Down Expand Up @@ -181,14 +181,16 @@ export function linkify(
siteDir: string,
blogPath: string,
blogPosts: BlogPost[],
) {
): string {
let fencedBlock = false;
const lines = fileContent.split('\n').map((line) => {
if (line.trim().startsWith('```')) {
fencedBlock = !fencedBlock;
}

if (fencedBlock) return line;
if (fencedBlock) {
return line;
}

let modifiedLine = line;
const mdRegex = /(?:(?:\]\()|(?:\]:\s?))(?!https)([^'")\]\s>]+\.mdx?)/g;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
},
"license": "MIT",
"devDependencies": {
"@docusaurus/types": "^2.0.0-alpha.58",
"commander": "^5.0.0",
"picomatch": "^2.1.1"
},
"dependencies": {
"@docusaurus/mdx-loader": "^2.0.0-alpha.58",
"@docusaurus/types": "^2.0.0-alpha.58",
"@docusaurus/utils": "^2.0.0-alpha.58",
"execa": "^3.4.0",
"fs-extra": "^8.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe('versioned website', () => {
permalink: '/docs/next/',
},
});
expect(docsMetadata['hello']).toEqual({
expect(docsMetadata.hello).toEqual({
id: 'hello',
isDocsHomePage: true,
permalink: '/docs/next/',
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
function getFirstDocLinkOfSidebar(
sidebarItems: DocsSidebarItem[],
): string | null {
for (let sidebarItem of sidebarItems) {
for (const sidebarItem of sidebarItems) {
if (sidebarItem.type === 'category') {
const url = getFirstDocLinkOfSidebar(sidebarItem.items);
if (url) {
Expand Down Expand Up @@ -534,7 +534,7 @@ Available document ids=
options: {
siteDir,
docsDir,
sourceToPermalink: sourceToPermalink,
sourceToPermalink,
versionedDir,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function (
siteDir: string,
sourceToPermalink: SourceToPermalink,
versionedDir?: string,
) {
): string {
// Determine the source dir. e.g: /website/docs, /website/versioned_docs/version-1.0.0
let sourceDir: string | undefined;
const thisSource = filePath;
Expand All @@ -40,7 +40,9 @@ export default function (
if (line.trim().startsWith('```')) {
fencedBlock = !fencedBlock;
}
if (fencedBlock) return line;
if (fencedBlock) {
return line;
}

let modifiedLine = line;
// Replace inline-style links or reference-style links e.g:
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] {
case 'doc':
assertIsDoc(item);
return [item];
default:
default: {
const extraMigrationError =
item.type === 'subcategory'
? "Docusaurus v2: 'subcategory' has been renamed as 'category'"
Expand All @@ -145,6 +145,7 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] {
item.type
}]. Sidebar item=${JSON.stringify(item)} ${extraMigrationError}`,
);
}
}
}

Expand All @@ -168,7 +169,7 @@ function normalizeSidebar(sidebars: SidebarRaw): Sidebar {

export default function loadSidebars(sidebarPaths?: string[]): Sidebar {
// We don't want sidebars to be cached because of hot reloading.
let allSidebars: SidebarRaw = {};
const allSidebars: SidebarRaw = {};

if (!sidebarPaths || !sidebarPaths.length) {
return {} as Sidebar;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function docsVersion(
version: string | null | undefined,
siteDir: string,
options: PathOptions,
) {
): void {
if (!version) {
throw new Error(
'No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('createSitemap', () => {

test('empty site', () => {
expect(() => {
createSitemap({} as any, [], {} as any);
createSitemap({} as DocusaurusConfig, [], {} as any);
}).toThrowErrorMatchingInlineSnapshot(
`"url in docusaurus.config.js cannot be empty/undefined"`,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'fs-extra';
import path from 'path';
import {PluginOptions} from './types';
import createSitemap from './createSitemap';
import {LoadContext, Props} from '@docusaurus/types';
import {LoadContext, Props, Plugin} from '@docusaurus/types';

const DEFAULT_OPTIONS: PluginOptions = {
cacheTime: 600 * 1000, // 600 sec - cache purge period.
Expand All @@ -20,7 +20,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
export default function pluginSitemap(
_context: LoadContext,
opts: Partial<PluginOptions>,
) {
): Plugin<void> {
const options = {...DEFAULT_OPTIONS, ...opts};

return {
Expand Down
Loading