From 0fc3516e1d2a490684536c117ab561edb3e1018c Mon Sep 17 00:00:00 2001 From: Tyler Smith Date: Mon, 19 Aug 2024 16:27:09 -0300 Subject: [PATCH] Update test --- src/findNodes.spec.ts | 23 +++++++++++++++++++---- src/findNodes.ts | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/findNodes.spec.ts b/src/findNodes.spec.ts index 1d82491..64875d6 100644 --- a/src/findNodes.spec.ts +++ b/src/findNodes.spec.ts @@ -6,9 +6,10 @@ import undent from 'undent'; describe('findnode', () => { let program: Program; + const rootDir = path.join(__dirname, '../.tmp'); beforeEach(() => { - program = new Program({}); + program = new Program({rootDir: rootDir}); program.plugins.add(new Plugin()); }); @@ -167,13 +168,27 @@ describe('findnode', () => { program.validate(); expect( - program.getDiagnostics().map(x => ({ message: x.message, range: x.range })) + program.getDiagnostics().map(x => ({ message: x.message, range: x.range, relatedInformation: x.relatedInformation })) ).to.eql([{ message: `Unnecessary call to 'm.top.findNode("helloZombieText")'`, - range: util.createRange(2, 36, 2, 69) + range: util.createRange(2, 36, 2, 69), + relatedInformation: [{ + message: `In scope 'components/ZombieKeyboard.xml'`, + location: util.createLocation( + util.pathToUri(`${rootDir}/components/ZombieKeyboard.xml`), + util.createRange(4, 31, 4, 46) + ) + }] }, { message: `Unnecessary call to 'm.top.findNode("helloZombieText")'`, - range: util.createRange(3, 37, 3, 70) + range: util.createRange(3, 37, 3, 70), + relatedInformation: [{ + message: `In scope 'components/ZombieKeyboard.xml'`, + location: util.createLocation( + util.pathToUri(`${rootDir}/components/ZombieKeyboard.xml`), + util.createRange(4, 31, 4, 46) + ) + }] }]); }); diff --git a/src/findNodes.ts b/src/findNodes.ts index f7b0e85..4b5bc77 100644 --- a/src/findNodes.ts +++ b/src/findNodes.ts @@ -7,7 +7,7 @@ function findChildrenWithIDs(children: Array): Map { if (children) { children.forEach(child => { if (child.id) { - foundIDs.set(child.id, child.attributes.find(x => x.key.text === 'id')?.key.range ?? util.createRange(0, 0, 0, 100)); + foundIDs.set(child.id, child.attributes.find(x => x.key.text === 'id')?.value?.range ?? util.createRange(0, 0, 0, 100)); } const subChildren = findChildrenWithIDs(child.children); foundIDs = new Map([...foundIDs, ...subChildren]);