@konvert7/klint 0.1.0 → 0.2.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/core/arch.ts +9 -7
- package/package.json +1 -1
package/core/arch.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { dirname, relative, resolve } from "node:path";
|
|
1
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { walkAst } from "./ast";
|
|
4
4
|
import type { ArchConfig, Severity, Violation } from "./types";
|
|
5
5
|
|
|
6
|
+
const toSlash = (p: string) => p.replaceAll("\\", "/");
|
|
7
|
+
|
|
6
8
|
interface AliasEntry {
|
|
7
9
|
/** The prefix to match (pattern with `/*` stripped, e.g. `"@"` from `"@/*"`). */
|
|
8
10
|
prefix: string;
|
|
@@ -29,7 +31,7 @@ function loadPathAliases(root: string): AliasEntry[] {
|
|
|
29
31
|
const prefix = isWildcard ? pattern.slice(0, -2) : pattern;
|
|
30
32
|
const targetStr = targets[0];
|
|
31
33
|
const targetBase = targetStr.endsWith("/*") ? targetStr.slice(0, -2) : targetStr;
|
|
32
|
-
entries.push({ prefix, base: resolve(base, targetBase), isWildcard });
|
|
34
|
+
entries.push({ prefix, base: toSlash(resolve(base, targetBase)), isWildcard });
|
|
33
35
|
}
|
|
34
36
|
return entries;
|
|
35
37
|
}
|
|
@@ -39,7 +41,7 @@ function resolveAlias(importPath: string, aliases: AliasEntry[]): string | undef
|
|
|
39
41
|
if (alias.isWildcard) {
|
|
40
42
|
const matchPrefix = `${alias.prefix}/`;
|
|
41
43
|
if (importPath.startsWith(matchPrefix)) {
|
|
42
|
-
return resolve(alias.base, importPath.slice(matchPrefix.length));
|
|
44
|
+
return toSlash(resolve(alias.base, importPath.slice(matchPrefix.length)));
|
|
43
45
|
}
|
|
44
46
|
} else if (importPath === alias.prefix) {
|
|
45
47
|
return alias.base;
|
|
@@ -56,11 +58,11 @@ interface ImportRecord {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
function isBareSpecifier(path: string): boolean {
|
|
59
|
-
return !path.startsWith(".") && !path
|
|
61
|
+
return !path.startsWith(".") && !isAbsolute(path);
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
function globToPrefix(glob: string, root: string): string {
|
|
63
|
-
return resolve(root, glob.split("/**")[0].split("/*")[0].split("*")[0]);
|
|
65
|
+
return toSlash(resolve(root, glob.split("/**")[0].split("/*")[0].split("*")[0]));
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
function resolveGlobs(
|
|
@@ -126,7 +128,7 @@ function scanImports(
|
|
|
126
128
|
if (isBareSpecifier(path)) {
|
|
127
129
|
resolved = resolveAlias(path, aliases) ?? path;
|
|
128
130
|
} else {
|
|
129
|
-
resolved = resolve(fileDir, path);
|
|
131
|
+
resolved = toSlash(resolve(fileDir, path));
|
|
130
132
|
}
|
|
131
133
|
const { line } = src.getLineAndCharacterOfPosition(specifierNode.getStart());
|
|
132
134
|
records.push({ path, resolved, isTypeOnly, line: line + 1 });
|
|
@@ -210,7 +212,7 @@ export function runArchRules(
|
|
|
210
212
|
|
|
211
213
|
for (const rule of arch.singleton ?? []) {
|
|
212
214
|
const severity: Severity = rule.severity ?? "error";
|
|
213
|
-
const onlyFile = resolve(root, rule.only);
|
|
215
|
+
const onlyFile = toSlash(resolve(root, rule.only));
|
|
214
216
|
const inFiles = rule.in
|
|
215
217
|
? resolveLayerFiles(rule.in, layers, root, allFiles)
|
|
216
218
|
: allFiles;
|
package/package.json
CHANGED