yamllint-js 0.2.1 β 0.2.2
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 +7 -0
- package/README.md +6 -4
- package/dist/config.d.mts +5 -2
- package/dist/config.mjs +52 -22
- package/dist/constants.mjs +8 -10
- package/dist/package.mjs +6 -2
- package/dist/utils.mjs +11 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.2](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.1...v0.2.2) (2026-02-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### π Bug Fixes
|
|
7
|
+
|
|
8
|
+
* detection yamllint field in package.json ([#37](https://github.com/kimzuni-labs/yamllint-js/issues/37)) ([5fe02d7](https://github.com/kimzuni-labs/yamllint-js/commit/5fe02d73c299bba7a53edb90a56aa16fad4fc845))
|
|
9
|
+
|
|
3
10
|
## [0.2.1](https://github.com/kimzuni-labs/yamllint-js/compare/v0.2.0...v0.2.1) (2026-02-14)
|
|
4
11
|
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -130,14 +130,15 @@ In addition to the yamllint configuration format,
|
|
|
130
130
|
JavaScript and TypeScript configuration files are also supported:
|
|
131
131
|
|
|
132
132
|
- [yamllint configuration files and environment variables](https://yamllint.readthedocs.io/en/stable/configuration.html):
|
|
133
|
-
-
|
|
134
|
-
+ `package.json` (`"yamllint-js"
|
|
135
|
-
+ `
|
|
133
|
+
- `package.json` or js/ts config files
|
|
134
|
+
+ `package.json` (`"yamllint-js"`, `"yamllint"` fields)
|
|
135
|
+
+ `yamllint-js.config.js`, `.ts`, `.cjs`, `.mjs`
|
|
136
|
+
+ `yamllint.config.js`, `.ts`, `.cjs`, `.mjs`
|
|
136
137
|
|
|
137
138
|
Configuration can be easily defined with type hints, like:
|
|
138
139
|
|
|
139
140
|
```typescript
|
|
140
|
-
/** @type {import("yamllint-js").UserConfig
|
|
141
|
+
/** @type {import("yamllint-js").UserConfig} */
|
|
141
142
|
|
|
142
143
|
const config = {/* ... */};
|
|
143
144
|
|
|
@@ -220,3 +221,4 @@ rules:
|
|
|
220
221
|
## License
|
|
221
222
|
|
|
222
223
|
[GPL version 3](./LICENSE)
|
|
224
|
+
(port of [yamllint](https://github.com/adrienverge/yamllint))
|
package/dist/config.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Level } from "./constants.mjs";
|
|
|
2
2
|
import { Rule, RuleConf } from "./rules/types.mjs";
|
|
3
3
|
import { RuleId } from "./rules/index.mjs";
|
|
4
4
|
import { AllLevel, BuiltInExtendName, MaybeCamelCaseKeys, Prettify, ToCamelCaseKeys } from "./types.mjs";
|
|
5
|
-
import * as cosmiconfig0 from "cosmiconfig";
|
|
6
5
|
import { Ignore } from "ignore";
|
|
7
6
|
|
|
8
7
|
//#region src/config.d.ts
|
|
@@ -70,6 +69,10 @@ declare class YamlLintConfig {
|
|
|
70
69
|
enabledRules(filepath?: string): Rule[];
|
|
71
70
|
extend(baseConfig: unknown): void;
|
|
72
71
|
}
|
|
72
|
+
interface LoadConfigFileOptions {
|
|
73
|
+
startDir?: string;
|
|
74
|
+
stopDir?: string;
|
|
75
|
+
}
|
|
73
76
|
/**
|
|
74
77
|
* Load YAML lint configuration from a file.
|
|
75
78
|
*
|
|
@@ -80,7 +83,7 @@ declare class YamlLintConfig {
|
|
|
80
83
|
* const specified = await loadConfigFile("path/to/yamllint.yaml");
|
|
81
84
|
* ```
|
|
82
85
|
*/
|
|
83
|
-
declare const loadConfigFile: (filepath?: string) => Promise<
|
|
86
|
+
declare const loadConfigFile: (filepath?: string | LoadConfigFileOptions) => Promise<unknown>;
|
|
84
87
|
/**
|
|
85
88
|
* Detect user global config file path.
|
|
86
89
|
*
|
package/dist/config.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ALIASES,
|
|
2
|
-
import { formatErrorMessage, getHomedir, splitlines, toKebabCaseKeys } from "./utils.mjs";
|
|
1
|
+
import { ALIASES, COMMAND_NAMES, LEVELS, PY_YAMLLINT_CONFIG_FILES, YAML_OPTIONS } from "./constants.mjs";
|
|
2
|
+
import { formatErrorMessage, getHomedir, getNodeSearchPlaces, splitlines, toKebabCaseKeys } from "./utils.mjs";
|
|
3
3
|
import { autoDecode, linesInFiles } from "./decoder.mjs";
|
|
4
4
|
import { get } from "./rules/index.mjs";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { cosmiconfig, defaultLoaders } from "cosmiconfig";
|
|
8
7
|
import assert from "node:assert";
|
|
9
8
|
import yaml from "yaml";
|
|
10
9
|
import z from "zod";
|
|
11
10
|
import ignore$1 from "ignore";
|
|
11
|
+
import { createJiti } from "jiti";
|
|
12
12
|
/*!
|
|
13
13
|
* Copyright (C) 2016 Adrien VergΓ©
|
|
14
14
|
* Copyright (C) 2025 kimzuni
|
|
@@ -79,7 +79,7 @@ var YamlLintConfig = class YamlLintConfig {
|
|
|
79
79
|
if (props._data !== void 0 || props.data !== void 0) this.#data = props._data ?? props.data;
|
|
80
80
|
else try {
|
|
81
81
|
if (props.content !== void 0) this.#data = yaml.parse(props.content, YAML_OPTIONS);
|
|
82
|
-
else this.#data = await loadConfigFile(props.file)
|
|
82
|
+
else this.#data = await loadConfigFile(props.file);
|
|
83
83
|
} catch (e) {
|
|
84
84
|
throw new YamlLintConfigError(formatErrorMessage("invalid config: ", e));
|
|
85
85
|
}
|
|
@@ -165,24 +165,54 @@ async function validateRuleConf(rule, config) {
|
|
|
165
165
|
return conf;
|
|
166
166
|
}
|
|
167
167
|
const loadConfigFile = (() => {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
".
|
|
180
|
-
|
|
181
|
-
|
|
168
|
+
const jsReg = /\.[cm]?js$/;
|
|
169
|
+
const homeDir = getHomedir();
|
|
170
|
+
const filenames = [
|
|
171
|
+
"package.json",
|
|
172
|
+
...getNodeSearchPlaces(COMMAND_NAMES),
|
|
173
|
+
...PY_YAMLLINT_CONFIG_FILES
|
|
174
|
+
];
|
|
175
|
+
const loadFile = async (filepath, throwOnFailure = false) => {
|
|
176
|
+
try {
|
|
177
|
+
filepath = path.resolve(filepath);
|
|
178
|
+
const filename = path.basename(filepath);
|
|
179
|
+
if (jsReg.test(filepath) || filepath.endsWith(".ts")) {
|
|
180
|
+
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;
|
|
185
|
+
} else if (filename === "package.json") {
|
|
186
|
+
const content = autoDecode(await fs.readFile(filepath));
|
|
187
|
+
const pkg = JSON.parse(content);
|
|
188
|
+
if (typeof pkg !== "object" || pkg === null) return;
|
|
189
|
+
for (const name of COMMAND_NAMES) {
|
|
190
|
+
const value = pkg[name];
|
|
191
|
+
if (value) return value;
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
const content = autoDecode(await fs.readFile(filepath));
|
|
195
|
+
return yaml.parse(content, YAML_OPTIONS);
|
|
196
|
+
}
|
|
197
|
+
} catch {
|
|
198
|
+
if (throwOnFailure) throw new YamlLintConfigError(`failed to load config file "${filepath}"`);
|
|
199
|
+
return;
|
|
182
200
|
}
|
|
183
|
-
}
|
|
184
|
-
return function loadConfigFile(filepath) {
|
|
185
|
-
|
|
201
|
+
};
|
|
202
|
+
return async function loadConfigFile(filepath) {
|
|
203
|
+
if (typeof filepath === "string") return loadFile(filepath, true);
|
|
204
|
+
const { startDir = process.cwd(), stopDir } = filepath ?? {};
|
|
205
|
+
let currDir = path.resolve(startDir);
|
|
206
|
+
do {
|
|
207
|
+
for (const filename of filenames) {
|
|
208
|
+
const curr = path.join(currDir, filename);
|
|
209
|
+
if (await fs.stat(curr).then((x) => x.isFile() || x.isSymbolicLink()).catch(() => false)) {
|
|
210
|
+
const content = await loadFile(curr);
|
|
211
|
+
if (content) return content;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
currDir = path.dirname(currDir);
|
|
215
|
+
} while (currDir !== stopDir && currDir !== homeDir && currDir !== path.dirname(currDir));
|
|
186
216
|
};
|
|
187
217
|
})();
|
|
188
218
|
async function detectUserGlobalConfig() {
|
|
@@ -196,7 +226,7 @@ async function loadYamlLintConfig() {
|
|
|
196
226
|
let userGlobalConfig;
|
|
197
227
|
let load;
|
|
198
228
|
let conf;
|
|
199
|
-
if (load = await loadConfigFile()) conf = await YamlLintConfig.init({ _data: load
|
|
229
|
+
if (load = await loadConfigFile()) conf = await YamlLintConfig.init({ _data: load });
|
|
200
230
|
else if (userGlobalConfig = await detectUserGlobalConfig()) conf = await YamlLintConfig.init({ file: userGlobalConfig });
|
|
201
231
|
else conf = await YamlLintConfig.init({ content: "extends: default" });
|
|
202
232
|
return conf;
|
package/dist/constants.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { description, name, version } from "./package.mjs";
|
|
2
|
-
|
|
1
|
+
import { bin, description, name, version } from "./package.mjs";
|
|
2
|
+
const COMMAND_NAMES = Object.keys(bin);
|
|
3
3
|
const APP = {
|
|
4
4
|
NAME: name,
|
|
5
5
|
VERSION: version,
|
|
@@ -10,17 +10,15 @@ const APP = {
|
|
|
10
10
|
"such as lines length, trailing spaces, indentation, etc."
|
|
11
11
|
].join(" ")
|
|
12
12
|
};
|
|
13
|
-
const
|
|
14
|
-
version: "1.1",
|
|
15
|
-
uniqueKeys: false
|
|
16
|
-
};
|
|
17
|
-
const CONFIG_SEARCH_PLACES = [
|
|
18
|
-
...getDefaultSearchPlaces(APP.NAME).filter((x) => !x.includes(`${APP.NAME}rc`)),
|
|
19
|
-
...getDefaultSearchPlaces("yamllint").filter((x) => !x.includes("yamllintrc")),
|
|
13
|
+
const PY_YAMLLINT_CONFIG_FILES = [
|
|
20
14
|
".yamllint",
|
|
21
15
|
".yamllint.yaml",
|
|
22
16
|
".yamllint.yml"
|
|
23
17
|
];
|
|
18
|
+
const YAML_OPTIONS = {
|
|
19
|
+
version: "1.1",
|
|
20
|
+
uniqueKeys: false
|
|
21
|
+
};
|
|
24
22
|
const LEVELS = [
|
|
25
23
|
null,
|
|
26
24
|
"warning",
|
|
@@ -40,4 +38,4 @@ const PROBLEM_LEVELS = {
|
|
|
40
38
|
};
|
|
41
39
|
const PY_EOL = /\r\n|\r|\n|\v|\f|\x1c|\x1d|\x1e|\x85|\u2028|\u2029/;
|
|
42
40
|
const PY_EOL_END = new RegExp(`(${PY_EOL.source})$`);
|
|
43
|
-
export { ALIASES, APP,
|
|
41
|
+
export { ALIASES, APP, COMMAND_NAMES, LEVELS, PROBLEM_LEVELS, PY_EOL, PY_EOL_END, PY_YAMLLINT_CONFIG_FILES, YAML_OPTIONS };
|
package/dist/package.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
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.
|
|
4
|
-
|
|
3
|
+
var version = "0.2.2";
|
|
4
|
+
var bin = {
|
|
5
|
+
"yamllint-js": "dist/main.mjs",
|
|
6
|
+
"yamllint": "dist/main.mjs"
|
|
7
|
+
};
|
|
8
|
+
export { bin, description, name, version };
|
package/dist/utils.mjs
CHANGED
|
@@ -49,4 +49,14 @@ const toKebabCaseKeys = (data) => {
|
|
|
49
49
|
for (const key in data) newData[toKebabCase(key)] = data[key];
|
|
50
50
|
return newData;
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
const getNodeSearchPlaces = (name, set = /* @__PURE__ */ new Set()) => {
|
|
53
|
+
const names = Array.isArray(name) ? name : [name];
|
|
54
|
+
for (const n of names) {
|
|
55
|
+
set.add(`${n}.config.js`);
|
|
56
|
+
set.add(`${n}.config.ts`);
|
|
57
|
+
set.add(`${n}.config.cjs`);
|
|
58
|
+
set.add(`${n}.config.mjs`);
|
|
59
|
+
}
|
|
60
|
+
return set;
|
|
61
|
+
};
|
|
62
|
+
export { B, bufferStartsWith, formatErrorMessage, getHomedir, getNodeSearchPlaces, once, splitlines, toKebabCaseKeys };
|
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.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
"lint:eslint": "eslint .",
|
|
24
24
|
"lint:types": "tsc --noEmit",
|
|
25
25
|
"lint:markdown": "markdownlint-cli2",
|
|
26
|
-
"lint:yaml": "node dist/main.mjs -c yamllint.self.config.js .
|
|
27
|
-
"
|
|
26
|
+
"lint:yaml": "node dist/main.mjs -c yamllint.self.config.js .",
|
|
27
|
+
"prelint:yaml": "npm run build:nodts",
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"build:nodts": "tsdown --no-dts"
|
|
28
30
|
},
|
|
29
31
|
"files": [
|
|
30
32
|
"dist",
|
|
@@ -51,9 +53,9 @@
|
|
|
51
53
|
"./internal": "./dist/internal.mjs"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
|
-
"cosmiconfig": "^9.0.0",
|
|
55
56
|
"iconv-lite": "^0.7.2",
|
|
56
57
|
"ignore": "^7.0.5",
|
|
58
|
+
"jiti": "^2.6.1",
|
|
57
59
|
"recheck": "^4.5.0",
|
|
58
60
|
"yaml": "^2.8.2",
|
|
59
61
|
"yargs": "^18.0.0",
|
|
@@ -67,11 +69,9 @@
|
|
|
67
69
|
"@vitest/coverage-v8": "^4.0.18",
|
|
68
70
|
"@vitest/ui": "^4.0.18",
|
|
69
71
|
"eslint": "^9.39.2",
|
|
70
|
-
"jiti": "^2.6.1",
|
|
71
72
|
"markdownlint-cli2": "^0.20.0",
|
|
72
73
|
"standard-version": "^9.5.0",
|
|
73
74
|
"tsdown": "^0.20.1",
|
|
74
|
-
"tsx": "^4.21.0",
|
|
75
75
|
"typescript": "^5.9.3",
|
|
76
76
|
"typescript-eslint": "^8.54.0",
|
|
77
77
|
"vitest": "^4.0.18"
|