Skip to content

Commit c3f5ec3

Browse files
committed
Code cleanup
1 parent c1d0483 commit c3f5ec3

25 files changed

Lines changed: 101 additions & 181 deletions

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sonar.projectKey=TypesXML
33
# this is the name displayed in the SonarQube UI
44
sonar.projectName=TypesXML
5-
sonar.projectVersion=1.10.0
5+
sonar.projectVersion=2.0.0
66

77
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
88
# Since SonarQube 4.2, this property is optional if sonar.modules is set.

ts/DOMBuilder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export class DOMBuilder implements ContentHandler {
257257
}
258258

259259
endElement(name: string): void {
260+
XMLUtils.ignoreUnused(name);
260261
this.stack.pop();
261262
}
262263

ts/SAXParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ export class SAXParser {
339339
!this.inComment && !this.inDoctype && !this.inProcessingInstruction) {
340340
throw new Error('Entity reference not allowed in this context');
341341
}
342-
const textForValidation: string = this.characterRun ? this.normalizeCharacterRun(this.characterRun) : '';
343342
this.cleanCharacterRun();
344343
this.pointer++; // skip '&'
345344
let name: string = '';
@@ -942,6 +941,7 @@ export class SAXParser {
942941
}
943942

944943
parseRelaxNG(href: string) {
944+
XMLUtils.ignoreUnused(href);
945945
// TODO Silently ignored, not implemented yet
946946
}
947947

ts/XMLCanonicalizer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ import { XMLDocument } from "./XMLDocument";
1818
import { XMLElement } from "./XMLElement";
1919
import { CData } from "./CData";
2020
import { Grammar } from "./grammar/Grammar";
21+
import { XMLUtils } from "./XMLUtils";
2122

2223
export class XMLCanonicalizer {
2324

24-
private grammar: Grammar | undefined;
25-
2625
public static canonicalize(document: XMLDocument, grammar?: Grammar): string {
2726
const canonicalizer = new XMLCanonicalizer();
28-
if (grammar) {
29-
canonicalizer.grammar = grammar;
30-
} else if (document.getGrammar) {
31-
canonicalizer.grammar = document.getGrammar();
32-
}
27+
XMLUtils.ignoreUnused(grammar);
3328
return canonicalizer.canonicalizeDocument(document);
3429
}
3530

ts/XMLUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export class XMLUtils {
5959
return String(text).split(search).join(replacement);
6060
}
6161

62+
static ignoreUnused(...args: unknown[]): void {
63+
if (args.length > 0) {
64+
void args[0];
65+
}
66+
}
67+
6268
static escapeRegExpChars(text: string): string {
6369
let result: string = '';
6470
let length: number = text.length;

ts/dtd/DTDGrammar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export class DTDGrammar implements Grammar {
213213
}
214214

215215
validateElement(element: string, content: ValidationContext): ValidationResult {
216+
XMLUtils.ignoreUnused(content);
216217
const colonIndex = element.indexOf(':');
217218
const elementName = colonIndex !== -1 ? element.substring(colonIndex + 1) : element;
218219
const elementDecl = this.elementDeclMap.get(elementName);
@@ -228,6 +229,7 @@ export class DTDGrammar implements Grammar {
228229
}
229230

230231
validateAttributes(element: string, attributes: Map<string, string>, context: ValidationContext): ValidationResult {
232+
XMLUtils.ignoreUnused(element, attributes, context);
231233
// DTD attribute validation - simplified for now
232234
return ValidationResult.success();
233235
}

ts/dtd/dtdName.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Maxprograms - initial API and implementation
1111
*******************************************************************************/
1212

13+
import { XMLUtils } from "../XMLUtils";
1314
import { Cardinality } from "./ContentModel";
1415
import { ContentParticle, ContentParticleType } from "./contentParticle";
1516

@@ -32,7 +33,7 @@ export class DTDName implements ContentParticle {
3233
}
3334

3435
public addParticle(particle: ContentParticle) {
35-
// Do nothing
36+
XMLUtils.ignoreUnused(particle);
3637
}
3738

3839
getParticles(): Array<ContentParticle> {

ts/dtd/dtdPCData.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Maxprograms - initial API and implementation
1111
*******************************************************************************/
1212

13+
import { XMLUtils } from "../XMLUtils";
1314
import { Cardinality } from "./ContentModel";
1415
import { ContentParticle, ContentParticleType } from "./contentParticle";
1516

@@ -20,11 +21,11 @@ export class DTDPCData implements ContentParticle {
2021
}
2122

2223
addParticle(particle: ContentParticle): void {
23-
// do nothing
24+
XMLUtils.ignoreUnused(particle);
2425
}
2526

2627
setCardinality(cardinality: (typeof Cardinality)[keyof typeof Cardinality]): void {
27-
// do nothing
28+
XMLUtils.ignoreUnused(cardinality);
2829
}
2930

3031
getCardinality(): (typeof Cardinality)[keyof typeof Cardinality] {

ts/grammar/CompositeGrammar.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import { existsSync, readFileSync } from 'fs';
1414
import { resolve } from 'path';
15+
import { XMLUtils } from '../XMLUtils';
1516
import { AttributeGroup } from '../schema/AttributeGroup';
1617
import { BuiltinTypes } from '../schema/BuiltinTypes';
1718
import { ContentModel } from '../schema/ContentModel';
@@ -340,6 +341,7 @@ export class CompositeGrammar implements Grammar {
340341
resolveCrossSchemaGroup(qualifiedName: string): ContentModel | undefined {
341342
// Try to find the group in all loaded XMLSchemaGrammar instances
342343
for (const [namespace, grammar] of this.grammars.entries()) {
344+
XMLUtils.ignoreUnused(namespace);
343345
if (grammar instanceof XMLSchemaGrammar) {
344346
const group = grammar.getGroupDefinition(qualifiedName);
345347
if (group) {
@@ -354,6 +356,7 @@ export class CompositeGrammar implements Grammar {
354356
resolveAllGroupReferences(): void {
355357
// Go through all XMLSchemaGrammar instances and try to resolve any unresolved group references
356358
for (const [namespace, grammar] of this.grammars.entries()) {
359+
XMLUtils.ignoreUnused(namespace);
357360
if (grammar instanceof XMLSchemaGrammar) {
358361
// For now, this would need access to unresolved group references
359362
// This is a placeholder for post-loading resolution
@@ -564,6 +567,7 @@ export class CompositeGrammar implements Grammar {
564567
context: ValidationContext,
565568
grammar: any
566569
): ValidationResult {
570+
XMLUtils.ignoreUnused(context);
567571
// Get element declaration and its complex type
568572
const elementAttrs = grammar.getElementAttributes(elementName);
569573
if (!elementAttrs || elementAttrs.size === 0) {
@@ -620,16 +624,6 @@ export class CompositeGrammar implements Grammar {
620624
return errors.length > 0 ? new ValidationResult(false, errors) : ValidationResult.success();
621625
}
622626

623-
private performAttributeValidation(grammar: Grammar, elementName: string, attributes: Map<string, string>, context: ValidationContext): ValidationResult {
624-
// For XMLSchemaGrammar, we handle the validation here in CompositeGrammar
625-
if (grammar.getGrammarType().toString() === 'xmlschema') {
626-
return (grammar as any).validateAttributes(elementName, attributes, context);
627-
}
628-
629-
// For other grammar types, delegate to the grammar
630-
return grammar.validateAttributes(elementName, attributes, context);
631-
}
632-
633627
private performValidation(grammar: Grammar, elementName: string, context: ValidationContext): ValidationResult {
634628
// For XMLSchemaGrammar, we handle the validation here in CompositeGrammar
635629
if (grammar.getGrammarType().toString() === 'xmlschema') {
@@ -837,6 +831,7 @@ export class CompositeGrammar implements Grammar {
837831
resolveAttributeGroup(attributeGroupName: string): AttributeGroup | undefined {
838832
// First try to resolve in all XMLSchema grammars
839833
for (const [namespace, grammar] of this.grammars) {
834+
XMLUtils.ignoreUnused(namespace);
840835
if (grammar instanceof XMLSchemaGrammar) {
841836
const attributeGroup = grammar.getAttributeGroupDefinition(attributeGroupName);
842837
if (attributeGroup) {
@@ -871,6 +866,7 @@ export class CompositeGrammar implements Grammar {
871866

872867
// Finally, try unqualified name in all grammars
873868
for (const [namespace, grammar] of this.grammars) {
869+
XMLUtils.ignoreUnused(namespace);
874870
if (grammar instanceof XMLSchemaGrammar) {
875871
const attributeGroup = grammar.getAttributeGroupDefinition(attributeGroupName);
876872
if (attributeGroup) {
@@ -1062,6 +1058,7 @@ export class CompositeGrammar implements Grammar {
10621058
}
10631059

10641060
private validateComplexType(elementName: string, context: ValidationContext, complexType: any, grammar: any): ValidationResult {
1061+
XMLUtils.ignoreUnused(elementName);
10651062
// Attributes are already validated during startElement by SAXParser.validateAttributes()
10661063
// No need to validate them again during content validation (endElement)
10671064

ts/grammar/DTDComposite.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Maxprograms - initial API and implementation
1111
*******************************************************************************/
1212

13+
import { XMLUtils } from '../XMLUtils';
1314
import { AttDecl } from '../dtd/AttDecl';
1415
import { DTDGrammar } from '../dtd/DTDGrammar';
1516
import { ElementDecl } from '../dtd/ElementDecl';
@@ -20,7 +21,6 @@ import { AttributeInfo, Grammar, GrammarType, ValidationContext, ValidationResul
2021
export class DTDComposite implements Grammar {
2122

2223
private static instance: DTDComposite | undefined;
23-
private validating: boolean = false;
2424
private internalDTD: DTDGrammar | undefined;
2525
private externalDTDs: DTDGrammar[] = [];
2626
private sharedParameterEntities: Map<string, EntityDecl> = new Map();
@@ -43,7 +43,6 @@ export class DTDComposite implements Grammar {
4343
}
4444

4545
reset(): void {
46-
this.validating = false;
4746
this.internalDTD = undefined;
4847
this.externalDTDs = [];
4948
this.sharedParameterEntities.clear();
@@ -59,7 +58,7 @@ export class DTDComposite implements Grammar {
5958
}
6059

6160
setValidating(validating: boolean): void {
62-
this.validating = validating;
61+
XMLUtils.ignoreUnused(validating);
6362
}
6463

6564
setIncludeDefaultAttributes(include: boolean): void {
@@ -80,7 +79,7 @@ export class DTDComposite implements Grammar {
8079
const sharedGrammar = new DTDGrammar();
8180

8281
// Add all shared parameter entities to the new grammar
83-
this.sharedParameterEntities.forEach((entity, name) => {
82+
this.sharedParameterEntities.forEach((entity) => {
8483
sharedGrammar.addEntity(entity);
8584
});
8685

@@ -119,6 +118,7 @@ export class DTDComposite implements Grammar {
119118
}
120119

121120
validateAttributes(element: string, attributes: Map<string, string>, context: ValidationContext): ValidationResult {
121+
XMLUtils.ignoreUnused(context);
122122
// Use merged attribute information for validation
123123
const declaredAttributes = this.getElementAttributes(element);
124124

0 commit comments

Comments
 (0)