Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
cache: npm
- run: npm ci
- name: Enforce code style
run: npx prettier --list-different "src/**/*.[jt]s" "tests/**/*.[jt]s" "src/**/*.vue"
run: npx prettier --list-different "src/**/*.[jt]s" "tests/**/*.[jt]s" "src/**/*.vue" "packages/dicom/**/*.{ts,md}"
- name: Lint
run: npm run lint
- name: Quality ratchets
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/cache@v4
with:
path: .tmp/datasets
key: e2e-datasets-${{ hashFiles('tests/datasets.ts') }}
key: e2e-datasets-${{ hashFiles('tests/datasets.ts', 'tests/dicomVolumeCorpus.json', 'tests/dicomCompositionCorpus.json') }}
restore-keys: e2e-datasets-
- name: Download missing datasets
run: node tests/downloadDatasets.ts
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v4
with:
path: .tmp/datasets
key: e2e-datasets-${{ hashFiles('tests/datasets.ts') }}
key: e2e-datasets-${{ hashFiles('tests/datasets.ts', 'tests/dicomVolumeCorpus.json', 'tests/dicomCompositionCorpus.json') }}
restore-keys: e2e-datasets-
- name: Run E2E on chrome (linux)
if: matrix.os == 'ubuntu-latest'
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dist
node_modules
public
src/io/itk-dicom
src/io/resample
*.json
115 changes: 95 additions & 20 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import eslintPluginVue from 'eslint-plugin-vue';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from 'eslint-config-prettier';
import globals from 'globals';
import { limits } from './scripts/checks/config.mjs';

const limitRules = (level) => ({
complexity: [level, limits.complexity],
'max-depth': [level, limits['max-depth']],
'max-params': [level, limits['max-params']],
'max-lines': [
level,
{ max: limits['max-lines'], skipBlankLines: true, skipComments: true },
],
});

// ---------------------------------------------------------------------------
// Feature layering boundaries.
Expand All @@ -12,7 +23,7 @@ import globals from 'globals';
// not a dependency of this repo, and the built-in rule expresses the same
// zones with no new dependency. Two zones per feature:
// 1. Code OUTSIDE the feature directory may reach it ONLY through its public
// surface `@/src/<dir>` (the index), never a deep path.
// modules listed in its public surface.
// 2. The feature's pure layer may not import stores, components, or the
// upper feature modules, and stays framework-free (no pinia, no vue) —
// dependencies point downward only.
Expand Down Expand Up @@ -64,16 +75,29 @@ const ownFeatureExceptPure = (feature) => {
const upperLayerMessage = (feature) =>
`The ${feature.dir} pure layer must not import stores, components, or upper feature modules. Dependencies point downward only.`;

// The DICOM module's public surface is its two entry points, core and vtk.
const dicomPublicSurface = {
regex: '(^|/)packages/dicom(?!/(core|vtk)$)',
message:
'Import the DICOM module only through @/packages/dicom/core or @/packages/dicom/vtk.',
};

const featureBoundaries = (features) => {
const publicSurface = ({ dir }) => ({
group: [`@/src/${dir}/*`, `@/src/${dir}/*/**`, `!@/src/${dir}/index`],
message: `Import the ${dir} feature only from its public surface \`@/src/${dir}\` (src/${dir}/index.ts). A deep import bypasses the feature boundary.`,
const publicSurface = ({ dir, publicModules }) => ({
group: [
`@/src/${dir}/*`,
`@/src/${dir}/*/**`,
...publicModules.map((module) => `!@/src/${dir}/${module}`),
],
message: `Import the ${dir} feature only through its defining public modules: ${publicModules.join(', ')}.`,
});
const publicFeatures = features.filter(
(feature) => feature.publicSurface !== false
);
const otherSurfaces = (feature) =>
publicFeatures.filter((other) => other !== feature).map(publicSurface);
const otherSurfaces = (feature) => [
dicomPublicSurface,
...publicFeatures.filter((other) => other !== feature).map(publicSurface),
];

return [
{
Expand All @@ -82,7 +106,12 @@ const featureBoundaries = (features) => {
rules: {
'no-restricted-imports': [
'error',
{ patterns: publicFeatures.map(publicSurface) },
{
patterns: [
dicomPublicSurface,
...publicFeatures.map(publicSurface),
],
},
],
},
},
Expand Down Expand Up @@ -149,7 +178,6 @@ const E2E_TIMEOUT_DEBT = [
'tests/specs/cine-ruler-session.e2e.ts',
'tests/specs/crosshairs-multi-image.e2e.ts',
'tests/specs/delete-selected-annotation.e2e.ts',
'tests/specs/dicom-dimension-mismatch.e2e.ts',
'tests/specs/different-direction-labelmap.e2e.ts',
'tests/specs/imageCacheUtils.ts',
'tests/specs/layer-source-lifetime.e2e.ts',
Expand All @@ -172,7 +200,6 @@ const E2E_TIMEOUT_DEBT = [
export default tseslint.config(
{
ignores: [
'src/io/itk-dicom/emscripten-build/**',
'src/io/resample/emscripten-build/**',
'**/*.d.ts',
'dist/**',
Expand Down Expand Up @@ -247,9 +274,10 @@ export default tseslint.config(
'no-restricted-syntax': [
'error',
{
selector: "Property[key.name='timeout']",
selector:
"Property[key.name='timeout']:not([value.type='Identifier'][value.name='DOWNLOAD_TIMEOUT'])",
message:
'Wait for a state the page publishes rather than passing a timeout.',
'Wait for a state the page publishes; use DOWNLOAD_TIMEOUT for data-loading readiness.',
},
{
selector:
Expand Down Expand Up @@ -293,7 +321,7 @@ export default tseslint.config(
},
},
{
files: ['src/vtk/**/*.{js,ts}'],
files: ['src/vtk/**/*.{js,ts}', 'packages/dicom/vtk/**/*.{js,ts}'],
rules: {
'no-param-reassign': [
'error',
Expand Down Expand Up @@ -336,6 +364,7 @@ export default tseslint.config(
},
{
dir: 'processing',
publicModules: ['integration', 'store', 'types'],
pure: [
'src/processing/engine/**/*.{js,ts}',
'src/processing/types.ts',
Expand All @@ -344,6 +373,12 @@ export default tseslint.config(
},
{
dir: 'referenceLines',
publicModules: [
'ReferenceLines.vue',
'ReferenceLineSegments.vue',
'geometry',
'store',
],
pure: [
'src/referenceLines/geometry.ts',
'src/referenceLines/crossings.ts',
Expand All @@ -368,8 +403,8 @@ export default tseslint.config(
],
},
},
// Mirrors the limits scripts/checks/complexity.mjs enforces per commit. Warn
// level because the ratchet only fails a file whose debt grows, so existing
// The limits scripts/checks/complexity.mjs enforces per commit. Warn level
// in src because the ratchet only fails a file whose debt grows, so existing
// files stay over these numbers without failing `npm run lint`.
{
files: ['src/**/*.{js,ts,vue}'],
Expand All @@ -379,13 +414,53 @@ export default tseslint.config(
'src/**/*.d.ts',
'**/emscripten-build/**',
],
rules: limitRules('warn'),
},
// The DICOM module carries no debt, so it is held to the limits outright.
{
files: ['packages/dicom/**/*.{js,ts}'],
ignores: ['packages/dicom/**/__tests__/**'],
rules: limitRules('error'),
},
{
files: ['tests/**/*.{js,ts,mjs}'],
rules: {
complexity: ['warn', 10],
'max-depth': ['warn', 3],
'max-params': ['warn', 4],
'max-lines': [
'warn',
{ max: 600, skipBlankLines: true, skipComments: true },
'no-restricted-imports': ['error', { patterns: [dicomPublicSurface] }],
},
},
{
files: ['packages/dicom/core/**/*.{js,ts}'],
ignores: ['**/__tests__/**'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
regex: '^(?!\\.\\.?/|(comlink|dcmjs|itk-wasm)$)',
message:
'DICOM core imports only relative paths and comlink, dcmjs and itk-wasm. A new dependency is a deliberate change to this list.',
},
],
},
],
},
},
{
files: ['packages/dicom/vtk/**/*.{js,ts}'],
ignores: ['**/__tests__/**'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
regex: '^(@/|@src/|vue(?:/|$)|pinia(?:/|$)|@vueuse/)',
message:
'DICOM module internals use relative imports and cannot depend on application state or UI frameworks.',
},
],
},
],
},
},
Expand Down
Loading
Loading