declapract-typescript-ehmpathy 0.47.48 → 0.47.49

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.
Files changed (13) hide show
  1. package/dist/practices/directory-structure-src/bad-practices/data-dir/src/<star><star>/data/<star><star>/<star>.declapract.ts +19 -0
  2. package/dist/practices/directory-structure-src/bad-practices/domain-dir/src/<star><star>/domain/<star><star>/<star>.declapract.ts +17 -0
  3. package/dist/practices/directory-structure-src/bad-practices/logic-dir/src/{logic → <star><star>/logic}/<star><star>/<star>.declapract.ts +3 -3
  4. package/dist/practices/directory-structure-src/bad-practices/model-dir/src/{model/<star><star>/<star>.ts.declapract.ts → <star><star>/model/<star><star>/<star>.declapract.ts} +2 -2
  5. package/dist/practices/directory-structure-src/bad-practices/nonpublished-modules-dir/src/__nonpublished_modules__/<star><star>/<star>.declapract.ts +17 -0
  6. package/dist/practices/directory-structure-src/bad-practices/old-import-paths/src/<star><star>/<star>.ts.declapract.ts +9 -1
  7. package/dist/practices/directory-structure-src/bad-practices/services-dir/src/<star><star>/services/<star><star>/<star>.declapract.ts +16 -0
  8. package/package.json +5 -5
  9. package/dist/practices/directory-structure-src/bad-practices/data-dir/src/data/<star><star>/<star>.ts.declapract.ts +0 -19
  10. package/dist/practices/directory-structure-src/bad-practices/domain-dir/src/domain/<star><star>/<star>.ts.declapract.ts +0 -17
  11. package/dist/practices/directory-structure-src/bad-practices/services-dir/src/services/<star><star>/<star>.ts.declapract.ts +0 -3
  12. package/dist/practices/tests/bad-practices/unquoted-shell-vars-in-test-scripts/package.json +0 -5
  13. package/dist/practices/tests/bad-practices/unquoted-shell-vars-in-test-scripts/package.json.declapract.ts +0 -70
@@ -0,0 +1,19 @@
1
+ import { FileCheckType, type FileFixFunction } from 'declapract';
2
+
3
+ // if files exist in any /data/, this is a bad practice
4
+ export const check = FileCheckType.EXISTS;
5
+
6
+ export const fix: FileFixFunction = (contents, context) => {
7
+ // move any /data/dao/* to /access/daos/*
8
+ // move any /data/clients/* to /access/sdks/*
9
+ // move other /data/* to /access/*
10
+ const newPath = context.relativeFilePath
11
+ .replace(/\/data\/dao\//g, '/access/daos/')
12
+ .replace(/\/data\/clients\//g, '/access/sdks/')
13
+ .replace(/\/data\//g, '/access/');
14
+
15
+ return {
16
+ contents: contents ?? null,
17
+ relativeFilePath: newPath,
18
+ };
19
+ };
@@ -0,0 +1,17 @@
1
+ import { FileCheckType, type FileFixFunction } from 'declapract';
2
+
3
+ // if files exist in any /domain/, this is a bad practice
4
+ export const check = FileCheckType.EXISTS;
5
+
6
+ export const fix: FileFixFunction = (contents, context) => {
7
+ // move any /domain/objects/* to /domain.objects/*
8
+ // move any /domain/* to /domain.objects/*
9
+ const newPath = context.relativeFilePath
10
+ .replace(/\/domain\/objects\//g, '/domain.objects/')
11
+ .replace(/\/domain\//g, '/domain.objects/');
12
+
13
+ return {
14
+ contents: contents ?? null,
15
+ relativeFilePath: newPath,
16
+ };
17
+ };
@@ -3,13 +3,13 @@ import { FileCheckType, type FileFixFunction } from 'declapract';
3
3
  export const check = FileCheckType.EXISTS;
4
4
 
5
5
  /**
6
- * .what = moves any file from src/logic/ to src/domain.operations/
6
+ * .what = moves any file from any /logic/ to /domain.operations/
7
7
  * .why = ensures all files are moved, not just .ts files — prevents silent data loss for hidden paths
8
8
  */
9
9
  export const fix: FileFixFunction = (contents, context) => {
10
10
  const newPath = context.relativeFilePath.replace(
11
- 'src/logic/',
12
- 'src/domain.operations/',
11
+ /\/logic\//g,
12
+ '/domain.operations/',
13
13
  );
14
14
 
15
15
  return {
@@ -10,7 +10,7 @@ export const fix: FileFixFunction = (contents, context) => {
10
10
  "export * from './';",
11
11
  ) ?? null,
12
12
  relativeFilePath: context.relativeFilePath
13
- .replace('src/model/domainObjects/', 'src/domain.objects/')
14
- .replace('src/model/', 'src/domain.objects/'),
13
+ .replace(/\/model\/domainObjects\//g, '/domain.objects/')
14
+ .replace(/\/model\//g, '/domain.objects/'),
15
15
  };
16
16
  };
@@ -0,0 +1,17 @@
1
+ import { FileCheckType, type FileFixFunction } from 'declapract';
2
+
3
+ // if files exist in __nonpublished_modules__/, this is a bad practice
4
+ export const check = FileCheckType.EXISTS;
5
+
6
+ export const fix: FileFixFunction = (contents, context) => {
7
+ // move any /__nonpublished_modules__/ to /_topublish/
8
+ const newPath = context.relativeFilePath.replace(
9
+ /__nonpublished_modules__\//g,
10
+ '_topublish/',
11
+ );
12
+
13
+ return {
14
+ contents: contents ?? null,
15
+ relativeFilePath: newPath,
16
+ };
17
+ };
@@ -8,6 +8,9 @@ const OLD_PATH_PATTERNS = [
8
8
  /from\s+['"][^'"]*\/domain\/objects/,
9
9
  /from\s+['"][^'"]*\/domain\//,
10
10
  /from\s+['"][^'"]*\/logic\//,
11
+ /from\s+['"][^'"]*\/model\/domainObjects/,
12
+ /from\s+['"][^'"]*\/model\//,
13
+ /from\s+['"][^'"]*\/services\//,
11
14
  ];
12
15
 
13
16
  export const check: FileCheckFunction = (contents) => {
@@ -35,7 +38,12 @@ export const fix: FileFixFunction = (contents) => {
35
38
  .replace(/(['"])([^'"]*?)\/domain\/objects\b/g, '$1$2/domain.objects')
36
39
  .replace(/(['"])([^'"]*?)\/domain\//g, '$1$2/domain.objects/')
37
40
  // logic layer fixes
38
- .replace(/(['"])([^'"]*?)\/logic\//g, '$1$2/domain.operations/');
41
+ .replace(/(['"])([^'"]*?)\/logic\//g, '$1$2/domain.operations/')
42
+ // model layer fixes (old structure before domain.objects)
43
+ .replace(/(['"])([^'"]*?)\/model\/domainObjects\b/g, '$1$2/domain.objects')
44
+ .replace(/(['"])([^'"]*?)\/model\//g, '$1$2/domain.objects/')
45
+ // services layer fixes (services = business logic, not service clients)
46
+ .replace(/(['"])([^'"]*?)\/services\//g, '$1$2/domain.operations/');
39
47
 
40
48
  return { contents: fixed };
41
49
  };
@@ -0,0 +1,16 @@
1
+ import { FileCheckType, type FileFixFunction } from 'declapract';
2
+
3
+ export const check = FileCheckType.EXISTS; // if a file exists with this path pattern, then it's bad practice
4
+
5
+ export const fix: FileFixFunction = (contents, context) => {
6
+ // move any /services/* to /domain.operations/* (services = business logic)
7
+ const newPath = context.relativeFilePath.replace(
8
+ /\/services\//g,
9
+ '/domain.operations/',
10
+ );
11
+
12
+ return {
13
+ contents: contents ?? null,
14
+ relativeFilePath: newPath,
15
+ };
16
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "declapract-typescript-ehmpathy",
3
3
  "author": "ehmpathy",
4
4
  "description": "declapract best practices declarations for typescript",
5
- "version": "0.47.48",
5
+ "version": "0.47.49",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "repository": "ehmpathy/declapract-typescript-ehmpathy",
@@ -75,11 +75,11 @@
75
75
  "esbuild-register": "3.6.0",
76
76
  "husky": "8.0.3",
77
77
  "jest": "30.2.0",
78
- "rhachet": "1.37.14",
78
+ "rhachet": "1.37.16",
79
79
  "rhachet-brains-anthropic": "0.3.3",
80
- "rhachet-roles-bhrain": "0.17.1",
81
- "rhachet-roles-bhuild": "0.13.8",
82
- "rhachet-roles-ehmpathy": "1.27.11",
80
+ "rhachet-roles-bhrain": "0.20.0",
81
+ "rhachet-roles-bhuild": "0.14.2",
82
+ "rhachet-roles-ehmpathy": "1.27.16",
83
83
  "tsc-alias": "1.8.10",
84
84
  "tsx": "4.20.6",
85
85
  "type-fns": "0.8.1",
@@ -1,19 +0,0 @@
1
- import { FileCheckType, type FileFixFunction } from 'declapract';
2
-
3
- // if files exist in src/data/, this is a bad practice
4
- export const check = FileCheckType.EXISTS;
5
-
6
- export const fix: FileFixFunction = (contents, context) => {
7
- // move src/data/dao/* to src/access/daos/*
8
- // move src/data/clients/* to src/access/sdks/*
9
- // move other src/data/* to src/access/*
10
- const newPath = context.relativeFilePath
11
- .replace('src/data/dao/', 'src/access/daos/')
12
- .replace('src/data/clients/', 'src/access/sdks/')
13
- .replace('src/data/', 'src/access/');
14
-
15
- return {
16
- contents,
17
- relativeFilePath: newPath,
18
- };
19
- };
@@ -1,17 +0,0 @@
1
- import { FileCheckType, type FileFixFunction } from 'declapract';
2
-
3
- // if files exist in src/domain/, this is a bad practice
4
- export const check = FileCheckType.EXISTS;
5
-
6
- export const fix: FileFixFunction = (contents, context) => {
7
- // move src/domain/objects/* to src/domain.objects/*
8
- // move src/domain/* to src/domain.objects/*
9
- const newPath = context.relativeFilePath
10
- .replace('src/domain/objects/', 'src/domain.objects/')
11
- .replace('src/domain/', 'src/domain.objects/');
12
-
13
- return {
14
- contents,
15
- relativeFilePath: newPath,
16
- };
17
- };
@@ -1,3 +0,0 @@
1
- import { FileCheckType } from 'declapract';
2
-
3
- export const check = FileCheckType.EXISTS; // if a file exists with this path pattern, then it's bad practice
@@ -1,5 +0,0 @@
1
- {
2
- "scripts": {
3
- "test:unit": "@declapract{check.exists}"
4
- }
5
- }
@@ -1,70 +0,0 @@
1
- import type { FileCheckFunction, FileFixFunction } from 'declapract';
2
-
3
- /**
4
- * .what = detects unsafe shell variable references in test scripts
5
- *
6
- * .why = unsafe shell variables cause bugs:
7
- * - unquoted `[ -n $VAR ]` becomes `[ -n ]` when VAR is unset → returns TRUE
8
- * - quoted `[ -n "$VAR" ]` fails with `set -u` (unbound variable error)
9
- * - both caused CI issues: snapshots silently passed or workflows failed
10
- *
11
- * .pattern:
12
- * - bad: `$([ -n $RESNAP ] && ...)` (unquoted)
13
- * - bad: `$([ -n "$RESNAP" ] && ...)` (quoted without default)
14
- * - good: `$([ -n "${RESNAP:-}" ] && ...)` (quoted with default)
15
- */
16
-
17
- const VARS = ['RESNAP', 'THOROUGH', 'CI', 'ECHO'];
18
-
19
- const UNSAFE_VAR_PATTERNS = VARS.flatMap((v) => [
20
- // unquoted: [ -n $VAR ] or [ -z $VAR ]
21
- new RegExp(`\\[ -n \\$${v} \\]`, 'g'),
22
- new RegExp(`\\[ -z \\$${v} \\]`, 'g'),
23
- // quoted without default: [ -n "$VAR" ] or [ -z "$VAR" ]
24
- // in JSON this appears as: [ -n \"$VAR\" ] or [ -z \"$VAR\" ]
25
- // but NOT [ -n "${VAR:-}" ] (the safe form)
26
- new RegExp(`\\[ -n \\\\"\\$${v}\\\\" \\]`, 'g'),
27
- new RegExp(`\\[ -z \\\\"\\$${v}\\\\" \\]`, 'g'),
28
- ]);
29
-
30
- export const check: FileCheckFunction = (contents) => {
31
- if (!contents) throw new Error('no contents');
32
-
33
- // check if any unsafe patterns exist
34
- const hasUnsafeVars = UNSAFE_VAR_PATTERNS.some((pattern) =>
35
- pattern.test(contents),
36
- );
37
-
38
- if (hasUnsafeVars) return; // bad practice detected
39
- throw new Error('no unsafe shell variables found');
40
- };
41
-
42
- export const fix: FileFixFunction = (contents) => {
43
- if (!contents) return { contents };
44
-
45
- let fixed = contents;
46
-
47
- // fix all unsafe patterns to use ${VAR:-} syntax
48
- for (const v of VARS) {
49
- // unquoted → quoted with default
50
- fixed = fixed.replace(
51
- new RegExp(`\\[ -n \\$${v} \\]`, 'g'),
52
- `[ -n "\${${v}:-}" ]`,
53
- );
54
- fixed = fixed.replace(
55
- new RegExp(`\\[ -z \\$${v} \\]`, 'g'),
56
- `[ -z "\${${v}:-}" ]`,
57
- );
58
- // quoted without default → quoted with default (JSON-escaped quotes)
59
- fixed = fixed.replace(
60
- new RegExp(`\\[ -n \\\\"\\$${v}\\\\" \\]`, 'g'),
61
- `[ -n \\"\${${v}:-}\\" ]`,
62
- );
63
- fixed = fixed.replace(
64
- new RegExp(`\\[ -z \\\\"\\$${v}\\\\" \\]`, 'g'),
65
- `[ -z \\"\${${v}:-}\\" ]`,
66
- );
67
- }
68
-
69
- return { contents: fixed };
70
- };