Skip to content

Commit

Permalink
docs: use custom diff code blocks (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jun 10, 2022
1 parent cb2d446 commit 331ff3b
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Expand Up @@ -73,8 +73,10 @@
"linebreaks",
"lzstring",
"markdownlint",
"metastring",
"necroing",
"nocheck",
"noninteractive",
"nullish",
"OOM",
"OOMs",
Expand Down
34 changes: 18 additions & 16 deletions docs/linting/MONOREPO.md
Expand Up @@ -18,22 +18,24 @@ Earlier in our docs on [typed linting](./TYPED_LINTING.md), we showed you how to

For example, this is how we specify all of our `tsconfig.json` within this repo.

```diff title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
- project: ['./tsconfig.json'],
+ project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
};
```js title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
// Remove this line
project: ['./tsconfig.json'],
// Add this line
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
};
```

If you're looking for an example of what the `.eslintrc.js`, and referenced `tsconfig.json` might look like in a real example, look no further than this very repo. We're a multi-package monorepo that uses one `tsconfig.json` per package, that also uses typed linting.
Expand Down
82 changes: 42 additions & 40 deletions docs/linting/README.md
Expand Up @@ -136,19 +136,18 @@ If you use [`prettier`](https://www.npmjs.com/package/prettier), there is also a

Using this config by adding it to the end of your `extends`:

```diff title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
+ 'prettier',
],
};
```js title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// Add this line
'prettier',
],
};
```

### Community Configs
Expand All @@ -163,19 +162,20 @@ A few popular all-in-one configs are:
To use one of these complete config packages, you would replace the `extends` with the package name.
For example:

```diff title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
- 'eslint:recommended',
- 'plugin:@typescript-eslint/recommended',
+ 'airbnb-typescript',
],
};
```js title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
// Removed lines start
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// Removed lines end
// Add this line
'airbnb-typescript',
],
};
```

<!-- markdownlint-disable MD044 -->
Expand All @@ -196,20 +196,22 @@ Below are just a few examples:
Every plugin that is out there includes documentation on the various configurations and rules they offer.
A typical plugin might be used like:

```diff title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
+ 'jest',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
+ 'plugin:jest/recommended',
],
};
```js title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
// Add this line
'jest',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// Add this line
'plugin:jest/recommended',
],
};
```

<!-- markdownlint-disable MD044 -->
Expand Down
15 changes: 9 additions & 6 deletions docs/linting/TROUBLESHOOTING.md
Expand Up @@ -42,12 +42,15 @@ See our docs on [type aware linting](./TYPED_LINTING.md#i-get-errors-telling-me-

You can use `parserOptions.extraFileExtensions` to specify an array of non-TypeScript extensions to allow, for example:

```diff
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
+ extraFileExtensions: ['.vue'],
},
```js title=".eslintrc.js"
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
// Add this line
extraFileExtensions: ['.vue'],
},
};
```

## One of my lint rules isn't working correctly on a pure JavaScript file
Expand Down
33 changes: 18 additions & 15 deletions docs/linting/TYPED_LINTING.md
Expand Up @@ -8,21 +8,24 @@ Under the hood, the typescript-eslint parser uses TypeScript's compiler APIs to

To tap into TypeScript's additional powers, there are two small changes you need to make to your config file:

```diff title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
+ parserOptions: {
+ tsconfigRootDir: __dirname,
+ project: ['./tsconfig.json'],
+ },
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
};
```js title=".eslintrc.js"
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
// Added lines start
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
// Added lines end
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
// Add this line
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
};
```

In more detail:
Expand Down
17 changes: 17 additions & 0 deletions packages/website/docusaurusConfig.ts
Expand Up @@ -139,6 +139,23 @@ const themeConfig: ThemeCommonConfig & AlgoliaThemeConfig = {
styles: [],
},
additionalLanguages: ['ignore'],
magicComments: [
{
className: 'theme-code-block-highlighted-line',
line: 'highlight-next-line',
block: { start: 'highlight-start', end: 'highlight-end' },
},
{
className: 'code-block-removed-line',
line: 'Remove this line',
block: { start: 'Removed lines start', end: 'Removed lines end' },
},
{
className: 'code-block-added-line',
line: 'Add this line',
block: { start: 'Added lines start', end: 'Added lines end' },
},
],
},
tableOfContents: {
maxHeadingLevel: 4,
Expand Down
1 change: 1 addition & 0 deletions packages/website/package.json
Expand Up @@ -26,6 +26,7 @@
"json5": "^2.2.1",
"konamimojisplosion": "^0.5.1",
"lzstring.ts": "^2.0.2",
"prism-react-renderer": "^1.3.3",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"remark-docusaurus-tabs": "^0.2.0",
Expand Down
38 changes: 35 additions & 3 deletions packages/website/src/css/custom.css
Expand Up @@ -109,7 +109,39 @@ h6 {
background-color: var(--code-line-decoration);
}

/* indent the nested checklist for the rule doc attributes */
ul.contains-task-list > li > ul.contains-task-list {
padding-left: 24px;
.code-block-removed-line::before {
content: '-';
display: inline-block;
width: 0px;
position: relative;
left: -0.7em;
color: red;
}

.code-block-removed-line {
background-color: #ff000020;
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
user-select: none;
}

.code-block-added-line::before {
content: '+';
display: inline-block;
width: 0px;
position: relative;
left: -0.7em;
color: rgb(2, 164, 113);
}

.code-block-added-line {
background-color: #00ff9540;
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
}

[data-theme='dark'] .code-block-added-line {
background-color: #00ff9510;
}

0 comments on commit 331ff3b

Please sign in to comment.