Fix linting and add new lint rules
This commit is contained in:
@ -33,6 +33,7 @@ export class CustomProperties extends XmlComponent {
|
||||
}
|
||||
|
||||
public addCustomProperty(property: ICustomPropertyOptions): void {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.properties.push(new CustomProperty(this.nextId++, property));
|
||||
}
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ export interface ISectionOptions {
|
||||
}
|
||||
|
||||
export class File {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private currentRelationshipId: number = 1;
|
||||
|
||||
private readonly documentWrapper: DocumentWrapper;
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly headers: IDocumentHeader[] = [];
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly footers: IDocumentFooter[] = [];
|
||||
private readonly coreProperties: CoreProperties;
|
||||
private readonly numbering: Numbering;
|
||||
@ -128,7 +128,7 @@ export class File {
|
||||
}
|
||||
|
||||
if (options.footnotes) {
|
||||
// tslint:disable-next-line: forin
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const key in options.footnotes) {
|
||||
this.footnotesWrapper.View.createFootNote(parseFloat(key), options.footnotes[key].children);
|
||||
}
|
||||
@ -156,6 +156,7 @@ export class File {
|
||||
}
|
||||
|
||||
private createHeader(header: Header): HeaderWrapper {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
const wrapper = new HeaderWrapper(this.media, this.currentRelationshipId++);
|
||||
|
||||
for (const child of header.options.children) {
|
||||
@ -167,6 +168,7 @@ export class File {
|
||||
}
|
||||
|
||||
private createFooter(footer: Footer): FooterWrapper {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
const wrapper = new FooterWrapper(this.media, this.currentRelationshipId++);
|
||||
|
||||
for (const child of footer.options.children) {
|
||||
@ -178,6 +180,7 @@ export class File {
|
||||
}
|
||||
|
||||
private addHeaderToDocument(header: HeaderWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.headers.push({ header, type });
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
header.View.ReferenceId,
|
||||
@ -188,6 +191,7 @@ export class File {
|
||||
}
|
||||
|
||||
private addFooterToDocument(footer: FooterWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.footers.push({ footer, type });
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
footer.View.ReferenceId,
|
||||
@ -220,26 +224,31 @@ export class File {
|
||||
);
|
||||
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.currentRelationshipId++,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
|
||||
"styles.xml",
|
||||
);
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.currentRelationshipId++,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
|
||||
"numbering.xml",
|
||||
);
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.currentRelationshipId++,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",
|
||||
"footnotes.xml",
|
||||
);
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.currentRelationshipId++,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
|
||||
"settings.xml",
|
||||
);
|
||||
this.documentWrapper.Relationships.createRelationship(
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
this.currentRelationshipId++,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
|
||||
"comments.xml",
|
||||
|
@ -6,13 +6,17 @@ export interface IHeaderOptions {
|
||||
}
|
||||
|
||||
export class Header {
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {
|
||||
// noop
|
||||
public readonly options: IHeaderOptions;
|
||||
|
||||
public constructor(options: IHeaderOptions = { children: [] }) {
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
||||
export class Footer {
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {
|
||||
// noop
|
||||
public readonly options: IHeaderOptions;
|
||||
|
||||
public constructor(options: IHeaderOptions = { children: [] }) {
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ describe("Media", () => {
|
||||
});
|
||||
|
||||
it("should return UInt8Array if atob is present", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const image = new Media().addMedia("", {
|
||||
@ -45,11 +46,12 @@ describe("Media", () => {
|
||||
});
|
||||
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
||||
|
||||
// tslint:disable-next-line: no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
|
||||
it("should use data as is if its not a string", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const image = new Media().addMedia(Buffer.from(""), {
|
||||
@ -58,7 +60,7 @@ describe("Media", () => {
|
||||
});
|
||||
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
||||
|
||||
// tslint:disable-next-line: no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
});
|
||||
|
@ -34,13 +34,14 @@ describe("Numbering", () => {
|
||||
.filter((el) => el["w:lvl"])
|
||||
.forEach((el, ix) => {
|
||||
expect(Object.keys(el)).to.have.lengthOf(1);
|
||||
expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal(["_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr"]);
|
||||
expect(Object.keys(el["w:lvl"])).to.deep.equal(["_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr"]);
|
||||
expect(el["w:lvl"]).to.have.deep.members([
|
||||
{ _attr: { "w:ilvl": ix, "w15:tentative": 1 } },
|
||||
{ "w:start": [{ _attr: { "w:val": 1 } }] },
|
||||
{ "w:lvlJc": [{ _attr: { "w:val": "left" } }] },
|
||||
{ "w:numFmt": [{ _attr: { "w:val": "bullet" } }] },
|
||||
]);
|
||||
// TODO
|
||||
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
|
||||
// {"w:lvlText": {"_attr": {"w:val": "•"}}},
|
||||
// {"w:rPr": [{"w:rFonts": {"_attr": {"w:ascii": "Symbol", "w:cs": "Symbol", "w:eastAsia": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}}]},
|
||||
|
@ -771,7 +771,7 @@ describe("ImageRun", () => {
|
||||
],
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
|
||||
@ -1028,7 +1028,7 @@ describe("ImageRun", () => {
|
||||
],
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
// eslint-disable @typescript-eslint/no-explicit-any
|
||||
import { Element as XmlElement, xml2js } from "xml-js";
|
||||
|
||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
@ -15,7 +14,9 @@ export const convertToXmlComponent = (element: XmlElement): ImportedXmlComponent
|
||||
switch (element.type) {
|
||||
case undefined:
|
||||
case "element":
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const xmlComponent = new ImportedXmlComponent(element.name as string, element.attributes);
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const childElements = element.elements || [];
|
||||
for (const childElm of childElements) {
|
||||
const child = convertToXmlComponent(childElm);
|
||||
@ -31,6 +32,7 @@ export const convertToXmlComponent = (element: XmlElement): ImportedXmlComponent
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
class ImportedXmlComponentAttributes extends XmlAttributeComponent<any> {
|
||||
// noop
|
||||
}
|
||||
@ -54,7 +56,7 @@ export class ImportedXmlComponent extends XmlComponent {
|
||||
* @param importedContent xml content of the imported component
|
||||
*/
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public constructor(rootKey: string, _attr?: any) {
|
||||
super(rootKey);
|
||||
if (_attr) {
|
||||
@ -71,7 +73,7 @@ export class ImportedXmlComponent extends XmlComponent {
|
||||
* Used for the attributes of root element that is being imported.
|
||||
*/
|
||||
export class ImportedRootElementAttributes extends XmlComponent {
|
||||
// tslint:disable-next-line:variable-name
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public constructor(private readonly _attr: any) {
|
||||
super("");
|
||||
}
|
||||
|
Reference in New Issue
Block a user