@20baht/strict 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -2
- package/bin/cli.js +68 -0
- package/ci/ci.yml +138 -0
- package/ci/setup/action.yml +15 -0
- package/package.json +106 -4
- package/src/depcruise/index.d.ts +54 -0
- package/src/depcruise/index.js +241 -0
- package/src/eslint/bahtui.js +335 -0
- package/src/eslint/index.d.ts +36 -0
- package/src/eslint/index.js +207 -0
- package/src/presets/commitlint.d.ts +2 -0
- package/src/presets/commitlint.js +1 -0
- package/src/presets/gitleaks.toml +6 -0
- package/src/presets/husky/commit-msg +1 -0
- package/src/presets/husky/pre-commit +8 -0
- package/src/presets/husky/pre-push +1 -0
- package/src/presets/jscpd.d.ts +10 -0
- package/src/presets/jscpd.js +40 -0
- package/src/presets/knip.d.ts +10 -0
- package/src/presets/knip.js +13 -0
- package/src/presets/lint-staged.d.ts +2 -0
- package/src/presets/lint-staged.js +5 -0
- package/src/presets/renovate.json +32 -0
- package/src/prettier/index.d.ts +5 -0
- package/src/prettier/index.js +10 -0
- package/src/tsconfig/base.json +22 -0
- package/src/tsconfig/node.json +5 -0
- package/src/tsconfig/web.json +19 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import css from '@eslint/css';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import prettier from 'eslint-config-prettier';
|
|
4
|
+
import sonarjs from 'eslint-plugin-sonarjs';
|
|
5
|
+
import { defineConfig } from 'eslint/config';
|
|
6
|
+
import tseslint from 'typescript-eslint';
|
|
7
|
+
|
|
8
|
+
import { bahtui as bahtuiPlugin } from './bahtui.js';
|
|
9
|
+
|
|
10
|
+
// angular-eslint is an optional peer: only the `angular` preset needs it.
|
|
11
|
+
const angularEslint = await import('angular-eslint').then(
|
|
12
|
+
(m) => m.default ?? m,
|
|
13
|
+
() => undefined,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const TS = ['**/*.{ts,tsx}'];
|
|
17
|
+
|
|
18
|
+
const BYPASS_SECURITY = {
|
|
19
|
+
selector: 'CallExpression[callee.property.name=/^bypassSecurityTrust/]',
|
|
20
|
+
message: 'bypassSecurityTrust* turns off Angular sanitization; render safe values instead.',
|
|
21
|
+
};
|
|
22
|
+
const SCRIPT_URL_TEMPLATE = {
|
|
23
|
+
selector: 'TemplateLiteral > TemplateElement:first-child[value.raw=/^\\s*javascript:/i]',
|
|
24
|
+
message: 'javascript: URLs run code; use an event handler.',
|
|
25
|
+
};
|
|
26
|
+
const TEST_FILES = ['**/*.test.ts', '**/*.spec.ts'];
|
|
27
|
+
|
|
28
|
+
export { bahtuiPlugin };
|
|
29
|
+
|
|
30
|
+
/** Ignores, JS, type-aware TypeScript, sonarjs, prettier last. */
|
|
31
|
+
export const base = defineConfig([
|
|
32
|
+
{
|
|
33
|
+
name: 'bank20baht/ignores',
|
|
34
|
+
ignores: [
|
|
35
|
+
'**/.agents/**',
|
|
36
|
+
'**/dist/**',
|
|
37
|
+
'**/node_modules/**',
|
|
38
|
+
'**/*.gen.ts',
|
|
39
|
+
'**/.angular/**',
|
|
40
|
+
'**/.wrangler/**',
|
|
41
|
+
'**/coverage/**',
|
|
42
|
+
// Bundled release output (konmek's `bun run release` writes `.release/`).
|
|
43
|
+
'**/.release/**',
|
|
44
|
+
'**/playwright-report/**',
|
|
45
|
+
'**/test-results/**',
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
// Plain JS config files: no type information available.
|
|
50
|
+
name: 'bank20baht/js',
|
|
51
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
52
|
+
extends: [js.configs.recommended],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'bank20baht/ts',
|
|
56
|
+
files: TS,
|
|
57
|
+
extends: [
|
|
58
|
+
js.configs.recommended,
|
|
59
|
+
...tseslint.configs.strictTypeChecked,
|
|
60
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
61
|
+
],
|
|
62
|
+
languageOptions: { parserOptions: { projectService: true } },
|
|
63
|
+
linterOptions: { reportUnusedDisableDirectives: 'error' },
|
|
64
|
+
rules: {
|
|
65
|
+
'@typescript-eslint/no-unused-vars': [
|
|
66
|
+
'error',
|
|
67
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
|
68
|
+
],
|
|
69
|
+
'@typescript-eslint/consistent-type-imports': 'error',
|
|
70
|
+
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
|
71
|
+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
|
|
72
|
+
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'bank20baht/sonarjs',
|
|
77
|
+
files: TS,
|
|
78
|
+
plugins: { sonarjs },
|
|
79
|
+
rules: {
|
|
80
|
+
'sonarjs/no-identical-functions': 'error',
|
|
81
|
+
'sonarjs/no-identical-expressions': 'error',
|
|
82
|
+
'sonarjs/cognitive-complexity': ['error', 15],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
// Repeated literals are ordinary in tests, so the rule only guards production code.
|
|
87
|
+
name: 'bank20baht/sonarjs-strings',
|
|
88
|
+
files: TS,
|
|
89
|
+
ignores: [...TEST_FILES, 'apps/e2e/**'],
|
|
90
|
+
plugins: { sonarjs },
|
|
91
|
+
rules: { 'sonarjs/no-duplicate-string': ['error', { threshold: 4 }] },
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'bank20baht/security',
|
|
95
|
+
files: ['**/*.{js,mjs,cjs,ts,tsx}'],
|
|
96
|
+
rules: {
|
|
97
|
+
'no-script-url': 'error',
|
|
98
|
+
'no-restricted-syntax': ['error', BYPASS_SECURITY, SCRIPT_URL_TEMPLATE],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{ name: 'bank20baht/prettier', ...prettier },
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Angular: inline-template processor, template a11y, no inline styles, restricted imports.
|
|
106
|
+
* @param {import('./index.d.ts').AngularOptions} options
|
|
107
|
+
*/
|
|
108
|
+
export function angular({ files, restrictedImports = [], templateFiles } = {}) {
|
|
109
|
+
if (!angularEslint) {
|
|
110
|
+
throw new Error('@20baht/strict/eslint: angular() needs the optional peer angular-eslint');
|
|
111
|
+
}
|
|
112
|
+
if (!files?.length) throw new Error('@20baht/strict/eslint: angular({ files }) is required');
|
|
113
|
+
const ts = files.filter((f) => /\.tsx?$/.test(f) || f.endsWith('/**'));
|
|
114
|
+
const html = templateFiles ?? files.map((f) => f.replace(/\*\*$/, '**/*.html'));
|
|
115
|
+
return defineConfig([
|
|
116
|
+
{
|
|
117
|
+
name: 'bank20baht/angular-ts',
|
|
118
|
+
files: ts.map((f) => (f.endsWith('/**') ? `${f}/*.ts` : f)),
|
|
119
|
+
...(angularEslint.processInlineTemplates === undefined
|
|
120
|
+
? {}
|
|
121
|
+
: { processor: angularEslint.processInlineTemplates }),
|
|
122
|
+
rules: {
|
|
123
|
+
'no-restricted-imports': 'off',
|
|
124
|
+
'@typescript-eslint/no-restricted-imports': ['error', { paths: restrictedImports }],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'bank20baht/angular-template',
|
|
129
|
+
files: html,
|
|
130
|
+
languageOptions: { parser: angularEslint.templateParser },
|
|
131
|
+
plugins: { '@angular-eslint/template': angularEslint.templatePlugin },
|
|
132
|
+
extends: [...angularEslint.configs.templateAccessibility],
|
|
133
|
+
rules: {
|
|
134
|
+
// `[style.width.%]` bindings are how bars get their length; static style="" is not.
|
|
135
|
+
'@angular-eslint/template/no-inline-styles': ['error', { allowBindToStyle: true }],
|
|
136
|
+
'no-restricted-syntax': [
|
|
137
|
+
'error',
|
|
138
|
+
{
|
|
139
|
+
selector: 'BoundAttribute[name=/^(innerHTML|outerHTML)$/]',
|
|
140
|
+
message: '[innerHTML] renders markup from data; bind text or use a component.',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
selector:
|
|
144
|
+
'TextAttribute[name=/^(href|src|action|formaction)$/][value=/^\\s*javascript:/i]',
|
|
145
|
+
message: 'javascript: URLs run code; use (click).',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* bahtui design-system rules: no raw controls / hand-placed fields in templates, known tokens
|
|
155
|
+
* and no raw colours in component CSS.
|
|
156
|
+
* @param {import('./index.d.ts').BahtuiOptions} options
|
|
157
|
+
*/
|
|
158
|
+
export function bahtui({ files, tokenFiles = [], templateFiles, cssFiles } = {}) {
|
|
159
|
+
if (!files?.length) throw new Error('@20baht/strict/eslint: bahtui({ files }) is required');
|
|
160
|
+
const html = templateFiles ?? files.map((f) => f.replace(/\*\*$/, '**/*.html'));
|
|
161
|
+
const styles = cssFiles ?? files.map((f) => f.replace(/\*\*$/, '**/*.css'));
|
|
162
|
+
return defineConfig([
|
|
163
|
+
{
|
|
164
|
+
name: 'bank20baht/bahtui-template',
|
|
165
|
+
files: html,
|
|
166
|
+
plugins: { bahtui: bahtuiPlugin },
|
|
167
|
+
rules: { 'bahtui/no-hand-placed-field': 'error', 'bahtui/no-raw-control': 'error' },
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'bank20baht/bahtui-css',
|
|
171
|
+
files: styles,
|
|
172
|
+
language: 'css/css',
|
|
173
|
+
plugins: { css, bahtui: bahtuiPlugin },
|
|
174
|
+
rules: {
|
|
175
|
+
'css/no-empty-blocks': 'error',
|
|
176
|
+
'css/no-duplicate-imports': 'error',
|
|
177
|
+
'css/no-invalid-at-rules': 'error',
|
|
178
|
+
// (`css/no-invalid-properties` is off: it cannot see custom properties declared in
|
|
179
|
+
// other files, so every var(--baht-*) reads as unknown.)
|
|
180
|
+
'bahtui/known-token': ['error', { extraFiles: tokenFiles }],
|
|
181
|
+
// The app's token files are its theme: the only place a --baht-* definition may hold a
|
|
182
|
+
// colour literal. Without tokenFiles the rule keeps allowing such definitions anywhere.
|
|
183
|
+
'bahtui/no-raw-color': tokenFiles.length ? ['error', { themeFiles: tokenFiles }] : 'error',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Plain CSS hygiene, without the bahtui token rules.
|
|
191
|
+
* @param {{ files?: string[] }} [options]
|
|
192
|
+
*/
|
|
193
|
+
export function cssRules({ files = ['**/*.css'] } = {}) {
|
|
194
|
+
return defineConfig([
|
|
195
|
+
{
|
|
196
|
+
name: 'bank20baht/css',
|
|
197
|
+
files,
|
|
198
|
+
language: 'css/css',
|
|
199
|
+
plugins: { css },
|
|
200
|
+
rules: {
|
|
201
|
+
'css/no-empty-blocks': 'error',
|
|
202
|
+
'css/no-duplicate-imports': 'error',
|
|
203
|
+
'css/no-invalid-at-rules': 'error',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { extends: ['@commitlint/config-conventional'] };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bunx commitlint --edit "$1"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Secret scan of what is about to be committed. CI runs the same scan over the
|
|
2
|
+
# whole history, so a machine without gitleaks only loses the early warning.
|
|
3
|
+
if command -v gitleaks >/dev/null 2>&1; then
|
|
4
|
+
gitleaks git --pre-commit --staged --redact --no-banner || exit 1
|
|
5
|
+
else
|
|
6
|
+
echo "gitleaks is not installed - skipping the local secret scan (CI still runs it). brew install gitleaks" >&2
|
|
7
|
+
fi
|
|
8
|
+
bunx lint-staged
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bun run check:fast
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface JscpdOptions {
|
|
2
|
+
path: string[];
|
|
3
|
+
threshold: number;
|
|
4
|
+
ignore?: string[];
|
|
5
|
+
replaceIgnore?: boolean;
|
|
6
|
+
format?: string[];
|
|
7
|
+
minTokens?: number;
|
|
8
|
+
minLines?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function jscpd(options: JscpdOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const COMMON_IGNORE = [
|
|
2
|
+
'**/node_modules/**',
|
|
3
|
+
'**/dist/**',
|
|
4
|
+
'**/.angular/**',
|
|
5
|
+
'**/coverage/**',
|
|
6
|
+
'**/test-results/**',
|
|
7
|
+
'**/playwright-report/**',
|
|
8
|
+
'**/*.spec.ts',
|
|
9
|
+
'**/*.test.ts',
|
|
10
|
+
'**/*.d.ts',
|
|
11
|
+
'**/*.gen.ts',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `threshold` is per app (max duplicated %), so it is required. `ignore` appends to the
|
|
16
|
+
* common ignores; pass `replaceIgnore: true` to swap them.
|
|
17
|
+
* @param {{ path: string[], threshold: number, ignore?: string[], replaceIgnore?: boolean,
|
|
18
|
+
* format?: string[], minTokens?: number, minLines?: number }} options
|
|
19
|
+
*/
|
|
20
|
+
export function jscpd({
|
|
21
|
+
path,
|
|
22
|
+
threshold,
|
|
23
|
+
ignore = [],
|
|
24
|
+
replaceIgnore = false,
|
|
25
|
+
format = ['typescript', 'markup', 'css'],
|
|
26
|
+
minTokens = 50,
|
|
27
|
+
minLines = 5,
|
|
28
|
+
}) {
|
|
29
|
+
if (typeof threshold !== 'number') throw new Error('@20baht/strict/jscpd: threshold is required');
|
|
30
|
+
return {
|
|
31
|
+
path,
|
|
32
|
+
format,
|
|
33
|
+
ignore: replaceIgnore ? ignore : [...COMMON_IGNORE, ...ignore],
|
|
34
|
+
minTokens,
|
|
35
|
+
minLines,
|
|
36
|
+
gitignore: true,
|
|
37
|
+
reporters: ['console'],
|
|
38
|
+
threshold,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface KnipWorkspace {
|
|
2
|
+
entry?: string[];
|
|
3
|
+
project?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface KnipOptions {
|
|
6
|
+
workspaces?: Record<string, KnipWorkspace>;
|
|
7
|
+
ignoreDependencies?: string[];
|
|
8
|
+
ignoreBinaries?: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function knip(options?: KnipOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ workspaces?: Record<string, { entry?: string[]; project?: string[] }>,
|
|
3
|
+
* ignoreDependencies?: string[], ignoreBinaries?: string[] }} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function knip({ workspaces = {}, ignoreDependencies = [], ignoreBinaries = [] } = {}) {
|
|
6
|
+
return {
|
|
7
|
+
$schema: 'https://unpkg.com/knip@latest/schema.json',
|
|
8
|
+
// loaded by name from @20baht/strict/commitlint, so knip cannot see the use
|
|
9
|
+
ignoreDependencies: ['@commitlint/config-conventional', ...ignoreDependencies],
|
|
10
|
+
workspaces,
|
|
11
|
+
ignoreBinaries: ['gitleaks', ...ignoreBinaries],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"extends": ["config:recommended", ":semanticCommitTypeAll(chore)"],
|
|
4
|
+
"timezone": "Asia/Bangkok",
|
|
5
|
+
"schedule": ["before 6am on monday"],
|
|
6
|
+
"prConcurrentLimit": 4,
|
|
7
|
+
"packageRules": [
|
|
8
|
+
{
|
|
9
|
+
"description": "Everything not matched below: one weekly PR.",
|
|
10
|
+
"matchPackageNames": ["*"],
|
|
11
|
+
"groupName": "others"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"description": "Dev tooling: linters, formatters, test runners, type packages.",
|
|
15
|
+
"matchDepTypes": ["devDependencies"],
|
|
16
|
+
"groupName": "dev-deps"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"description": "Angular packages move together (framework, CLI, build, eslint, and their peers).",
|
|
20
|
+
"matchPackageNames": [
|
|
21
|
+
"/^@angular//",
|
|
22
|
+
"/^@angular-devkit//",
|
|
23
|
+
"/^@angular-eslint//",
|
|
24
|
+
"angular-eslint",
|
|
25
|
+
"rxjs",
|
|
26
|
+
"tslib",
|
|
27
|
+
"zone.js"
|
|
28
|
+
],
|
|
29
|
+
"groupName": "angular"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @type {import('prettier').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
semi: false,
|
|
4
|
+
singleQuote: true,
|
|
5
|
+
trailingComma: 'all',
|
|
6
|
+
printWidth: 100,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Prettier cannot extend ignore files: copy these lines into `.prettierignore`. */
|
|
10
|
+
export const ignore = ['node_modules', 'dist', 'bun.lock', '.agents', '.angular', 'coverage'];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"noUncheckedIndexedAccess": true,
|
|
15
|
+
"noImplicitOverride": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"exactOptionalPropertyTypes": true,
|
|
19
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
20
|
+
"noEmit": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "./base.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"target": "ES2022",
|
|
6
|
+
"module": "preserve",
|
|
7
|
+
"allowImportingTsExtensions": false,
|
|
8
|
+
"noEmit": false,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"importHelpers": true
|
|
12
|
+
},
|
|
13
|
+
"angularCompilerOptions": {
|
|
14
|
+
"enableI18nLegacyMessageIdFormat": false,
|
|
15
|
+
"strictInjectionParameters": true,
|
|
16
|
+
"strictTemplates": true,
|
|
17
|
+
"strictInputAccessModifiers": true
|
|
18
|
+
}
|
|
19
|
+
}
|