Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Fixes "no-nested-ternary"
Browse files Browse the repository at this point in the history
  • Loading branch information
jesec committed Jun 7, 2021
1 parent ff56872 commit 30b25ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
2 changes: 0 additions & 2 deletions .eslintrc
Expand Up @@ -3,7 +3,6 @@
"rules": {
"no-bitwise": "off",
"no-continue": "off",
"no-nested-ternary": "off",
"no-await-in-loop": "off",
"no-constant-condition": "off",
"no-param-reassign": "off",
Expand Down Expand Up @@ -32,7 +31,6 @@
"no-bitwise": "off",
"no-constant-condition": "off",
"no-continue": "off",
"no-nested-ternary": "off",
"no-param-reassign": "off",
"no-restricted-syntax": "off"
}
Expand Down
66 changes: 25 additions & 41 deletions lib/common.ts
Expand Up @@ -46,8 +46,22 @@ function removeTrailingSlashes(f: string) {

const isUrl = (p: unknown): p is URL => hasURL && p instanceof URL;

function pathToString(p: string | URL | Buffer, win: boolean): string {
let result: string;

if (Buffer.isBuffer(p)) {
result = p.toString();
} else if (isUrl(p)) {
result = win ? p.pathname.replace(/^\//, '') : p.pathname;
} else {
result = p;
}

return result;
}

export function isRootPath(p: string | URL | Buffer) {
let file = Buffer.isBuffer(p) ? p.toString() : isUrl(p) ? p.pathname : p;
let file = pathToString(p, false);

if (file === '.') {
file = path.resolve(file);
Expand All @@ -57,28 +71,16 @@ export function isRootPath(p: string | URL | Buffer) {
}

export function normalizePath(f: string | URL | Buffer) {
if (win32) {
let file = Buffer.isBuffer(f)
? f.toString()
: isUrl(f)
? f.pathname.replace(/^\//, '')
: f;

if (!/^.:$/.test(file)) {
file = path.normalize(file);
} // 'c:' -> 'c:.'

file = uppercaseDriveLetter(file);

return removeTrailingSlashes(file);
}

let file = Buffer.isBuffer(f) ? f.toString() : isUrl(f) ? f.pathname : f;
let file = pathToString(f, win32);

if (!/^.:$/.test(file)) {
file = path.normalize(file);
} // 'c:' -> 'c:.'

if (win32) {
file = uppercaseDriveLetter(file);
}

return removeTrailingSlashes(file);
}

Expand Down Expand Up @@ -179,19 +181,13 @@ export function snapshotify(file: string, slash: string) {
}

export function insideSnapshot(f: Buffer | string | URL) {
if (win32) {
if (Buffer.isBuffer(f)) {
f = f.toString();
}
f = pathToString(f, win32);

if (hasURL && f instanceof URL) {
f = f.pathname.replace(/^\//, '');
}

if (typeof f !== 'string') {
return false;
}
if (typeof f !== 'string') {
return false;
}

if (win32) {
const slice112 = f.slice(1, 12);

return (
Expand All @@ -204,18 +200,6 @@ export function insideSnapshot(f: Buffer | string | URL) {
);
}

if (Buffer.isBuffer(f)) {
f = f.toString();
}

if (hasURL && f instanceof URL) {
f = f.pathname;
}

if (typeof f !== 'string') {
return false;
}

const slice010 = f.slice(0, 10);

return slice010 === '/snapshot/' || slice010 === '/snapshot';
Expand Down

0 comments on commit 30b25ab

Please sign in to comment.