From 1011938a70c75609f1638299e50f23ad7757df92 Mon Sep 17 00:00:00 2001 From: Sadiq Khoja Date: Thu, 9 May 2024 12:11:22 -0400 Subject: [PATCH] fixes #108: resolve existing eslint warnings --- eslint.config.js | 22 +------------ .../src/body/text/TextElementDefinition.ts | 2 -- .../test/native/comparison-operator.spec.ts | 32 +++++++++---------- .../test/native/comparison-operator2.spec.ts | 12 +++---- .../test/native/namespace-resolver.spec.ts | 4 +-- packages/xpath/test/native/node-name.spec.ts | 2 +- 6 files changed, 26 insertions(+), 48 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index e33706613..bdf27168e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -67,13 +67,6 @@ const typeScriptFileExtensions = /** @type {const} */ ([ 'tsx', ]); -/** - * @param {string} pathSansExtension - */ -const typeScriptGlob = (pathSansExtension) => { - return extensionsGlob(pathSansExtension, typeScriptFileExtensions); -}; - const vueFileExtensions = [...typeScriptFileExtensions, 'vue']; /** @@ -321,7 +314,7 @@ export default tseslint.config( ], 'no-only-tests/no-only-tests': 'error', '@typescript-eslint/no-shadow': 'error', - 'no-console': 'warn', + 'no-console': 'error', '@typescript-eslint/class-literal-property-style': 'error', '@typescript-eslint/consistent-indexed-object-style': 'error', @@ -434,18 +427,5 @@ export default tseslint.config( rules: { 'no-restricted-imports': 'off', }, - }, - - { - files: [ - typeScriptGlob('packages/**/e2e/*'), - typeScriptGlob('packages/**/test/*'), - typeScriptGlob('packages/**/*.{spec,test}'), - ], - rules: { - 'no-console': 'warn', - '@typescript-eslint/no-shadow': 'warn', - '@typescript-eslint/no-non-null-asserted-optional-chain': 'warn', - }, } ); diff --git a/packages/xforms-engine/src/body/text/TextElementDefinition.ts b/packages/xforms-engine/src/body/text/TextElementDefinition.ts index 4989b4ec9..9f97c8aa6 100644 --- a/packages/xforms-engine/src/body/text/TextElementDefinition.ts +++ b/packages/xforms-engine/src/body/text/TextElementDefinition.ts @@ -78,8 +78,6 @@ export abstract class TextElementDefinition< return []; } - console.error('Unexpected text element child', node); - throw new Error(`Unexpected <${element.nodeName}> child element`); }); diff --git a/packages/xpath/test/native/comparison-operator.spec.ts b/packages/xpath/test/native/comparison-operator.spec.ts index 991eaebb8..6e9b594ac 100644 --- a/packages/xpath/test/native/comparison-operator.spec.ts +++ b/packages/xpath/test/native/comparison-operator.spec.ts @@ -43,12 +43,12 @@ describe('Comparison operator', () => { { expression: `${lhs} != ${rhs}`, expected: expected[1] }, ]; - cases.forEach(({ expression, expected }) => { - it(`evaluates ${expression} to ${expected}${contextSuffix}`, () => { + cases.forEach(({ expression, expected: expectedResult }) => { + it(`evaluates ${expression} to ${expectedResult}${contextSuffix}`, () => { const contextNode = id == null ? testContext.document : testContext.document.getElementById(id); - testContext.assertBooleanValue(expression, expected, { + testContext.assertBooleanValue(expression, expectedResult, { contextNode, }); }); @@ -109,12 +109,12 @@ describe('Comparison operator', () => { { expression: `${lhs} >= ${rhs}`, expected: expected[3] }, ]; - cases.forEach(({ expression, expected }) => { - it(`evaluates ${expression} to ${expected}${contextSuffix}`, () => { + cases.forEach(({ expression, expected: expectedResult }) => { + it(`evaluates ${expression} to ${expectedResult}${contextSuffix}`, () => { const contextNode = id == null ? testContext.document : testContext.document.getElementById(id); - testContext.assertBooleanValue(expression, expected, { + testContext.assertBooleanValue(expression, expectedResult, { contextNode, }); }); @@ -153,7 +153,7 @@ describe('Comparison operator', () => { document = testContext.document; }); - const equalityCases: readonly EqualityCase[] = [ + const equalityWithNodesCases: readonly EqualityCase[] = [ // assertOps1(doc, // "id('ComparisonOperatorCaseNodesetNegative5to5')/*", // "id('ComparisonOperatorCaseNodesetEmpty')/*", [false, false]); @@ -205,25 +205,25 @@ describe('Comparison operator', () => { { lhs: "''", rhs: '*', id: 'ComparisonOperatorCaseNodesetStrings', expected: [false, true] }, ]; - equalityCases.forEach(({ lhs, rhs, id, expected }) => { + equalityWithNodesCases.forEach(({ lhs, rhs, id, expected }) => { const contextSuffix = id == null ? '' : ` (with context #${id})`; const cases = [ { expression: `${lhs} = ${rhs}`, expected: expected[0] }, { expression: `${lhs} != ${rhs}`, expected: expected[1] }, ]; - cases.forEach(({ expression, expected }) => { - it(`evaluates ${expression} to ${expected}${contextSuffix}`, () => { + cases.forEach(({ expression, expected: expectedResult }) => { + it(`evaluates ${expression} to ${expectedResult}${contextSuffix}`, () => { const contextNode = id == null ? document : document.getElementById(id); - testContext.assertBooleanValue(expression, expected, { + testContext.assertBooleanValue(expression, expectedResult, { contextNode, }); }); }); }); - const relativeCases: readonly RelativeCase[] = [ + const relativeWithNodesCases: readonly RelativeCase[] = [ // assertOps2(doc, // "id('ComparisonOperatorCaseNodesetNegative5to5')/*", // "id('ComparisonOperatorCaseNodesetEmpty')/*", @@ -385,7 +385,7 @@ describe('Comparison operator', () => { }, ]; - relativeCases.forEach(({ lhs, rhs, id, expected }) => { + relativeWithNodesCases.forEach(({ lhs, rhs, id, expected }) => { const contextSuffix = id == null ? '' : ` (with context #${id})`; const cases = [ { expression: `${lhs} < ${rhs}`, expected: expected[0] }, @@ -394,12 +394,12 @@ describe('Comparison operator', () => { { expression: `${lhs} >= ${rhs}`, expected: expected[3] }, ]; - cases.forEach(({ expression, expected }) => { - it(`evaluates ${expression} to ${expected}${contextSuffix}`, () => { + cases.forEach(({ expression, expected: expectedResult }) => { + it(`evaluates ${expression} to ${expectedResult}${contextSuffix}`, () => { const contextNode = id == null ? testContext.document : testContext.document.getElementById(id); - testContext.assertBooleanValue(expression, expected, { + testContext.assertBooleanValue(expression, expectedResult, { contextNode, }); }); diff --git a/packages/xpath/test/native/comparison-operator2.spec.ts b/packages/xpath/test/native/comparison-operator2.spec.ts index f1aef7a3d..268d6aef4 100644 --- a/packages/xpath/test/native/comparison-operator2.spec.ts +++ b/packages/xpath/test/native/comparison-operator2.spec.ts @@ -161,12 +161,12 @@ describe('Comparison operator (2)', () => { }); describe('<, <=, >, >=', () => { - interface TestCaseInput { + interface InequalityTestCaseInput { readonly operands: readonly [lhs: string, rhs: string]; readonly expected: readonly [lt: boolean, lte: boolean, gt: boolean, gte: boolean]; } - const input: readonly TestCaseInput[] = [ + const cases: readonly InequalityTestCaseInput[] = [ { operands: ['1', '2'], expected: [true, true, false, false] }, { operands: ['1', '1'], expected: [false, true, false, true] }, { operands: ['1', '0'], expected: [false, false, true, true] }, @@ -204,7 +204,7 @@ describe('Comparison operator (2)', () => { // [[ "''", "'0'" ], [ false, false, false, false ]], ]; - input.forEach(({ operands, expected }) => { + cases.forEach(({ operands, expected }) => { const [lhs, rhs] = operands; ['<', '<=', '>', '>='].forEach((operator, index) => { @@ -219,13 +219,13 @@ describe('Comparison operator (2)', () => { }); describe('with nodes', () => { - interface TestCaseInput { + interface WithNodesTestCaseInput { readonly operands: readonly [lhs: string, rhs: string]; readonly id?: string; readonly expected: readonly [lt: boolean, lte: boolean, gt: boolean, gte: boolean]; } - const input: readonly TestCaseInput[] = [ + const cases: readonly WithNodesTestCaseInput[] = [ { operands: ['true()', '*'], expected: [true, true, true, true], @@ -369,7 +369,7 @@ describe('Comparison operator (2)', () => { }, ]; - input.forEach(({ operands, id, expected }) => { + cases.forEach(({ operands, id, expected }) => { const [operand0, operand1] = operands; ['<', '<=', '>', '>='].forEach((operator, index) => { diff --git a/packages/xpath/test/native/namespace-resolver.spec.ts b/packages/xpath/test/native/namespace-resolver.spec.ts index 9ec4d8c14..0a89f1b23 100644 --- a/packages/xpath/test/native/namespace-resolver.spec.ts +++ b/packages/xpath/test/native/namespace-resolver.spec.ts @@ -147,7 +147,7 @@ describe.skip('namespace resolver', () => { }); it('looks up namespaceURIs that have changed', () => { - const contextNode = document.getElementById('testXPathNSResolverNode')?.firstElementChild!; + const contextNode = document.getElementById('testXPathNSResolverNode')!.firstElementChild!; const resolver = document.createNSResolver(contextNode); expect(resolver.lookupNamespaceURI('')).to.equal('http://www.w3.org/TR/REC-html40'); @@ -185,7 +185,7 @@ describe.skip('namespace resolver', () => { // check default prefix in parents expect(resolver.lookupNamespaceURI('')).to.equal('http://www.w3.org/1999/xhtml'); - resolver = document.createNSResolver(contextNode?.firstElementChild!.firstElementChild!); + resolver = document.createNSResolver(contextNode.firstElementChild!.firstElementChild!); expect(resolver.lookupNamespaceURI('')).to.equal('http://www.w3.org/TR/REC-html40'); }); }); diff --git a/packages/xpath/test/native/node-name.spec.ts b/packages/xpath/test/native/node-name.spec.ts index 6eebfd3f9..15f5ad096 100644 --- a/packages/xpath/test/native/node-name.spec.ts +++ b/packages/xpath/test/native/node-name.spec.ts @@ -84,7 +84,7 @@ describe('node name for', () => { it('attribute with a specific name', () => { const contextNode = document.getElementById('StepNodeTestCaseNameTestAttribute')!; const attribute = getNonNamespaceAttributes(contextNode).find( - (attribute) => attribute.localName === 'attrib3' + (att) => att.localName === 'attrib3' ); expect(attribute).not.to.be.null;