Skip to content

Commit

Permalink
chore: add cSpell for spell checking (#6456)
Browse files Browse the repository at this point in the history
* chore: Add cSpell for spell checking

* chore: exclude map files and remove dups

* chore: exclude more binary files

* chore: remove MD headings

* Update .cspell.json

* fix a few spellings

* fix more

* fix

Signed-off-by: Joshua Chen <sidachen2003@gmail.com>

* fix a few

* oops

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
nschonni and Josh-Cena committed Jan 25, 2022
1 parent a41a5c3 commit 521eb11
Show file tree
Hide file tree
Showing 64 changed files with 852 additions and 142 deletions.
36 changes: 36 additions & 0 deletions .cspell.json
@@ -0,0 +1,36 @@
{
"version": "0.2",
"gitignoreRoot": ".",
"useGitignore": true,
"dictionaries": [
"css",
"html",
"fonts",
"typescript",
"softwareTerms",
"companies",
"lorem-ipsum",
"project-words"
],
"dictionaryDefinitions": [
{
"name": "project-words",
"path": "./project-words.txt",
"noSuggest": true
}
],
"ignorePaths": [
"CHANGELOG.md",
"examples",
"packages/docusaurus-theme-translations/locales",
"__tests__",
"package.json",
"yarn.lock",
"project-words.txt",
"website/src/data/users.tsx",
"*.xyz",
"*.docx",
"versioned_docs"
],
"ignoreRegExpList": ["Email", "Urls", "#[\\w-]*"]
}
16 changes: 16 additions & 0 deletions .github/workflows/cspell-problem-matcher.json
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "cspell",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+)\\s+\\-\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Expand Up @@ -22,6 +22,8 @@ jobs:
- name: Check immutable yarn.lock
run: git diff --exit-code
- name: Lint
run: yarn lint:ci
run: |
echo "::add-matcher::.github/workflows/cspell-problem-matcher.json"
yarn lint:ci
- name: Prettier Code
run: yarn format:diff
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -42,9 +42,10 @@
"prepare": "husky install",
"format": "prettier --write .",
"format:diff": "prettier --list-different .",
"lint": "yarn lint:js && yarn lint:style",
"lint:ci": "yarn lint:js --quiet && yarn lint:style",
"lint": "yarn lint:js && yarn lint:style && yarn lint:spelling",
"lint:ci": "yarn lint:js --quiet && yarn lint:style && yarn lint:spelling",
"lint:js": "eslint --cache --report-unused-disable-directives \"**/*.{js,jsx,ts,tsx,mjs}\"",
"lint:spelling": "cspell \"**\" --no-progress",
"lint:style": "stylelint \"**/*.css\"",
"lerna": "lerna",
"test": "cross-env TZ=UTC jest",
Expand Down Expand Up @@ -84,6 +85,7 @@
"@typescript-eslint/parser": "^5.8.1",
"concurrently": "^7.0.0",
"cross-env": "^7.0.3",
"cspell": "^5.16.0",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.0",
"eslint-config-prettier": "^8.3.0",
Expand Down Expand Up @@ -123,7 +125,8 @@
"stylelint --allow-empty-input --fix"
],
"*": [
"prettier --ignore-unknown --write"
"prettier --ignore-unknown --write",
"cspell --no-progress"
]
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-mdx-loader/src/index.ts
Expand Up @@ -156,7 +156,7 @@ export default async function mdxLoader(
}

// MDX partials are MDX files starting with _ or in a folder starting with _
// Partial are not expected to have an associated metadata file or frontmatter
// Partial are not expected to have an associated metadata file or front matter
const isMDXPartial = options.isMDXPartial && options.isMDXPartial(filePath);
if (isMDXPartial && hasFrontMatter) {
const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter.
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-migrate/src/frontMatter.ts
Expand Up @@ -38,9 +38,9 @@ export default function extractMetadata(content: string): Data {
// New line characters => to handle all operating systems.
const lines = (both.header ?? '').split(/\r?\n/);
for (let i = 0; i < lines.length - 1; i += 1) {
const keyvalue = lines[i].split(':');
const key = keyvalue[0].trim();
let value = keyvalue.slice(1).join(':').trim();
const keyValue = lines[i].split(':');
const key = keyValue[0].trim();
let value = keyValue.slice(1).join(':').trim();
try {
value = JSON.parse(value);
} catch (err) {
Expand All @@ -51,7 +51,7 @@ export default function extractMetadata(content: string): Data {
return {metadata, rawContent: both.content};
}

// The new frontmatter parser need some special chars to
// The new front matter parser need some special chars to
export function shouldQuotifyFrontMatter([key, value]: [
string,
string,
Expand All @@ -67,7 +67,7 @@ export function shouldQuotifyFrontMatter([key, value]: [
return true;
}
// TODO this is not ideal to have to maintain such a list of allowed chars
// maybe we should quotify if graymatter throws instead?
// maybe we should quotify if gray-matter throws instead?
return !String(value).match(
/^([\w .\-sàáâãäåçèéêëìíîïðòóôõöùúûüýÿ!;,=+_?'`&#()[\]§%€$])+$/,
);
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-migrate/src/transform.ts
Expand Up @@ -165,7 +165,7 @@ export default function transformer(file: string): string {
return root.toSource();
}

function getDefaultImportDeclarators(rootAst: Collection) {
function getDefaultImportDeclarations(rootAst: Collection) {
// var ... = require('y')
return rootAst
.find(VariableDeclarator, {
Expand All @@ -178,7 +178,7 @@ function getDefaultImportDeclarators(rootAst: Collection) {
.filter((variableDeclarator) => !!variableDeclarator.value);
}

function getNamedImportDeclarators(rootAst: Collection) {
function getNamedImportDeclarations(rootAst: Collection) {
// var ... = require('y').x
return rootAst.find(VariableDeclarator, {
init: {
Expand All @@ -192,9 +192,9 @@ function getNamedImportDeclarators(rootAst: Collection) {
}

function getImportDeclaratorPaths(variableDeclaration: Collection) {
const defaultImports = getDefaultImportDeclarators(variableDeclaration);
const defaultImports = getDefaultImportDeclarations(variableDeclaration);

const namedImports = getNamedImportDeclarators(variableDeclaration);
const namedImports = getNamedImportDeclarations(variableDeclaration);

return [...defaultImports.paths(), ...namedImports.paths()];
}
Expand Up @@ -16,7 +16,7 @@ describe('createToExtensionsRedirects', () => {
createToExtensionsRedirects(['/'], ['']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\"\\" is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -25,7 +25,7 @@ describe('createToExtensionsRedirects', () => {
createToExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -34,7 +34,7 @@ describe('createToExtensionsRedirects', () => {
createToExtensionsRedirects(['/'], ['ht/ml']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -43,7 +43,7 @@ describe('createToExtensionsRedirects', () => {
createToExtensionsRedirects(['/'], [',']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\",\\" contains invalid URI characters.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand Down Expand Up @@ -80,7 +80,7 @@ describe('createFromExtensionsRedirects', () => {
createFromExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -89,7 +89,7 @@ describe('createFromExtensionsRedirects', () => {
createFromExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -98,7 +98,7 @@ describe('createFromExtensionsRedirects', () => {
createFromExtensionsRedirects(['/'], ['ht/ml']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand All @@ -107,7 +107,7 @@ describe('createFromExtensionsRedirects', () => {
createFromExtensionsRedirects(['/'], [',']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\",\\" contains invalid URI characters.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
If the redirect extension system is not good enough for your use case, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

Expand Down
Expand Up @@ -13,7 +13,7 @@ import {
import type {RedirectMetadata} from './types';

const ExtensionAdditionalMessage =
'If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the "createRedirects" plugin option.';
'If the redirect extension system is not good enough for your use case, you can create redirects yourself with the "createRedirects" plugin option.';

const validateExtension = (ext: string) => {
if (!ext) {
Expand Down
Expand Up @@ -31,7 +31,7 @@ describe('getBlogPostAuthors', () => {
).toEqual([]);
});

test('can read author from legacy frontmatter', () => {
test('can read author from legacy front matter', () => {
expect(
getBlogPostAuthors({
frontMatter: {
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('getBlogPostAuthors', () => {
`);
});

test('throw when mixing legacy/new authors frontmatter', () => {
test('throw when mixing legacy/new authors front matter', () => {
expect(() =>
getBlogPostAuthors({
frontMatter: {
Expand All @@ -261,8 +261,8 @@ describe('getBlogPostAuthors', () => {
authorsMap: undefined,
}),
).toThrowErrorMatchingInlineSnapshot(`
"To declare blog post authors, use the 'authors' FrontMatter in priority.
Don't mix 'authors' with other existing 'author_*' FrontMatter. Choose one or the other, not both at the same time."
"To declare blog post authors, use the 'authors' front matter in priority.
Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time."
`);

expect(() =>
Expand All @@ -274,8 +274,8 @@ describe('getBlogPostAuthors', () => {
authorsMap: {slorber: {name: 'Sébastien Lorber'}},
}),
).toThrowErrorMatchingInlineSnapshot(`
"To declare blog post authors, use the 'authors' FrontMatter in priority.
Don't mix 'authors' with other existing 'author_*' FrontMatter. Choose one or the other, not both at the same time."
"To declare blog post authors, use the 'authors' front matter in priority.
Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time."
`);
});
});
Expand Down
Expand Up @@ -47,7 +47,7 @@ function testField(params: {
// eslint-disable-next-line jest/no-jasmine-globals
fail(
new Error(
`Blog frontmatter is expected to be rejected, but was accepted successfully:\n ${JSON.stringify(
`Blog front matter is expected to be rejected, but was accepted successfully:\n ${JSON.stringify(
frontMatter,
null,
2,
Expand Down Expand Up @@ -105,8 +105,8 @@ describe('validateBlogPostFrontMatter id', () => {
});
});

describe('validateBlogPostFrontMatter handles legacy/new author frontmatter', () => {
test('allow legacy author frontmatter', () => {
describe('validateBlogPostFrontMatter handles legacy/new author front matter', () => {
test('allow legacy author front matter', () => {
const frontMatter: BlogPostFrontMatter = {
author: 'Sebastien',
author_url: 'https://sebastienlorber.com',
Expand All @@ -116,7 +116,7 @@ describe('validateBlogPostFrontMatter handles legacy/new author frontmatter', ()
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
});

test('allow new authors frontmatter', () => {
test('allow new authors front matter', () => {
const frontMatter: BlogPostFrontMatter = {
authors: [
'slorber',
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin-content-blog/src/authors.ts
Expand Up @@ -54,7 +54,7 @@ type AuthorsParam = {
authorsMap: AuthorsMap | undefined;
};

// Legacy v1/early-v2 frontmatter fields
// Legacy v1/early-v2 front matter fields
// We may want to deprecate those in favor of using only frontMatter.authors
function getFrontMatterAuthorLegacy(
frontMatter: BlogPostFrontMatter,
Expand Down Expand Up @@ -123,7 +123,7 @@ ${Object.keys(authorsMap)

function toAuthor(frontMatterAuthor: BlogPostFrontMatterAuthor): Author {
return {
// Author def from authorsMap can be locally overridden by frontmatter
// Author def from authorsMap can be locally overridden by front matter
...getAuthorsMapAuthor(frontMatterAuthor.key),
...frontMatterAuthor,
};
Expand All @@ -137,11 +137,11 @@ export function getBlogPostAuthors(params: AuthorsParam): Author[] {
const authors = getFrontMatterAuthors(params);

if (authorLegacy) {
// Technically, we could allow mixing legacy/authors frontmatter, but do we really want to?
// Technically, we could allow mixing legacy/authors front matter, but do we really want to?
if (authors.length > 0) {
throw new Error(
`To declare blog post authors, use the 'authors' FrontMatter in priority.
Don't mix 'authors' with other existing 'author_*' FrontMatter. Choose one or the other, not both at the same time.`,
`To declare blog post authors, use the 'authors' front matter in priority.
Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time.`,
);
}
return [authorLegacy];
Expand Down
Expand Up @@ -6,7 +6,7 @@
*/

import {
JoiFrontMatter as Joi, // Custom instance for frontmatter
JoiFrontMatter as Joi, // Custom instance for front matter
URISchema,
validateFrontMatter,
FrontMatterTagsSchema,
Expand Down Expand Up @@ -35,7 +35,7 @@ const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({
draft: Joi.boolean(),
date: Joi.date().raw(),

// New multi-authors frontmatter:
// New multi-authors front matter:
authors: Joi.alternatives()
.try(
Joi.string(),
Expand All @@ -50,7 +50,7 @@ const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({
.messages({
'alternatives.match': FrontMatterAuthorErrorMessage,
}),
// Legacy author frontmatter
// Legacy author front matter
author: Joi.string(),
author_title: Joi.string(),
author_url: URISchema,
Expand Down
Expand Up @@ -30,11 +30,11 @@ declare module '@docusaurus/plugin-content-blog' {
tags?: FrontMatterTag[];
slug?: string;
draft?: boolean;
date?: Date | string; // Yaml automagically convert some string patterns as Date, but not all
date?: Date | string; // Yaml automatically convert some string patterns as Date, but not all

authors?: BlogPostFrontMatterAuthors;

// We may want to deprecate those older author frontmatter fields later:
// We may want to deprecate those older author front matter fields later:
author?: string;
author_title?: string;
author_url?: string;
Expand Down
@@ -1,6 +1,6 @@
---
custom_edit_url: https://github.com/customUrl/docs/lorem.md
unrelated_frontmatter: won't be part of metadata
unrelated_front_matter: won't be part of metadata
---

Lorem ipsum.

0 comments on commit 521eb11

Please sign in to comment.