Skip to content

Commit 585f1be

Browse files
committed
test: migrate stdin-filepath tests
Copies the stdin-filepath tests from prettier. Notable differences: - Blocked by #21 - Syntax errors output the `stdin-filepath` basename in prettier but not in this CLI (e.g. `[Error] foo.js SyntaxError blah`)
1 parent ad666d6 commit 585f1be

13 files changed

Lines changed: 272 additions & 2 deletions

File tree

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/js-yaml": "^4.0.9",
6666
"@types/node": "^20.12.7",
6767
"cross-env": "^7.0.3",
68+
"dedent": "^1.5.3",
6869
"jest": "^29.7.0",
6970
"jest-snapshot-serializer-ansi": "^2.1.0",
7071
"jest-snapshot-serializer-raw": "^2.0.0",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { fastRelativePath, isNull, isString, isUndefined, negate, pluralize, tri
1616
import type { FormatOptions, Options, PluginsOptions } from "./types.js";
1717

1818
async function run(options: Options, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<void> {
19-
if (options.globs.length || !isString(await getStdin())) {
19+
if (options.globs.length || (!isString(await getStdin()) && !("stdinFilepath" in options))) {
2020
return runGlobs(options, pluginsDefaultOptions, pluginsCustomOptions);
2121
} else {
2222
return runStdin(options, pluginsDefaultOptions, pluginsCustomOptions);

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ async function normalizeOptions(options: unknown, targets: unknown[]): Promise<O
330330

331331
const stdin = await getStdin();
332332

333-
if (!isString(stdin) && !globs.length) exit("Expected at least one target file/dir/glob");
333+
if (!isString(stdin) && !globs.length && !("stdinFilepath" in options)) {
334+
exit("Expected at least one target file/dir/glob");
335+
}
334336

335337
const check = "check" in options && !!options.check;
336338
const list = "listDifferent" in options && !!options.listDifferent;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*.js]
4+
indent_style = tab
5+
tab_width = 8
6+
indent_size = 2 # overridden by tab_width since indent_style = tab
7+
max_line_length = 100
8+
9+
# Indentation override for all JS under lib directory
10+
[lib/**.js]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[lib/indent_size=tab.js]
15+
indent_size = tab
16+
17+
[tab_width=unset.js]
18+
tab_width = unset
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("should have tab width 8");
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("should have space width 2");
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("should have space width 8");
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This isn't really a Mercurial repo, but we want to pretend it is for testing purposes.
2+
See https://github.com/prettier/prettier/pull/3559#issuecomment-353857109
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f() {
2+
console.log("should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present");
3+
}

0 commit comments

Comments
 (0)