@ign-junn/code-rules
v0.1.0
Published
Code rules of the Junn React applications (IGN): the junn-rules checks, a shared Biome configuration and a base TypeScript configuration
Readme
@ign-junn/code-rules
The code rules shared by the Junn React applications (IGN): the junn-rules command, which checks what Biome does not
cover, a shared Biome configuration and a base TypeScript configuration. It replaces the check:rules scripts copied
from one repository to the next (junn-apps, junn-design-system, flowbench, the junn-publication site).
bun add -d @ign-junn/code-rulesThe command
// package.json
"scripts": {
"check:rules": "junn-rules",
"fix:rules": "junn-rules --fix"
}Run from the root of the project, on the TypeScript files of src/. --fix adds the missing blank lines before
return; --list lists the rules; --config <file> reads another configuration file.
| Rule | What it enforces |
|---|---|
| syntax | Arrow functions only, no let, no for / while loop |
| html-tags | No HTML tag in JSX (.tsx): components with their component prop |
| hardcoded-text | No accented text in the code: texts in the translations (textAllowed excepted) |
| negated-optional-chain | No !x?.y: a type guard, then the positive case |
| typeof-compare | No typeof x === '…' outside the shared type guards (typeofAllowed) |
| blank-line-before-return | A blank line before every return (fixed by --fix) |
| declaration-order | In a function: library hooks, application hooks, values, functions, return |
| design-system | app: the design system components instead of Mantine's, its single entry, its icons; library: its own components outside their files, no translation library |
| import-boundaries | The imports each folder may not use (imports) |
| forbidden-files | Files that may not exist (forbiddenFiles) |
Configuration
In the junnRules field of package.json, or in junn-rules.config.json. Every field is optional:
{
"junnRules": {
"src": "src",
"ignore": ["src/api/generated/**"],
"textAllowed": ["src/locales/**", "src/tests/**"],
"typeofAllowed": ["src/types/common.ts"],
"designSystem": "app",
"imports": [
{ "files": "src/components/**", "forbid": ["@/features/", "@/services/"] },
{ "files": "src/utils/**", "forbid": ["@/features/", "@/components/"], "except": ["src/utils/router.tsx"] }
],
"forbiddenFiles": [{ "files": "src/services/**/*.tsx", "message": "no JSX in services" }],
"off": []
}
}designSystem:app(default) for an application,libraryfor the design system itself (thenwrappers: the files that wrap a Mantine component),falseto skip the check.off: names of rules to turn off.
Shared configurations
// biome.json
{ "extends": ["@ign-junn/code-rules/biome"], "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true } }// tsconfig.app.json
{
"extends": "@ign-junn/code-rules/tsconfig",
"compilerOptions": { "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", "paths": { "@/*": ["./src/*"] } },
"include": ["src"]
}Develop
bun install
bun run check # Biome
bun run typecheck # TypeScript
bun test # the rules on throw-away projectsPublished by hand in the public npm organization ign-junn, as the design system (cp .env.example .env, paste the
token, npm version <patch|minor|major>, bun run release, git push --follow-tags).
