fix(lint): satisfy path display rules
This commit is contained in:
parent
1dd9f65467
commit
a0f1c92d18
1 changed files with 4 additions and 8 deletions
|
|
@ -15,10 +15,6 @@ function isWindowsAbsolutePath(input: string): boolean {
|
||||||
return /^[A-Za-z]:[/\\]/.test(input) || input.startsWith('\\\\') || input.startsWith('//');
|
return /^[A-Za-z]:[/\\]/.test(input) || input.startsWith('\\\\') || input.startsWith('//');
|
||||||
}
|
}
|
||||||
|
|
||||||
function comparePath(input: string, caseInsensitive: boolean): string {
|
|
||||||
return caseInsensitive ? input.toLowerCase() : input;
|
|
||||||
}
|
|
||||||
|
|
||||||
function pathSeparatorFor(root: string): '/' | '\\' {
|
function pathSeparatorFor(root: string): '/' | '\\' {
|
||||||
return root.includes('\\') && !root.includes('/') ? '\\' : '/';
|
return root.includes('\\') && !root.includes('/') ? '\\' : '/';
|
||||||
}
|
}
|
||||||
|
|
@ -44,8 +40,8 @@ export function shortenDisplayPath(fullPath: string, projectRoot?: string, maxLe
|
||||||
if (projectRoot) {
|
if (projectRoot) {
|
||||||
const root = projectRoot.replace(/[/\\]$/, '');
|
const root = projectRoot.replace(/[/\\]$/, '');
|
||||||
const caseInsensitive = isWindowsAbsolutePath(p) || isWindowsAbsolutePath(root);
|
const caseInsensitive = isWindowsAbsolutePath(p) || isWindowsAbsolutePath(root);
|
||||||
const pathForCompare = comparePath(p, caseInsensitive);
|
const pathForCompare = caseInsensitive ? p.toLowerCase() : p;
|
||||||
const rootForCompare = comparePath(root, caseInsensitive);
|
const rootForCompare = caseInsensitive ? root.toLowerCase() : root;
|
||||||
if (
|
if (
|
||||||
pathForCompare.startsWith(rootForCompare + '/') ||
|
pathForCompare.startsWith(rootForCompare + '/') ||
|
||||||
pathForCompare.startsWith(rootForCompare + '\\')
|
pathForCompare.startsWith(rootForCompare + '\\')
|
||||||
|
|
@ -58,7 +54,7 @@ export function shortenDisplayPath(fullPath: string, projectRoot?: string, maxLe
|
||||||
p = p
|
p = p
|
||||||
.replace(/^\/Users\/[^/]+/, '~')
|
.replace(/^\/Users\/[^/]+/, '~')
|
||||||
.replace(/^\/home\/[^/]+/, '~')
|
.replace(/^\/home\/[^/]+/, '~')
|
||||||
.replace(/^[A-Za-z]:\\Users\\[^\\]+/i, '~');
|
.replace(/^[A-Z]:\\Users\\[^\\]+/i, '~');
|
||||||
|
|
||||||
// 3. If short enough, return as-is
|
// 3. If short enough, return as-is
|
||||||
if (p.length <= maxLength) return p;
|
if (p.length <= maxLength) return p;
|
||||||
|
|
@ -88,7 +84,7 @@ function inferHomeDir(projectRoot: string): string | null {
|
||||||
const match =
|
const match =
|
||||||
/^(\/Users\/[^/]+)/.exec(projectRoot) ??
|
/^(\/Users\/[^/]+)/.exec(projectRoot) ??
|
||||||
/^(\/home\/[^/]+)/.exec(projectRoot) ??
|
/^(\/home\/[^/]+)/.exec(projectRoot) ??
|
||||||
/^([A-Za-z]:\\Users\\[^\\]+)/i.exec(projectRoot);
|
/^([A-Z]:\\Users\\[^\\]+)/i.exec(projectRoot);
|
||||||
return match?.[1] ?? null;
|
return match?.[1] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue