Skip to content

Commit

Permalink
fixes #108: resolve existing eslint warnings (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja authored May 20, 2024
1 parent 24277c2 commit ab7a23a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 46 deletions.
22 changes: 1 addition & 21 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ const typeScriptFileExtensions = /** @type {const} */ ([
'tsx',
]);

/**
* @param {string} pathSansExtension
*/
const typeScriptGlob = (pathSansExtension) => {
return extensionsGlob(pathSansExtension, typeScriptFileExtensions);
};

const vueFileExtensions = [...typeScriptFileExtensions, 'vue'];

/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
},
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export abstract class TextElementDefinition<
return [];
}

// eslint-disable-next-line no-console
console.error('Unexpected text element child', node);

throw new Error(`Unexpected <${element.nodeName}> child element`);
Expand Down
32 changes: 16 additions & 16 deletions packages/xpath/test/native/comparison-operator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down Expand Up @@ -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,
});
});
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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')/*",
Expand Down Expand Up @@ -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] },
Expand All @@ -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,
});
});
Expand Down
12 changes: 6 additions & 6 deletions packages/xpath/test/native/comparison-operator2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ describe('Comparison operator (2)', () => {
});

describe('<, <=, >, >=', () => {
interface TestCaseInput {
interface RelationalExprTestCaseInput {
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 RelationalExprTestCaseInput[] = [
{ operands: ['1', '2'], expected: [true, true, false, false] },
{ operands: ['1', '1'], expected: [false, true, false, true] },
{ operands: ['1', '0'], expected: [false, false, true, true] },
Expand Down Expand Up @@ -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) => {
Expand All @@ -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],
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/xpath/test/native/namespace-resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion packages/xpath/test/native/node-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
(attr) => attr.localName === 'attrib3'
);

expect(attribute).not.to.be.null;
Expand Down

0 comments on commit ab7a23a

Please sign in to comment.