Skip to content

Commit d2241fc

Browse files
authored
Revert "Respect EditorConfig settings" (#3213)
* Revert "Respect EditorConfig settings (#2760)" This reverts commit 8f58ca0.
1 parent 7fb8e3f commit d2241fc

15 files changed

Lines changed: 19 additions & 315 deletions

docs/configuration.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,3 @@ For more information on how to use the CLI to locate a file, see the [CLI](cli.m
8383
## Configuration Schema
8484

8585
If you'd like a JSON schema to validate your configuration, one is available here: http://json.schemastore.org/prettierrc.
86-
87-
## EditorConfig
88-
89-
If an [`.editorconfig` file](http://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding prettier configuration. This configuration will be overridden by `.prettierrc`, etc. Currently, the following EditorConfig properties are supported:
90-
91-
* `indent_style`
92-
* `indent_size`/`tab_width`
93-
* `max_line_length`

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
"cosmiconfig": "3.1.0",
2323
"dashify": "0.2.2",
2424
"diff": "3.2.0",
25-
"editorconfig": "0.14.2",
26-
"editorconfig-to-prettier": "0.0.1",
2725
"emoji-regex": "6.5.1",
2826
"escape-string-regexp": "1.0.5",
2927
"esutils": "2.0.2",
@@ -39,7 +37,6 @@
3937
"minimatch": "3.0.4",
4038
"minimist": "1.2.0",
4139
"parse5": "3.0.3",
42-
"path-root": "0.1.1",
4340
"postcss-less": "1.1.1",
4441
"postcss-media-query-parser": "0.2.3",
4542
"postcss-scss": "1.0.2",

src/resolve-config-editorconfig.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/resolve-config.js

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const minimatch = require("minimatch");
55
const path = require("path");
66
const mem = require("mem");
77

8-
const resolveEditorConfig = require("./resolve-config-editorconfig");
9-
108
const getExplorerMemoized = mem(opts =>
119
cosmiconfig("prettier", {
1210
sync: opts.sync,
@@ -28,43 +26,23 @@ function getLoadFunction(opts) {
2826
return getExplorerMemoized(opts).load;
2927
}
3028

31-
function _resolveConfig(filePath, opts, sync) {
29+
function resolveConfig(filePath, opts) {
3230
opts = Object.assign({ useCache: true }, opts);
33-
const loadOpts = { cache: !!opts.useCache, sync: !!sync };
34-
const load = getLoadFunction(loadOpts);
35-
const loadEditorConfig = resolveEditorConfig.getLoadFunction(loadOpts);
36-
const arr = [load, loadEditorConfig].map(l => l(filePath, opts.config));
37-
38-
const unwrapAndMerge = arr => {
39-
const result = arr[0];
40-
const editorConfigured = arr[1];
41-
const merged = Object.assign(
42-
{},
43-
editorConfigured,
44-
mergeOverrides(Object.assign({}, result), filePath)
45-
);
46-
47-
if (Object.keys(merged).length === 0) {
48-
return null;
49-
}
50-
51-
return merged;
52-
};
53-
54-
if (loadOpts.sync) {
55-
return unwrapAndMerge(arr);
56-
}
57-
58-
return Promise.all(arr).then(unwrapAndMerge);
31+
const load = getLoadFunction({ cache: !!opts.useCache, sync: false });
32+
return load(filePath, opts.config).then(result => {
33+
return !result ? null : mergeOverrides(result, filePath);
34+
});
5935
}
6036

61-
const resolveConfig = (filePath, opts) => _resolveConfig(filePath, opts, false);
62-
63-
resolveConfig.sync = (filePath, opts) => _resolveConfig(filePath, opts, true);
37+
resolveConfig.sync = (filePath, opts) => {
38+
opts = Object.assign({ useCache: true }, opts);
39+
const load = getLoadFunction({ cache: !!opts.useCache, sync: true });
40+
const result = load(filePath, opts.config);
41+
return !result ? null : mergeOverrides(result, filePath);
42+
};
6443

6544
function clearCache() {
6645
mem.clear(getExplorerMemoized);
67-
resolveEditorConfig.clearCache();
6846
}
6947

7048
function resolveConfigFile(filePath) {

tests_integration/__tests__/__snapshots__/config-resolution.js.snap

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33
exports[`CLI overrides take precedence (stderr) 1`] = `""`;
44

55
exports[`CLI overrides take precedence (stdout) 1`] = `
6-
"function f() {
7-
console.log(
8-
\\"should have tab width 8\\"
9-
)
10-
}
11-
function f() {
12-
console.log(
13-
\\"should have space width 2\\"
14-
)
15-
}
16-
function f() {
17-
console.log(
18-
\\"should have space width 8\\"
19-
)
20-
}
21-
console.log(
6+
"console.log(
227
\\"jest/__best-tests__/file.js should have semi\\"
238
);
249
console.log(
@@ -99,16 +84,7 @@ exports[`resolves configuration file with --find-config-path file (write) 1`] =
9984
exports[`resolves configuration from external files (stderr) 1`] = `""`;
10085

10186
exports[`resolves configuration from external files (stdout) 1`] = `
102-
"function f() {
103-
console.log(\\"should have tab width 8\\")
104-
}
105-
function f() {
106-
console.log(\\"should have space width 2\\")
107-
}
108-
function f() {
109-
console.log(\\"should have space width 8\\")
110-
}
111-
console.log(\\"jest/__best-tests__/file.js should have semi\\");
87+
"console.log(\\"jest/__best-tests__/file.js should have semi\\");
11288
console.log(\\"jest/Component.js should not have semi\\")
11389
console.log(\\"jest/Component.test.js should have semi\\");
11490
function js() {

tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,7 @@ exports[`CLI overrides take lower precedence with --config-precedence file-overr
8080
exports[`CLI overrides take precedence with --config-precedence cli-override (stderr) 1`] = `""`;
8181
8282
exports[`CLI overrides take precedence with --config-precedence cli-override (stdout) 1`] = `
83-
"function f() {
84-
console.log(
85-
\\"should have tab width 8\\"
86-
)
87-
}
88-
function f() {
89-
console.log(
90-
\\"should have space width 2\\"
91-
)
92-
}
93-
function f() {
94-
console.log(
95-
\\"should have space width 8\\"
96-
)
97-
}
98-
console.log(
83+
"console.log(
9984
\\"jest/__best-tests__/file.js should have semi\\"
10085
);
10186
console.log(
@@ -152,22 +137,7 @@ exports[`CLI overrides take precedence with --config-precedence cli-override (wr
152137
exports[`CLI overrides take precedence without --config-precedence (stderr) 1`] = `""`;
153138
154139
exports[`CLI overrides take precedence without --config-precedence (stdout) 1`] = `
155-
"function f() {
156-
console.log(
157-
\\"should have tab width 8\\"
158-
)
159-
}
160-
function f() {
161-
console.log(
162-
\\"should have space width 2\\"
163-
)
164-
}
165-
function f() {
166-
console.log(
167-
\\"should have space width 8\\"
168-
)
169-
}
170-
console.log(
140+
"console.log(
171141
\\"jest/__best-tests__/file.js should have semi\\"
172142
);
173143
console.log(

tests_integration/__tests__/config-resolution.js

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -102,98 +102,6 @@ test("API resolveConfig.sync with file arg and extension override", () => {
102102
});
103103
});
104104

105-
test("API resolveConfig with file arg and .editorconfig", () => {
106-
const file = path.resolve(
107-
path.join(__dirname, "../cli/config/editorconfig/file.js")
108-
);
109-
return prettier.resolveConfig(file).then(result => {
110-
expect(result).toMatchObject({
111-
useTabs: true,
112-
tabWidth: 8,
113-
printWidth: 100
114-
});
115-
});
116-
});
117-
118-
test("API resolveConfig.sync with file arg and .editorconfig", () => {
119-
const file = path.resolve(
120-
path.join(__dirname, "../cli/config/editorconfig/file.js")
121-
);
122-
expect(prettier.resolveConfig.sync(file)).toMatchObject({
123-
useTabs: true,
124-
tabWidth: 8,
125-
printWidth: 100
126-
});
127-
});
128-
129-
test("API resolveConfig with nested file arg and .editorconfig", () => {
130-
const file = path.resolve(
131-
path.join(__dirname, "../cli/config/editorconfig/lib/file.js")
132-
);
133-
return prettier.resolveConfig(file).then(result => {
134-
expect(result).toMatchObject({
135-
useTabs: false,
136-
tabWidth: 2,
137-
printWidth: 100
138-
});
139-
});
140-
});
141-
142-
test("API resolveConfig.sync with nested file arg and .editorconfig", () => {
143-
const file = path.resolve(
144-
path.join(__dirname, "../cli/config/editorconfig/lib/file.js")
145-
);
146-
expect(prettier.resolveConfig.sync(file)).toMatchObject({
147-
useTabs: false,
148-
tabWidth: 2,
149-
printWidth: 100
150-
});
151-
});
152-
153-
test("API resolveConfig with nested file arg and .editorconfig and indent_size = tab", () => {
154-
const file = path.resolve(
155-
path.join(__dirname, "../cli/config/editorconfig/lib/indent_size=tab.js")
156-
);
157-
return prettier.resolveConfig(file).then(result => {
158-
expect(result).toMatchObject({
159-
useTabs: false,
160-
tabWidth: 8,
161-
printWidth: 100
162-
});
163-
});
164-
});
165-
166-
test("API resolveConfig.sync with nested file arg and .editorconfig and indent_size = tab", () => {
167-
const file = path.resolve(
168-
path.join(__dirname, "../cli/config/editorconfig/lib/indent_size=tab.js")
169-
);
170-
expect(prettier.resolveConfig.sync(file)).toMatchObject({
171-
useTabs: false,
172-
tabWidth: 8,
173-
printWidth: 100
174-
});
175-
});
176-
177-
test("API resolveConfig with missing file arg", () => {
178-
const file = path.resolve(
179-
path.join(__dirname, "../cli/config/editorconfig/file.shouldnotexist")
180-
);
181-
return prettier.resolveConfig(file).then(result => {
182-
expect(result).toBeNull();
183-
});
184-
});
185-
186-
test("API resolveConfig.sync with missing file arg", () => {
187-
const file = path.resolve(
188-
path.join(__dirname, "../cli/config/editorconfig/file.shouldnotexist")
189-
);
190-
expect(prettier.resolveConfig.sync(file)).toBeNull();
191-
});
192-
193-
test("API clearConfigCache", () => {
194-
expect(() => prettier.clearConfigCache()).not.toThrowError();
195-
});
196-
197105
test("API resolveConfig.sync overrides work with absolute paths", () => {
198106
// Absolute path
199107
const file = path.join(__dirname, "../cli/config/filepath/subfolder/file.js");
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
semi: false
2+
13
overrides:
2-
- files: "*.js"
3-
options:
4-
semi: false
54
- files: "*.ts"
65
options:
76
semi: true

tests_integration/cli/config/editorconfig/.editorconfig

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests_integration/cli/config/editorconfig/file.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)