Skip to content

Commit

Permalink
Merge branch 'main' into static-directory-sourcing
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Nov 18, 2021
2 parents 52c353a + 0374426 commit 4901a12
Show file tree
Hide file tree
Showing 125 changed files with 2,867 additions and 2,557 deletions.
23 changes: 17 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
'plugin:react-hooks/recommended',
'airbnb',
'prettier',
'prettier/react',
],
settings: {
'import/resolver': {
Expand Down Expand Up @@ -61,6 +60,7 @@ module.exports = {
},
],
'import/extensions': OFF,
'no-restricted-exports': OFF,
'header/header': [
ERROR,
'block',
Expand Down Expand Up @@ -90,6 +90,14 @@ module.exports = {
'react/prefer-stateless-function': WARNING,
'react/jsx-props-no-spreading': OFF,
'react/require-default-props': [ERROR, {ignoreFunctionalComponents: true}],
'react/function-component-definition': [
WARNING,
{
namedComponents: 'function-declaration',
unnamedComponents: 'arrow-function',
},
],
'react/no-unstable-nested-components': [WARNING, {allowAsProps: true}],
'@typescript-eslint/no-inferrable-types': OFF,
'import/first': OFF,
'import/order': OFF,
Expand All @@ -104,19 +112,16 @@ module.exports = {
'no-unused-vars': OFF,
'no-nested-ternary': WARNING,
'@typescript-eslint/no-empty-function': OFF,
'@typescript-eslint/no-non-null-assertion': OFF, // Have to use type assertion anyways
'@typescript-eslint/no-non-null-assertion': OFF,
'@typescript-eslint/no-unused-vars': [
ERROR,
{argsIgnorePattern: '^_', ignoreRestSiblings: true},
],
'@typescript-eslint/explicit-module-boundary-types': WARNING,
'@typescript-eslint/ban-ts-comment': [
ERROR,
{'ts-expect-error': 'allow-with-description'},
],

// TODO re-enable some these as errors
// context: https://github.com/facebook/docusaurus/pull/2949
'@typescript-eslint/ban-types': WARNING,
'import/no-extraneous-dependencies': ERROR,
'no-useless-escape': WARNING,
'prefer-template': WARNING,
Expand Down Expand Up @@ -189,6 +194,12 @@ module.exports = {
'import/no-duplicates': OFF,
},
},
{
files: ['*.ts', '*.tsx'],
rules: {
'import/no-import-module-exports': OFF,
},
},
{
files: ['*.js'],
rules: {
Expand Down
10 changes: 4 additions & 6 deletions __tests__/validate-package-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ async function getPackagesJsonFiles(): Promise<PackageJsonFile[]> {
const files = await glob('packages/*/package.json');

return Promise.all(
files.map(async (file) => {
return {
file,
content: JSON.parse(await readFile(file, 'utf8')),
};
}),
files.map(async (file) => ({
file,
content: JSON.parse(await readFile(file, 'utf8')),
})),
);
}

Expand Down
2 changes: 1 addition & 1 deletion admin/new.docusaurus.io/functionUtils/playgroundUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function createPlaygroundResponse(
// Inspired by https://stackoverflow.com/a/3409200/82609
function parseCookieString(cookieString: string): Record<string, string> {
const result: Record<string, string> = {};
cookieString.split(';').forEach(function (cookie) {
cookieString.split(';').forEach((cookie) => {
const [name, value] = cookie.split('=');
result[name.trim()] = decodeURI(value);
});
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
"lock:update": "npx yarn-deduplicate"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.15.7",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
"@babel/plugin-proposal-optional-chaining": "^7.12.16",
"@babel/plugin-transform-modules-commonjs": "^7.12.13",
"@babel/preset-typescript": "^7.12.16",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@crowdin/cli": "^3.7.1",
"@formatjs/intl-datetimeformat": "^3.2.12",
"@formatjs/intl-numberformat": "^6.2.2",
Expand All @@ -87,18 +87,18 @@
"@types/shelljs": "^0.8.6",
"@types/wait-on": "^5.2.0",
"@types/webpack-dev-server": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"concurrently": "^6.2.1",
"cross-env": "^7.0.3",
"eslint": "^7.20.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.3.0",
"glob": "^7.1.6",
"husky": "^5.0.9",
"is-ci": "^3.0.0",
Expand All @@ -117,7 +117,7 @@
"serve": "^12.0.1",
"stylelint": "^13.10.0",
"tslib": "^2.3.1",
"typescript": "^4.1.5"
"typescript": "^4.5.2"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
7 changes: 6 additions & 1 deletion packages/create-docusaurus/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ program
.option('--typescript')
.description('Initialize website.')
.action(
(siteName, template, rootDir = '.', {useNpm, skipInstall, typescript}) => {
(
siteName,
template,
rootDir = '.',
{useNpm, skipInstall, typescript} = {},
) => {
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
useNpm,
skipInstall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "2.0.0-beta.9",
"@tsconfig/docusaurus": "^1.0.4",
"typescript": "^4.3.5"
"typescript": "^4.5.2"
},
"browserslist": {
"production": [
Expand Down
9 changes: 8 additions & 1 deletion packages/create-docusaurus/templates/facebook/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
parserOptions: {
allowImportExportEverywhere: true,
},
extends: ['airbnb', 'prettier', 'prettier/react'],
extends: ['airbnb', 'prettier'],
plugins: ['react-hooks', 'header'],
rules: {
// Ignore certain webpack alias because it can't be resolved
Expand Down Expand Up @@ -56,5 +56,12 @@ module.exports = {
'react/jsx-filename-extension': OFF,
'react-hooks/rules-of-hooks': ERROR,
'react/prop-types': OFF, // PropTypes aren't used much these days.
'react/function-component-definition': [
WARNING,
{
namedComponents: 'function-declaration',
unnamedComponents: 'arrow-function',
},
],
},
};
18 changes: 9 additions & 9 deletions packages/create-docusaurus/templates/facebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.15.7",
"eslint": "^7.20.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^2.2.1",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.3.0",
"prettier": "^2.4.1",
"stylelint": "^13.2.1"
},
"browserslist": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-migrate/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cli
.option('--mdx', 'try to migrate MD to MDX too')
.option('--page', 'try to migrate pages too')
.description('Migrate between versions of Docusaurus website.')
.action((siteDir = '.', newDir = '.', {mdx, page}) => {
.action((siteDir = '.', newDir = '.', {mdx, page} = {}) => {
const sitePath = path.resolve(siteDir);
const newSitePath = path.resolve(newDir);
wrapCommand(migrateDocusaurusProject)(sitePath, newSitePath, mdx, page);
Expand Down
45 changes: 21 additions & 24 deletions packages/docusaurus-migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ function sanitizedFileContent(
): string {
const extractedData = extractMetadata(content);
const extractedMetaData = Object.entries(extractedData.metadata).reduce(
(metaData, [key, value]) => {
return `${metaData}\n${key}: ${
(metaData, [key, value]) =>
`${metaData}\n${key}: ${
shouldQuotifyFrontMatter([key, value]) ? `"${value}"` : value
}`;
},
}`,
'',
);
const sanitizedData = `---${extractedMetaData}\n---\n${
Expand Down Expand Up @@ -618,28 +617,26 @@ function migrateVersionedSidebar(
const newSidebar = Object.entries(sidebar.entries).reduce(
(acc: SidebarEntries, val) => {
const key = `version-${sidebar.version}/${val[0]}`;
acc[key] = Object.entries(val[1]).map((value) => {
return {
type: 'category',
label: value[0],
items: (value[1] as Array<SidebarEntry>).map((sidebarItem) => {
if (typeof sidebarItem === 'string') {
return {
type: 'doc',
id: `version-${sidebar.version}/${sidebarItem}`,
};
}
acc[key] = Object.entries(val[1]).map((value) => ({
type: 'category',
label: value[0],
items: (value[1] as Array<SidebarEntry>).map((sidebarItem) => {
if (typeof sidebarItem === 'string') {
return {
type: 'category',
label: sidebarItem.label,
items: sidebarItem.ids.map((id: string) => ({
type: 'doc',
id: `version-${sidebar.version}/${id}`,
})),
type: 'doc',
id: `version-${sidebar.version}/${sidebarItem}`,
};
}),
};
});
}
return {
type: 'category',
label: sidebarItem.label,
items: sidebarItem.ids.map((id: string) => ({
type: 'doc',
id: `version-${sidebar.version}/${id}`,
})),
};
}),
}));
return acc;
},
{},
Expand Down
10 changes: 3 additions & 7 deletions packages/docusaurus-migrate/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ export default function transformer(file: string): string {
type: 'Identifier',
},
})
.filter(function (p) {
return p.parentPath.parentPath.name === 'body';
})
.forEach(function (p) {
.filter((p) => p.parentPath.parentPath.name === 'body')
.forEach((p) => {
const exportDecl = jscodeshift.exportDeclaration(
true,
jscodeshift.arrowFunctionExpression(
Expand Down Expand Up @@ -177,9 +175,7 @@ function getDefaultImportDeclarators(rootAst: Collection) {
},
},
})
.filter((variableDeclarator) => {
return !!variableDeclarator.value;
});
.filter((variableDeclarator) => !!variableDeclarator.value);
}

function getNamedImportDeclarators(rootAst: Collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,10 @@ describe('collectRedirects', () => {
collectRedirects(
createTestPluginContext(
{
createRedirects: (routePath) => {
return [
`${removeTrailingSlash(routePath)}/some/path/suffix1`,
`${removeTrailingSlash(routePath)}/some/other/path/suffix2`,
];
},
createRedirects: (routePath) => [
`${removeTrailingSlash(routePath)}/some/path/suffix1`,
`${removeTrailingSlash(routePath)}/some/other/path/suffix2`,
],
},
['/', '/testpath', '/otherPath.html'],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ describe('normalizePluginOptions', () => {
});

test('should override all default options with valid user options', () => {
const createRedirects: CreateRedirectsFnOption = (_routePath: string) => {
return [];
};
const createRedirects: CreateRedirectsFnOption = (_routePath: string) => [];
expect(
normalizePluginOptions({
fromExtensions: ['exe', 'zip'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ function applyRedirectsTrailingSlash(
redirects: RedirectMetadata[],
params: ApplyTrailingSlashParams,
) {
return redirects.map((redirect) => {
return {
...redirect,
to: applyTrailingSlash(redirect.to, params),
};
});
return redirects.map((redirect) => ({
...redirect,
to: applyTrailingSlash(redirect.to, params),
}));
}

function validateCollectedRedirects(
Expand Down Expand Up @@ -181,12 +179,10 @@ function createCreateRedirectsOptionRedirects(
const froms: string[] =
typeof fromsMixed === 'string' ? [fromsMixed] : fromsMixed;

return froms.map((from) => {
return {
from,
to: path,
};
});
return froms.map((from) => ({
from,
to: path,
}));
}

return paths.flatMap(createPathRedirects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type CreateRedirectPageOptions = {
toUrl: string;
};

const getCompiledRedirectPageTemplate = memoize(() => {
return eta.compile(redirectPageTemplate.trim());
});
const getCompiledRedirectPageTemplate = memoize(() =>
eta.compile(redirectPageTemplate.trim()),
);

function renderRedirectPageTemplate(data: Record<string, unknown>) {
const compiled = getCompiledRedirectPageTemplate();
Expand Down
Loading

0 comments on commit 4901a12

Please sign in to comment.