Use new eslint-plugin-functional instead of tslint-immutable

This commit is contained in:
Dolan Miu
2022-09-15 20:00:50 +01:00
parent d020d59b11
commit e90d97b813
70 changed files with 321 additions and 436 deletions

View File

@ -7,10 +7,10 @@ import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attri
export class Bookmark {
public readonly start: BookmarkStart;
public readonly children: ParagraphChild[];
public readonly children: readonly ParagraphChild[];
public readonly end: BookmarkEnd;
public constructor(options: { readonly id: string; readonly children: ParagraphChild[] }) {
public constructor(options: { readonly id: string; readonly children: readonly ParagraphChild[] }) {
const linkId = uniqueNumericId();
this.start = new BookmarkStart(options.id, linkId);

View File

@ -13,7 +13,7 @@ export enum HyperlinkType {
export class ConcreteHyperlink extends XmlComponent {
public readonly linkId: string;
public constructor(children: ParagraphChild[], relationshipId: string, anchor?: string) {
public constructor(children: readonly ParagraphChild[], relationshipId: string, anchor?: string) {
super("w:hyperlink");
this.linkId = relationshipId;
@ -33,13 +33,13 @@ export class ConcreteHyperlink extends XmlComponent {
}
export class InternalHyperlink extends ConcreteHyperlink {
public constructor(options: { readonly children: ParagraphChild[]; readonly anchor: string }) {
public constructor(options: { readonly children: readonly ParagraphChild[]; readonly anchor: string }) {
super(options.children, uniqueId(), options.anchor);
}
}
export class ExternalHyperlink extends XmlComponent {
public constructor(public readonly options: { readonly children: ParagraphChild[]; readonly link: string }) {
public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) {
super("w:externalHyperlink");
}
}

View File

@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathAngledBrackets extends XmlComponent {
public constructor(options: { readonly children: MathComponent[] }) {
public constructor(options: { readonly children: readonly MathComponent[] }) {
super("m:d");
this.root.push(

View File

@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathCurlyBrackets extends XmlComponent {
public constructor(options: { readonly children: MathComponent[] }) {
public constructor(options: { readonly children: readonly MathComponent[] }) {
super("m:d");
this.root.push(

View File

@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathRoundBrackets extends XmlComponent {
public constructor(options: { readonly children: MathComponent[] }) {
public constructor(options: { readonly children: readonly MathComponent[] }) {
super("m:d");
this.root.push(new MathBracketProperties());

View File

@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
import { MathBracketProperties } from "./math-bracket-properties";
export class MathSquareBrackets extends XmlComponent {
public constructor(options: { readonly children: MathComponent[] }) {
public constructor(options: { readonly children: readonly MathComponent[] }) {
super("m:d");
this.root.push(

View File

@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathDenominator extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:den");
for (const child of children) {

View File

@ -5,8 +5,8 @@ import { MathDenominator } from "./math-denominator";
import { MathNumerator } from "./math-numerator";
export interface IMathFractionOptions {
readonly numerator: MathComponent[];
readonly denominator: MathComponent[];
readonly numerator: readonly MathComponent[];
readonly denominator: readonly MathComponent[];
}
export class MathFraction extends XmlComponent {

View File

@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathNumerator extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:num");
for (const child of children) {

View File

@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathFunctionName extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:fName");
for (const child of children) {

View File

@ -7,8 +7,8 @@ import { MathFunctionName } from "./math-function-name";
import { MathFunctionProperties } from "./math-function-properties";
export interface IMathFunctionOptions {
readonly children: MathComponent[];
readonly name: MathComponent[];
readonly children: readonly MathComponent[];
readonly name: readonly MathComponent[];
}
export class MathFunction extends XmlComponent {

View File

@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "./math-component";
export interface IMathOptions {
readonly children: MathComponent[];
readonly children: readonly MathComponent[];
}
export class Math extends XmlComponent {

View File

@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathBase extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:e");
for (const child of children) {

View File

@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathSubScriptElement extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:sub");
for (const child of children) {

View File

@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script";
import { MathSuperScriptElement } from "./math-super-script";
export interface IMathSumOptions {
readonly children: MathComponent[];
readonly subScript?: MathComponent[];
readonly superScript?: MathComponent[];
readonly children: readonly MathComponent[];
readonly subScript?: readonly MathComponent[];
readonly superScript?: readonly MathComponent[];
}
export class MathSum extends XmlComponent {

View File

@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathSuperScriptElement extends XmlComponent {
public constructor(children: MathComponent[]) {
public constructor(children: readonly MathComponent[]) {
super("m:sup");
for (const child of children) {

View File

@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
import { MathComponent } from "../math-component";
export class MathDegree extends XmlComponent {
public constructor(children?: MathComponent[]) {
public constructor(children?: readonly MathComponent[]) {
super("m:deg");
if (!!children) {

View File

@ -7,8 +7,8 @@ import { MathDegree } from "./math-degree";
import { MathRadicalProperties } from "./math-radical-properties";
export interface IMathRadicalOptions {
readonly children: MathComponent[];
readonly degree?: MathComponent[];
readonly children: readonly MathComponent[];
readonly degree?: readonly MathComponent[];
}
export class MathRadical extends XmlComponent {

View File

@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
export interface IMathPreSubSuperScriptOptions {
readonly children: MathComponent[];
readonly subScript: MathComponent[];
readonly superScript: MathComponent[];
readonly children: readonly MathComponent[];
readonly subScript: readonly MathComponent[];
readonly superScript: readonly MathComponent[];
}
export class MathPreSubSuperScript extends XmlComponent {

View File

@ -6,8 +6,8 @@ import { MathBase, MathSubScriptElement } from "../../n-ary";
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
export interface IMathSubScriptOptions {
readonly children: MathComponent[];
readonly subScript: MathComponent[];
readonly children: readonly MathComponent[];
readonly subScript: readonly MathComponent[];
}
export class MathSubScript extends XmlComponent {

View File

@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
export interface IMathSubSuperScriptOptions {
readonly children: MathComponent[];
readonly subScript: MathComponent[];
readonly superScript: MathComponent[];
readonly children: readonly MathComponent[];
readonly subScript: readonly MathComponent[];
readonly superScript: readonly MathComponent[];
}
export class MathSubSuperScript extends XmlComponent {

View File

@ -6,8 +6,8 @@ import { MathBase, MathSuperScriptElement } from "../../n-ary";
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
export interface IMathSuperScriptOptions {
readonly children: MathComponent[];
readonly superScript: MathComponent[];
readonly children: readonly MathComponent[];
readonly superScript: readonly MathComponent[];
}
export class MathSuperScript extends XmlComponent {

View File

@ -36,7 +36,7 @@ export type ParagraphChild =
export interface IParagraphOptions extends IParagraphPropertiesOptions {
readonly text?: string;
readonly children?: ParagraphChild[];
readonly children?: readonly ParagraphChild[];
}
export class Paragraph extends XmlComponent {

View File

@ -26,9 +26,7 @@ describe("ParagraphProperties", () => {
// tslint:disable-next-line: no-object-literal-type-assertion
file: {
Numbering: {
createConcreteNumberingInstance: (_: string, __: number) => {
return;
},
createConcreteNumberingInstance: (_: string, __: number) => undefined,
},
} as File,
// tslint:disable-next-line: no-object-literal-type-assertion

View File

@ -41,7 +41,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean;
readonly tabStops?: {
readonly tabStops?: readonly {
readonly position: number | TabStopPosition;
readonly type: TabStopType;
readonly leader?: LeaderType;
@ -57,6 +57,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
}
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
// eslint-disable-next-line functional/prefer-readonly-type
private readonly numberingReferences: { readonly reference: string; readonly instance: number }[] = [];
public constructor(options?: IParagraphPropertiesOptions) {

View File

@ -12,7 +12,7 @@ export interface ICommentOptions {
}
export interface ICommentsOptions {
readonly children: ICommentOptions[];
readonly children: readonly ICommentOptions[];
}
class CommentAttributes extends XmlAttributeComponent<{

View File

@ -40,7 +40,7 @@ describe("ImageRun", () => {
const tree = new Formatter().format(currentImageRun, {
file: {
Media: {
// tslint:disable-next-line: no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
addImage: () => {},
},
} as unknown as File,
@ -290,7 +290,7 @@ describe("ImageRun", () => {
const tree = new Formatter().format(currentImageRun, {
file: {
Media: {
// tslint:disable-next-line: no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
addImage: () => {},
},
} as unknown as File,
@ -519,6 +519,7 @@ describe("ImageRun", () => {
});
it("should return UInt8Array if atob is present", () => {
// eslint-disable-next-line functional/immutable-data
global.atob = () => "atob result";
const currentImageRun = new ImageRun({
@ -542,7 +543,7 @@ describe("ImageRun", () => {
const tree = new Formatter().format(currentImageRun, {
file: {
Media: {
// tslint:disable-next-line: no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
addImage: () => {},
},
} as unknown as File,
@ -775,6 +776,7 @@ describe("ImageRun", () => {
});
it("should use data as is if its not a string", () => {
// eslint-disable-next-line functional/immutable-data
global.atob = () => "atob result";
const currentImageRun = new ImageRun({
@ -798,7 +800,7 @@ describe("ImageRun", () => {
const tree = new Formatter().format(currentImageRun, {
file: {
Media: {
// tslint:disable-next-line: no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
addImage: () => {},
},
} as unknown as File,

View File

@ -62,6 +62,7 @@ export class ImageRun extends Run {
.map((c) => c.charCodeAt(0)),
);
} else {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const b = require("buf" + "fer");
return new b.Buffer(dataURI, "base64");
}

View File

@ -12,7 +12,7 @@ import { Text } from "./run-components/text";
import { TextAttributes } from "./text-attributes";
export interface IRunOptions extends IRunPropertiesOptions {
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
readonly children?: readonly (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
readonly break?: number;
readonly text?: string;
}