add types instead of using any in project.ts (#18091)

This commit is contained in:
Kim Santiago
2022-01-14 12:53:57 -08:00
committed by GitHub
parent a8a049624f
commit 6a288dcaa5

View File

@@ -586,11 +586,11 @@ export class Project implements ISqlProject {
await this.createCleanFileNode(beforeBuildNode); await this.createCleanFileNode(beforeBuildNode);
} }
private async createCleanFileNode(parentNode: any): Promise<void> { private async createCleanFileNode(parentNode: Element): Promise<void> {
const deleteFileNode = this.projFileXmlDoc!.createElement(constants.Delete); const deleteFileNode = this.projFileXmlDoc!.createElement(constants.Delete);
deleteFileNode.setAttribute(constants.Files, constants.ProjJsonToClean); deleteFileNode.setAttribute(constants.Files, constants.ProjJsonToClean);
parentNode.appendChild(deleteFileNode); parentNode.appendChild(deleteFileNode);
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
/** /**
@@ -740,7 +740,7 @@ export class Project implements ISqlProject {
} }
} }
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
} }
@@ -881,7 +881,7 @@ export class Project implements ISqlProject {
sqlObjectType); sqlObjectType);
} }
private findOrCreateItemGroup(containedTag?: string, prePostScriptExist?: { scriptExist: boolean; }): any { private findOrCreateItemGroup(containedTag?: string, prePostScriptExist?: { scriptExist: boolean; }): Element {
let outputItemGroup = undefined; let outputItemGroup = undefined;
// search for a particular item goup if a child type is provided // search for a particular item goup if a child type is provided
@@ -990,7 +990,7 @@ export class Project implements ISqlProject {
if (this.isSdkStyleProject) { if (this.isSdkStyleProject) {
// write any changes from removing an include node and get the current files included in the project // write any changes from removing an include node and get the current files included in the project
if (deleted) { if (deleted) {
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
const currentFiles = await this.readFilesInProject(); const currentFiles = await this.readFilesInProject();
@@ -1007,22 +1007,24 @@ export class Project implements ISqlProject {
throw new Error(constants.unableToFindObject(path, constants.fileObject)); throw new Error(constants.unableToFindObject(path, constants.fileObject));
} }
private removeNode(includeString: string, nodes: any): boolean { private removeNode(includeString: string, nodes: HTMLCollectionOf<Element>): boolean {
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
const parent = nodes[i].parentNode; const parent = nodes[i].parentNode;
if (nodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(includeString)) { if (parent) {
parent.removeChild(nodes[i]); if (nodes[i].getAttribute(constants.Include) === utils.convertSlashesForSqlProj(includeString)) {
parent.removeChild(nodes[i]);
// delete ItemGroup if this was the only entry // delete ItemGroup if this was the only entry
// only want element nodes, not text nodes // only want element nodes, not text nodes
const otherChildren = Array.from(parent.childNodes).filter((c: any) => c.childNodes); const otherChildren = Array.from(parent.childNodes).filter((c: ChildNode) => c.childNodes);
if (otherChildren.length === 0) { if (otherChildren.length === 0) {
parent.parentNode.removeChild(parent); parent.parentNode?.removeChild(parent);
}
return true;
} }
return true;
} }
} }
@@ -1095,7 +1097,7 @@ export class Project implements ISqlProject {
} }
private async writeToSqlProjAndUpdateFilesFolders(): Promise<void> { private async writeToSqlProjAndUpdateFilesFolders(): Promise<void> {
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
const projFileText = await fs.readFile(this._projectFilePath); const projFileText = await fs.readFile(this._projectFilePath);
this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString()); this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString());
this._files = await this.readFilesInProject(); this._files = await this.readFilesInProject();
@@ -1170,7 +1172,7 @@ export class Project implements ISqlProject {
return found; return found;
} }
private async addDatabaseReferenceChildren(referenceNode: any, entry: IDatabaseReferenceProjectEntry): Promise<void> { private async addDatabaseReferenceChildren(referenceNode: Element, entry: IDatabaseReferenceProjectEntry): Promise<void> {
const suppressMissingDependenciesErrorNode = this.projFileXmlDoc!.createElement(constants.SuppressMissingDependenciesErrors); const suppressMissingDependenciesErrorNode = this.projFileXmlDoc!.createElement(constants.SuppressMissingDependenciesErrors);
const suppressMissingDependenciesErrorTextNode = this.projFileXmlDoc!.createTextNode(entry.suppressMissingDependenciesErrors ? constants.True : constants.False); const suppressMissingDependenciesErrorTextNode = this.projFileXmlDoc!.createTextNode(entry.suppressMissingDependenciesErrors ? constants.True : constants.False);
suppressMissingDependenciesErrorNode.appendChild(suppressMissingDependenciesErrorTextNode); suppressMissingDependenciesErrorNode.appendChild(suppressMissingDependenciesErrorTextNode);
@@ -1202,7 +1204,7 @@ export class Project implements ISqlProject {
} }
} }
private addProjectReferenceChildren(referenceNode: any, entry: SqlProjectReferenceProjectEntry): void { private addProjectReferenceChildren(referenceNode: Element, entry: SqlProjectReferenceProjectEntry): void {
// project name // project name
const nameElement = this.projFileXmlDoc!.createElement(constants.Name); const nameElement = this.projFileXmlDoc!.createElement(constants.Name);
const nameTextNode = this.projFileXmlDoc!.createTextNode(entry.projectName); const nameTextNode = this.projFileXmlDoc!.createTextNode(entry.projectName);
@@ -1237,7 +1239,7 @@ export class Project implements ISqlProject {
this._sqlCmdVariables[entry.variableName] = <string>entry.defaultValue; this._sqlCmdVariables[entry.variableName] = <string>entry.defaultValue;
} }
private addSqlCmdVariableChildren(sqlCmdVariableNode: any, entry: SqlCmdVariableProjectEntry): void { private addSqlCmdVariableChildren(sqlCmdVariableNode: Element, entry: SqlCmdVariableProjectEntry): void {
// add default value // add default value
const defaultValueNode = this.projFileXmlDoc!.createElement(constants.DefaultValue); const defaultValueNode = this.projFileXmlDoc!.createElement(constants.DefaultValue);
const defaultValueText = this.projFileXmlDoc!.createTextNode(entry.defaultValue); const defaultValueText = this.projFileXmlDoc!.createTextNode(entry.defaultValue);
@@ -1272,7 +1274,7 @@ export class Project implements ISqlProject {
return highestNumber + 1; return highestNumber + 1;
} }
private async updateImportedTargetsToProjFile(condition: string, projectAttributeVal: string, oldImportNode?: any): Promise<any> { private async updateImportedTargetsToProjFile(condition: string, projectAttributeVal: string, oldImportNode?: Element): Promise<Element> {
const importNode = this.projFileXmlDoc!.createElement(constants.Import); const importNode = this.projFileXmlDoc!.createElement(constants.Import);
importNode.setAttribute(constants.Condition, condition); importNode.setAttribute(constants.Condition, condition);
importNode.setAttribute(constants.Project, projectAttributeVal); importNode.setAttribute(constants.Project, projectAttributeVal);
@@ -1285,7 +1287,7 @@ export class Project implements ISqlProject {
this._importedTargets.push(projectAttributeVal); // Add new import target to the list this._importedTargets.push(projectAttributeVal); // Add new import target to the list
} }
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
return importNode; return importNode;
} }
@@ -1298,7 +1300,7 @@ export class Project implements ISqlProject {
this.findOrCreateItemGroup(constants.PackageReference).appendChild(packageRefNode); this.findOrCreateItemGroup(constants.PackageReference).appendChild(packageRefNode);
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
public containsSSDTOnlySystemDatabaseReferences(): boolean { public containsSSDTOnlySystemDatabaseReferences(): boolean {
@@ -1368,7 +1370,7 @@ export class Project implements ISqlProject {
break; // not required but adding so that we dont miss when we add new items break; // not required but adding so that we dont miss when we add new items
} }
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
private async removeFromProjFile(entries: ProjectEntry | ProjectEntry[]): Promise<void> { private async removeFromProjFile(entries: ProjectEntry | ProjectEntry[]): Promise<void> {
@@ -1399,17 +1401,17 @@ export class Project implements ISqlProject {
} }
} }
await this.serializeToProjFile(this.projFileXmlDoc); await this.serializeToProjFile(this.projFileXmlDoc!);
} }
private async serializeToProjFile(projFileContents: any): Promise<void> { private async serializeToProjFile(projFileContents: Document): Promise<void> {
let xml = new xmldom.XMLSerializer().serializeToString(projFileContents); let xml = new xmldom.XMLSerializer().serializeToString(projFileContents);
xml = xmlFormat(xml, <any>{ xml = xmlFormat(xml, <xmlFormat.Options>{
collapseContent: true, collapseContent: true,
indentation: ' ', indentation: ' ',
lineSeparator: os.EOL, lineSeparator: os.EOL,
whiteSpaceAtEndOfSelfclosingTag: true whiteSpaceAtEndOfSelfclosingTag: true
}); // TODO: replace <any> });
await fs.writeFile(this._projectFilePath, xml); await fs.writeFile(this._projectFilePath, xml);