declapract-typescript-ehmpathy 0.47.36 → 0.47.38
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.
|
@@ -101,26 +101,26 @@ const ensureSection = (
|
|
|
101
101
|
): string => {
|
|
102
102
|
const lines = content.split('\n');
|
|
103
103
|
|
|
104
|
+
// find which entries are absent from the content
|
|
105
|
+
const entriesAbsent = section.entries.latest.filter(
|
|
106
|
+
(entry) => !content.includes(entry),
|
|
107
|
+
);
|
|
108
|
+
|
|
104
109
|
// find the header line index
|
|
105
110
|
const headerIndex = lines.findIndex(
|
|
106
111
|
(line) => line.trim() === section.header.latest,
|
|
107
112
|
);
|
|
108
113
|
|
|
109
|
-
// if header not found, append
|
|
114
|
+
// if header not found, append header and only absent entries
|
|
110
115
|
if (headerIndex === -1) {
|
|
111
116
|
return (
|
|
112
117
|
content.trimEnd() +
|
|
113
118
|
'\n\n' +
|
|
114
|
-
[section.header.latest, ...
|
|
119
|
+
[section.header.latest, ...entriesAbsent].join('\n') +
|
|
115
120
|
'\n'
|
|
116
121
|
);
|
|
117
122
|
}
|
|
118
123
|
|
|
119
|
-
// find which entries are absent
|
|
120
|
-
const entriesAbsent = section.entries.latest.filter(
|
|
121
|
-
(entry) => !content.includes(entry),
|
|
122
|
-
);
|
|
123
|
-
|
|
124
124
|
// if all entries present, no fix required
|
|
125
125
|
if (entriesAbsent.length === 0) return content;
|
|
126
126
|
|
|
@@ -2,7 +2,10 @@ import type { FileCheckFunction, FileFixFunction } from 'declapract';
|
|
|
2
2
|
import { dedupe } from 'domain-objects';
|
|
3
3
|
import expect from 'expect';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* ignores that can be sorted alphabetically (no order dependencies)
|
|
7
|
+
*/
|
|
8
|
+
const ignoresSortable = [
|
|
6
9
|
'*.log',
|
|
7
10
|
'*.tsbuildinfo',
|
|
8
11
|
'.artifact', // deployment artifacts from `simple-artifact-builder` are produced here
|
|
@@ -17,15 +20,38 @@ const expectedIgnores = [
|
|
|
17
20
|
'*.bak.*', // backup files
|
|
18
21
|
'coverage',
|
|
19
22
|
'dist',
|
|
20
|
-
'node_modules',
|
|
21
23
|
].sort();
|
|
22
24
|
|
|
25
|
+
/**
|
|
26
|
+
* ignores that must appear in a specific order (negations must follow their targets)
|
|
27
|
+
*
|
|
28
|
+
* note
|
|
29
|
+
* - node_modules under .test* dirs are test fixtures (cloned repos via genTempDir)
|
|
30
|
+
* - gitignore negation requires the negated pattern to come after the original
|
|
31
|
+
*/
|
|
32
|
+
const ignoresOrdered = [
|
|
33
|
+
'node_modules',
|
|
34
|
+
'!.test*/**/node_modules',
|
|
35
|
+
'!.test*/**/node_modules/**',
|
|
36
|
+
];
|
|
37
|
+
|
|
23
38
|
const defineExpectedContents = (contents: string | null): string => {
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
// parse ignores from file
|
|
40
|
+
const ignoresFromFile = contents ? contents.split('\n') : [];
|
|
41
|
+
|
|
42
|
+
// separate into sortable vs ordered
|
|
43
|
+
const orderedPatterns = new Set(ignoresOrdered);
|
|
44
|
+
const ignoresFromFileSortable = ignoresFromFile.filter(
|
|
45
|
+
(line) => !!line && !orderedPatterns.has(line),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// combine and sort the sortable ignores
|
|
49
|
+
const sortedIgnores = dedupe([...ignoresFromFileSortable, ...ignoresSortable])
|
|
50
|
+
.sort()
|
|
51
|
+
.filter((line) => !!line);
|
|
52
|
+
|
|
53
|
+
// append ordered ignores at the end (order preserved)
|
|
54
|
+
return [...sortedIgnores, ...ignoresOrdered, ''].join('\n');
|
|
29
55
|
};
|
|
30
56
|
|
|
31
57
|
export const check: FileCheckFunction = (contents) => {
|
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.38",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"repository": "ehmpathy/declapract-typescript-ehmpathy",
|