CAITSGet started

Change the rules and the tools

CAITS sets up each tool of the harness: the architecture rules, ESLint, Vite and Vitest, Playwright, Stryker and TypeScript. It gives the defaults, and your files have the last word. This page also shows how to update CAITS, and how to add it to a project.

Your files, and CAITS's

FilesOwnerWhat they hold
quality/caits/*CAITSThe defaults. npx caits update writes them again: don't change them.
quality/*, tsconfig.jsonYouYour settings. Each file starts from CAITS's defaults, then changes them. CAITS never touches them.

An exception to a check lives here, and only here. The code holds no eslint-disable, no @ts-ignore, no v8 ignore, no Stryker disable, and no skipped test: the rule exceptions-in-quality refuses them. Make each exception as narrow as it can be: one rule, for the one file that needs it.

The architecture rules

caits architecture checks the rules that quality/architecture.mjs exports. Remove one:

quality/architecture.mjs

import { rules } from "./caits/architecture.mjs";

export default rules.filter(rule => rule.name !== "routes-folders");

Or add your own. A rule has a name, a description, what it reads (on), and a check:

quality/architecture.mjs

import { rules } from "./caits/architecture.mjs";

const noUtilsFile = {
  name: "no-utils-file",
  description: "No file is named utils: a name says what the file holds.",
  on: "file",
  check: ({ path }) => /\/utils?\.ts$/.test(path) && "A file named utils says nothing of what it holds. Name it after what it does."
};

export default [...rules, noUtilsFile];

npm run lint:architecture

src/frontend/messages/presentation/view/message-board/utils.ts [no-utils-file] A file named utils says nothing of what it holds. Name it after what it does.
  • To replace a rule, remove it, then add yours under the same name.
  • A check gives false or undefined when the rule holds. Otherwise, a message, { line, message }, or a list of them. Write the message as full sentences: what is wrong, then how to fix it.
  • on: "import" reads each import of the production code ({ file, from, to, specifier, line }), on: "file" each file, on: "project" the whole project once. from and to say where a file lives: its side, context, layer and use case.
  • @ingenioz-it/caits/quality/architecture gives the helpers of CAITS's own rules (locate, portOf, adapterOf…), and checkArchitecture, to test your rules in quality/*.test.mjs. quality/caits/architecture.mjs has many examples.

The packages of each layer

quality/imports.mjs lists the packages that each layer may import. CAITS closes the domain (the kernel's Result, Token and DomainEvent) and the application (plus EventPublisher); the other layers import any package. To let the domain use a package:

quality/imports.mjs

import { allowed } from "./caits/imports.mjs";

export default { ...allowed, domain: [...allowed.domain, "uuid"] };

Before you list a package, ask whether it holds technology: the clock, chance, a file, the network. If it does, put it behind a port instead.

ESLint

quality/eslint.config.js is a list. ESLint applies its entries in order, so yours win:

quality/eslint.config.js

import caits from "./caits/eslint.js";

export default [
  ...caits,
  { files: ["src/**/*.ts"], rules: { "no-console": "error" } }
];

Vite and Vitest

quality/vite.config.ts sets up the build, the development server and the unit tests. mergeConfig adds your settings to CAITS's, and adds to its lists, such as plugins:

quality/vite.config.ts

import { mergeConfig } from "vitest/config";
import caits from "./caits/vite.ts";

export default mergeConfig(caits, {
  test: { coverage: { thresholds: { branches: 90 } } }
});

Playwright and Stryker

Here, your values replace CAITS's. To change one value of an object, copy the others:

quality/playwright.config.ts

import { defineConfig } from "@playwright/test";
import caits from "./caits/playwright.ts";

export default defineConfig({
  ...caits,
  use: { ...caits.use, locale: "fr-FR" }
});

quality/stryker.config.mjs

import caits from "./caits/stryker.mjs";

export default {
  ...caits,
  concurrency: 4
};

To keep one mutant out, with its reason, see An equivalent mutant. Think twice before you lower a threshold: a test that checks nothing then has a place to hide.

TypeScript

tsconfig.json extends quality/caits/tsconfig.json. Your options replace CAITS's, each as a whole:

tsconfig.json

{
  "extends": "./quality/caits/tsconfig.json",
  "compilerOptions": { "noUnusedParameters": true }
}

If you set paths, copy CAITS's two shortcuts into yours: #shared/* to ./src/backend/shared/*, and #frontend-shared/* to ./src/frontend/shared/*.

The packages

A new project has no vulnerability, and warns of nothing, from npm install to npm run check. Besides the scripts and the packages, init writes two values in package.json:

  • overrides: some tools ask for versions of a package that have an advisory, which a later version fixes. npm installs the fixed version in their place, and npm audit finds nothing. When the tools ask for fixed versions, a new CAITS changes or removes the override.
  • allowScripts: npm runs the install scripts of a package only when the project allows them, and warns about the others. esbuild and @parcel/watcher work without theirs: CAITS denies them, and npm runs no code of theirs as it installs.

Update CAITS

Read the changelog first: it says what to change in your project when a version breaks something. Then:

Terminal, in the folder of the project

npm install --save-dev @ingenioz-it/caits@latest
npx caits update
  1. npm install gets the new CAITS.
  2. npx caits update writes its defaults to quality/caits/, and lists the packages whose version differs from what CAITS suggests. When a new version needs a package that package.json lacks, it gives the npm install command that adds it; when it needs a value that package.json lacks, as an override, the npm pkg set command that adds it, then run npm install. It changes neither your files nor your versions.
  3. Review git diff quality/caits/, then run npm run check.

Skip step 2, and the CAITS commands warn you that quality/caits/ comes from another version. npm update gets the fixes of your minor version (0.8.2 for 0.8.1), never a new minor version: run npx caits update after it too. A new minor version can move files: npm run lint:architecture names each one, and the changelog says where it goes.

Add CAITS to a project

CAITS fits a Marko app, or a nearly empty folder. In the folder of the project:

Terminal, in the folder of the project

npx @ingenioz-it/caits init
  • It writes only the files that the project doesn't have, plus quality/caits/. In package.json and .gitignore, it adds only what is missing.
  • It lists what it kept. Compare it with node_modules/@ingenioz-it/caits/template/project/.
  • Without a folder name, it needs a package.json in the current folder: you can't write a project into the wrong folder by mistake.

In a project with another structure, the architecture check fails until the code moves into contexts. The options of init are in Commands.