Skip to content

Commit 462b1cf

Browse files
Josh-Cenaslorber
andauthored
style(v2): reduce number of ESLint warnings (facebook#4993)
* Initial work Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * More fixes Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Update packages/docusaurus-theme-classic/src/theme/ThemedImage/index.tsx Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> * Update packages/docusaurus-theme-bootstrap/src/theme/ThemedImage/index.tsx Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> * Fix Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Replace versionPathPart with function Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Prefer non-null assertions Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Substitute for-of with forEach Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fill `catch` block with placeholder comment Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Ignore local require Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Revert global require change Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Tighten eslint disable range Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Make eslint ignore examples and more tolerating to templates Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Use reduce to handle doc items sequentially Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Revert "Use reduce to handle doc items sequentially" This reverts commit c7525d4. * Address change requests Signed-off-by: Josh-Cena <sidachen2003@gmail.com> Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
1 parent 364051f commit 462b1cf

20 files changed

Lines changed: 75 additions & 35 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jest.config.js
88
jest.transform.js
99
website/
1010
scripts
11+
examples/
1112

1213
packages/docusaurus/lib/
1314
packages/docusaurus-*/lib/*

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module.exports = {
9292
'no-unused-vars': OFF,
9393
'no-nested-ternary': WARNING,
9494
'@typescript-eslint/no-empty-function': OFF,
95+
'@typescript-eslint/no-non-null-assertion': OFF, // Have to use type assertion anyways
9596
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
9697
'@typescript-eslint/ban-ts-comment': [
9798
ERROR,
@@ -113,7 +114,7 @@ module.exports = {
113114
'prefer-destructuring': WARNING,
114115
yoda: WARNING,
115116
'no-control-regex': WARNING,
116-
'no-empty': WARNING,
117+
'no-empty': [WARNING, {allowEmptyCatch: true}],
117118
'no-prototype-builtins': WARNING,
118119
'no-case-declarations': WARNING,
119120
'no-undef': OFF,
@@ -130,6 +131,7 @@ module.exports = {
130131
],
131132
rules: {
132133
'header/header': OFF,
134+
'global-require': OFF,
133135
},
134136
},
135137
{

packages/docusaurus-plugin-content-docs/src/docs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function doProcessDocMetadata({
130130

131131
// Strip number prefixes by default (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) by default,
132132
// but allow to disable this behavior with frontmatterr
133+
// eslint-disable-next-line camelcase
133134
parse_number_prefixes = true,
134135
} = frontMatter;
135136

@@ -144,6 +145,7 @@ function doProcessDocMetadata({
144145
// ex: myDoc -> .
145146
const sourceDirName = path.dirname(source);
146147

148+
// eslint-disable-next-line camelcase
147149
const {filename: unprefixedFileName, numberPrefix} = parse_number_prefixes
148150
? options.numberPrefixParser(sourceFileNameWithoutExtension)
149151
: {filename: sourceFileNameWithoutExtension, numberPrefix: undefined};
@@ -172,6 +174,7 @@ function doProcessDocMetadata({
172174
return undefined;
173175
}
174176
// Eventually remove the number prefixes from intermediate directories
177+
// eslint-disable-next-line camelcase
175178
return parse_number_prefixes
176179
? stripPathNumberPrefixes(sourceDirName, options.numberPrefixParser)
177180
: sourceDirName;

packages/docusaurus-plugin-content-docs/src/sidebars.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ function assertIsCategory(
127127
);
128128
}
129129
// "collapsed" is an optional property
130-
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
130+
if (
131+
typeof item.collapsed !== 'undefined' &&
132+
typeof item.collapsed !== 'boolean'
133+
) {
131134
throw new Error(
132135
`Error loading ${JSON.stringify(item)}: "collapsed" must be a boolean.`,
133136
);
@@ -438,7 +441,20 @@ export function collectSidebarsDocIds(
438441
});
439442
}
440443

441-
export function createSidebarsUtils(sidebars: Sidebars) {
444+
export function createSidebarsUtils(
445+
sidebars: Sidebars,
446+
): {
447+
getFirstDocIdOfFirstSidebar: () => string | undefined;
448+
getSidebarNameByDocId: (docId: string) => string | undefined;
449+
getDocNavigation: (
450+
docId: string,
451+
) => {
452+
sidebarName: string | undefined;
453+
previousId: string | undefined;
454+
nextId: string | undefined;
455+
};
456+
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
457+
} {
442458
const sidebarNameToDocIds = collectSidebarsDocIds(sidebars);
443459

444460
function getFirstDocIdOfFirstSidebar(): string | undefined {

packages/docusaurus-plugin-content-docs/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export type LastUpdateData = {
187187
};
188188

189189
export type DocFrontMatter = {
190+
// Front matter uses snake case
191+
/* eslint-disable camelcase */
190192
id?: string;
191193
title?: string;
192194
hide_title?: boolean;
@@ -200,6 +202,7 @@ export type DocFrontMatter = {
200202
pagination_label?: string;
201203
custom_edit_url?: string | null;
202204
parse_number_prefixes?: boolean;
205+
/* eslint-enable camelcase */
203206
};
204207

205208
export type DocMetadataBase = LastUpdateData & {
@@ -213,7 +216,6 @@ export type DocMetadataBase = LastUpdateData & {
213216
sourceDirName: string; // relative to the docs folder (can be ".")
214217
slug: string;
215218
permalink: string;
216-
// eslint-disable-next-line camelcase
217219
sidebarPosition?: number;
218220
editUrl?: string | null;
219221
frontMatter: DocFrontMatter & Record<string, unknown>;

packages/docusaurus-plugin-content-docs/src/versions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,13 @@ function createVersionMetadata({
341341
// retro-compatible values
342342
const defaultVersionLabel =
343343
versionName === CURRENT_VERSION_NAME ? 'Next' : versionName;
344-
const defaultVersionPathPart = isLast
345-
? ''
346-
: versionName === CURRENT_VERSION_NAME
347-
? 'next'
348-
: versionName;
344+
function getDefaultVersionPathPart() {
345+
if (isLast) {
346+
return '';
347+
}
348+
return versionName === CURRENT_VERSION_NAME ? 'next' : versionName;
349+
}
350+
const defaultVersionPathPart = getDefaultVersionPathPart();
349351

350352
const versionOptions: VersionOptions = options.versions[versionName] ?? {};
351353

packages/docusaurus-plugin-ideal-image/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default function (
3939
options: {
4040
emitFile: !isServer, // don't emit for server-side rendering
4141
disable: !isProd,
42+
// eslint-disable-next-line global-require
4243
adapter: require('@docusaurus/responsive-loader/sharp'),
4344
name: isProd
4445
? 'assets/ideal-img/[name].[hash:hex:7].[width].[ext]'

packages/docusaurus-theme-bootstrap/src/theme/ThemedImage/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const ThemedImage = (props: Props): JSX.Element => {
2121

2222
type SourceName = keyof Props['sources'];
2323

24+
const clientThemes: SourceName[] = isDarkTheme ? ['dark'] : ['light'];
25+
2426
const renderedSourceNames: SourceName[] = isClient
25-
? isDarkTheme
26-
? ['dark']
27-
: ['light']
27+
? clientThemes
2828
: // We need to render both images on the server to avoid flash
2929
// See https://github.com/facebook/docusaurus/pull/3730
3030
['light', 'dark'];

packages/docusaurus-theme-classic/src/theme/ThemedImage/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const ThemedImage = (props: Props): JSX.Element => {
2121

2222
type SourceName = keyof Props['sources'];
2323

24+
const clientThemes: SourceName[] = isDarkTheme ? ['dark'] : ['light'];
25+
2426
const renderedSourceNames: SourceName[] = isClient
25-
? isDarkTheme
26-
? ['dark']
27-
: ['light']
27+
? clientThemes
2828
: // We need to render both images on the server to avoid flash
2929
// See https://github.com/facebook/docusaurus/pull/3730
3030
['light', 'dark'];

packages/docusaurus-theme-classic/src/theme/hooks/useTabGroupChoice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const useTabGroupChoice = (): useTabGroupChoiceReturns => {
2222
useEffect(() => {
2323
try {
2424
const localStorageChoices = {};
25-
for (const storageKey of listStorageKeys()) {
25+
listStorageKeys().forEach((storageKey) => {
2626
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
2727
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
2828
localStorageChoices[groupId] = createStorageSlot(storageKey).get();
2929
}
30-
}
30+
});
3131
setChoices(localStorageChoices);
3232
} catch (err) {
3333
console.error(err);

0 commit comments

Comments
 (0)