-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Revert "Revert "Respect EditorConfig settings" (#3213)" This reverts commit d2241fc. * Comment out EditorConfig docs See #3213 (comment) * editorconfig: Support `indent_size = 0` See #2760 (comment) and josephfrazier/editorconfig-to-prettier@c38b84c * Revert "Comment out EditorConfig docs" This reverts commit ddfa529. * Mark EditorConfig functionality as v1.9.0+ See #3255 (comment) * editorconfig: Upgrade editorconfig-to-prettier to 0.0.4 * editorconfig: Only enable for CLI, by default #3255 (comment) * editorconfig: Add tests confirming that editorconfig is ignored by default in the API #3255 (comment) * editorconfig: Add/fix CLI option parsing * editorconfig: Move docs from configuration.md to options.md * editorconfig: Add `oppositeDescription` to show docs for `--no-editorconfig` Addresses #3255 (comment) * editorconfig: Update test snapshots * editorconfig: Remove unnecessary options parsing code Addresses #3255 (comment) * editorconfig: Move docs from options.md to api.md and cli.md Addresses #3255 (comment) * resolveConfig: return null if both .prettierrc and .editorconfig are missing Addresses #3255 (comment) * Don't add now-failing tests The way these tests work, both `tests_integration/cli/config/.prettierrc` and `.prettierrc` apply to `tests_integration/cli/config/editorconfig/file.shouldnotexist`, so the test wouldn't work even on master. Here's a way to confirm that: ```js const path = require('path') const assert = require('assert') const prettier = require('./') const file = './tests_integration/cli/config/editorconfig/file.shouldnotexist' console.log(prettier.resolveConfig.sync(file)) assert(prettier.resolveConfig.sync(file) === null) ```
- Loading branch information
1 parent
1122701
commit cecf065
Showing
19 changed files
with
365 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
|
||
const editorconfig = require("editorconfig"); | ||
const mem = require("mem"); | ||
const pathRoot = require("path-root"); | ||
const editorConfigToPrettier = require("editorconfig-to-prettier"); | ||
|
||
const maybeParse = (filePath, config, parse) => { | ||
const root = filePath && pathRoot(filePath); | ||
return filePath && !config && parse(filePath, { root }); | ||
}; | ||
|
||
const editorconfigAsyncNoCache = (filePath, config) => { | ||
return Promise.resolve(maybeParse(filePath, config, editorconfig.parse)).then( | ||
editorConfigToPrettier | ||
); | ||
}; | ||
const editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache); | ||
|
||
const editorconfigSyncNoCache = (filePath, config) => { | ||
return editorConfigToPrettier( | ||
maybeParse(filePath, config, editorconfig.parseSync) | ||
); | ||
}; | ||
const editorconfigSyncWithCache = mem(editorconfigSyncNoCache); | ||
|
||
function getLoadFunction(opts) { | ||
if (!opts.editorconfig) { | ||
return () => null; | ||
} | ||
|
||
if (opts.sync) { | ||
return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache; | ||
} | ||
|
||
return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache; | ||
} | ||
|
||
function clearCache() { | ||
mem.clear(editorconfigSyncWithCache); | ||
mem.clear(editorconfigAsyncWithCache); | ||
} | ||
|
||
module.exports = { | ||
getLoadFunction, | ||
clearCache | ||
}; |
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.