yamllint-js 0.2.2 → 0.2.4

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.4](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.3...v0.2.4) (2026-02-22)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * correct detect config file in stopDir ([f1b182c](https://github.com/kimzuni-labs/yamllint-js/commit/f1b182c7f646e8d8ab169e36984681d9a2e03109))
9
+ * move package.json to after getNodeSearchPlaces ([f1b182c](https://github.com/kimzuni-labs/yamllint-js/commit/f1b182c7f646e8d8ab169e36984681d9a2e03109))
10
+
11
+ ## [0.2.3](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.2...v0.2.3) (2026-02-19)
12
+
13
+
14
+ ### ✨ Features
15
+
16
+ * support options on loadYamlLintConfig ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
17
+
18
+
19
+ ### 🐛 Bug Fixes
20
+
21
+ * stopDir option on loadConfigFile ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
22
+ * throw on failure in loadConfigFile ([9f67bea](https://github.com/kimzuni-labs/yamllint-js/commit/9f67beab94698b64c1b09c332a246d4099ff0cbc))
23
+
3
24
  ## [0.2.2](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.1...v0.2.2) (2026-02-19)
4
25
 
5
26
 
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,10 +166,9 @@ 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
- "package.json",
172
170
  ...getNodeSearchPlaces(COMMAND_NAMES),
171
+ "package.json",
173
172
  ...PY_YAMLLINT_CONFIG_FILES
174
173
  ];
175
174
  const loadFile = async (filepath, throwOnFailure = false) => {
@@ -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) < 1) throw new Error();
182
- const mod = await jiti.import(filepath, { default: true });
183
- const value = mod.default ?? mod;
184
- if (typeof value === "object" && value !== null) return value;
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,16 +194,18 @@ 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 { startDir = process.cwd(), stopDir } = filepath ?? {};
205
- let currDir = path.resolve(startDir);
204
+ const startDir = filepath?.startDir ?? process.cwd();
205
+ const stopDir = filepath?.stopDir === void 0 ? getHomedir() : path.resolve(filepath.stopDir);
206
+ let currDir = path.resolve(startDir, "xxx");
206
207
  do {
208
+ currDir = path.dirname(currDir);
207
209
  for (const filename of filenames) {
208
210
  const curr = path.join(currDir, filename);
209
211
  if (await fs.stat(curr).then((x) => x.isFile() || x.isSymbolicLink()).catch(() => false)) {
@@ -211,8 +213,7 @@ const loadConfigFile = (() => {
211
213
  if (content) return content;
212
214
  }
213
215
  }
214
- currDir = path.dirname(currDir);
215
- } while (currDir !== stopDir && currDir !== homeDir && currDir !== path.dirname(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
@@ -1,6 +1,6 @@
1
1
  var name = "yamllint-js";
2
2
  var description = "A linter for YAML files — an unofficial native Node.js port of Python yamllint.";
3
- var version = "0.2.2";
3
+ var version = "0.2.4";
4
4
  var bin = {
5
5
  "yamllint-js": "dist/main.mjs",
6
6
  "yamllint": "dist/main.mjs"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yamllint-js",
3
3
  "description": "A linter for YAML files — an unofficial native Node.js port of Python yamllint.",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
7
7
  "author": {