-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consistent with the ESLint Formatter behavior
- use 1-based line and 1-based column - use absolute path instead of relative path
- Loading branch information
Showing
11 changed files
with
115 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as fs from "node:fs/promises"; | ||
import * as os from "node:os"; | ||
import * as path from "node:path"; | ||
|
||
const TMP_DIR = await fs.realpath(os.tmpdir()); | ||
const ROOT_DIR = path.resolve(__dirname, ".."); | ||
|
||
function test(value: any) { | ||
return hasString(value, (_) => _.includes(ROOT_DIR) || _.includes(TMP_DIR)); | ||
} | ||
|
||
function print(value: unknown, serialize: (value: unknown) => string) { | ||
return serialize( | ||
mapString(value, (_) => | ||
_.replaceAll(ROOT_DIR, "<rootDir>") // | ||
.replaceAll(TMP_DIR, "<tmpDir>"), | ||
), | ||
); | ||
} | ||
|
||
export default { test, print }; | ||
|
||
function hasString(value: any, predicate: (value: string) => boolean): boolean { | ||
switch (typeof value) { | ||
case "string": | ||
return predicate(value); | ||
case "object": | ||
if (Array.isArray(value)) { | ||
return value.some((_) => hasString(_, predicate)); | ||
} | ||
if (value) { | ||
return Object.values(value).some((_) => hasString(_, predicate)); | ||
} | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
function mapString<T>(value: T, transform: (value: string) => string): T { | ||
switch (typeof value) { | ||
case "string": | ||
return transform(value) as T; | ||
case "object": | ||
if (Array.isArray(value)) { | ||
return value.map((_) => mapString(_, transform)) as T; | ||
} | ||
if (value) { | ||
return Object.fromEntries( | ||
Object.entries(value).map(([k, v]) => [k, mapString(v, transform)]), | ||
) as T; | ||
} | ||
return value; | ||
default: | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.