Skip to content

Commit 0932a47

Browse files
committed
chore: fix lint issues
1 parent bb21749 commit 0932a47

File tree

11 files changed

+256
-242
lines changed

11 files changed

+256
-242
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"@types/unist": "^3.0.3",
4343
"@unts/patch-package": "^8.1.1",
4444
"concurrently": "^9.1.2",
45-
"eslint": "^9.25.0",
45+
"eslint": "^9.25.1",
46+
"eslint-plugin-jest": "^28.11.0",
4647
"eslint-plugin-react": "^7.37.5",
4748
"globals": "^16.0.0",
4849
"jest": "^30.0.0-alpha.7",

packages/eslint-mdx/shim.d.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,26 @@ declare module 'espree/lib/token-translator' {
44
export default TokenTranslator
55

66
export interface Location {
7-
/**
8-
* The start position.
9-
*/
7+
/** The start position. */
108
start: acorn.Position
11-
/**
12-
* The end position.
13-
*/
9+
/** The end position. */
1410
end: acorn.Position
1511
}
1612

1713
export type Range = [number, number]
1814

1915
export interface EsprimaToken {
20-
/**
21-
* The type of this token.
22-
*/
16+
/** The type of this token. */
2317
type: string
24-
/**
25-
* The string content of the token.
26-
*/
18+
/** The string content of the token. */
2719
value: string
28-
/**
29-
* Location in source text.
30-
*/
20+
/** Location in source text. */
3121
loc: Location | undefined
32-
/**
33-
* start column.
34-
*/
22+
/** Start column. */
3523
start: number | undefined
36-
/**
37-
* end column.
38-
*/
24+
/** End column. */
3925
end: number | undefined
40-
/**
41-
* [start, end] range
42-
*/
26+
/** [start, end] range */
4327
range: Range | undefined
4428
}
4529

packages/eslint-mdx/src/helpers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export const arrayify = <T, R = T extends Array<infer S> ? S : T>(
1717
}, [])
1818

1919
/**
20-
* Given a filepath, get the nearest path that is a regular file.
21-
* The filepath provided by eslint may be a virtual filepath rather than a file
22-
* on disk. This attempts to transform a virtual path into an on-disk path
20+
* Given a filepath, get the nearest path that is a regular file. The filepath
21+
* provided by eslint may be a virtual filepath rather than a file on disk. This
22+
* attempts to transform a virtual path into an on-disk path
2323
*/
2424
export const getPhysicalFilename = (
2525
filename: string,
@@ -122,5 +122,6 @@ export const nextCharOffsetFactory = (text: string) => {
122122
}
123123

124124
/* istanbul ignore next */
125-
export const cjsRequire: CjsRequire =
126-
typeof require === 'undefined' ? createRequire(import.meta.url) : require
125+
export const cjsRequire: CjsRequire = import.meta.url
126+
? createRequire(import.meta.url)
127+
: require

packages/eslint-mdx/src/tokens.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export const restoreTokens = (
132132
}
133133

134134
/**
135-
* not available yet
135+
* Not available yet
136+
*
136137
* @see https://github.com/mdx-js/mdx/issues/2034
137138
*/
138139

packages/eslint-mdx/src/types.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface PackageJson {
7474
}
7575

7676
/**
77-
* temporary workaround for missing `Ignore` from `unified-engine`
77+
* Temporary workaround for missing `Ignore` from `unified-engine`
7878
*
7979
* See also {@link https://github.com/unifiedjs/unified-engine/pull/79}
8080
*
@@ -91,16 +91,10 @@ export type IgnoreClass = typeof Ignore
9191
export type Callback = (error?: Error, result?: boolean) => void
9292

9393
export interface Options {
94-
/**
95-
* Base.
96-
*/
94+
/** Base. */
9795
cwd: string
98-
/**
99-
* Whether to detect ignore files.
100-
*/
96+
/** Whether to detect ignore files. */
10197
detectIgnore: boolean | undefined
102-
/**
103-
* Basename of ignore files.
104-
*/
98+
/** Basename of ignore files. */
10599
ignoreName?: string
106100
}

packages/eslint-mdx/src/worker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ runAsWorker(
231231
sharedTokens.length = 0
232232

233233
/**
234-
* unified plugins are using ESM version of acorn,
235-
* so we have to use the same version as well,
236-
* otherwise the TokenType will be different class
234+
* Unified plugins are using ESM version of acorn, so we have to use the
235+
* same version as well, otherwise the TokenType will be different class
236+
*
237237
* @see also https://github.com/acornjs/acorn-jsx/issues/133
238238
*/
239239
if (!acornParser) {
@@ -754,7 +754,8 @@ runAsWorker(
754754
}
755755

756756
/**
757-
* Copied from @see https://github.com/eslint/espree/blob/1584ddb00f0b4e3ada764ac86ae20e1480003de3/lib/espree.js#L227-L241
757+
* Copied from @see
758+
* https://github.com/eslint/espree/blob/1584ddb00f0b4e3ada764ac86ae20e1480003de3/lib/espree.js#L227-L241
758759
*/
759760
const templateElement = node
760761

packages/eslint-plugin-mdx/src/configs/recommended.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const addPrettierRules = () => {
2929
/* istanbul ignore next */
3030
const version = meta?.version || ''
3131

32-
/**
33-
* @see https://github.com/prettier/eslint-plugin-prettier/releases/tag/v5.1.2
34-
*/
32+
/** @see https://github.com/prettier/eslint-plugin-prettier/releases/tag/v5.1.2 */
3533
const [major, minor, patch] = version.split('.')
3634

3735
/* istanbul ignore if -- We can't cover all versions in one test */

packages/eslint-plugin-mdx/src/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export const getGlobals = <
2323
)
2424

2525
/* istanbul ignore next */
26-
export const cjsRequire: CjsRequire =
27-
typeof require === 'undefined' ? createRequire(import.meta.url) : require
26+
export const cjsRequire: CjsRequire = import.meta.url
27+
? createRequire(import.meta.url)
28+
: require

packages/eslint-plugin-mdx/src/processors/markdown.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* {@link https://github.com/eslint/markdown/blob/f17311eb250fe3f41a24fd52be9c6713d12b7d67/src/processor.js}
3-
*/
1+
/** {@link https://github.com/eslint/markdown/blob/f17311eb250fe3f41a24fd52be9c6713d12b7d67/src/processor.js} */
42

53
import type { AST, Linter, Rule } from 'eslint'
64
import type { Node, Parent, Nodes, Root, RootContentMap } from 'mdast'
@@ -23,6 +21,7 @@ const blocksCache: Map<string, CodeBlock[]> = new Map()
2321

2422
/**
2523
* Performs a depth-first traversal of the Markdown AST.
24+
*
2625
* @param node A Markdown AST node.
2726
* @param callbacks A map of node types to callbacks.
2827
*/
@@ -66,9 +65,10 @@ const eslintCommentRegex = /^(?:eslint\b|global\s)/u
6665

6766
/**
6867
* Extracts `eslint-*` or `global` comments from HTML/MDX comments if present.
68+
*
6969
* @param value The text content of an HTML/MDX AST node.
70-
* @returns The comment's text without the opening and closing tags or
71-
* an empty string if the text is not an ESLint HTML/MDX comment.
70+
* @returns The comment's text without the opening and closing tags or an empty
71+
* string if the text is not an ESLint HTML/MDX comment.
7272
*/
7373
function getComment(value: string, isMdx = false) {
7474
const [commentStart, commentEnd] = COMMENTS[+isMdx]
@@ -96,8 +96,9 @@ function getComment(value: string, isMdx = false) {
9696
const leadingWhitespaceRegex = /^[>\s]*/u
9797

9898
/**
99-
* Gets the offset for the first column of the node's first line in the
100-
* original source text.
99+
* Gets the offset for the first column of the node's first line in the original
100+
* source text.
101+
*
101102
* @param node A Markdown code block AST node.
102103
* @returns The offset for the first column of the node's first line.
103104
*/
@@ -108,10 +109,11 @@ function getBeginningOfLineOffset(node: Node) {
108109
/**
109110
* Gets the leading text, typically whitespace with possible blockquote chars,
110111
* used to indent a code block.
112+
*
111113
* @param text The text of the file.
112114
* @param node A Markdown code block AST node.
113-
* @returns The text from the start of the first line to the opening
114-
* fence of the code block.
115+
* @returns The text from the start of the first line to the opening fence of
116+
* the code block.
115117
*/
116118
function getIndentText(text: string, node: Node) {
117119
return leadingWhitespaceRegex.exec(
@@ -122,7 +124,8 @@ function getIndentText(text: string, node: Node) {
122124
/**
123125
* When applying fixes, the postprocess step needs to know how to map fix ranges
124126
* from their location in the linted JS to the original offset in the Markdown.
125-
* Configuration comments and indentation trimming both complicate this process.
127+
* Configuration comments and indentation trimming both complicate this
128+
* process.
126129
*
127130
* Configuration comments appear in the linted JS but not in the Markdown code
128131
* block. Fixes to configuration comments would cause undefined behavior and
@@ -142,23 +145,24 @@ function getIndentText(text: string, node: Node) {
142145
* suffix of the corresponding line in the Markdown code block. There are no
143146
* differences within the line, so the mapping need only provide the offset
144147
* delta at the beginning of each line.
148+
*
145149
* @param text The text of the file.
146150
* @param node A Markdown code block AST node.
147-
* @param comments List of configuration comment strings that will be
148-
* inserted at the beginning of the code block.
149-
* @returns A list of offset-based adjustments, where lookups are
150-
* done based on the `js` key, which represents the range in the linted JS,
151-
* and the `md` key is the offset delta that, when added to the JS range,
152-
* returns the corresponding location in the original Markdown source.
151+
* @param comments List of configuration comment strings that will be inserted
152+
* at the beginning of the code block.
153+
* @returns A list of offset-based adjustments, where lookups are done based on
154+
* the `js` key, which represents the range in the linted JS, and the `md` key
155+
* is the offset delta that, when added to the JS range, returns the
156+
* corresponding location in the original Markdown source.
153157
*/
154158
function getBlockRangeMap(text: string, node: Node, comments: string[]) {
155159
/**
156160
* The parser sets the fenced code block's start offset to wherever content
157161
* should normally begin (typically the first column of the line, but more
158162
* inside a list item, for example). The code block's opening fence may be
159163
* further indented by up to three characters. If the code block has
160-
* additional indenting, the opening fence's first backtick may be up to
161-
* three whitespace characters after the start offset.
164+
* additional indenting, the opening fence's first backtick may be up to three
165+
* whitespace characters after the start offset.
162166
*/
163167
const startOffset = getBeginningOfLineOffset(node)
164168

@@ -178,8 +182,8 @@ function getBlockRangeMap(text: string, node: Node, comments: string[]) {
178182
const baseIndent = getIndentText(text, node).length
179183

180184
/**
181-
* Track the length of any inserted configuration comments at the beginning
182-
* of the linted JS and start the JS offset lookup keys at this index.
185+
* Track the length of any inserted configuration comments at the beginning of
186+
* the linted JS and start the JS offset lookup keys at this index.
183187
*/
184188
const commentLength = comments.reduce(
185189
(len, comment) => len + comment.length + 1,
@@ -188,9 +192,9 @@ function getBlockRangeMap(text: string, node: Node, comments: string[]) {
188192

189193
/**
190194
* In case there are configuration comments, initialize the map so that the
191-
* first lookup index is always 0. If there are no configuration comments,
192-
* the lookup index will also be 0, and the lookup should always go to the
193-
* last range that matches, skipping this initialization entry.
195+
* first lookup index is always 0. If there are no configuration comments, the
196+
* lookup index will also be 0, and the lookup should always go to the last
197+
* range that matches, skipping this initialization entry.
194198
*/
195199
const rangeMap: RangeMap[] = [
196200
{
@@ -247,6 +251,7 @@ const codeBlockFileNameRegex =
247251

248252
/**
249253
* Parses the file name from a block meta, if available.
254+
*
250255
* @param block A code block.
251256
* @returns The filename, if parsed from block meta.
252257
*/
@@ -259,6 +264,7 @@ function fileNameFromMeta(block: CodeBlock) {
259264

260265
/**
261266
* Extracts lintable code blocks from Markdown text.
267+
*
262268
* @param sourceText The text of the file.
263269
* @param filename The filename of the file
264270
* @returns Source code blocks to lint.
@@ -278,10 +284,10 @@ function preprocess(sourceText: string, filename: string) {
278284

279285
/**
280286
* During the depth-first traversal, keep track of any sequences of HTML/MDX
281-
* comment nodes containing `eslint-*` or `global` comments. If a code
282-
* block immediately follows such a sequence, insert the comments at the
283-
* top of the code block. Any non-ESLint comment or other node type breaks
284-
* and empties the sequence.
287+
* comment nodes containing `eslint-*` or `global` comments. If a code block
288+
* immediately follows such a sequence, insert the comments at the top of the
289+
* code block. Any non-ESLint comment or other node type breaks and empties
290+
* the sequence.
285291
*/
286292
let allComments: string[] = []
287293

@@ -301,6 +307,7 @@ function preprocess(sourceText: string, filename: string) {
301307

302308
/**
303309
* Visit a code node.
310+
*
304311
* @param node The visited node.
305312
*/
306313
code(node) {
@@ -331,6 +338,7 @@ function preprocess(sourceText: string, filename: string) {
331338

332339
/**
333340
* Visit an HTML node.
341+
*
334342
* @param node The visited node.
335343
*/
336344
html(node) {
@@ -357,6 +365,7 @@ function preprocess(sourceText: string, filename: string) {
357365

358366
/**
359367
* Adjusts a fix in a code block.
368+
*
360369
* @param block A code block.
361370
* @param fix A fix to adjust.
362371
* @returns The fix with adjusted ranges.
@@ -382,6 +391,7 @@ function adjustFix(block: CodeBlock, fix: Rule.Fix): Rule.Fix {
382391

383392
/**
384393
* Creates a map function that adjusts messages in a code block.
394+
*
385395
* @param block A code block.
386396
* @returns A function that adjusts messages in a code block.
387397
*/
@@ -395,6 +405,7 @@ function adjustBlock(block: CodeBlock) {
395405

396406
/**
397407
* Adjusts ESLint messages to point to the correct location in the Markdown.
408+
*
398409
* @param message A message from ESLint.
399410
* @returns The same message, but adjusted to the correct location.
400411
*/
@@ -447,6 +458,7 @@ function adjustBlock(block: CodeBlock) {
447458

448459
/**
449460
* Excludes unsatisfiable rules from the list of messages.
461+
*
450462
* @param message A message from the linter.
451463
* @returns True if the message should be included in output.
452464
*/
@@ -456,8 +468,9 @@ function excludeUnsatisfiableRules(message: Linter.LintMessage) {
456468

457469
/**
458470
* Transforms generated messages for output.
459-
* @param messages An array containing one array of messages
460-
* for each code block returned from `preprocess`.
471+
*
472+
* @param messages An array containing one array of messages for each code block
473+
* returned from `preprocess`.
461474
* @param filename The filename of the file
462475
* @returns A flattened array of messages with mapped locations.
463476
*/

packages/eslint-plugin-mdx/src/processors/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* based on @link https://github.com/sveltejs/eslint-plugin-svelte3/blob/master/src/processor_options.js
2+
* Based on @link
3+
* https://github.com/sveltejs/eslint-plugin-svelte3/blob/master/src/processor_options.js
34
*/
45

56
import type * as ESLint from 'eslint'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy