Skip to content

Commit 086c44c

Browse files
committed
test: add the progress so far
1 parent c9533e7 commit 086c44c

5 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/config_editorconfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const getEditorConfig = memoize((folderPath: string, filesNames: string[]): Prom
1010
for (let i = 0, l = filesNames.length; i < l; i++) {
1111
const fileName = filesNames[i];
1212
const filePath = fastJoinedPath(folderPath, fileName);
13-
if (!Known.hasFilePath(filePath)) continue;
13+
// if (!Known.hasFilePath(filePath)) continue;
1414
return fs.readFile(filePath, "utf8").then(EditorConfig.parse).catch(noop);
1515
}
1616
});

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ async function runStdin(options: Options, pluginsDefaultOptions: PluginsOptions,
3232
const fileContent = (await getStdin()) || "";
3333

3434
try {
35-
const formatted = await prettier.format(fileName, fileContent, options.formatOptions, options.contextOptions, pluginsDefaultOptions, pluginsCustomOptions);
35+
const editorConfigNames = options.editorConfig ? [".editorconfig"] : [];
36+
const editorConfig = options.editorConfig ? getEditorConfigFormatOptions(await getEditorConfigResolved(fileName, editorConfigNames)) : {};
37+
const formatOptions = { ...editorConfig, ...options.formatOptions };
38+
39+
const formatted = await prettier.format(fileName, fileContent, formatOptions, options.contextOptions, pluginsDefaultOptions, pluginsCustomOptions);
3640
if (options.check || options.list) {
3741
if (formatted !== fileContent) {
3842
stdout.warn("(stdin)");

src/known.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Known {
44
private filesPaths: Set<string> = new Set();
5-
private filesNames: Set<string> = new Set();
5+
filesNames: Set<string> = new Set();
66

77
addFilesPaths = (filesPaths: Array<string> | Set<string>): void => {
88
if (!this.filesPaths.size) {

test/__tests__/__snapshots__/stdin-filepath.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ exports[`apply editorconfig for stdin-filepath with nonexistent file (stdout) 1`
4040

4141
exports[`apply editorconfig for stdin-filepath with nonexistent file (write) 1`] = `[]`;
4242

43-
exports[`dont apply editorconfig outside project for stdin-filepath with nonexistent directory (stderr) 1`] = `""`;
43+
exports[`don't apply editorconfig outside project for stdin-filepath with nonexistent directory (stderr) 1`] = `""`;
4444

45-
exports[`dont apply editorconfig outside project for stdin-filepath with nonexistent directory (stdout) 1`] = `
45+
exports[`don't apply editorconfig outside project for stdin-filepath with nonexistent directory (stdout) 1`] = `
4646
"function f() {
47-
console.log("should be indented with 2 spaces")
47+
console.log("should be indented with 2 spaces");
4848
}"
4949
`;
5050

51-
exports[`dont apply editorconfig outside project for stdin-filepath with nonexistent directory (write) 1`] = `[]`;
51+
exports[`don't apply editorconfig outside project for stdin-filepath with nonexistent directory (write) 1`] = `[]`;
5252

5353
exports[`format correctly if stdin content compatible with stdin-filepath (stderr) 1`] = `""`;
5454

test/__tests__/stdin-filepath.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("gracefully handle stdin-filepath with nonexistent directory", () => {
3232
});
3333

3434
describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
35-
runCli("", ["--stdin-filepath", "editorconfig/nonexistent.js"], {
35+
runCli("editorconfig", ["--stdin-filepath", "nonexistent.js"], {
3636
input: dedent`
3737
function f() {
3838
console.log("should be indented with a tab");
@@ -45,8 +45,8 @@ describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
4545

4646
describe("apply editorconfig for stdin-filepath with nonexistent directory", () => {
4747
runCli(
48-
"",
49-
["--stdin-filepath", "editorconfig/nonexistent/one/two/three.js"],
48+
"editorconfig",
49+
["--stdin-filepath", "nonexistent/one/two/three.js"],
5050
{
5151
input: dedent`
5252
function f() {
@@ -61,8 +61,8 @@ describe("apply editorconfig for stdin-filepath with nonexistent directory", ()
6161

6262
describe("apply editorconfig for stdin-filepath with a deep path", () => {
6363
runCli(
64-
"",
65-
["--stdin-filepath", "editorconfig/" + "a/".repeat(30) + "three.js"],
64+
"editorconfig",
65+
["--stdin-filepath", "a/".repeat(30) + "three.js"],
6666
{
6767
input: dedent`
6868
function f() {
@@ -75,6 +75,8 @@ describe("apply editorconfig for stdin-filepath with a deep path", () => {
7575
});
7676
});
7777

78+
// TODO: This is currently a false positive as no config actually gets resolved, but Prettier
79+
// somehow formats the input correctly anyway.
7880
describe("apply editorconfig for stdin-filepath in root", () => {
7981
const code = dedent`
8082
function f() {
@@ -93,8 +95,8 @@ describe("apply editorconfig for stdin-filepath in root", () => {
9395

9496
describe("apply editorconfig for stdin-filepath with a deep path", () => {
9597
runCli(
96-
"",
97-
["--stdin-filepath", "editorconfig/" + "a/".repeat(30) + "three.js"],
98+
"editorconfig",
99+
["--stdin-filepath", "a/".repeat(30) + "three.js"],
98100
{
99101
input: dedent`
100102
function f() {
@@ -107,7 +109,9 @@ describe("apply editorconfig for stdin-filepath with a deep path", () => {
107109
});
108110
});
109111

110-
describe("don’t apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
112+
// TODO: This is currently a false positive. Gotta investigate how it's handled in Prettier v3 to
113+
// gauge the expected behavior.
114+
describe("don't apply editorconfig outside project for stdin-filepath with nonexistent directory", () => {
111115
runCli(
112116
"",
113117
[

0 commit comments

Comments
 (0)