Skip to content

Commit 00c25bc

Browse files
Copilotrubensworks
andcommitted
chore: migrate from tslint to eslint (partial fixes)
Agent-Logs-Url: https://github.com/rubensworks/rdfa-streaming-parser.js/sessions/3244748a-5ae5-4252-a0f9-7f7e0b1e696e Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
1 parent 2afa72f commit 00c25bc

5 files changed

Lines changed: 133 additions & 45 deletions

File tree

eslint.config.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,74 @@ module.exports = config([
1010
},
1111
},
1212
},
13+
{
14+
rules: {
15+
// This rule requires strictNullChecks, which is not enabled in this project
16+
'ts/prefer-nullish-coalescing': 'off',
17+
18+
// Allow importing Node.js built-in modules (used in tests and webpack config)
19+
'import/no-nodejs-modules': 'off',
20+
21+
// Allow file extensions in import paths (required for JSON imports)
22+
'import/extensions': 'off',
23+
24+
// Extended naming conventions for this project
25+
'ts/naming-convention': [
26+
'error',
27+
{
28+
selector: 'default',
29+
format: [ 'camelCase' ],
30+
leadingUnderscore: 'forbid',
31+
trailingUnderscore: 'forbid',
32+
},
33+
{
34+
selector: 'import',
35+
format: null,
36+
},
37+
{
38+
selector: 'variable',
39+
format: [ 'camelCase', 'UPPER_CASE' ],
40+
leadingUnderscore: 'forbid',
41+
trailingUnderscore: 'forbid',
42+
},
43+
{
44+
selector: 'typeLike',
45+
format: [ 'PascalCase' ],
46+
},
47+
{
48+
selector: [ 'typeParameter' ],
49+
format: [ 'PascalCase' ],
50+
prefix: [ 'T' ],
51+
},
52+
{
53+
selector: 'interface',
54+
format: [ 'PascalCase' ],
55+
custom: {
56+
regex: '^I[A-Z]',
57+
match: true,
58+
},
59+
},
60+
{
61+
// Allow UPPER_CASE for static class properties (e.g., namespace constants)
62+
selector: 'classProperty',
63+
modifiers: [ 'static' ],
64+
format: [ 'camelCase', 'UPPER_CASE' ],
65+
leadingUnderscore: 'forbid',
66+
trailingUnderscore: 'forbid',
67+
},
68+
{
69+
// Allow leading underscore for class methods (e.g., _transform, _flush from Node.js Transform API)
70+
selector: 'classMethod',
71+
format: [ 'camelCase' ],
72+
leadingUnderscore: 'allow',
73+
trailingUnderscore: 'forbid',
74+
},
75+
{
76+
// Allow any format for object literal property names (e.g., MIME type keys like 'text/html')
77+
selector: 'objectLiteralProperty',
78+
format: null,
79+
},
80+
],
81+
},
82+
},
1383
]);

lib/RdfaParser.ts

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { DomHandler } from 'domhandler';
2-
import EventEmitter = NodeJS.EventEmitter;
31
import type * as RDF from '@rdfjs/types';
2+
import type { DomHandler } from 'domhandler';
43
import { Parser as HtmlParser } from 'htmlparser2';
54
import { PassThrough, Transform } from 'readable-stream';
65
import type { IActiveTag } from './IActiveTag';
@@ -12,6 +11,8 @@ import type { IRdfaFeatures, RdfaProfile } from './RdfaProfile';
1211
import { RDFA_FEATURES } from './RdfaProfile';
1312
import { Util } from './Util';
1413

14+
type EventEmitter = NodeJS.EventEmitter;
15+
1516
/**
1617
* A stream transformer that parses RDFa (text) streams to an {@link RDF.Stream}.
1718
*/
@@ -27,7 +28,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
2728

2829
private readonly activeTagStack: IActiveTag[] = [];
2930

30-
constructor(options?: IRdfaParserOptions) {
31+
public constructor(options?: IRdfaParserOptions) {
3132
super({ readableObjectMode: true });
3233
options = options || {};
3334
this.options = options;
@@ -74,7 +75,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
7475
}
7576

7677
public _transform(chunk: any, encoding: string, callback: (error?: Error | null, data?: any) => void): void {
77-
this.parser.write(chunk.toString());
78+
this.parser.write(String(chunk));
7879
callback();
7980
}
8081

@@ -83,7 +84,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
8384
callback();
8485
}
8586

86-
public onTagOpen(name: string, attributes: Record<string, string>) {
87+
public onTagOpen(name: string, attributes: Record<string, string>): void {
8788
// Determine the parent tag (ignore skipped tags)
8889
let parentTagI: number = this.activeTagStack.length - 1;
8990
while (parentTagI > 0 && this.activeTagStack[parentTagI].skipElement) {
@@ -238,7 +239,9 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
238239
}
239240

240241
// 3: handle prefixes
241-
activeTag.prefixesCustom = Util.parsePrefixes(attributes, parentTag.prefixesCustom, Boolean(this.features.xmlnsPrefixMappings));
242+
activeTag.prefixesCustom = Util.parsePrefixes(
243+
attributes, parentTag.prefixesCustom, Boolean(this.features.xmlnsPrefixMappings),
244+
);
242245
activeTag.prefixesAll = Object.keys(activeTag.prefixesCustom).length > 0 ?
243246
{ ...parentTag.prefixesAll, ...activeTag.prefixesCustom } :
244247
parentTag.prefixesAll;
@@ -338,7 +341,8 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
338341
typedResource = newSubject;
339342
}
340343
}
341-
} else { // Either rel or rev is present
344+
} else {
345+
// Either rel or rev is present
342346
// 6: Determine the new subject when rel or rev are present
343347

344348
// Define new subject
@@ -396,15 +400,17 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
396400
if (currentObjectResource) {
397401
// Handle list mapping
398402
if ('rel' in attributes && 'inlist' in attributes) {
399-
for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
403+
for (const predicate of
404+
this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
400405
this.addListMapping(activeTag, newSubject!, predicate, currentObjectResource);
401406
}
402407
}
403408

404409
// Determine predicates using rel or rev (unless rel and inlist are present)
405410
if (!('rel' in attributes && 'inlist' in attributes)) {
406411
if ('rel' in attributes) {
407-
for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
412+
for (const predicate of
413+
this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
408414
this.emitTriple(
409415
this.util.getResourceOrBaseIri(newSubject!, activeTag),
410416
predicate,
@@ -413,7 +419,8 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
413419
}
414420
}
415421
if ('rev' in attributes) {
416-
for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates, false)) {
422+
for (const predicate of
423+
this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates, false)) {
417424
this.emitTriple(
418425
this.util.getResourceOrBaseIri(currentObjectResource, activeTag),
419426
predicate,
@@ -428,18 +435,21 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
428435
if (!currentObjectResource) {
429436
if ('rel' in attributes) {
430437
if ('inlist' in attributes) {
431-
for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
438+
for (const predicate of
439+
this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
432440
this.addListMapping(activeTag, newSubject!, predicate, false);
433441
activeTag.incompleteTriples!.push({ predicate, reverse: false, list: true });
434442
}
435443
} else {
436-
for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
444+
for (const predicate of
445+
this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates, false)) {
437446
activeTag.incompleteTriples!.push({ predicate, reverse: false });
438447
}
439448
}
440449
}
441450
if ('rev' in attributes) {
442-
for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates, false)) {
451+
for (const predicate of
452+
this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates, false)) {
443453
activeTag.incompleteTriples!.push({ predicate, reverse: true });
444454
}
445455
}
@@ -553,30 +563,30 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
553563
this.emitTriple(object, incompleteTriple.predicate, subject);
554564
} else if (incompleteTriple.list) {
555565
// Find the active tag that defined the list by going up the stack
556-
let firstInListTag: any = null;
566+
let firstInListTag: IActiveTag | null = null;
557567
for (let i = this.activeTagStack.length - 1; i >= 0; i--) {
558568
if (this.activeTagStack[i].inlist) {
559569
firstInListTag = this.activeTagStack[i];
560570
break;
561571
}
562572
}
563573
// FirstInListTag is guaranteed to be non-null
564-
this.addListMapping(firstInListTag, newSubject, incompleteTriple.predicate, object);
574+
this.addListMapping(firstInListTag!, newSubject, incompleteTriple.predicate, object);
565575
} else {
566576
this.emitTriple(subject, incompleteTriple.predicate, object);
567577
}
568578
}
569579
}
570580
if (!incompleteTriplesCompleted && parentTag.incompleteTriples!.length > 0) {
571-
activeTag.incompleteTriples = activeTag.incompleteTriples!.concat(parentTag.incompleteTriples!);
581+
activeTag.incompleteTriples = [ ...activeTag.incompleteTriples!, ...parentTag.incompleteTriples! ];
572582
}
573583

574584
// 13: Save evaluation context into active tag
575585
activeTag.subject = newSubject || parentTag.subject;
576586
activeTag.object = currentObjectResource || newSubject;
577587
}
578588

579-
public onText(data: string) {
589+
public onText(data: string): void {
580590
const activeTag: IActiveTag = this.activeTagStack.at(-1);
581591

582592
// Collect text in pattern tag if needed
@@ -596,7 +606,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
596606
activeTag.textWithoutTags.push(data);
597607
}
598608

599-
public onTagClose() {
609+
public onTagClose(): void {
600610
// Get the active tag
601611
const activeTag: IActiveTag = this.activeTagStack.at(-1);
602612
const parentTag: IActiveTag = this.activeTagStack.at(-2);
@@ -696,21 +706,21 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
696706
// If we still have text contents, try to append it to the parent tag
697707
if (activeTag.textWithTags && parentTag) {
698708
if (parentTag.textWithTags) {
699-
parentTag.textWithTags = parentTag.textWithTags.concat(activeTag.textWithTags);
709+
parentTag.textWithTags = [ ...parentTag.textWithTags, ...activeTag.textWithTags ];
700710
} else {
701711
parentTag.textWithTags = activeTag.textWithTags;
702712
}
703713
}
704714
if (activeTag.textWithoutTags && parentTag) {
705715
if (parentTag.textWithoutTags) {
706-
parentTag.textWithoutTags = parentTag.textWithoutTags.concat(activeTag.textWithoutTags);
716+
parentTag.textWithoutTags = [ ...parentTag.textWithoutTags, ...activeTag.textWithoutTags ];
707717
} else {
708718
parentTag.textWithoutTags = activeTag.textWithoutTags;
709719
}
710720
}
711721
}
712722

713-
public onEnd() {
723+
public onEnd(): void {
714724
if (this.features.copyRdfaPatterns) {
715725
this.features.copyRdfaPatterns = false;
716726

@@ -747,7 +757,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
747757
* @param {string} name The current tag name.
748758
* @returns {boolean} If the subject can be inherited.
749759
*/
750-
protected isInheritSubjectInHeadBody(name: string) {
760+
protected isInheritSubjectInHeadBody(name: string): boolean {
751761
return this.features.inheritSubjectInHeadBody && (name === 'head' || name === 'body');
752762
}
753763

@@ -759,12 +769,19 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
759769
* @param {Term} predicate A predicate term.
760770
* @param {Term | boolean} currentObjectResource The current object resource.
761771
*/
762-
protected addListMapping(activeTag: IActiveTag, subject: RDF.Quad_Subject | boolean, predicate: RDF.Quad_Predicate, currentObjectResource: RDF.Quad_Object | boolean) {
772+
protected addListMapping(
773+
activeTag: IActiveTag,
774+
subject: RDF.Quad_Subject | boolean,
775+
predicate: RDF.Quad_Predicate,
776+
currentObjectResource: RDF.Quad_Object | boolean,
777+
): void {
763778
if (activeTag.explicitNewSubject) {
764779
const bNode = this.util.createBlankNode();
765780
this.emitTriple(this.util.getResourceOrBaseIri(subject, activeTag), predicate, bNode);
766-
this.emitTriple(bNode, this.util.dataFactory.namedNode(`${Util.RDF}first`), this.util.getResourceOrBaseIri(currentObjectResource, activeTag));
767-
this.emitTriple(bNode, this.util.dataFactory.namedNode(`${Util.RDF}rest`), this.util.dataFactory.namedNode(`${Util.RDF}nil`));
781+
this.emitTriple(bNode, this.util.dataFactory.namedNode(`${Util.RDF}first`),
782+
this.util.getResourceOrBaseIri(currentObjectResource, activeTag));
783+
this.emitTriple(bNode, this.util.dataFactory.namedNode(`${Util.RDF}rest`),
784+
this.util.dataFactory.namedNode(`${Util.RDF}nil`));
768785
} else {
769786
let predicateList = activeTag.listMappingLocal[predicate.value];
770787
if (!predicateList) {
@@ -782,7 +799,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
782799
* @param {Term} predicate A predicate term.
783800
* @param {Term} object An object term.
784801
*/
785-
protected emitTriple(subject: RDF.Quad_Subject, predicate: RDF.Quad_Predicate, object: RDF.Quad_Object) {
802+
protected emitTriple(subject: RDF.Quad_Subject, predicate: RDF.Quad_Predicate, object: RDF.Quad_Object): void {
786803
// Validate IRIs
787804
if ((subject.termType === 'NamedNode' && !subject.value.includes(':')) ||
788805
(predicate.termType === 'NamedNode' && !predicate.value.includes(':')) ||
@@ -798,7 +815,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
798815
* @param {IRdfaPattern} pattern The pattern to instantiate.
799816
* @param {string} rootPatternId The pattern id.
800817
*/
801-
protected emitPatternCopy(parentTag: IActiveTag, pattern: IRdfaPattern, rootPatternId: string) {
818+
protected emitPatternCopy(parentTag: IActiveTag, pattern: IRdfaPattern, rootPatternId: string): void {
802819
this.activeTagStack.push(parentTag);
803820
pattern.referenced = true;
804821

@@ -833,7 +850,7 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
833850
* @param {boolean} root If this is the root call for the given pattern.
834851
* @param {string} rootPatternId The pattern id.
835852
*/
836-
protected emitPatternCopyAbsolute(pattern: IRdfaPattern, root: boolean, rootPatternId: string) {
853+
protected emitPatternCopyAbsolute(pattern: IRdfaPattern, root: boolean, rootPatternId: string): void {
837854
// Stop on detection of cyclic patterns
838855
if (!root && pattern.attributes.property === 'rdfa:copy' && pattern.attributes.href === rootPatternId) {
839856
return;

lib/RdfaProfile.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
* A type of RDFa profile
33
*/
44
export type RdfaProfile =
5-
'' | // All possible RDFa features
6-
'core' | // https://www.w3.org/TR/rdfa-core/
7-
'html' | // https://www.w3.org/TR/html-rdfa/
8-
'xhtml' | // https://www.w3.org/TR/xhtml-rdfa/
5+
// All possible RDFa features
6+
'' |
7+
// https://www.w3.org/TR/rdfa-core/
8+
'core' |
9+
// https://www.w3.org/TR/html-rdfa/
10+
'html' |
11+
// https://www.w3.org/TR/xhtml-rdfa/
12+
'xhtml' |
913
'xml';
1014

1115
export interface IRdfaFeatures {
@@ -70,7 +74,6 @@ export interface IRdfaFeatures {
7074
/**
7175
* A mapping of RDFa profile to a features object.
7276
*/
73-
// tslint:disable:object-literal-sort-keys
7477
export const RDFA_FEATURES: Record<string, IRdfaFeatures> = {
7578
'': {
7679
baseTag: true,
@@ -143,9 +146,7 @@ export const RDFA_FEATURES: Record<string, IRdfaFeatures> = {
143146
roleAttribute: true,
144147
},
145148
};
146-
// Tslint:enable:object-literal-sort-keys
147149

148-
// tslint:disable:object-literal-sort-keys
149150
export const RDFA_CONTENTTYPES: Record<string, RdfaProfile> = {
150151
// HTML
151152
'text/html': 'html',
@@ -158,4 +159,3 @@ export const RDFA_CONTENTTYPES: Record<string, RdfaProfile> = {
158159
'text/xml': 'xml',
159160
'image/svg+xml': 'xml',
160161
};
161-
// Tslint:enable:object-literal-sort-keys

0 commit comments

Comments
 (0)