Skip to content

Commit f4a7afa

Browse files
authored
Add types for config related functions (#18376)
1 parent 9266e3e commit f4a7afa

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/config/editorconfig/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import {
66
} from "../find-project-root.js";
77
import editorConfigToPrettier from "./editorconfig-to-prettier.js";
88

9+
/**
10+
@typedef {ReturnType<editorConfigToPrettier>} EditorConfig
11+
*/
12+
13+
/**
14+
@type {Map<string, Promise<EditorConfig>>}
15+
*/
916
const editorconfigCache = new Map();
1017

1118
function clearEditorconfigCache() {
@@ -22,9 +29,9 @@ async function loadEditorconfigInternal(file, { shouldCache }) {
2229
}
2330

2431
/**
25-
* @param {string} file
26-
* @param {{shouldCache?: boolean}} options
27-
*/
32+
@param {string} file
33+
@param {{shouldCache?: boolean}} options
34+
*/
2835
function loadEditorconfig(file, { shouldCache }) {
2936
file = path.resolve(file);
3037

src/config/resolve-config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ function clearCache() {
1717
clearEditorconfigCache();
1818
}
1919

20+
/**
21+
@param {string} file
22+
@param {{
23+
editorconfig?: boolean,
24+
useCache?: boolean,
25+
}} options
26+
*/
2027
function loadEditorconfig(file, options) {
2128
if (!file || !options.editorconfig) {
2229
return;
@@ -26,6 +33,17 @@ function loadEditorconfig(file, options) {
2633
return loadEditorconfigForFile(file, { shouldCache });
2734
}
2835

36+
/**
37+
@param {string} file
38+
@param {{
39+
useCache?: boolean,
40+
config?: string | URL
41+
}} options
42+
@returns {{
43+
config: any,
44+
configFile: string,
45+
} | void}
46+
*/
2947
async function loadPrettierConfig(file, options) {
3048
const shouldCache = options.useCache;
3149
let configFile = options.config;
@@ -45,6 +63,10 @@ async function loadPrettierConfig(file, options) {
4563
return { config, configFile };
4664
}
4765

66+
/**
67+
@param {string | URL} fileUrlOrPath
68+
@param {*} options
69+
*/
4870
async function resolveConfig(fileUrlOrPath, options) {
4971
options = { useCache: true, ...options };
5072
const filePath = toPath(fileUrlOrPath);
@@ -74,6 +96,9 @@ async function resolveConfig(fileUrlOrPath, options) {
7496
return merged;
7597
}
7698

99+
/**
100+
@param {string | URL} fileUrlOrPath
101+
*/
77102
async function resolveConfigFile(fileUrlOrPath) {
78103
const directory = fileUrlOrPath
79104
? path.dirname(path.resolve(toPath(fileUrlOrPath)))

0 commit comments

Comments
 (0)