editorconfig: Only search for .editorconfig up to the VCS directory (#3559)
* editorconfig: Only search for .editorconfig up to $PWD This addresses https://github.com/prettier/prettier/issues/3558 I'm not sure if this is the best way to find the "project root", but it seems better than before. * editorconfig: Search for `.editorconfig` up to the VCS directory This uses [find-project-root] to find the nearest directory containing `.git` or `.hg` See here for context: https://github.com/prettier/prettier/pull/3559#issuecomment-353756948 [find-project-root]: https://github.com/kirstein/find-project-root * editorconfig: Add test for finding VCS directory It's a little hacky in that the .hg file isn't really a Mercurial repository, but it's enough to illustrate the intent. See here for context: https://github.com/prettier/prettier/pull/3559#issuecomment-353857109master
parent
1a3248bbc2
commit
7b211eab24
|
@ -27,6 +27,7 @@
|
|||
"emoji-regex": "6.5.1",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"esutils": "2.0.2",
|
||||
"find-project-root": "1.1.1",
|
||||
"flow-parser": "0.59.0",
|
||||
"get-stream": "3.0.0",
|
||||
"globby": "6.1.0",
|
||||
|
@ -39,7 +40,6 @@
|
|||
"minimatch": "3.0.4",
|
||||
"minimist": "1.2.0",
|
||||
"parse5": "3.0.3",
|
||||
"path-root": "0.1.1",
|
||||
"postcss-less": "1.1.3",
|
||||
"postcss-media-query-parser": "0.2.3",
|
||||
"postcss-scss": "1.0.2",
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const editorconfig = require("editorconfig");
|
||||
const mem = require("mem");
|
||||
const pathRoot = require("path-root");
|
||||
const editorConfigToPrettier = require("editorconfig-to-prettier");
|
||||
const findProjectRoot = require("find-project-root");
|
||||
|
||||
const maybeParse = (filePath, config, parse) => {
|
||||
const root = filePath && pathRoot(filePath);
|
||||
const root = findProjectRoot(path.dirname(path.resolve(filePath)));
|
||||
return filePath && !config && parse(filePath, { root });
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@ function f() {
|
|||
\\"should have space width 8\\"
|
||||
)
|
||||
}
|
||||
function f() {
|
||||
console.log(
|
||||
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
|
||||
)
|
||||
}
|
||||
console.log(
|
||||
\\"jest/__best-tests__/file.js should have semi\\"
|
||||
);
|
||||
|
@ -108,6 +113,11 @@ function f() {
|
|||
function f() {
|
||||
console.log(\\"should have space width 8\\")
|
||||
}
|
||||
function f() {
|
||||
console.log(
|
||||
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
|
||||
)
|
||||
}
|
||||
console.log(\\"jest/__best-tests__/file.js should have semi\\");
|
||||
console.log(\\"jest/Component.js should not have semi\\")
|
||||
console.log(\\"jest/Component.test.js should have semi\\");
|
||||
|
|
|
@ -95,6 +95,11 @@ function f() {
|
|||
\\"should have space width 8\\"
|
||||
)
|
||||
}
|
||||
function f() {
|
||||
console.log(
|
||||
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
|
||||
)
|
||||
}
|
||||
console.log(
|
||||
\\"jest/__best-tests__/file.js should have semi\\"
|
||||
);
|
||||
|
@ -167,6 +172,11 @@ function f() {
|
|||
\\"should have space width 8\\"
|
||||
)
|
||||
}
|
||||
function f() {
|
||||
console.log(
|
||||
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
|
||||
)
|
||||
}
|
||||
console.log(
|
||||
\\"jest/__best-tests__/file.js should have semi\\"
|
||||
);
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
This isn't really a Mercurial repo, but we want to pretend it is for testing purposes.
|
||||
See https://github.com/prettier/prettier/pull/3559#issuecomment-353857109
|
|
@ -0,0 +1,3 @@
|
|||
function f() {
|
||||
console.log("should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present");
|
||||
}
|
14
yarn.lock
14
yarn.lock
|
@ -1774,6 +1774,10 @@ fill-range@^2.1.0:
|
|||
repeat-element "^1.1.2"
|
||||
repeat-string "^1.5.2"
|
||||
|
||||
find-project-root@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/find-project-root/-/find-project-root-1.1.1.tgz#d242727a2d904725df5714f23dfdcdedda0b6ef8"
|
||||
|
||||
find-up@^1.0.0:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
|
||||
|
@ -3363,16 +3367,6 @@ path-parse@^1.0.5:
|
|||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
|
||||
|
||||
path-root-regex@^0.1.0:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/path-root-regex/-/path-root-regex-0.1.2.tgz#bfccdc8df5b12dc52c8b43ec38d18d72c04ba96d"
|
||||
|
||||
path-root@0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/path-root/-/path-root-0.1.1.tgz#9a4a6814cac1c0cd73360a95f32083c8ea4745b7"
|
||||
dependencies:
|
||||
path-root-regex "^0.1.0"
|
||||
|
||||
path-to-regexp@^1.0.1:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
|
||||
|
|
Loading…
Reference in New Issue