Skip to content

Commit 968507e

Browse files
committed
Refactor code-style
1 parent 0abf9b0 commit 968507e

File tree

3 files changed

+67
-64
lines changed

3 files changed

+67
-64
lines changed

lib/find-repo.node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* @import {VFile} from 'vfile'
44
*/
55

6+
import {exec as execCallback} from 'node:child_process'
67
import path from 'node:path'
78
import {promisify} from 'node:util'
8-
import {exec as execCallback} from 'node:child_process'
99

1010
const exec = promisify(execCallback)
1111

lib/index.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
/**
99
* @typedef {Map<string, Map<string, boolean>>} Landmarks
1010
* Landmarks.
11-
*
11+
*/
12+
13+
/**
1214
* @typedef Options
1315
* Configuration.
1416
* @property {string | false | null | undefined} [repository]
@@ -26,28 +28,33 @@
2628
* Config on how hosted Git works (default: detected from repo);
2729
* `github.com`, `gitlab.com`, or `bitbucket.org` work automatically;
2830
* otherwise, pass `urlConfig` manually.
29-
*
31+
*/
32+
33+
/**
3034
* @callback Propose
3135
* @param {string} value
3236
* @param {ReadonlyArray<string>} dictionary
3337
* @param {Readonly<ProposeOptions> | null | undefined} [options]
3438
* @returns {string | undefined}
35-
*
39+
*/
40+
41+
/**
3642
* @typedef ProposeOptions
3743
* Configuration for `propose`.
3844
* @property {number| null | undefined} [threshold]
3945
* Threshold.
40-
*
41-
* @typedef {Extract<Nodes, Resource>} Resources
42-
* Resources.
43-
*
46+
*/
47+
48+
/**
4449
* @typedef Reference
4550
* Reference to something.
4651
* @property {string} filePath
4752
* Path to file.
4853
* @property {string | undefined} hash
4954
* Hash.
50-
*
55+
*/
56+
57+
/**
5158
* @typedef ReferenceInfo
5259
* Info on a reference.
5360
* @property {VFile} file
@@ -56,7 +63,14 @@
5663
* Reference.
5764
* @property {ReadonlyArray<Readonly<Resources>>} nodes
5865
* Nodes that reference it.
59-
*
66+
*/
67+
68+
/**
69+
* @typedef {Extract<Nodes, Resource>} Resources
70+
* Resources.
71+
*/
72+
73+
/**
6074
* @typedef State
6175
* Info passed around.
6276
* @property {string} base
@@ -67,7 +81,9 @@
6781
* Path to Git folder.
6882
* @property {Readonly<UrlConfig>} urlConfig
6983
* Configuration.
70-
*
84+
*/
85+
86+
/**
7187
* @typedef UrlConfig
7288
* Hosted Git info.
7389
*
@@ -101,7 +117,6 @@
101117
* lines: false
102118
* }
103119
* ```
104-
*
105120
* @property {string | null | undefined} [headingPrefix]
106121
* Prefix of headings (example: `'#'`, `'#markdown-header-'`).
107122
* @property {string | null | undefined} [hostname]
@@ -136,7 +151,7 @@ const propose = /** @type {Propose} */ (propose_)
136151
cliCompleter.pluginId = constants.sourceId
137152

138153
/** @type {Readonly<Partial<Record<Hosts, string>>>} */
139-
const viewPaths = {github: 'blob', gitlab: 'blob', bitbucket: 'src'}
154+
const viewPaths = {bitbucket: 'src', github: 'blob', gitlab: 'blob'}
140155
/** @type {Readonly<Partial<Record<Hosts, string>>>} */
141156
const headingPrefixes = {
142157
bitbucket: '#markdown-header-',
@@ -159,7 +174,7 @@ const slashes = '//'
159174
const lineExpression = /^#l\d/i
160175

161176
// List from: https://github.com/github/markup#markups
162-
const readmeExtensions = new Set(['.markdown', '.mdown', '.mkdn', '.md'])
177+
const readmeExtensions = new Set(['.markdown', '.mdown', '.md', '.mkdn'])
163178
const readmeBasename = /^readme$/i
164179

165180
/**
@@ -409,13 +424,10 @@ export default function remarkValidateLinks(options, fileSet) {
409424
} catch {}
410425

411426
const files = entries.sort()
412-
let index = -1
413427
/** @type {string | undefined} */
414428
let file
415429

416-
while (++index < files.length) {
417-
const entry = entries[index]
418-
430+
for (const entry of files) {
419431
if (readme(entry)) {
420432
file = entry
421433
break
@@ -464,10 +476,8 @@ async function checkAll(files) {
464476
// Merge landmarks.
465477
/** @type {Landmarks} */
466478
const landmarks = new Map()
467-
let index = -1
468479

469-
while (++index < files.length) {
470-
const file = files[index]
480+
for (const file of files) {
471481
const fileLandmarks = /** @type {Landmarks | undefined} */ (
472482
file.data[constants.landmarkId]
473483
)
@@ -482,10 +492,8 @@ async function checkAll(files) {
482492
// Merge references.
483493
/** @type {Map<string, Map<string, Array<ReferenceInfo>>>} */
484494
const references = new Map()
485-
index = -1
486495

487-
while (++index < files.length) {
488-
const file = files[index]
496+
for (const file of files) {
489497
const fileReferences =
490498
/** @type {Map<string, Map<string, Array<Resources>>> | undefined} */ (
491499
file.data[constants.referenceId]
@@ -538,10 +546,8 @@ async function checkAll(files) {
538546
}
539547
}
540548

541-
index = -1
542-
543-
while (++index < missing.length) {
544-
warn(landmarks, missing[index])
549+
for (const reference of missing) {
550+
warn(landmarks, reference)
545551
}
546552
}
547553

@@ -613,10 +619,7 @@ function warn(landmarks, reference) {
613619
reason += '; did you mean `' + suggestion + '`'
614620
}
615621

616-
let index = -1
617-
618-
while (++index < reference.nodes.length) {
619-
const node = reference.nodes[index]
622+
for (const node of reference.nodes) {
620623
const message = reference.file.message(reason, {
621624
place: node.position,
622625
source: origin,

0 commit comments

Comments
 (0)