yamllint-js 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/config.d.mts +14 -1
- package/dist/config.mjs +11 -10
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.3](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.2...v0.2.3) (2026-02-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ✨ Features
|
|
7
|
+
|
|
8
|
+
* support options on loadYamlLintConfig ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 🐛 Bug Fixes
|
|
12
|
+
|
|
13
|
+
* stopDir option on loadConfigFile ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
|
|
14
|
+
* throw on failure in loadConfigFile ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
|
|
15
|
+
|
|
3
16
|
## [0.2.2](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.1...v0.2.2) (2026-02-19)
|
|
4
17
|
|
|
5
18
|
|
package/dist/config.d.mts
CHANGED
|
@@ -70,7 +70,15 @@ declare class YamlLintConfig {
|
|
|
70
70
|
extend(baseConfig: unknown): void;
|
|
71
71
|
}
|
|
72
72
|
interface LoadConfigFileOptions {
|
|
73
|
+
/**
|
|
74
|
+
* @default process.cwd()
|
|
75
|
+
*/
|
|
73
76
|
startDir?: string;
|
|
77
|
+
/**
|
|
78
|
+
* @default getHomedir()
|
|
79
|
+
*
|
|
80
|
+
* @see {@link getHomedir}
|
|
81
|
+
*/
|
|
74
82
|
stopDir?: string;
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
@@ -81,6 +89,7 @@ interface LoadConfigFileOptions {
|
|
|
81
89
|
* ```typescript
|
|
82
90
|
* const autoDetected = await loadConfigFile();
|
|
83
91
|
* const specified = await loadConfigFile("path/to/yamllint.yaml");
|
|
92
|
+
* const withOptions = await loadConfigFile({ startDir, stopDir });
|
|
84
93
|
* ```
|
|
85
94
|
*/
|
|
86
95
|
declare const loadConfigFile: (filepath?: string | LoadConfigFileOptions) => Promise<unknown>;
|
|
@@ -96,8 +105,12 @@ declare const loadConfigFile: (filepath?: string | LoadConfigFileOptions) => Pro
|
|
|
96
105
|
declare function detectUserGlobalConfig(): Promise<string | undefined>;
|
|
97
106
|
/**
|
|
98
107
|
* Load and return a fully resolved YamlLint configuration instance.
|
|
108
|
+
*
|
|
109
|
+
* - First, try to load config file from the current directory to user home directory.
|
|
110
|
+
* - If not found, try to load from the user global config file.
|
|
111
|
+
* - If not found, try to load from the default config.
|
|
99
112
|
*/
|
|
100
|
-
declare function loadYamlLintConfig(): Promise<YamlLintConfig>;
|
|
113
|
+
declare function loadYamlLintConfig(options?: LoadConfigFileOptions): Promise<YamlLintConfig>;
|
|
101
114
|
/**
|
|
102
115
|
* if value is {@link AllLevel} or undefined
|
|
103
116
|
* then convert to {@link Level} (undefined -> "error"),
|
package/dist/config.mjs
CHANGED
|
@@ -166,7 +166,6 @@ async function validateRuleConf(rule, config) {
|
|
|
166
166
|
}
|
|
167
167
|
const loadConfigFile = (() => {
|
|
168
168
|
const jsReg = /\.[cm]?js$/;
|
|
169
|
-
const homeDir = getHomedir();
|
|
170
169
|
const filenames = [
|
|
171
170
|
"package.json",
|
|
172
171
|
...getNodeSearchPlaces(COMMAND_NAMES),
|
|
@@ -178,10 +177,11 @@ const loadConfigFile = (() => {
|
|
|
178
177
|
const filename = path.basename(filepath);
|
|
179
178
|
if (jsReg.test(filepath) || filepath.endsWith(".ts")) {
|
|
180
179
|
const jiti = createJiti(import.meta.url);
|
|
181
|
-
if (await fs.stat(filepath).then((x) => x.size).catch(() => 0)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
if (await fs.stat(filepath).then((x) => x.size).catch(() => 0) > 0) {
|
|
181
|
+
const mod = await jiti.import(filepath, { default: true });
|
|
182
|
+
const value = mod.default ?? mod;
|
|
183
|
+
if (typeof value === "object" && value !== null) return value;
|
|
184
|
+
}
|
|
185
185
|
} else if (filename === "package.json") {
|
|
186
186
|
const content = autoDecode(await fs.readFile(filepath));
|
|
187
187
|
const pkg = JSON.parse(content);
|
|
@@ -194,14 +194,15 @@ const loadConfigFile = (() => {
|
|
|
194
194
|
const content = autoDecode(await fs.readFile(filepath));
|
|
195
195
|
return yaml.parse(content, YAML_OPTIONS);
|
|
196
196
|
}
|
|
197
|
+
throw new Error();
|
|
197
198
|
} catch {
|
|
198
199
|
if (throwOnFailure) throw new YamlLintConfigError(`failed to load config file "${filepath}"`);
|
|
199
|
-
return;
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
return async function loadConfigFile(filepath) {
|
|
203
203
|
if (typeof filepath === "string") return loadFile(filepath, true);
|
|
204
|
-
const
|
|
204
|
+
const startDir = filepath?.startDir ?? process.cwd();
|
|
205
|
+
const stopDir = filepath?.stopDir === void 0 ? getHomedir() : path.resolve(filepath.stopDir);
|
|
205
206
|
let currDir = path.resolve(startDir);
|
|
206
207
|
do {
|
|
207
208
|
for (const filename of filenames) {
|
|
@@ -212,7 +213,7 @@ const loadConfigFile = (() => {
|
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
215
|
currDir = path.dirname(currDir);
|
|
215
|
-
} while (currDir !== stopDir && currDir !==
|
|
216
|
+
} while (currDir !== stopDir && currDir !== path.dirname(currDir));
|
|
216
217
|
};
|
|
217
218
|
})();
|
|
218
219
|
async function detectUserGlobalConfig() {
|
|
@@ -222,11 +223,11 @@ async function detectUserGlobalConfig() {
|
|
|
222
223
|
else userGlobalConfig = path.join(getHomedir(), ".config", "yamllint", "config");
|
|
223
224
|
return await fs.stat(userGlobalConfig).then((x) => x.isFile()).catch(() => false) ? userGlobalConfig : void 0;
|
|
224
225
|
}
|
|
225
|
-
async function loadYamlLintConfig() {
|
|
226
|
+
async function loadYamlLintConfig(options) {
|
|
226
227
|
let userGlobalConfig;
|
|
227
228
|
let load;
|
|
228
229
|
let conf;
|
|
229
|
-
if (load = await loadConfigFile()) conf = await YamlLintConfig.init({ _data: load });
|
|
230
|
+
if (load = await loadConfigFile(options)) conf = await YamlLintConfig.init({ _data: load });
|
|
230
231
|
else if (userGlobalConfig = await detectUserGlobalConfig()) conf = await YamlLintConfig.init({ file: userGlobalConfig });
|
|
231
232
|
else conf = await YamlLintConfig.init({ content: "extends: default" });
|
|
232
233
|
return conf;
|
package/dist/package.mjs
CHANGED
package/package.json
CHANGED