Fix ESLinting errors and remove TSLint

This commit is contained in:
Dolan Miu
2022-08-31 08:59:27 +01:00
parent 1bdf9a4987
commit ebcb37cbed
30 changed files with 104 additions and 201 deletions

View File

@ -7,9 +7,7 @@ describe("DocumentWrapper", () => {
it("should create", () => {
const file = new DocumentWrapper({ background: {} });
// tslint:disable-next-line: no-unused-expression
expect(file.View).to.be.ok;
// tslint:disable-next-line: no-unused-expression
expect(file.Relationships).to.be.ok;
});
});

View File

@ -6,7 +6,7 @@ import { IDrawingOptions } from "../drawing";
import { TextWrappingType } from "../text-wrap";
import { Anchor } from "./anchor";
function createAnchor(drawingOptions: IDrawingOptions): Anchor {
const createAnchor = (drawingOptions: IDrawingOptions): Anchor => {
return new Anchor(
{
fileName: "test.png",
@ -34,7 +34,7 @@ function createAnchor(drawingOptions: IDrawingOptions): Anchor {
},
drawingOptions,
);
}
};
describe("Anchor", () => {
let anchor: Anchor;

View File

@ -6,7 +6,7 @@ import { Drawing, IDrawingOptions } from "./drawing";
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx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pC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
function createDrawing(drawingOptions?: IDrawingOptions): Drawing {
const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => {
return new Drawing(
{
fileName: "test.jpg",
@ -24,7 +24,7 @@ function createDrawing(drawingOptions?: IDrawingOptions): Drawing {
},
drawingOptions,
);
}
};
describe("Drawing", () => {
let currentBreak: Drawing;

View File

@ -1,8 +1,9 @@
// http://officeopenxml.com/drwPicFloating-textWrap.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { ITextWrapping, TextWrappingSide } from ".";
import { IDistance } from "../drawing";
import { IMargins } from "../floating";
import { ITextWrapping, TextWrappingSide } from "./text-wrapping";
interface IWrapSquareAttributes extends IDistance {
readonly wrapText?: TextWrappingSide;

View File

@ -397,7 +397,6 @@ describe("File", () => {
sections: [],
});
// tslint:disable-next-line: no-unused-expression
expect(doc.Comments).to.not.be.undefined;
});
});
@ -409,7 +408,6 @@ describe("File", () => {
sections: [],
});
// tslint:disable-next-line: no-unused-expression
expect(doc.Numbering).to.not.be.undefined;
});
});

View File

@ -63,13 +63,7 @@ export class File {
lastModifiedBy: options.lastModifiedBy ?? "Un-named",
});
this.numbering = new Numbering(
options.numbering
? options.numbering
: {
config: [],
},
);
this.numbering = new Numbering(options.numbering ? options.numbering : { config: [] });
this.comments = new Comments(options.comments ?? { children: [] });
this.fileRelationships = new Relationships();

View File

@ -7,9 +7,7 @@ describe("FootnotesWrapper", () => {
it("should create", () => {
const file = new FootnotesWrapper();
// tslint:disable-next-line: no-unused-expression
expect(file.View).to.be.ok;
// tslint:disable-next-line: no-unused-expression
expect(file.Relationships).to.be.ok;
});
});

View File

@ -68,7 +68,9 @@ export class Media {
.map((c) => c.charCodeAt(0)),
);
} else {
/* eslint @typescript-eslint/no-require-imports: 0 */
const b = require("buf" + "fer");
/* eslint @typescript-eslint/no-require-imports: 2 */
return new b.Buffer(dataURI, "base64");
}
}

View File

@ -1,9 +1,8 @@
import { expect } from "chai";
import { LevelFormat, LevelSuffix } from ".";
import { AlignmentType } from "..";
import { Level } from "./level";
import { Level, LevelFormat, LevelSuffix } from "./level";
describe("Level", () => {
describe("#constructor", () => {

View File

@ -180,9 +180,6 @@ export class LevelBase extends XmlComponent {
export class Level extends LevelBase {
// This is the level that sits under abstractNum. We make a
// handful of properties required
public constructor(options: ILevelsOptions) {
super(options);
}
}
export class LevelForOverride extends LevelBase {}

View File

@ -19,12 +19,8 @@ import { TextRun } from "./run";
describe("Paragraph", () => {
before(() => {
stub(convenienceFunctions, "uniqueId").callsFake(() => {
return "test-unique-id";
});
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => {
return -101;
});
stub(convenienceFunctions, "uniqueId").callsFake(() => "test-unique-id");
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => -101);
});
after(() => {

View File

@ -10,9 +10,7 @@ import { ImageRun } from "./image-run";
describe("ImageRun", () => {
before(() => {
stub(convenienceFunctions, "uniqueId").callsFake(() => {
return "test-unique-id";
});
stub(convenienceFunctions, "uniqueId").callsFake(() => "test-unique-id");
});
after(() => {

View File

@ -2,13 +2,11 @@ import { expect } from "chai";
import { Formatter } from "@export/formatter";
import { BorderStyle } from "@file/border";
// import { FootnoteReferenceRun } from "@file/footnotes/footnote/run/reference-run";
import { ShadingType } from "@file/shading";
import { SpaceType } from "@file/space-type";
import { Run } from "./";
import { EmphasisMarkType } from "./emphasis-mark";
import { PageNumber } from "./run";
import { PageNumber, Run } from "./run";
import { UnderlineType } from "./underline";
describe("Run", () => {

View File

@ -1,11 +1,9 @@
import { expect } from "chai";
import { EmphasisMarkType } from "./emphasis-mark";
import { Formatter } from "@export/formatter";
import { EmphasisMarkType } from "./emphasis-mark";
import { UnderlineType } from "./underline";
import { SymbolRun } from "./symbol-run";
describe("SymbolRun", () => {

View File

@ -1,9 +1,9 @@
import { expect } from "chai";
import { DocumentDefaults } from "./document-defaults";
import { Formatter } from "@export/formatter";
import { DocumentDefaults } from "./document-defaults";
describe("DocumentDefaults", () => {
it("#constructor", () => {
const defaults = new DocumentDefaults({

View File

@ -1,5 +1,4 @@
/* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
const createLsdException = (name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) => {
"use strict";
return [
@ -13,9 +12,9 @@ function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenU
},
},
];
}
};
export function DefaultStyle() {
export const DefaultStyle = () => {
var style = {
"w:styles": [
{
@ -208,4 +207,4 @@ export function DefaultStyle() {
};
return style;
}
};

View File

@ -1,10 +1,10 @@
import { expect } from "chai";
import { Formatter } from "@export/formatter";
import { EMPTY_OBJECT } from "@file/xml-components";
import * as defaultStyles from "./default-styles";
import { EMPTY_OBJECT } from "@file/xml-components";
describe("Default Styles", () => {
it("HeadingStyle#constructor", () => {

View File

@ -1,10 +1,10 @@
import { expect } from "chai";
import { EMPTY_OBJECT } from "@file/xml-components";
import { Formatter } from "@export/formatter";
import { GridCol, TableGrid } from "./grid";
import { EMPTY_OBJECT } from "@file/xml-components";
describe("GridCol", () => {
describe("#constructor", () => {

View File

@ -10,7 +10,7 @@ export interface ITableCellOptions extends ITableCellPropertiesOptions {
}
export class TableCell extends XmlComponent {
public constructor(readonly options: ITableCellOptions) {
public constructor(public readonly options: ITableCellOptions) {
super("w:tc");
this.root.push(new TableCellProperties(options));

View File

@ -1,9 +1,10 @@
import { expect } from "chai";
import { Element, xml2js } from "xml-js";
import { EMPTY_OBJECT, ImportedXmlComponent } from "./";
import { EMPTY_OBJECT } from "@file/xml-components";
import { convertToXmlComponent, ImportedXmlComponent } from "./imported-xml-component";
import { IContext } from "./base";
import { convertToXmlComponent } from "./imported-xml-component";
const xmlString = `
<w:p w:one="value 1" w:two="value 2">

View File

@ -1,6 +1,8 @@
// tslint:disable:no-any
import { Element as XmlElement, xml2js } from "xml-js";
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from ".";
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { IContext } from "./base";
/**
@ -8,7 +10,7 @@ import { IContext } from "./base";
* @param element the xml element in json presentation
*/
export function convertToXmlComponent(element: XmlElement): ImportedXmlComponent | string | undefined {
export const convertToXmlComponent = (element: XmlElement): ImportedXmlComponent | string | undefined => {
switch (element.type) {
case undefined:
case "element":
@ -26,7 +28,7 @@ export function convertToXmlComponent(element: XmlElement): ImportedXmlComponent
default:
return undefined;
}
}
};
class ImportedXmlComponentAttributes extends XmlAttributeComponent<any> {
// noop

View File

@ -5,7 +5,6 @@ import { Document } from "./index";
describe("Index", () => {
describe("Document", () => {
it("should instantiate the Document", () => {
// tslint:disable-next-line: no-unused-expression
expect(
new Document({
sections: [],

View File

@ -19,14 +19,12 @@ describe("Utility", () => {
describe("#uniqueNumericId", () => {
it("should generate a unique incrementing ID", () => {
// tslint:disable-next-line: no-unused-expression
expect(uniqueNumericId()).to.not.be.undefined;
});
});
describe("#uniqueId", () => {
it("should generate a unique pseudorandom ID", () => {
// tslint:disable-next-line: no-unused-expression
expect(uniqueId()).to.not.be.empty;
});
});

View File

@ -7,8 +7,6 @@ export const convertMillimetersToTwip = (millimeters: number): number => Math.fl
export const convertInchesToTwip = (inches: number): number => Math.floor(inches * 72 * 20);
export const uniqueNumericId = (): number => {
return ++currentCount;
};
export const uniqueNumericId = (): number => ++currentCount;
export const uniqueId = (): string => nanoid().toLowerCase();

View File

@ -7,63 +7,63 @@
// <xsd:simpleType name="ST_DecimalNumber">
// <xsd:restriction base="xsd:integer"/>
// </xsd:simpleType>
export function decimalNumber(val: number): number {
export const decimalNumber = (val: number): number => {
if (isNaN(val)) {
throw new Error(`Invalid value '${val}' specified. Must be an integer.`);
}
return Math.floor(val);
}
};
// <xsd:simpleType name="ST_UnsignedDecimalNumber">
// <xsd:restriction base="xsd:unsignedLong"/>
// </xsd:simpleType>
export function unsignedDecimalNumber(val: number): number {
export const unsignedDecimalNumber = (val: number): number => {
const value = decimalNumber(val);
if (value < 0) {
throw new Error(`Invalid value '${val}' specified. Must be a positive integer.`);
}
return value;
}
};
// The xsd:hexBinary type represents binary data as a sequence of binary octets.
// It uses hexadecimal encoding, where each binary octet is a two-character hexadecimal number.
// Lowercase and uppercase letters A through F are permitted. For example, 0FB8 and 0fb8 are two
// equal xsd:hexBinary representations consisting of two octets.
// http://www.datypic.com/sc/xsd/t-xsd_hexBinary.html
function hexBinary(val: string, length: number): string {
const hexBinary = (val: string, length: number): string => {
const expectedLength = length * 2;
if (val.length !== expectedLength || isNaN(Number("0x" + val))) {
throw new Error(`Invalid hex value '${val}'. Expected ${expectedLength} digit hex value`);
}
return val;
}
};
// <xsd:simpleType name="ST_LongHexNumber">
// <xsd:restriction base="xsd:hexBinary">
// <xsd:length value="4"/>
// </xsd:restriction>
// </xsd:simpleType>
export function longHexNumber(val: string): string {
export const longHexNumber = (val: string): string => {
return hexBinary(val, 4);
}
};
// <xsd:simpleType name="ST_ShortHexNumber">
// <xsd:restriction base="xsd:hexBinary">
// <xsd:length value="2"/>
// </xsd:restriction>
// </xsd:simpleType>
export function shortHexNumber(val: string): string {
export const shortHexNumber = (val: string): string => {
return hexBinary(val, 2);
}
};
// <xsd:simpleType name="ST_UcharHexNumber">
// <xsd:restriction base="xsd:hexBinary">
// <xsd:length value="1"/>
// </xsd:restriction>
// </xsd:simpleType>
export function uCharHexNumber(val: string): string {
export const uCharHexNumber = (val: string): string => {
return hexBinary(val, 1);
}
};
// <xsd:simpleType name="ST_LongHexNumber">
// <xsd:restriction base="xsd:hexBinary">
@ -76,7 +76,7 @@ export function uCharHexNumber(val: string): string {
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
// </xsd:restriction>
// </xsd:simpleType>
export function universalMeasureValue(val: string): string {
export const universalMeasureValue = (val: string): string => {
const unit = val.slice(-2);
if (!universalMeasureUnits.includes(unit)) {
throw new Error(`Invalid unit '${unit}' specified. Valid units are ${universalMeasureUnits.join(", ")}`);
@ -86,7 +86,7 @@ export function universalMeasureValue(val: string): string {
throw new Error(`Invalid value '${amount}' specified. Expected a valid number.`);
}
return `${Number(amount)}${unit}`;
}
};
const universalMeasureUnits = ["mm", "cm", "in", "pt", "pc", "pi"];
// <xsd:simpleType name="ST_PositiveUniversalMeasure">
@ -94,13 +94,13 @@ const universalMeasureUnits = ["mm", "cm", "in", "pt", "pc", "pi"];
// <xsd:pattern value="[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
// </xsd:restriction>
// </xsd:simpleType>
export function positiveUniversalMeasureValue(val: string): string {
export const positiveUniversalMeasureValue = (val: string): string => {
const value = universalMeasureValue(val);
if (parseFloat(value) < 0) {
throw new Error(`Invalid value '${value}' specified. Expected a positive number.`);
}
return value;
}
};
// <xsd:simpleType name="ST_HexColor">
// <xsd:union memberTypes="ST_HexColorAuto s:ST_HexColorRGB"/>
@ -116,7 +116,7 @@ export function positiveUniversalMeasureValue(val: string): string {
// <xsd:length value="3" fixed="true"/>
// </xsd:restriction>
// </xsd:simpleType>
export function hexColorValue(val: string): string {
export const hexColorValue = (val: string): string => {
if (val === "auto") {
return val;
}
@ -124,42 +124,42 @@ export function hexColorValue(val: string): string {
// Most clients work with it, but strip it off anyway for strict compliance.
const color = val.charAt(0) === "#" ? val.substring(1) : val;
return hexBinary(color, 3);
}
};
// <xsd:simpleType name="ST_SignedTwipsMeasure">
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
// </xsd:simpleType>
export function signedTwipsMeasureValue(val: string | number): string | number {
export const signedTwipsMeasureValue = (val: string | number): string | number => {
return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
}
};
// <xsd:simpleType name="ST_HpsMeasure">
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure"/>
// </xsd:simpleType>
export function hpsMeasureValue(val: string | number): string | number {
export const hpsMeasureValue = (val: string | number): string | number => {
return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
}
};
// <xsd:simpleType name="ST_SignedHpsMeasure">
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
// </xsd:simpleType>
export function signedHpsMeasureValue(val: string | number): string | number {
export const signedHpsMeasureValue = (val: string | number): string | number => {
return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
}
};
// <xsd:simpleType name="ST_TwipsMeasure">
// <xsd:union memberTypes="ST_UnsignedDecimalNumber ST_PositiveUniversalMeasure"/>
// </xsd:simpleType>
export function twipsMeasureValue(val: string | number): string | number {
export const twipsMeasureValue = (val: string | number): string | number => {
return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
}
};
// <xsd:simpleType name="ST_Percentage">
// <xsd:restriction base="xsd:string">
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/>
// </xsd:restriction>
// </xsd:simpleType>
export function percentageValue(val: string): string {
export const percentageValue = (val: string): string => {
if (val.slice(-1) !== "%") {
throw new Error(`Invalid value '${val}'. Expected percentage value (eg '55%')`);
}
@ -168,7 +168,7 @@ export function percentageValue(val: string): string {
throw new Error(`Invalid value '${percent}' specified. Expected a valid number.`);
}
return `${Number(percent)}%`;
}
};
// <xsd:simpleType name="ST_MeasurementOrPercent">
// <xsd:union memberTypes="ST_DecimalNumberOrPercent s:ST_UniversalMeasure"/>
@ -182,7 +182,7 @@ export function percentageValue(val: string): string {
// <xsd:restriction base="xsd:integer"/>
// </xsd:simpleType>
export function measurementOrPercentValue(val: number | string): number | string {
export const measurementOrPercentValue = (val: number | string): number | string => {
if (typeof val === "number") {
return decimalNumber(val);
}
@ -190,7 +190,7 @@ export function measurementOrPercentValue(val: number | string): number | string
return percentageValue(val);
}
return universalMeasureValue(val);
}
};
// <xsd:simpleType name="ST_EighthPointMeasure">
// <xsd:restriction base="s:ST_UnsignedDecimalNumber"/>
@ -222,6 +222,6 @@ export const pointMeasureValue = unsignedDecimalNumber;
//
// Luckily, js has this format built in already. See:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
export function dateTimeValue(val: Date): string {
export const dateTimeValue = (val: Date): string => {
return val.toISOString();
}
};