Skip to content

Commit 30d5132

Browse files
committed
Refactor to remove some ts-expect-errors
1 parent 79f0306 commit 30d5132

File tree

11 files changed

+67
-27
lines changed

11 files changed

+67
-27
lines changed

packages/retext-dutch/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import type {Plugin} from 'unified'
44
// See `parse-latin`.
55
type Extension<Node extends Nodes> = (node: Node) => undefined | void
66

7+
// Note: we have to use manual types here,
8+
// instead of getting them from `lib/index.js`,
9+
// because TS generates wrong types for functions that use `this`.
10+
// TS makes them into classes which is incorrect.
711
/**
812
* Add support for parsing Dutch natural language.
913
*

packages/retext-dutch/lib/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
/**
22
* @import {Root} from 'nlcst'
3-
* @import {Parser, Processor} from 'unified'
3+
* @import {Processor} from 'unified'
44
*/
55

66
import {ParseDutch} from 'parse-dutch'
77

88
/**
99
* Add support for parsing Dutch natural language.
1010
*
11+
* @this {Processor<Root>}
12+
* Processor.
1113
* @returns {undefined}
1214
* Nothing.
1315
*/
1416
export default function retextDutch() {
15-
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
16-
// eslint-disable-next-line unicorn/no-this-assignment
17-
const self = /** @type {Processor<Root>} */ (this)
17+
const self = this
1818

1919
self.parser = parser
2020

21-
/** @type {Parser<Root>} */
21+
/**
22+
* @param {string} value
23+
* Document.
24+
* @returns {Root}
25+
* Tree.
26+
*/
2227
function parser(value) {
2328
const parser = new ParseDutch()
2429
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))

packages/retext-dutch/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
}
6262
}
6363
],
64-
"prettier": true
64+
"prettier": true,
65+
"rules": {
66+
"unicorn/no-this-assignment": "off"
67+
}
6568
}
6669
}

packages/retext-english/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import type {Plugin} from 'unified'
44
// See `parse-latin`.
55
type Extension<Node extends Nodes> = (node: Node) => undefined | void
66

7+
// Note: we have to use manual types here,
8+
// instead of getting them from `lib/index.js`,
9+
// because TS generates wrong types for functions that use `this`.
10+
// TS makes them into classes which is incorrect.
711
/**
812
* Add support for parsing English natural language.
913
*

packages/retext-english/lib/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
/**
22
* @import {Root} from 'nlcst'
3-
* @import {Parser, Processor} from 'unified'
3+
* @import {Processor} from 'unified'
44
*/
55

66
import {ParseEnglish} from 'parse-english'
77

88
/**
99
* Add support for parsing English natural language.
1010
*
11+
* @this {Processor<Root>}
12+
* Processor.
1113
* @returns {undefined}
1214
* Nothing.
1315
*/
1416
export default function retextEnglish() {
15-
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
16-
// eslint-disable-next-line unicorn/no-this-assignment
17-
const self = /** @type {Processor<Root>} */ (this)
17+
const self = this
1818

1919
self.parser = parser
2020

21-
/** @type {Parser<Root>} */
21+
/**
22+
* @param {string} value
23+
* Document.
24+
* @returns {Root}
25+
* Tree.
26+
*/
2227
function parser(value) {
2328
const parser = new ParseEnglish()
2429
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))

packages/retext-english/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
}
6262
}
6363
],
64-
"prettier": true
64+
"prettier": true,
65+
"rules": {
66+
"unicorn/no-this-assignment": "off"
67+
}
6568
}
6669
}

packages/retext-latin/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import type {Plugin} from 'unified'
44
// See `parse-latin`.
55
type Extension<Node extends Nodes> = (node: Node) => undefined | void
66

7+
// Note: we have to use manual types here,
8+
// instead of getting them from `lib/index.js`,
9+
// because TS generates wrong types for functions that use `this`.
10+
// TS makes them into classes which is incorrect.
711
/**
812
* Add support for parsing Latin-script natural language.
913
*

packages/retext-latin/lib/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ import {ParseLatin} from 'parse-latin'
88
/**
99
* Add support for parsing Latin-script natural language.
1010
*
11+
* @this {Processor<Root>}
12+
* Processor.
1113
* @returns {undefined}
1214
* Nothing.
1315
*/
1416
export default function retextLatin() {
15-
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
16-
// eslint-disable-next-line unicorn/no-this-assignment
17-
const self = /** @type {Processor<Root>} */ (this)
17+
const self = this
1818

1919
self.parser = parser
2020

21-
/** @type {Parser<Root>} */
21+
/**
22+
* @param {string} value
23+
* Document.
24+
* @returns {Root}
25+
* Tree.
26+
*/
2227
function parser(value) {
2328
const parser = new ParseLatin()
2429
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))

packages/retext-latin/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
}
6262
}
6363
],
64-
"prettier": true
64+
"prettier": true,
65+
"rules": {
66+
"unicorn/no-this-assignment": "off"
67+
}
6568
}
6669
}

packages/retext-stringify/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type {Root} from 'nlcst'
22
import type {Plugin} from 'unified'
33

4+
// Note: we have to use manual types here,
5+
// instead of getting them from `lib/index.js`,
6+
// because TS generates wrong types for functions that use `this`.
7+
// TS makes them into classes which is incorrect.
48
/**
59
* Add support for serializing natural language.
610
*

0 commit comments

Comments
 (0)