Skip to content

Commit 7acd080

Browse files
authored
Upgrade to Deno to 2.1.12 and include override keyword for Deno type checker (#4)
1 parent e1eb9b6 commit 7acd080

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+213
-222
lines changed

.eslintrc.js

-9
This file was deleted.

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ jobs:
2525

2626
- name: Setup Deno
2727
# uses: denoland/setup-deno@v1
28-
uses: denoland/setup-deno@004814556e37c54a2f6e31384c9e18e983317366
28+
uses: denoland/setup-deno@v2
2929
with:
30-
deno-version: v1.x
30+
deno-version: "2.1.12"
3131

3232
# Uncomment this step to verify the use of 'deno fmt' on each commit.
3333
# - name: Verify formatting
3434
# run: deno fmt --check
3535

3636
- name: Run linter
37-
run: npm install && deno task lint
37+
run: deno task lint
3838

3939
- name: Run tests
4040
run: deno task test

deno.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
2-
"$schema": "https://deno.land/x/deno@v1.22.1/cli/schemas/config-file.v1.json",
2+
"version": "2.1.12",
33
"compilerOptions": {
4-
"lib": ["deno.ns"]
4+
"strict": true,
5+
"lib": ["deno.ns", "dom", "dom.iterable"],
6+
"useUnknownInCatchVariables": true,
7+
"noImplicitAny": true
58
},
69
"tasks": {
710
"dnt": "deno run -A dnt.ts $(git describe --tags)",
811
"test": "deno test -A src",
912
"test:coverage": "TMP=$(mktemp -d) && deno task test --coverage=$TMP && deno coverage --exclude='utils/xml-validation/fontoxml' $TMP --lcov > $TMP/lcov.lcov && genhtml -o coverage $TMP/lcov.lcov",
10-
"lint": "deno lint src && npm run lint",
13+
"lint": "deno lint src",
1114
"precommit": "deno task lint && deno task test"
1215
}
1316
}

eslint.config.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from "eslint/config";
2+
3+
export default defineConfig([{
4+
rules: {
5+
"@typescript-eslint/no-explicit-any": "off",
6+
"@typescript-eslint/no-unused-vars": "off",
7+
},
8+
}]);

package.json

-11
This file was deleted.

src/classes/XmlFile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export class UnhandledXmlFile extends XmlFile {
8282
this.#xml = xml;
8383
}
8484

85-
protected toNode(): Document {
85+
protected override toNode(): Document {
8686
return parse(this.#xml);
8787
}
8888

89-
public static async fromArchive(archive: Archive, location: string) {
89+
public static override async fromArchive(archive: Archive, location: string) {
9090
return new UnhandledXmlFile(location, await archive.readText(location));
9191
}
9292
}

src/components/BookmarkRangeEnd.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export type BookmarkRangeEndProps =
2222
* The end of a range associated with a comment.
2323
*/
2424
export class BookmarkRangeEnd extends Component<BookmarkRangeEndProps, BookmarkRangeEndChild> {
25-
public static readonly children: string[] = [];
25+
public static override readonly children: string[] = [];
2626

27-
public static readonly mixed: boolean = false;
27+
public static override readonly mixed: boolean = false;
2828

2929
/**
3030
* Creates an XML DOM node for this component instance.
3131
*/
3232
// eslint-disable-next-line @typescript-eslint/no-unused-vars
33-
public toNode(_ancestry: ComponentAncestor[]): Node {
33+
public override toNode(_ancestry: ComponentAncestor[]): Node {
3434
return create(
3535
`element ${QNS.w}bookmarkEnd {
3636
attribute ${QNS.w}id { $id }
@@ -44,14 +44,14 @@ export class BookmarkRangeEnd extends Component<BookmarkRangeEndProps, BookmarkR
4444
/**
4545
* Asserts whether or not a given XML node correlates with this component.
4646
*/
47-
static matchesNode(node: Node): boolean {
47+
static override matchesNode(node: Node): boolean {
4848
return node.nodeName === 'w:bookmarkEnd';
4949
}
5050

5151
/**
5252
* Instantiate this component from the XML in an existing DOCX file.
5353
*/
54-
static fromNode(node: Node): BookmarkRangeEnd {
54+
static override fromNode(node: Node): BookmarkRangeEnd {
5555
return new BookmarkRangeEnd(
5656
evaluateXPathToMap<BookmarkRangeEndProps>(
5757
`map {

src/components/BookmarkRangeStart.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ export class BookmarkRangeStart extends Component<
3333
BookmarkRangeStartProps,
3434
BookmarkRangeStartChild
3535
> {
36-
public static readonly children: string[] = [];
36+
public static override readonly children: string[] = [];
3737

38-
public static readonly mixed: boolean = false;
38+
public static override readonly mixed: boolean = false;
3939

4040
/**
4141
* Creates an XML DOM node for this component instance.
4242
*/
4343
// eslint-disable-next-line @typescript-eslint/no-unused-vars
44-
public toNode(_ancestry: ComponentAncestor[]): Node {
44+
public override toNode(_ancestry: ComponentAncestor[]): Node {
4545
return create(
4646
`element ${QNS.w}bookmarkStart {
4747
attribute ${QNS.w}id { $id },
@@ -57,14 +57,14 @@ export class BookmarkRangeStart extends Component<
5757
/**
5858
* Asserts whether or not a given XML node correlates with this component.
5959
*/
60-
static matchesNode(node: Node): boolean {
60+
static override matchesNode(node: Node): boolean {
6161
return node.nodeName === 'w:bookmarkStart';
6262
}
6363

6464
/**
6565
* Instantiate this component from the XML in an existing DOCX file.
6666
*/
67-
static fromNode(node: Node): BookmarkRangeStart {
67+
static override fromNode(node: Node): BookmarkRangeStart {
6868
return new BookmarkRangeStart(
6969
evaluateXPathToMap<BookmarkRangeStartProps>(
7070
`map {

src/components/Break.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export type BreakProps = {
3030
* this in one of the `<Text>`, `<TextAddition>` or `<TextDeletion>` components.
3131
*/
3232
export class Break extends Component<BreakProps, BreakChild> {
33-
public static readonly children: string[] = [];
33+
public static override readonly children: string[] = [];
3434

35-
public static readonly mixed: boolean = false;
35+
public static override readonly mixed: boolean = false;
3636

3737
/**
3838
* Creates an XML DOM node for this component instance.
3939
*/
4040
// eslint-disable-next-line @typescript-eslint/no-unused-vars
41-
public toNode(_ancestry: ComponentAncestor[]): Node {
41+
public override toNode(_ancestry: ComponentAncestor[]): Node {
4242
return create(
4343
`
4444
element ${QNS.w}br {
@@ -56,14 +56,14 @@ export class Break extends Component<BreakProps, BreakChild> {
5656
/**
5757
* Asserts whether or not a given XML node correlates with this component.
5858
*/
59-
static matchesNode(node: Node): boolean {
59+
static override matchesNode(node: Node): boolean {
6060
return node.nodeName === 'w:br';
6161
}
6262

6363
/**
6464
* Instantiate this component from the XML in an existing DOCX file.
6565
*/
66-
static fromNode(node: Node): Break {
66+
static override fromNode(node: Node): Break {
6767
return new Break(
6868
evaluateXPathToMap<BreakProps>(
6969
`map {

src/components/Cell.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export type CellProps = Omit<TableCellProperties, 'width'>;
3131
* quietly fix that for you if you don't have a paragraph there already.
3232
*/
3333
export class Cell extends Component<CellProps, CellChild> {
34-
public static readonly children: string[] = [
34+
public static override readonly children: string[] = [
3535
'Paragraph',
3636
'Table',
3737
'BookmarkRangeStart',
3838
'BookmarkRangeEnd',
3939
];
40-
public static readonly mixed: boolean = false;
40+
public static override readonly mixed: boolean = false;
4141

4242
public constructor(cellProps: CellProps, ...cellChild: CellChild[]) {
4343
// Ensure that properties of type `number` are not `NaN`.
@@ -48,7 +48,7 @@ export class Cell extends Component<CellProps, CellChild> {
4848
/**
4949
* Creates an XML DOM node for this component instance.
5050
*/
51-
public async toNode(ancestry: ComponentAncestor[]): Promise<Node> {
51+
public override async toNode(ancestry: ComponentAncestor[]): Promise<Node> {
5252
const table = ancestry.find((ancestor): ancestor is Table => ancestor instanceof Table);
5353
if (!table) {
5454
throw new Error('A cell cannot be rendered outside the context of a table');
@@ -147,14 +147,14 @@ export class Cell extends Component<CellProps, CellChild> {
147147
/**
148148
* Asserts whether or not a given XML node correlates with this component.
149149
*/
150-
static matchesNode(node: Node): boolean {
150+
static override matchesNode(node: Node): boolean {
151151
return node.nodeName === 'w:tc';
152152
}
153153

154154
/**
155155
* Instantiate this component from the XML in an existing DOCX file.
156156
*/
157-
static fromNode(node: Node, context: ComponentContext): null | Cell {
157+
static override fromNode(node: Node, context: ComponentContext): null | Cell {
158158
const { mergedAway, children, ...props } = evaluateXPathToMap<
159159
CellProps & { mergedAway: boolean; children: Node[] }
160160
>(

src/components/Comment.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export type CommentProps = {
2121
* The start of a range associated with a comment.
2222
*/
2323
export class Comment extends Component<CommentProps, CommentChild> {
24-
public static readonly children: string[] = [];
24+
public static override readonly children: string[] = [];
2525

26-
public static readonly mixed: boolean = false;
26+
public static override readonly mixed: boolean = false;
2727

2828
/**
2929
* Creates an XML DOM node for this component instance.
3030
*/
31-
public toNode(ancestry: ComponentAncestor[]): Node {
31+
public override toNode(ancestry: ComponentAncestor[]): Node {
3232
const doc = ancestry.find(
3333
(ancestor): ancestor is DocumentXml => ancestor instanceof DocumentXml,
3434
);
@@ -57,14 +57,14 @@ export class Comment extends Component<CommentProps, CommentChild> {
5757
/**
5858
* Asserts whether or not a given XML node correlates with this component.
5959
*/
60-
static matchesNode(node: Node): boolean {
60+
static override matchesNode(node: Node): boolean {
6161
return node.nodeName === 'w:commentRangeStart';
6262
}
6363

6464
/**
6565
* Instantiate this component from the XML in an existing DOCX file.
6666
*/
67-
static fromNode(node: Node): Comment {
67+
static override fromNode(node: Node): Comment {
6868
return new Comment(
6969
evaluateXPathToMap<CommentProps>(
7070
`

src/components/CommentRangeEnd.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export type CommentRangeEndProps = {
2020
* The end of a range associated with a comment.
2121
*/
2222
export class CommentRangeEnd extends Component<CommentRangeEndProps, CommentRangeEndChild> {
23-
public static readonly children: string[] = [];
23+
public static override readonly children: string[] = [];
2424

25-
public static readonly mixed: boolean = false;
25+
public static override readonly mixed: boolean = false;
2626

2727
/**
2828
* Creates an XML DOM node for this component instance.
2929
*/
3030
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31-
public toNode(_ancestry: ComponentAncestor[]): Node {
31+
public override toNode(_ancestry: ComponentAncestor[]): Node {
3232
return create(
3333
`
3434
element ${QNS.w}commentRangeEnd {
@@ -44,14 +44,14 @@ export class CommentRangeEnd extends Component<CommentRangeEndProps, CommentRang
4444
/**
4545
* Asserts whether or not a given XML node correlates with this component.
4646
*/
47-
static matchesNode(node: Node): boolean {
47+
static override matchesNode(node: Node): boolean {
4848
return node.nodeName === 'w:commentRangeEnd';
4949
}
5050

5151
/**
5252
* Instantiate this component from the XML in an existing DOCX file.
5353
*/
54-
static fromNode(node: Node): CommentRangeEnd {
54+
static override fromNode(node: Node): CommentRangeEnd {
5555
return new CommentRangeEnd(
5656
evaluateXPathToMap<CommentRangeEndProps>(
5757
`

src/components/CommentRangeStart.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export type CommentRangeStartProps = {
2020
* The start of a range associated with a comment.
2121
*/
2222
export class CommentRangeStart extends Component<CommentRangeStartProps, CommentRangeStartChild> {
23-
public static readonly children: string[] = [];
23+
public static override readonly children: string[] = [];
2424

25-
public static readonly mixed: boolean = false;
25+
public static override readonly mixed: boolean = false;
2626

2727
/**
2828
* Creates an XML DOM node for this component instance.
2929
*/
3030
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31-
public toNode(_ancestry: ComponentAncestor[]): Node {
31+
public override toNode(_ancestry: ComponentAncestor[]): Node {
3232
return create(
3333
`
3434
element ${QNS.w}commentRangeStart {
@@ -44,14 +44,14 @@ export class CommentRangeStart extends Component<CommentRangeStartProps, Comment
4444
/**
4545
* Asserts whether or not a given XML node correlates with this component.
4646
*/
47-
static matchesNode(node: Node): boolean {
47+
static override matchesNode(node: Node): boolean {
4848
return node.nodeName === 'w:commentRangeStart';
4949
}
5050

5151
/**
5252
* Instantiate this component from the XML in an existing DOCX file.
5353
*/
54-
static fromNode(node: Node): CommentRangeStart {
54+
static override fromNode(node: Node): CommentRangeStart {
5555
return new CommentRangeStart(
5656
evaluateXPathToMap<CommentRangeStartProps>(
5757
`

src/components/Field.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export type FieldProps = {
5454
* A component that represents a (simple) instruction field.
5555
*/
5656
export class Field extends Component<FieldProps, FieldChild> {
57-
public static readonly children: string[] = [
57+
public static override readonly children: string[] = [
5858
'BookmarkRangeStart',
5959
'BookmarkRangeEnd',
6060
'CommentRangeStart',
@@ -65,13 +65,13 @@ export class Field extends Component<FieldProps, FieldChild> {
6565
'Hyperlink',
6666
];
6767

68-
public static readonly mixed: boolean = false;
68+
public static override readonly mixed: boolean = false;
6969

7070
/**
7171
* Creates an XML DOM node for this component instance.
7272
*/
7373
// eslint-disable-next-line @typescript-eslint/no-unused-vars
74-
public async toNode(ancestry: ComponentAncestor[]): Promise<Node> {
74+
public override async toNode(ancestry: ComponentAncestor[]): Promise<Node> {
7575
return create(
7676
`
7777
element ${QNS.w}fldSimple {
@@ -93,14 +93,14 @@ export class Field extends Component<FieldProps, FieldChild> {
9393
/**
9494
* Asserts whether or not a given XML node correlates with this component.
9595
*/
96-
static matchesNode(node: Node): boolean {
96+
static override matchesNode(node: Node): boolean {
9797
return node.nodeName === 'w:fldSimple';
9898
}
9999

100100
/**
101101
* Instantiate this component from the XML in an existing DOCX file.
102102
*/
103-
static fromNode(node: Node, context: ComponentContext): Field {
103+
static override fromNode(node: Node, context: ComponentContext): Field {
104104
const { children, ...props } = evaluateXPathToMap<FieldProps & { children: Node[] }>(
105105
`map {
106106
"instruction": ./@${QNS.w}instruction/string(),

0 commit comments

Comments
 (0)