Skip to content

Commit

Permalink
Fix tooling, lint errors, finish setting up initial @odk/xpath tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelidlessness committed Oct 18, 2023
1 parent 9c6ab45 commit a80f139
Show file tree
Hide file tree
Showing 176 changed files with 13,308 additions and 12,748 deletions.
173 changes: 115 additions & 58 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/// <reference path="./vendor-types/@eslint/eslintrc.d.ts" />
/// <reference path="./vendor-types/@typescript-eslint/parser.d.ts" />
/// <reference path="./vendor-types/eslint-plugin-no-only-tests.d.ts" />
// @ts-check

import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typeScriptESLintParser from '@typescript-eslint/parser';
import noOnlyTestsPlugin from 'eslint-plugin-no-only-tests';
import { builtinModules } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import eslintConfigPrettier from 'eslint-config-prettier';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -16,10 +22,29 @@ const compat = new FlatCompat({
allConfig: js.configs.all,
});

const typeScriptFileExtensions = /** @type {const} */ ([
'cjs',
'cts',
'js',
'jsx',
'mjs',
'mts',
'ts',
'tsx',
]);
const typeScriptExtensionsGlobPattern = `.{${typeScriptFileExtensions.join(',')}}`;

/**
* @param {string} pathSansExtension
*/
const typeScriptGlob = (pathSansExtension) => {
return `${pathSansExtension}${typeScriptExtensionsGlobPattern}`;
};

/** @type {import('eslint').Linter.FlatConfig[]} */
const configs = [
...compat.config({
ignorePatterns: [
{
ignores: [
'.changeset',
'.github',
'examples/**/*',
Expand All @@ -32,33 +57,60 @@ const configs = [
'packages/tree-sitter-xpath/types/**/*',
'**/vendor',
],
},

{
languageOptions: {
parser: typeScriptESLintParser,
parserOptions: {
ecmaFeatures: {
modules: true,
},
ecmaVersion: 'latest',
project: [
'./tsconfig.json',
'./tsconfig.tools.json',
'./tsconfig.vendor-types.json',
'./examples/*/tsconfig.json',
'./packages/**/tsconfig.json',
'./scripts/tsconfig.json',
],
tsconfigRootDir: __dirname,
},
sourceType: 'module',
globals: {
globalThis: false, // Apparently this means read-only?
},
},

linterOptions: {
reportUnusedDisableDirectives: true,
},

plugins: {
'no-only-tests': noOnlyTestsPlugin,
},
},

...compat.config({
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: [
'./packages/*/tsconfig.json',
'./scripts/tsconfig.json',
'./tsconfig.eslint.json',
'./tsconfig.test.json',
'./tsconfig.build.json',
],
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint', 'prettier', 'no-only-tests'],
}),

eslintConfigPrettier,

{
rules: {
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'no-only-tests/no-only-tests': 'error',
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/no-shadow': 'error',
'no-console': 'warn',

'@typescript-eslint/class-literal-property-style': 'error',
Expand Down Expand Up @@ -91,7 +143,12 @@ const configs = [
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/await-thenable': 'error',

'@typescript-eslint/no-empty-interface': [
'error',
{
allowSingleExtends: true,
},
],
'prefer-const': 'error',

// Ensure Node built-ins aren't used by default
Expand All @@ -103,48 +160,48 @@ const configs = [
},
],
},
overrides: [
{
files: [
'eslint.config.js',
'scripts/**/*.js',
'packages/*/playwright.config.ts',
// TODO: in theory, all e2e tests (if they continue to be run with
// Playwright) are technically run in a "Node" environment, although
// they will likely exercise non-Node code when calling into the
// Playwright-managed browser process. I'm adding this special case
// mainly to make note of this because it's unclear what the best
// solution will be for mixed Node-/browser-API code in terms of type
// safety and linting.
'packages/tree-sitter-xpath/e2e/sub-expression-queries.test.ts',
],
env: {
node: true,
},
rules: {
'no-restricted-imports': 'off',
},
},
{
files: ['eslint.config.js'],
rules: {
'@typescript-eslint/triple-slash-reference': 'warn',
},
},
{
files: ['packages/**/test/*.js', 'packages/**/*.js'],
env: {
mocha: true,
},
globals: {
globalThis: false, // false means read-only
},
rules: {
'no-console': 'warn',
},
},
},

{
files: ['eslint.config.js'],
rules: {
'@typescript-eslint/triple-slash-reference': 'off',
},
},

{
files: [
'eslint.config.js',
'scripts/**/*.js',
'packages/*/playwright.config.ts',
'packages/*/vite.config.ts',

// TODO: in theory, all e2e tests (if they continue to be run with
// Playwright) are technically run in a "Node" environment, although
// they will likely exercise non-Node code when calling into the
// Playwright-managed browser process. I'm adding this special case
// mainly to make note of this because it's unclear what the best
// solution will be for mixed Node-/browser-API code in terms of type
// safety and linting.
'packages/tree-sitter-xpath/e2e/sub-expression-queries.test.ts',
],
}),
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',
},
},
];

export default configs;
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
"@changesets/cli": "^2.26.2",
"@eslint/js": "^8.51.0",
"@eslint/eslintrc": "^2.1.2",
"@types/chai": "^4.3.7",
"@types/eslint__js": "^8.42.1",
"@types/eslint": "^8.44.4",
"@types/eslint-config-prettier": "^6.11.1",
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"chai": "^4.3.10",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-no-only-tests": "^3.1.0",
Expand Down
7 changes: 2 additions & 5 deletions packages/odk-web-forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@
"dev": "vite",
"test": "npm-run-all -nl test:*",
"test:e2e": "playwright test",
"test:mocha": "mocha --exit --timeout 30000 ./test/**/*.test.js",
"test:types": "tsc --project ./tsconfig.test-types.json"
"test:types": "tsc --project ./tsconfig.json"
},
"devDependencies": {
"@playwright/test": "^1.38.1",
"@types/mocha": "^10.0.1",
"mocha": "^10.2.0"
"@playwright/test": "^1.38.1"
}
}
12 changes: 0 additions & 12 deletions packages/odk-web-forms/test/noop.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/odk-web-forms/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"declarationDir": "./dist",
Expand Down
7 changes: 0 additions & 7 deletions packages/odk-web-forms/tsconfig.test-types.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/odk-xpath/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["."]
}
21 changes: 13 additions & 8 deletions packages/odk-xpath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@
"build": "npm-run-all -nl build:*",
"build:clean": "rimraf dist/",
"build:js": "vite build",
"_build:types": "tsc --project ./tsconfig.json",
"build:types": "tsc --project ./tsconfig.json",
"dev": "vite",
"test": "npm-run-all -nl test:*",
"test:e2e": "playwright test",
"test:vitest": "vitest",
"_test:types": "tsc --project ./tsconfig.test-types.json"
"//": "echo '--continue-on-error is temporary, intent to show all test environments running in CI'",
"test": "npm-run-all --continue-on-error --print-name --print-label test-node:* test-browser:*",
"test-node:jsdom": "vitest run",
"test-browser:chromium": "BROWSER_NAME=chromium vitest run",
"test-browser:firefox": "BROWSER_NAME=firefox vitest run",
"test-browser:webkit": "BROWSER_NAME=webkit vitest run",
"test-watch:jsdom": "vitest",
"test-watch:chromium": "BROWSER_NAME=chromium vitest",
"test-watch:firefox": "BROWSER_NAME=firefox vitest",
"test-watch:webkit": "BROWSER_NAME=webkit vitest",
"test:types": "tsc --project ./tsconfig.json --noEmit"
},
"dependencies": {
"@js-temporal/polyfill": "^0.4.4",
Expand All @@ -47,10 +54,8 @@
"devDependencies": {
"@types/crypto-js": "^4.1.2",
"@playwright/test": "^1.38.1",
"@types/mocha": "^10.0.1",
"@vitest/browser": "^0.34.6",
"chai": "^4.3.10",
"mocha": "^10.2.0",
"jsdom": "^22.1.0",
"vite": "^4.4.11",
"vitest": "^0.34.6"
}
Expand Down
30 changes: 13 additions & 17 deletions packages/odk-xpath/src/context/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ import type { Temporal } from '@js-temporal/polyfill';
import type { XPathNamespaceResolverObject } from '../shared/interface.ts';
import type { Evaluator } from '../evaluator/Evaluator.ts';
import type { FunctionLibrary } from '../evaluator/functions/FunctionLibrary.ts';
import type {
ContextDocument,
ContextNode,
ContextParentNode,
} from '../lib/dom/types.ts';
import type { ContextDocument, ContextNode, ContextParentNode } from '../lib/dom/types.ts';

/**
* The context in which any XPath expression *or sub-expression* is evaluated.
*/
export interface Context {
// The evaluator itself acts as the containing context, and will provide
// several aspects of the context's own environment.
readonly evaluator: Evaluator;
// The evaluator itself acts as the containing context, and will provide
// several aspects of the context's own environment.
readonly evaluator: Evaluator;

readonly contextDocument: ContextDocument;
readonly rootNode: ContextParentNode;
readonly contextNodes: Iterable<ContextNode>;
readonly contextDocument: ContextDocument;
readonly rootNode: ContextParentNode;
readonly contextNodes: Iterable<ContextNode>;

contextPosition(): number;
contextSize(): number;
contextPosition(): number;
contextSize(): number;

// TODO: namespaced function libraries? Could accommodate custom functions
readonly functionLibrary: FunctionLibrary;
readonly namespaceResolver: XPathNamespaceResolverObject;
readonly timeZone: Temporal.TimeZoneProtocol;
// TODO: namespaced function libraries? Could accommodate custom functions
readonly functionLibrary: FunctionLibrary;
readonly namespaceResolver: XPathNamespaceResolverObject;
readonly timeZone: Temporal.TimeZoneProtocol;
}
Loading

0 comments on commit a80f139

Please sign in to comment.