Skip to content

Commit 86622da

Browse files
authored
fix dead URLs plugin, correct some broken links (facebook#4965)
1 parent 9f25239 commit 86622da

16 files changed

Lines changed: 38 additions & 44 deletions

File tree

docs/animations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ The native driver also works with `Animated.event`. This is especially useful fo
549549
</Animated.ScrollView>
550550
```
551551

552-
You can see the native driver in action by running the [RNTester app](https://github.com/facebook/react-native/blob/main/packages/rn-tester/), then loading the Native Animated Example. You can also take a look at the [source code](https://github.com/facebook/react-native/blob/master/packages/rn-tester/js/examples/NativeAnimation/NativeAnimationsExample.js) to learn how these examples were produced.
552+
You can see the native driver in action by running the [RNTester app](https://github.com/facebook/react-native/blob/main/packages/rn-tester/), then loading the Native Animated Example. You can also take a look at the [source code](https://github.com/facebook/react-native/blob/main/packages/rn-tester/js/examples/NativeAnimation/NativeAnimationsExample.js) to learn how these examples were produced.
553553

554554
#### Caveats
555555

docs/build-speed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Ccache works by wrapping the C++ compilers, storing the compilation results, and
120120
if an intermediate compilation result was originally stored.
121121

122122
Ccache is available in the package manager for most operating systems. On macOS, we can install ccache with `brew install ccache`.
123-
Or you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md) to install from source.
123+
Or you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/install.md) to install from source.
124124

125125
You can then do two clean builds (e.g. on Android you can first run `yarn react-native run-android`, delete the `android/app/build` folder and run the first command once more). You will notice that the second build was way faster than the first one (it should take seconds rather than minutes).
126126
While building, you can verify that `ccache` works correctly and check the cache hits/miss rate `ccache -s`

docs/debugging-release-builds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If a React Native app throws an unhandled exception in a release build, the outp
2020

2121
In the above stack trace, entries like `p@1:132161` are minified function names and bytecode offsets. To debug these calls, we want to translate these into file, line, and function name, e.g. `AwesomeProject/App.js:54:initializeMap`. This is known as **symbolication.**
2222

23-
You can symbolicate minified function names and bytecode like the above by passing the stack trace and a generated source map to [`metro-symbolicate`](http://npmjs.com/package/metro-symbolicate).
23+
You can symbolicate minified function names and bytecode like the above by passing the stack trace and a generated source map to [`metro-symbolicate`](https://www.npmjs.com/package/metro-symbolicate).
2424

2525
### Enabling source maps
2626

docs/element-nodes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ From [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element):
8484
- ℹ️ Returns the value of the `id` or `nativeID` props.
8585
- [`lastElementChild`](https://developer.mozilla.org/en-US/docs/Web/API/Element/lastElementChild)
8686
- [`nextElementSibling`](https://developer.mozilla.org/en-US/docs/Web/API/Element/nextElementSibling)
87-
- [`nodeName`](https://developer.mozilla.org/en-US/docs/Web/API/Element/nodeName)
88-
- [`nodeType`](https://developer.mozilla.org/en-US/docs/Web/API/Element/nodeType)
89-
- [`nodeValue`](https://developer.mozilla.org/en-US/docs/Web/API/Element/nodeValue)
87+
- [`nodeName`](https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName)
88+
- [`nodeType`](https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType)
89+
- [`nodeValue`](https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeValue)
9090
- [`previousElementSibling`](https://developer.mozilla.org/en-US/docs/Web/API/Element/previousElementSibling)
9191
- [`scrollHeight`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight)
9292
- [`scrollLeft`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft)
@@ -96,7 +96,7 @@ From [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element):
9696
- [`scrollWidth`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth)
9797
- [`tagName`](https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName)
9898
- ℹ️ Returns a normalized native component name prefixed with `RN:`, like `RN:View`.
99-
- [`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Element/textContent)
99+
- [`textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent)
100100
- Methods
101101
- [`getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect)
102102
- [`hasPointerCapture()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/hasPointerCapture)

docs/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Note that image sources required this way include size (width, height) info for
6767

6868
## Static Non-Image Resources
6969

70-
The `require` syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including `.mp3`, `.wav`, `.mp4`, `.mov`, `.html` and `.pdf`. See [bundler defaults](https://github.com/facebook/metro/blob/master/packages/metro-config/src/defaults/defaults.js#L14-L44) for the full list.
70+
The `require` syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including `.mp3`, `.wav`, `.mp4`, `.mov`, `.html`, `.pdf` and more. See [bundler defaults](https://github.com/facebook/metro/blob/main/packages/metro-config/src/defaults/defaults.js#L16-L51) for the full list.
7171

7272
You can add support for other types by adding an [`assetExts` resolver option](https://metrobundler.dev/docs/configuration#resolver-options) in your [Metro configuration](https://metrobundler.dev/docs/configuration).
7373

docs/testing-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Snapshots have several weak points:
245245

246246
Snapshots themselves do not ensure that your component render logic is correct, they are merely good at guarding against unexpected changes and for checking that the components in the React tree under test receive the expected props (styles and etc.).
247247

248-
We recommend that you only use small snapshots (see [`no-large-snapshots` rule](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md)). If you want to test a _change_ between two React component states, use [`snapshot-diff`](https://github.com/jest-community/snapshot-diff). When in doubt, prefer explicit expectations as described in the previous paragraph.
248+
We recommend that you only use small snapshots (see [`no-large-snapshots` rule](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md)). If you want to test a _change_ between two React component states, use [`snapshot-diff`](https://github.com/jest-community/snapshot-diff). When in doubt, prefer explicit expectations as described in the previous paragraph.
249249

250250
<img src="/docs/assets/p_tests-snapshot.svg" alt=" " />
251251

plugins/remark-lint-no-dead-urls/src/__tests__/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import {remark} from 'remark';
99
import dedent from 'dedent';
1010
import {jest, describe, beforeEach, test, expect} from '@jest/globals';
11+
import {Options} from '../index.ts';
1112

1213
const mockFetch = jest.fn() as jest.MockedFunction<
1314
(url: string, method: unknown, options?: object) => Promise<number>
@@ -19,7 +20,7 @@ jest.unstable_mockModule('../lib.ts', () => ({
1920

2021
const plugin = (await import('../index.ts')).default;
2122

22-
function processMarkdown(md: string, opts = {}) {
23+
function processMarkdown(md: string, opts: Options = {}) {
2324
return remark().use(plugin, opts).process(md);
2425
}
2526

plugins/remark-lint-no-dead-urls/src/index.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77

88
// Forked from: https://github.com/davidtheclark/remark-lint-no-dead-urls
99

10-
import {Method, RequestError} from 'got';
11-
import {Root} from 'mdast';
10+
import {type Method, RequestError} from 'got';
1211
import {URL} from 'node:url';
1312
import {lintRule} from 'unified-lint-rule';
1413
import {visit} from 'unist-util-visit';
15-
import type {VFile} from 'vfile';
14+
import {type VFile} from 'vfile';
1615

1716
import {fetch} from './lib.ts';
17+
import type {MDASTNode} from './types.d.ts';
18+
19+
export type Options = {
20+
baseUrl?: string;
21+
skipUrlPatterns?: RegExp[];
22+
headers?: Record<string, string>;
23+
};
1824

1925
const linkCache = new Map();
2026

@@ -32,11 +38,7 @@ const uri = {
3238
isPath: (url: string) => /^\/.*/.test(url),
3339
};
3440

35-
async function cacheFetch(
36-
urlOrPath: string,
37-
method: Method,
38-
options: {baseUrl?: string} & Record<string, unknown>
39-
) {
41+
async function cacheFetch(urlOrPath: string, method: Method, options: Options) {
4042
if (linkCache.has(urlOrPath)) {
4143
return [urlOrPath, linkCache.get(urlOrPath)];
4244
}
@@ -50,10 +52,7 @@ async function cacheFetch(
5052
return [urlOrPath, code];
5153
}
5254

53-
async function naiveLinkCheck(
54-
urls: string[],
55-
options: {baseUrl?: string} & Record<string, unknown>
56-
) {
55+
async function naiveLinkCheck(urls: string[], options: Options) {
5756
return Promise.allSettled(
5857
urls.map(async url => {
5958
try {
@@ -62,11 +61,11 @@ async function naiveLinkCheck(
6261
try {
6362
// Fallback, some endpoints don't support HEAD requests
6463
return await cacheFetch(url, 'GET', options);
65-
} catch (e) {
66-
if (!(e instanceof RequestError)) {
67-
throw e;
64+
} catch (err) {
65+
if (!(err instanceof RequestError)) {
66+
throw err;
6867
}
69-
const code = e.response?.statusCode ?? e.code;
68+
const code = err.response?.statusCode ?? err.code;
7069
linkCache.set(url, code);
7170
return [url, code];
7271
}
@@ -75,14 +74,7 @@ async function naiveLinkCheck(
7574
);
7675
}
7776

78-
async function noDeadUrls(
79-
ast: Root,
80-
file: VFile,
81-
options: {
82-
skipUrlPatterns?: string[];
83-
baseUrl?: string;
84-
} & Record<string, unknown> = {}
85-
) {
77+
async function noDeadUrls(ast: MDASTNode, file: VFile, options: Options) {
8678
const urlToNodes = new Map();
8779

8880
const {skipUrlPatterns, ...clientOptions} = options;

plugins/remark-lint-no-dead-urls/src/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import got, {Method} from 'got';
8+
import got, {type Method} from 'got';
99

1010
export async function fetch(url: string, method: Method, options = {}) {
1111
const {statusCode} = await got(url, {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {type Node as MDASTNode} from 'mdast';

0 commit comments

Comments
 (0)