@codest0411/pathport 0.0.0-stage → 0.1.0
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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +129 -2
- package/bin/pathport.js +7 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +169 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/reporters/json.d.ts +6 -0
- package/dist/reporters/json.d.ts.map +1 -0
- package/dist/reporters/json.js +7 -0
- package/dist/reporters/json.js.map +1 -0
- package/dist/reporters/text.d.ts +6 -0
- package/dist/reporters/text.d.ts.map +1 -0
- package/dist/reporters/text.js +45 -0
- package/dist/reporters/text.js.map +1 -0
- package/dist/rules/collisions.d.ts +4 -0
- package/dist/rules/collisions.d.ts.map +1 -0
- package/dist/rules/collisions.js +147 -0
- package/dist/rules/collisions.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +46 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/paths.d.ts +4 -0
- package/dist/rules/paths.d.ts.map +1 -0
- package/dist/rules/paths.js +111 -0
- package/dist/rules/paths.js.map +1 -0
- package/dist/rules/symlinks.d.ts +4 -0
- package/dist/rules/symlinks.d.ts.map +1 -0
- package/dist/rules/symlinks.js +60 -0
- package/dist/rules/symlinks.js.map +1 -0
- package/dist/rules/windows.d.ts +4 -0
- package/dist/rules/windows.d.ts.map +1 -0
- package/dist/rules/windows.js +85 -0
- package/dist/rules/windows.js.map +1 -0
- package/dist/scanner.d.ts +12 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +248 -0
- package/dist/scanner.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +65 -4
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export const COLLISION_RULES = [
|
|
2
|
+
{
|
|
3
|
+
id: "PP004",
|
|
4
|
+
name: "case-insensitive-collision",
|
|
5
|
+
defaultSeverity: "error",
|
|
6
|
+
platforms: ["windows", "macos"],
|
|
7
|
+
description: "Flags sibling entries in the same directory whose names differ only by letter case.",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "PP005",
|
|
11
|
+
name: "unicode-normalization-collision",
|
|
12
|
+
defaultSeverity: "error",
|
|
13
|
+
platforms: ["macos"],
|
|
14
|
+
description: "Flags sibling entries in the same directory whose names are identical after Unicode NFC normalization but differ in raw code points (e.g., NFC vs NFD).",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "PP006",
|
|
18
|
+
name: "git-case-collision-risk",
|
|
19
|
+
defaultSeverity: "warning",
|
|
20
|
+
platforms: ["linux"],
|
|
21
|
+
description: "Warns on Linux targets when sibling entries differ only by case, creating Git checkout risks on Windows or macOS.",
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
export function checkDirectoryCollisions(entries, platform) {
|
|
25
|
+
const diagnostics = [];
|
|
26
|
+
// Group entries by parent directory so we only compare siblings.
|
|
27
|
+
const byParent = new Map();
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const list = byParent.get(entry.parentRelativePath);
|
|
30
|
+
if (list !== undefined) {
|
|
31
|
+
list.push(entry);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
byParent.set(entry.parentRelativePath, [entry]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const checkCaseAsError = platform === "all" || platform === "windows" || platform === "macos";
|
|
38
|
+
const checkCaseAsGitWarning = platform === "linux";
|
|
39
|
+
const checkUnicodeNorm = platform === "all" || platform === "macos";
|
|
40
|
+
for (const siblings of byParent.values()) {
|
|
41
|
+
if (siblings.length < 2) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// 1. Case-insensitive collision detection (within same directory).
|
|
45
|
+
const caseGroups = new Map();
|
|
46
|
+
for (const entry of siblings) {
|
|
47
|
+
const folded = entry.name.toLowerCase();
|
|
48
|
+
const group = caseGroups.get(folded);
|
|
49
|
+
if (group !== undefined) {
|
|
50
|
+
group.push(entry);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
caseGroups.set(folded, [entry]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const group of caseGroups.values()) {
|
|
57
|
+
if (group.length < 2) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Verify they are not already identical strings (impossible in one POSIX dir, possible only if synthetic)
|
|
61
|
+
const uniqueNames = new Set(group.map((e) => e.name));
|
|
62
|
+
if (uniqueNames.size < 2) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const sorted = [...group].sort((a, b) => a.relativePath < b.relativePath ? -1 : a.relativePath > b.relativePath ? 1 : 0);
|
|
66
|
+
const primary = sorted[0];
|
|
67
|
+
if (primary === undefined) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const others = sorted.slice(1).map((e) => e.relativePath);
|
|
71
|
+
const allNames = sorted.map((e) => `'${e.name}'`).join(", ");
|
|
72
|
+
if (checkCaseAsError) {
|
|
73
|
+
const platforms = platform === "windows"
|
|
74
|
+
? ["windows"]
|
|
75
|
+
: platform === "macos"
|
|
76
|
+
? ["macos"]
|
|
77
|
+
: ["windows", "macos"];
|
|
78
|
+
diagnostics.push({
|
|
79
|
+
ruleId: "PP004",
|
|
80
|
+
ruleName: "case-insensitive-collision",
|
|
81
|
+
severity: "error",
|
|
82
|
+
platforms,
|
|
83
|
+
path: primary.relativePath,
|
|
84
|
+
relatedPaths: others,
|
|
85
|
+
message: `Case-insensitive collision between sibling entries: ${allNames}.`,
|
|
86
|
+
explanation: "Default Windows (NTFS) and macOS (APFS/HFS+) filesystems are case-insensitive. Checking out or extracting these entries on those platforms can cause one file or directory to overwrite or shadow another.",
|
|
87
|
+
remediation: "Rename one of the colliding entries so all sibling names remain distinct when compared case-insensitively (use `git mv` with a temporary name if renaming on a case-insensitive host).",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (checkCaseAsGitWarning) {
|
|
91
|
+
diagnostics.push({
|
|
92
|
+
ruleId: "PP006",
|
|
93
|
+
ruleName: "git-case-collision-risk",
|
|
94
|
+
severity: "warning",
|
|
95
|
+
platforms: ["linux"],
|
|
96
|
+
path: primary.relativePath,
|
|
97
|
+
relatedPaths: others,
|
|
98
|
+
message: `Git cross-platform case-collision risk between sibling entries: ${allNames}.`,
|
|
99
|
+
explanation: "While case-sensitive Linux filesystems (such as ext4) allow names differing only by case, cloning or checking out this repository via Git on default Windows or macOS filesystems will cause a case collision.",
|
|
100
|
+
remediation: "If this repository may be cloned on Windows or macOS, rename one of the entries so they differ beyond letter case.",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 2. Unicode NFC/NFD normalization collision detection.
|
|
105
|
+
if (checkUnicodeNorm) {
|
|
106
|
+
const normGroups = new Map();
|
|
107
|
+
for (const entry of siblings) {
|
|
108
|
+
const normalized = entry.name.normalize("NFC");
|
|
109
|
+
const group = normGroups.get(normalized);
|
|
110
|
+
if (group !== undefined) {
|
|
111
|
+
group.push(entry);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
normGroups.set(normalized, [entry]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const group of normGroups.values()) {
|
|
118
|
+
if (group.length < 2) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const uniqueRawNames = new Set(group.map((e) => e.name));
|
|
122
|
+
if (uniqueRawNames.size < 2) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const sorted = [...group].sort((a, b) => a.relativePath < b.relativePath ? -1 : a.relativePath > b.relativePath ? 1 : 0);
|
|
126
|
+
const primary = sorted[0];
|
|
127
|
+
if (primary === undefined) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const others = sorted.slice(1).map((e) => e.relativePath);
|
|
131
|
+
diagnostics.push({
|
|
132
|
+
ruleId: "PP005",
|
|
133
|
+
ruleName: "unicode-normalization-collision",
|
|
134
|
+
severity: "error",
|
|
135
|
+
platforms: ["macos"],
|
|
136
|
+
path: primary.relativePath,
|
|
137
|
+
relatedPaths: others,
|
|
138
|
+
message: `Unicode normalization collision (NFC/NFD) at '${primary.relativePath}' (${sorted.length} variants).`,
|
|
139
|
+
explanation: "macOS APFS and HFS+ treat canonically equivalent Unicode sequences (such as precomposed NFC and decomposed NFD) as the same file on disk, whereas Linux ext4 treats them as distinct byte sequences.",
|
|
140
|
+
remediation: "Consolidate to a single NFC-normalized filename and remove duplicate normalization variants.",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return diagnostics;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=collisions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collisions.js","sourceRoot":"","sources":["../../src/rules/collisions.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAA8B;IACxD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,4BAA4B;QAClC,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;QAC/B,WAAW,EACT,qFAAqF;KACxF;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,iCAAiC;QACvC,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,CAAC,OAAO,CAAC;QACpB,WAAW,EACT,yJAAyJ;KAC5J;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,yBAAyB;QAC/B,eAAe,EAAE,SAAS;QAC1B,SAA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,QAAQ,EAAE,iCAAiC;oBAC3C,QAAQ,EAAE,OAAO;oBACjB,SAAS,EAAE,CAAC,OAAO,CAAC;oBACpB,IAAI,EAAE,OAAO,CAAC,YAAY;oBAC1B,YAAY,EAAE,MAAM;oBACpB,OAAO,EAAE,iDAAiD,OAAO,CAAC,YAAY,MAAM,MAAM,CAAC,MAAM,aAAa;oBAC9G,WAAW,EACT,sMAAsM;oBACxM,WAAW,EACT,8FAA8F;iBACjG,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Diagnostic, Platform, RuleDefinition, ScannedEntry } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Stable registry of all PathPort rules ordered by Rule ID.
|
|
4
|
+
*/
|
|
5
|
+
export declare const RULE_REGISTRY: readonly RuleDefinition[];
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates all applicable rules for the target platform against the scanned entries.
|
|
8
|
+
*/
|
|
9
|
+
export declare function evaluateRules(entries: readonly ScannedEntry[], platform: Platform): Diagnostic[];
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMtF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,cAAc,EAKT,CAAC;AAE3C;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,UAAU,EAAE,CAgChG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { COLLISION_RULES, checkDirectoryCollisions } from "./collisions.js";
|
|
2
|
+
import { PATH_RULES, checkPathEntry } from "./paths.js";
|
|
3
|
+
import { SYMLINK_RULES, checkSymlinkEntry } from "./symlinks.js";
|
|
4
|
+
import { WINDOWS_RULES, checkWindowsEntry } from "./windows.js";
|
|
5
|
+
/**
|
|
6
|
+
* Stable registry of all PathPort rules ordered by Rule ID.
|
|
7
|
+
*/
|
|
8
|
+
export const RULE_REGISTRY = [
|
|
9
|
+
...WINDOWS_RULES,
|
|
10
|
+
...COLLISION_RULES,
|
|
11
|
+
...PATH_RULES,
|
|
12
|
+
...SYMLINK_RULES,
|
|
13
|
+
].sort((a, b) => a.id.localeCompare(b.id));
|
|
14
|
+
/**
|
|
15
|
+
* Evaluates all applicable rules for the target platform against the scanned entries.
|
|
16
|
+
*/
|
|
17
|
+
export function evaluateRules(entries, platform) {
|
|
18
|
+
const diagnostics = [];
|
|
19
|
+
const checkWin = platform === "all" || platform === "windows";
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (checkWin) {
|
|
22
|
+
diagnostics.push(...checkWindowsEntry(entry));
|
|
23
|
+
}
|
|
24
|
+
diagnostics.push(...checkPathEntry(entry, platform));
|
|
25
|
+
diagnostics.push(...checkSymlinkEntry(entry));
|
|
26
|
+
}
|
|
27
|
+
diagnostics.push(...checkDirectoryCollisions(entries, platform));
|
|
28
|
+
// Deterministic ordering: severity (error > warning > info), then path, then ruleId.
|
|
29
|
+
const severityRank = {
|
|
30
|
+
error: 0,
|
|
31
|
+
warning: 1,
|
|
32
|
+
info: 2,
|
|
33
|
+
};
|
|
34
|
+
diagnostics.sort((a, b) => {
|
|
35
|
+
const sevDiff = severityRank[a.severity] - severityRank[b.severity];
|
|
36
|
+
if (sevDiff !== 0) {
|
|
37
|
+
return sevDiff;
|
|
38
|
+
}
|
|
39
|
+
if (a.path !== b.path) {
|
|
40
|
+
return a.path < b.path ? -1 : 1;
|
|
41
|
+
}
|
|
42
|
+
return a.ruleId < b.ruleId ? -1 : a.ruleId > b.ruleId ? 1 : 0;
|
|
43
|
+
});
|
|
44
|
+
return diagnostics;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD,GAAG,aAAa;IAChB,GAAG,eAAe;IAClB,GAAG,UAAU;IACb,GAAG,aAAa;CACjB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgC,EAAE,QAAkB;IAChF,MAAM,WAAW,GAAiB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,SAAS,CAAC;IAE9D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,QAAQ,EAAE,CAAC;YACb,WAAW,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrD,WAAW,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,WAAW,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEjE,qFAAqF;IACrF,MAAM,YAAY,GAA2C;QAC3D,KAAK,EAAE,CAAC;QACR,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,CAAC;KACR,CAAC;IACF,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACpE,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;YAClB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Diagnostic, Platform, RuleDefinition, ScannedEntry } from "../types.js";
|
|
2
|
+
export declare const PATH_RULES: readonly RuleDefinition[];
|
|
3
|
+
export declare function checkPathEntry(entry: ScannedEntry, platform: Platform): Diagnostic[];
|
|
4
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/rules/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoBtF,eAAO,MAAM,UAAU,EAAE,SAAS,cAAc,EAuB/C,CAAC;AAOF,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,GAAG,UAAU,EAAE,CA+EpF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASCII control characters (0x00-0x1F) and DEL (0x7F).
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line no-control-regex
|
|
5
|
+
const CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/g;
|
|
6
|
+
/**
|
|
7
|
+
* Conservative relative-path threshold for Windows legacy MAX_PATH (260 chars),
|
|
8
|
+
* leaving room for a typical checkout prefix like "C:\Users\username\repos\project\".
|
|
9
|
+
*/
|
|
10
|
+
const WINDOWS_RELATIVE_PATH_WARN_LEN = 220;
|
|
11
|
+
/**
|
|
12
|
+
* Standard single-component byte limit on Linux (ext4/XFS/Btrfs) and macOS (APFS),
|
|
13
|
+
* and UTF-16 code unit limit (255) on Windows NTFS.
|
|
14
|
+
*/
|
|
15
|
+
const MAX_SEGMENT_BYTES = 255;
|
|
16
|
+
export const PATH_RULES = [
|
|
17
|
+
{
|
|
18
|
+
id: "PP007",
|
|
19
|
+
name: "macos-colon-character",
|
|
20
|
+
defaultSeverity: "warning",
|
|
21
|
+
platforms: ["macos"],
|
|
22
|
+
description: "Flags colons (:) in names, which macOS Finder and HFS+ map/disallow.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "PP008",
|
|
26
|
+
name: "control-character",
|
|
27
|
+
defaultSeverity: "warning",
|
|
28
|
+
platforms: ["windows", "macos", "linux"],
|
|
29
|
+
description: "Flags ASCII control characters (0x00-0x1F, 0x7F) in file or directory names.",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "PP009",
|
|
33
|
+
name: "path-length-limit",
|
|
34
|
+
defaultSeverity: "warning",
|
|
35
|
+
platforms: ["windows", "macos", "linux"],
|
|
36
|
+
description: "Flags path segments exceeding 255 bytes/code units and relative paths approaching Windows MAX_PATH (260 chars).",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
function formatCodePoint(ch) {
|
|
40
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
41
|
+
return `0x${code.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
42
|
+
}
|
|
43
|
+
export function checkPathEntry(entry, platform) {
|
|
44
|
+
const diagnostics = [];
|
|
45
|
+
const { name, relativePath } = entry;
|
|
46
|
+
// PP007: macOS colon character (Windows already flags ':' via PP003, so emit PP007 for macos or all).
|
|
47
|
+
if ((platform === "macos" || platform === "all") && name.includes(":")) {
|
|
48
|
+
diagnostics.push({
|
|
49
|
+
ruleId: "PP007",
|
|
50
|
+
ruleName: "macos-colon-character",
|
|
51
|
+
severity: "warning",
|
|
52
|
+
platforms: ["macos"],
|
|
53
|
+
path: relativePath,
|
|
54
|
+
message: `Name '${name}' contains a colon (':'), which is problematic on macOS.`,
|
|
55
|
+
explanation: "macOS Finder and Cocoa APIs disallow colons in filenames and map ':' to '/' in legacy HFS+/Carbon layers, causing confusing display or tool failures.",
|
|
56
|
+
remediation: `Replace ':' in '${name}' with '-' or '_'.`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// PP008: ASCII control characters (0x00-0x1F, 0x7F).
|
|
60
|
+
// Note: When platform is "windows", 0x00-0x1F is already flagged by PP003; we still flag 0x7F or non-windows platforms here.
|
|
61
|
+
const controlMatches = name.match(CONTROL_CHAR_RE);
|
|
62
|
+
if (controlMatches !== null && controlMatches.length > 0) {
|
|
63
|
+
const filtered = platform === "windows"
|
|
64
|
+
? controlMatches.filter((c) => c.codePointAt(0) === 0x7f)
|
|
65
|
+
: controlMatches;
|
|
66
|
+
if (filtered.length > 0) {
|
|
67
|
+
const hasNul = filtered.some((c) => c.codePointAt(0) === 0x00);
|
|
68
|
+
const codes = [...new Set(filtered)].map(formatCodePoint).join(", ");
|
|
69
|
+
diagnostics.push({
|
|
70
|
+
ruleId: "PP008",
|
|
71
|
+
ruleName: "control-character",
|
|
72
|
+
severity: hasNul ? "error" : "warning",
|
|
73
|
+
platforms: ["windows", "macos", "linux"],
|
|
74
|
+
path: relativePath,
|
|
75
|
+
message: `Name '${name}' contains ASCII control character(s): ${codes}.`,
|
|
76
|
+
explanation: "Control characters such as newlines, tabs, ESC, or DEL break shell scripts, CI logs, and Git tooling, and NUL (0x00) is forbidden by POSIX and Windows kernels.",
|
|
77
|
+
remediation: `Rename '${name}' to remove all control characters (${codes}).`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// PP009: Segment length (> 255 bytes / UTF-16 code units) and Windows MAX_PATH warning.
|
|
82
|
+
const utf8Bytes = Buffer.byteLength(name, "utf8");
|
|
83
|
+
const utf16Units = name.length;
|
|
84
|
+
if (utf8Bytes > MAX_SEGMENT_BYTES || utf16Units > MAX_SEGMENT_BYTES) {
|
|
85
|
+
diagnostics.push({
|
|
86
|
+
ruleId: "PP009",
|
|
87
|
+
ruleName: "path-length-limit",
|
|
88
|
+
severity: "error",
|
|
89
|
+
platforms: ["windows", "macos", "linux"],
|
|
90
|
+
path: relativePath,
|
|
91
|
+
message: `Segment '${name}' exceeds 255-unit filesystem component limit (${utf8Bytes} UTF-8 bytes, ${utf16Units} UTF-16 units).`,
|
|
92
|
+
explanation: "Most common filesystems (ext4, APFS, NTFS) enforce a 255-byte or 255-UTF-16-code-unit limit per individual filename or directory component.",
|
|
93
|
+
remediation: "Shorten the file or directory name to well under 255 bytes.",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else if ((platform === "windows" || platform === "all") &&
|
|
97
|
+
relativePath.length >= WINDOWS_RELATIVE_PATH_WARN_LEN) {
|
|
98
|
+
diagnostics.push({
|
|
99
|
+
ruleId: "PP009",
|
|
100
|
+
ruleName: "path-length-limit",
|
|
101
|
+
severity: "warning",
|
|
102
|
+
platforms: ["windows"],
|
|
103
|
+
path: relativePath,
|
|
104
|
+
message: `Relative path length (${relativePath.length} chars) may exceed Windows legacy MAX_PATH (260 chars) after checkout.`,
|
|
105
|
+
explanation: "Depending on the checkout directory prefix, Windows tools without LongPathsEnabled or Git without core.longpaths=true can fail when full paths reach 260 characters.",
|
|
106
|
+
remediation: "Shorten deeply nested directory or file names so relative paths stay well below 220 characters.",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return diagnostics;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/rules/paths.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,4CAA4C;AAC5C,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C;;;GAGG;AACH,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAE3C;;;GAGG;AACH,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,CAAC,MAAM,UAAU,GAA8B;IACnD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,uBAAuB;QAC7B,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,CAAC,OAAO,CAAC;QACpB,WAAW,EAAE,sEAAsE;KACpF;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,mBAAmB;QACzB,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC;QACxC,WAAW,EAAE,8EAA8E;KAC5F;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,mBAAmB;QACzB,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC;QACxC,WAAW,EACT,iHAAiH;KACpH;CACF,CAAC;AAEF,SAAS,eAAe,CAAC,EAAU;IACjC,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;IACL,CAAC;SAAM,IACL,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,KAAK,CAAC;QAC9C,YAAY,CAAC,MAAM,IAAI,8BAA8B,EACrD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,mBAAmB;YAC7B,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,CAAC,SAAS,CAAC;YACtB,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,yBAAyB,YAAY,CAAC,MAAM,wEAAwE;YAC7H,WAAW,EACT,sKAAsK;YACxK,WAAW,EACT,iGAAiG;SACpG,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symlinks.d.ts","sourceRoot":"","sources":["../../src/rules/symlinks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5E,eAAO,MAAM,aAAa,EAAE,SAAS,cAAc,EAelD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU,EAAE,CAmDnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const SYMLINK_RULES = [
|
|
2
|
+
{
|
|
3
|
+
id: "PP010",
|
|
4
|
+
name: "symlink-escapes-root",
|
|
5
|
+
defaultSeverity: "warning",
|
|
6
|
+
platforms: ["windows", "macos", "linux"],
|
|
7
|
+
description: "Flags symbolic links whose resolved target points outside the scan root.",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "PP011",
|
|
11
|
+
name: "symlink-loop-or-broken",
|
|
12
|
+
defaultSeverity: "warning",
|
|
13
|
+
platforms: ["windows", "macos", "linux"],
|
|
14
|
+
description: "Flags symbolic links that form a loop or point to a missing target.",
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
export function checkSymlinkEntry(entry) {
|
|
18
|
+
if (entry.kind !== "symlink") {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const diagnostics = [];
|
|
22
|
+
if (entry.symlinkEscapesRoot === true) {
|
|
23
|
+
diagnostics.push({
|
|
24
|
+
ruleId: "PP010",
|
|
25
|
+
ruleName: "symlink-escapes-root",
|
|
26
|
+
severity: "warning",
|
|
27
|
+
platforms: ["windows", "macos", "linux"],
|
|
28
|
+
path: entry.relativePath,
|
|
29
|
+
message: `Symbolic link '${entry.relativePath}' points outside the scan root (target: '${entry.symlinkTarget ?? "unknown"}').`,
|
|
30
|
+
explanation: "Symlinks escaping the repository root are non-portable across machines and CI environments, and may expose unexpected host paths if followed by build tools or archivers.",
|
|
31
|
+
remediation: "Replace the external symlink with a relative in-repository path or a regular file/configuration.",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (entry.symlinkLoop === true) {
|
|
35
|
+
diagnostics.push({
|
|
36
|
+
ruleId: "PP011",
|
|
37
|
+
ruleName: "symlink-loop-or-broken",
|
|
38
|
+
severity: "warning",
|
|
39
|
+
platforms: ["windows", "macos", "linux"],
|
|
40
|
+
path: entry.relativePath,
|
|
41
|
+
message: `Symbolic link '${entry.relativePath}' forms a symlink loop (target: '${entry.symlinkTarget ?? "unknown"}').`,
|
|
42
|
+
explanation: "Symlink cycles cause filesystem traversal tools and archivers to fail with ELOOP or recurse unexpectedly.",
|
|
43
|
+
remediation: "Break the symlink cycle by pointing to a non-cyclic target or removing the link.",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if (entry.symlinkBroken === true) {
|
|
47
|
+
diagnostics.push({
|
|
48
|
+
ruleId: "PP011",
|
|
49
|
+
ruleName: "symlink-loop-or-broken",
|
|
50
|
+
severity: "warning",
|
|
51
|
+
platforms: ["windows", "macos", "linux"],
|
|
52
|
+
path: entry.relativePath,
|
|
53
|
+
message: `Symbolic link '${entry.relativePath}' is broken (target: '${entry.symlinkTarget ?? "unknown"}').`,
|
|
54
|
+
explanation: "Dangling symlinks behave inconsistently across platforms and packaging tools (especially on Windows where symlinks may require Developer Mode or elevated privileges).",
|
|
55
|
+
remediation: "Update the symlink target to an existing in-repo path or remove the broken link.",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return diagnostics;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=symlinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symlinks.js","sourceRoot":"","sources":["../../src/rules/symlinks.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,sBAAsB;QAC5B,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC;QACxC,WAAW,EAAE,0EAA0E;KACxF;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,wBAAwB;QAC9B,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC;QACxC,WAAW,EAAE,qEAAqE;KACnF;CACF,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,KAAmB;IACnD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,EAAE,CAAC;QACtC,WAAW,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,sBAAsB;YAChC,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC;YACxC,IAAI,EAAE,KAAK,CAAC,YAAY;YACxB,OAAO,EAAE,kBAAkB,KAAK,CAAC,YAAY,4C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AAc,EAwBlD,CAAC;AAUF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU,EAAE,CAkDnE"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows Win32 reserved device names (case-insensitive, also reserved with any extension).
|
|
3
|
+
* Reference: Microsoft Learn "Naming Files, Paths, and Namespaces".
|
|
4
|
+
*/
|
|
5
|
+
const WINDOWS_RESERVED_NAME_RE = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
|
|
6
|
+
/**
|
|
7
|
+
* Characters forbidden in Windows Win32 filenames: < > : " / \ | ? * and ASCII 0x00-0x1F.
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
const WINDOWS_INVALID_CHAR_RE = /[<>:"/\\|?*\x00-\x1f]/g;
|
|
11
|
+
export const WINDOWS_RULES = [
|
|
12
|
+
{
|
|
13
|
+
id: "PP001",
|
|
14
|
+
name: "windows-reserved-name",
|
|
15
|
+
defaultSeverity: "error",
|
|
16
|
+
platforms: ["windows"],
|
|
17
|
+
description: "Flags Windows Win32 reserved device names (CON, PRN, AUX, NUL, COM1-COM9, LPT1-LPT9), including names with extensions.",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "PP002",
|
|
21
|
+
name: "windows-trailing-dot-or-space",
|
|
22
|
+
defaultSeverity: "error",
|
|
23
|
+
platforms: ["windows"],
|
|
24
|
+
description: "Flags file or directory names ending with a trailing dot (.) or space ( ).",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "PP003",
|
|
28
|
+
name: "windows-invalid-char",
|
|
29
|
+
defaultSeverity: "error",
|
|
30
|
+
platforms: ["windows"],
|
|
31
|
+
description: 'Flags characters forbidden in Windows Win32 filenames (< > : " / \\ | ? * and ASCII control characters 0x00-0x1F).',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
function formatControlOrChar(ch) {
|
|
35
|
+
const code = ch.codePointAt(0);
|
|
36
|
+
if (code !== undefined && (code < 0x20 || code === 0x7f)) {
|
|
37
|
+
return `0x${code.toString(16).toUpperCase().padStart(2, "0")}`;
|
|
38
|
+
}
|
|
39
|
+
return `'${ch}'`;
|
|
40
|
+
}
|
|
41
|
+
export function checkWindowsEntry(entry) {
|
|
42
|
+
const diagnostics = [];
|
|
43
|
+
const { name, relativePath } = entry;
|
|
44
|
+
if (WINDOWS_RESERVED_NAME_RE.test(name)) {
|
|
45
|
+
diagnostics.push({
|
|
46
|
+
ruleId: "PP001",
|
|
47
|
+
ruleName: "windows-reserved-name",
|
|
48
|
+
severity: "error",
|
|
49
|
+
platforms: ["windows"],
|
|
50
|
+
path: relativePath,
|
|
51
|
+
message: `Name '${name}' is a Windows reserved device name.`,
|
|
52
|
+
explanation: "Standard Windows Win32 APIs, Explorer, and many tools intercept CON, PRN, AUX, NUL, COM1-COM9, and LPT1-LPT9 (with or without extensions) as hardware device names rather than regular files.",
|
|
53
|
+
remediation: `Rename '${name}' to a non-reserved name (for example, prefix or suffix it, such as '${name}_file').`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (name.endsWith(".") || name.endsWith(" ")) {
|
|
57
|
+
const trailingKind = name.endsWith(".") ? "dot ('.')" : "space (' ')";
|
|
58
|
+
diagnostics.push({
|
|
59
|
+
ruleId: "PP002",
|
|
60
|
+
ruleName: "windows-trailing-dot-or-space",
|
|
61
|
+
severity: "error",
|
|
62
|
+
platforms: ["windows"],
|
|
63
|
+
path: relativePath,
|
|
64
|
+
message: `Name '${name}' ends with a trailing ${trailingKind}.`,
|
|
65
|
+
explanation: "Windows Win32 path normalization strips trailing spaces and periods from filenames, which can make files inaccessible, un-deletable, or collide with sibling names.",
|
|
66
|
+
remediation: `Remove the trailing ${trailingKind} from '${name}'.`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const invalidMatches = name.match(WINDOWS_INVALID_CHAR_RE);
|
|
70
|
+
if (invalidMatches !== null && invalidMatches.length > 0) {
|
|
71
|
+
const uniqueChars = [...new Set(invalidMatches)].map(formatControlOrChar).join(", ");
|
|
72
|
+
diagnostics.push({
|
|
73
|
+
ruleId: "PP003",
|
|
74
|
+
ruleName: "windows-invalid-char",
|
|
75
|
+
severity: "error",
|
|
76
|
+
platforms: ["windows"],
|
|
77
|
+
path: relativePath,
|
|
78
|
+
message: `Name '${name}' contains Windows-forbidden character(s): ${uniqueChars}.`,
|
|
79
|
+
explanation: 'Windows Win32 APIs forbid < > : " / \\ | ? * and ASCII control characters (0x00-0x1F) in file and directory names. Git checkouts and archive extractions on Windows can fail on these paths.',
|
|
80
|
+
remediation: `Replace or remove the forbidden character(s) (${uniqueChars}) in '${name}'.`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return diagnostics;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=windows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows.js","sourceRoot":"","sources":["../../src/rules/windows.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,wBAAwB,GAAG,+CAA+C,CAAC;AAEjF;;GAEG;AACH,4CAA4C;AAC5C,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEzD,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,uBAAuB;QAC7B,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,CAAC,SAAS,CAAC;QACtB,WAAW,EACT,wHAAwH;KAC3H;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,+BAA+B;QACrC,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,CAAC,SAAS,CAAC;QACtB,WAAW,EAAE,4EAA4E;KAC1F;IACD;QACE,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,sBAAsB;QAC5B,eAAe,EAAE,OAAO;QACxB,SAAS,EAAE,CAAC,SAAS,CAAC;Q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AA+B;YACzC,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,CAAC,SAAS,CAAC;YACtB,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,SAAS,IAAI,0BAA0B,YAAY,GAAG;YAC/D,WAAW,EACT,qKAAqK;YACvK,WAAW,EAAE,uBAAuB,YAAY,UAAU,IAAI,IAAI;SACnE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3D,IAAI,cAAc,KAAK,IAAI,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzD,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrF,WAAW,CAAC,IAAI,CAAC;YACf,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,sBAAsB;YAChC,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,CAAC,SAAS,CAAC;YACtB,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,SAAS,IAAI,8CAA8C,WAAW,GAAG;YAClF,WAAW,EACT,8LAA8L;YAChM,WAAW,EAAE,iDAAiD,WAAW,SAAS,IAAI,IAAI;SAC3F,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ScanOptions, ScanResult } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_EXCLUDES: readonly string[];
|
|
3
|
+
export declare const DEFAULT_MAX_DIAGNOSTICS = 1000;
|
|
4
|
+
export declare class ScannerOperationalError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(message: string, code?: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Performs a read-only cross-platform filename compatibility scan on a directory.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scanRepository(options: ScanOptions): Promise<ScanResult>;
|
|
12
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAIV,WAAW,EACX,UAAU,EAEX,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAA6B,CAAC;AAC5E,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,SAAgB;CAKlD;AAsGD;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CA+K9E"}
|