declapract-typescript-ehmpathy 0.47.20 → 0.47.22
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/dist/practices/git/best-practice/.gitattributes +5 -1
- package/dist/practices/git/best-practice/.gitattributes.declapract.ts +53 -26
- package/dist/practices/husky/best-practice/.husky/check.lockfile.sh +4 -0
- package/dist/practices/tests/bad-practices/old-acceptance-dir-location/.declapract.readme.md +3 -3
- package/dist/practices/tests/bad-practices/old-acceptance-dir-location/accept.blackbox/<star><star>/<star>.ts.declapract.ts +19 -0
- package/package.json +1 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
# exclude package locks from git diff; https://stackoverflow.com/a/72834452/3068233
|
|
2
|
-
pnpm-lock.
|
|
2
|
+
pnpm-lock.yaml -diff
|
|
3
3
|
package-lock.json -diff
|
|
4
|
+
|
|
5
|
+
# auto-resolve lock file conflicts by taking theirs; run install after merge
|
|
6
|
+
pnpm-lock.yaml merge=theirs
|
|
7
|
+
package-lock.json merge=theirs
|
|
@@ -6,44 +6,50 @@ import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
|
6
6
|
export const check: FileCheckType = FileCheckType.CONTAINS;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* sections of gitattributes entries to ensure exist
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const SECTIONS = [
|
|
12
|
+
{
|
|
13
|
+
header:
|
|
14
|
+
'# exclude package locks from git diff; https://stackoverflow.com/a/72834452/3068233',
|
|
15
|
+
entries: ['pnpm-lock.yaml -diff', 'package-lock.json -diff'],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
header:
|
|
19
|
+
'# auto-resolve lock file conflicts by taking theirs; run install after merge',
|
|
20
|
+
entries: ['pnpm-lock.yaml merge=theirs', 'package-lock.json merge=theirs'],
|
|
21
|
+
},
|
|
22
|
+
];
|
|
13
23
|
|
|
14
24
|
/**
|
|
15
|
-
*
|
|
25
|
+
* ensures a section with header and entries exists in the content
|
|
16
26
|
*/
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const fix: FileFixFunction = (contents) => {
|
|
23
|
-
// if no contents, create the file with the header and entries
|
|
24
|
-
if (!contents) {
|
|
25
|
-
return { contents: [HEADER, ...ENTRIES].join('\n') + '\n' };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const lines = contents.split('\n');
|
|
27
|
+
const ensureSection = (
|
|
28
|
+
content: string,
|
|
29
|
+
section: { header: string; entries: string[] },
|
|
30
|
+
): string => {
|
|
31
|
+
const lines = content.split('\n');
|
|
29
32
|
|
|
30
33
|
// find the header line index
|
|
31
|
-
const headerIndex = lines.findIndex((line) => line.trim() ===
|
|
34
|
+
const headerIndex = lines.findIndex((line) => line.trim() === section.header);
|
|
32
35
|
|
|
33
36
|
// if header not found, append the whole section at the end
|
|
34
37
|
if (headerIndex === -1) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
return (
|
|
39
|
+
content.trimEnd() +
|
|
40
|
+
'\n\n' +
|
|
41
|
+
[section.header, ...section.entries].join('\n') +
|
|
42
|
+
'\n'
|
|
43
|
+
);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
// find which entries are missing
|
|
41
|
-
const missingEntries =
|
|
46
|
+
// find which entries are missing
|
|
47
|
+
const missingEntries = section.entries.filter(
|
|
48
|
+
(entry) => !content.includes(entry),
|
|
49
|
+
);
|
|
42
50
|
|
|
43
51
|
// if no missing entries, nothing to fix
|
|
44
|
-
if (missingEntries.length === 0)
|
|
45
|
-
return { contents };
|
|
46
|
-
}
|
|
52
|
+
if (missingEntries.length === 0) return content;
|
|
47
53
|
|
|
48
54
|
// insert missing entries right after the header
|
|
49
55
|
const newLines = [
|
|
@@ -52,5 +58,26 @@ export const fix: FileFixFunction = (contents) => {
|
|
|
52
58
|
...lines.slice(headerIndex + 1),
|
|
53
59
|
];
|
|
54
60
|
|
|
55
|
-
return
|
|
61
|
+
return newLines.join('\n');
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* fix by ensuring all sections are present with their entries
|
|
66
|
+
*/
|
|
67
|
+
export const fix: FileFixFunction = (contents) => {
|
|
68
|
+
// if no contents, create the file with all sections
|
|
69
|
+
if (!contents) {
|
|
70
|
+
const allSections = SECTIONS.map((s) =>
|
|
71
|
+
[s.header, ...s.entries].join('\n'),
|
|
72
|
+
).join('\n\n');
|
|
73
|
+
return { contents: allSections + '\n' };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ensure each section exists
|
|
77
|
+
let result = contents;
|
|
78
|
+
for (const section of SECTIONS) {
|
|
79
|
+
result = ensureSection(result, section);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { contents: result };
|
|
56
83
|
};
|
|
@@ -8,3 +8,7 @@ changed () {
|
|
|
8
8
|
if changed 'package-lock.json'; then
|
|
9
9
|
echo "📦 package-lock.json changed. Run 'npm install' to update your locally installed dependencies."
|
|
10
10
|
fi
|
|
11
|
+
|
|
12
|
+
if changed 'pnpm-lock.yaml'; then
|
|
13
|
+
echo "📦 pnpm-lock.yaml changed. Run 'pnpm install' to update your locally installed dependencies."
|
|
14
|
+
fi
|
package/dist/practices/tests/bad-practices/old-acceptance-dir-location/.declapract.readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## .what
|
|
4
4
|
|
|
5
|
-
detects test files located in `acceptance/`
|
|
5
|
+
detects test files located in `acceptance/` or `accept.blackbox/` directories and migrates them to `blackbox/`.
|
|
6
6
|
|
|
7
7
|
## .why
|
|
8
8
|
|
|
@@ -11,11 +11,11 @@ the term "blackbox" makes the testing philosophy explicit:
|
|
|
11
11
|
- no access to internal implementation details
|
|
12
12
|
- tests validate behavior from the caller's perspective
|
|
13
13
|
|
|
14
|
-
the rename from `acceptance/` to `blackbox/` clarifies this intent.
|
|
14
|
+
the rename from `acceptance/` or `accept.blackbox/` to `blackbox/` clarifies this intent and simplifies the naming.
|
|
15
15
|
|
|
16
16
|
## .fix
|
|
17
17
|
|
|
18
|
-
moves all files from `acceptance/` to `blackbox/` while preserving the directory structure.
|
|
18
|
+
moves all files from `acceptance/` or `accept.blackbox/` to `blackbox/` while preserving the directory structure.
|
|
19
19
|
|
|
20
20
|
## .note
|
|
21
21
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileCheckType, type FileFixFunction } from 'declapract';
|
|
2
|
+
|
|
3
|
+
export const check = FileCheckType.EXISTS; // if any ts files exist in accept.blackbox/, flag as bad practice
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* .what = moves ts files from accept.blackbox/ to blackbox/
|
|
7
|
+
* .why = blackbox/ naming is simpler and makes the testing philosophy explicit
|
|
8
|
+
*/
|
|
9
|
+
export const fix: FileFixFunction = (contents, context) => {
|
|
10
|
+
// move from accept.blackbox/ to blackbox/
|
|
11
|
+
const newPath = context.relativeFilePath.replace(
|
|
12
|
+
/^accept\.blackbox\//,
|
|
13
|
+
'blackbox/',
|
|
14
|
+
);
|
|
15
|
+
return {
|
|
16
|
+
contents: contents ?? null,
|
|
17
|
+
relativeFilePath: newPath,
|
|
18
|
+
};
|
|
19
|
+
};
|
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.
|
|
5
|
+
"version": "0.47.22",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"repository": "ehmpathy/declapract-typescript-ehmpathy",
|