rintenki 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-PRESENT Kazuhiro Kobayashi<https://github.com/kzhrk>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { existsSync, readFileSync, writeFileSync } = require("fs");
4
+ const { resolve, relative } = require("path");
5
+ const { glob } = require("tinyglobby");
6
+ const { lint, fix } = require("../index");
7
+
8
+ const COLORS = {
9
+ red: "\x1b[31m",
10
+ yellow: "\x1b[33m",
11
+ gray: "\x1b[90m",
12
+ bold: "\x1b[1m",
13
+ reset: "\x1b[0m",
14
+ };
15
+
16
+ const CONFIG_FILES = [".rintenkirc.json", ".rintenkirc"];
17
+ const IGNORE_FILE = ".rintenkiignore";
18
+
19
+ function parseJsonFile(filePath) {
20
+ try {
21
+ return JSON.parse(readFileSync(filePath, "utf-8"));
22
+ } catch (err) {
23
+ console.error(`Failed to parse config file: ${filePath}`);
24
+ console.error(err.message);
25
+ process.exit(1);
26
+ }
27
+ }
28
+
29
+ function loadConfig(configPath) {
30
+ if (configPath) {
31
+ const abs = resolve(configPath);
32
+ if (!existsSync(abs)) {
33
+ console.error(`Config file not found: ${configPath}`);
34
+ process.exit(1);
35
+ }
36
+ return parseJsonFile(abs);
37
+ }
38
+
39
+ for (const name of CONFIG_FILES) {
40
+ const abs = resolve(name);
41
+ if (existsSync(abs)) {
42
+ return parseJsonFile(abs);
43
+ }
44
+ }
45
+
46
+ return undefined;
47
+ }
48
+
49
+ function loadIgnorePatterns(config) {
50
+ const patterns = [];
51
+
52
+ // From .rintenkiignore file
53
+ const ignorePath = resolve(IGNORE_FILE);
54
+ if (existsSync(ignorePath)) {
55
+ const content = readFileSync(ignorePath, "utf-8");
56
+ for (const line of content.split("\n")) {
57
+ const trimmed = line.trim();
58
+ if (trimmed && !trimmed.startsWith("#")) {
59
+ patterns.push(trimmed);
60
+ }
61
+ }
62
+ }
63
+
64
+ // From config.ignore field
65
+ if (config?.ignore && Array.isArray(config.ignore)) {
66
+ patterns.push(...config.ignore);
67
+ }
68
+
69
+ // Always ignore node_modules
70
+ patterns.push("**/node_modules/**");
71
+
72
+ return patterns;
73
+ }
74
+
75
+ function formatDiagnostic(diagnostic) {
76
+ const severity =
77
+ diagnostic.severity === "error"
78
+ ? `${COLORS.red}error${COLORS.reset}`
79
+ : `${COLORS.yellow}warning${COLORS.reset}`;
80
+ const loc = diagnostic.line != null ? `${COLORS.gray}line ${diagnostic.line}${COLORS.reset} ` : "";
81
+ return ` ${loc}${severity} ${diagnostic.message} ${COLORS.gray}${diagnostic.rule}${COLORS.reset}`;
82
+ }
83
+
84
+ function parseArgs(argv) {
85
+ const args = { files: [], config: undefined, help: false, maxWarnings: -1, format: "stylish", fix: false };
86
+ let i = 0;
87
+ while (i < argv.length) {
88
+ const arg = argv[i];
89
+ if (arg === "--help" || arg === "-h") {
90
+ args.help = true;
91
+ } else if (arg === "--config" || arg === "-c") {
92
+ args.config = argv[++i];
93
+ } else if (arg === "--max-warnings") {
94
+ args.maxWarnings = parseInt(argv[++i], 10);
95
+ } else if (arg === "--format" || arg === "-f") {
96
+ args.format = argv[++i];
97
+ } else if (arg === "--fix") {
98
+ args.fix = true;
99
+ } else if (!arg.startsWith("-")) {
100
+ args.files.push(arg);
101
+ }
102
+ i++;
103
+ }
104
+ return args;
105
+ }
106
+
107
+ async function main() {
108
+ const args = parseArgs(process.argv.slice(2));
109
+
110
+ if (args.help || args.files.length === 0) {
111
+ console.log(`Usage: rintenki [options] <files...>
112
+
113
+ Options:
114
+ -c, --config <path> Path to config file (default: .rintenkirc.json)
115
+ -f, --format <format> Output format: stylish (default), json
116
+ --fix Auto-fix fixable issues
117
+ --max-warnings <number> Exit with error if warnings exceed this number
118
+ -h, --help Show help
119
+
120
+ Ignore patterns:
121
+ Create a .rintenkiignore file or use "ignore" in config to exclude files.
122
+ node_modules is always ignored.
123
+
124
+ Examples:
125
+ rintenki index.html
126
+ rintenki "src/**/*.html"
127
+ rintenki --format json "src/**/*.html"`);
128
+ process.exit(0);
129
+ }
130
+
131
+ const config = loadConfig(args.config);
132
+ const ignorePatterns = loadIgnorePatterns(config);
133
+ const files = await glob(args.files, { absolute: true, ignore: ignorePatterns });
134
+
135
+ if (files.length === 0) {
136
+ console.error("No files matched the given patterns.");
137
+ process.exit(1);
138
+ }
139
+
140
+ let totalErrors = 0;
141
+ let totalWarnings = 0;
142
+ const jsonOutput = [];
143
+
144
+ let totalFixed = 0;
145
+
146
+ for (const file of files) {
147
+ let html = readFileSync(file, "utf-8");
148
+
149
+ if (args.fix) {
150
+ const fixResult = fix(html, config);
151
+ if (fixResult.fixedCount > 0) {
152
+ writeFileSync(file, fixResult.output, "utf-8");
153
+ html = fixResult.output;
154
+ totalFixed += fixResult.fixedCount;
155
+ }
156
+ }
157
+
158
+ const result = lint(html, config);
159
+ const rel = relative(process.cwd(), file);
160
+
161
+ for (const d of result.diagnostics) {
162
+ if (d.severity === "error") totalErrors++;
163
+ else totalWarnings++;
164
+ }
165
+
166
+ if (args.format === "json") {
167
+ if (result.diagnostics.length > 0) {
168
+ jsonOutput.push({
169
+ file: rel,
170
+ diagnostics: result.diagnostics,
171
+ });
172
+ }
173
+ } else {
174
+ if (result.diagnostics.length === 0) continue;
175
+ console.log(`\n${COLORS.bold}${rel}${COLORS.reset}`);
176
+ for (const d of result.diagnostics) {
177
+ console.log(formatDiagnostic(d));
178
+ }
179
+ }
180
+ }
181
+
182
+ if (args.format === "json") {
183
+ console.log(JSON.stringify(jsonOutput, null, 2));
184
+ } else if (totalErrors > 0 || totalWarnings > 0) {
185
+ const parts = [];
186
+ if (totalErrors > 0) parts.push(`${totalErrors} error${totalErrors > 1 ? "s" : ""}`);
187
+ if (totalWarnings > 0) parts.push(`${totalWarnings} warning${totalWarnings > 1 ? "s" : ""}`);
188
+ console.log(
189
+ `\n${COLORS.bold}${parts.join(", ")} in ${files.length} file${files.length > 1 ? "s" : ""}${COLORS.reset}\n`
190
+ );
191
+ } else if (totalFixed > 0) {
192
+ console.log(`Fixed ${totalFixed} issue${totalFixed > 1 ? "s" : ""}.`);
193
+ } else {
194
+ console.log("No issues found.");
195
+ }
196
+
197
+ if (totalErrors > 0) {
198
+ process.exit(1);
199
+ }
200
+
201
+ if (args.maxWarnings >= 0 && totalWarnings > args.maxWarnings) {
202
+ process.exit(1);
203
+ }
204
+ }
205
+
206
+ main().catch((err) => {
207
+ console.error(err);
208
+ process.exit(1);
209
+ });
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ export interface LintDiagnostic {
2
+ rule: string;
3
+ message: string;
4
+ severity: "error" | "warning";
5
+ line: number | null;
6
+ fixable: boolean;
7
+ }
8
+
9
+ export interface LintResult {
10
+ diagnostics: LintDiagnostic[];
11
+ }
12
+
13
+ export interface FixResult {
14
+ output: string;
15
+ fixedCount: number;
16
+ }
17
+
18
+ export type RuleSeverity = "error" | "warning" | "off" | boolean;
19
+
20
+ export interface LintConfig {
21
+ /**
22
+ * Rule name -> severity.
23
+ * - "error": report as error
24
+ * - "warning" | "warn": report as warning
25
+ * - "off" | false: disable the rule
26
+ * - true: use default severity
27
+ */
28
+ rules?: Record<string, RuleSeverity>;
29
+ }
30
+
31
+ export function lint(html: string, config?: LintConfig): LintResult;
32
+ export function fix(html: string, config?: LintConfig): FixResult;
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ const { existsSync } = require("fs");
2
+ const { join } = require("path");
3
+
4
+ const { platform, arch } = process;
5
+
6
+ function loadBinding() {
7
+ const triples = {
8
+ "darwin-arm64": "rintenki.darwin-arm64.node",
9
+ "darwin-x64": "rintenki.darwin-x64.node",
10
+ "linux-x64": "rintenki.linux-x64-gnu.node",
11
+ "linux-arm64": "rintenki.linux-arm64-gnu.node",
12
+ "win32-x64": "rintenki.win32-x64-msvc.node",
13
+ "win32-arm64": "rintenki.win32-arm64-msvc.node",
14
+ };
15
+
16
+ const packages = {
17
+ "darwin-arm64": "rintenki-darwin-arm64",
18
+ "darwin-x64": "rintenki-darwin-x64",
19
+ "linux-x64": "rintenki-linux-x64-gnu",
20
+ "linux-arm64": "rintenki-linux-arm64-gnu",
21
+ "win32-x64": "rintenki-win32-x64-msvc",
22
+ "win32-arm64": "rintenki-win32-arm64-msvc",
23
+ };
24
+
25
+ const key = `${platform}-${arch}`;
26
+ const file = triples[key];
27
+ if (!file) {
28
+ throw new Error(`Unsupported platform: ${key}`);
29
+ }
30
+
31
+ const localPath = join(__dirname, file);
32
+ if (existsSync(localPath)) {
33
+ return require(localPath);
34
+ }
35
+
36
+ const pkg = packages[key];
37
+ try {
38
+ return require(pkg);
39
+ } catch (_) {
40
+ throw new Error(
41
+ `Failed to load native binding for ${key}. ` +
42
+ `Tried ${localPath} and ${pkg}`
43
+ );
44
+ }
45
+ }
46
+
47
+ const binding = loadBinding();
48
+ module.exports.lint = binding.lint;
49
+ module.exports.fix = binding.fix;
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "rintenki",
3
+ "version": "0.0.0",
4
+ "description": "A fast HTML linter powered by html5ever + napi-rs",
5
+ "author": "Kazuhiro Kobayashi <https://github.com/kzhrk>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kzhrk/rintenki",
10
+ "directory": "packages/rintenki"
11
+ },
12
+ "homepage": "https://github.com/kzhrk/rintenki",
13
+ "bugs": {
14
+ "url": "https://github.com/kzhrk/rintenki/issues"
15
+ },
16
+ "keywords": [
17
+ "html",
18
+ "linter",
19
+ "lint",
20
+ "html5",
21
+ "html5ever",
22
+ "accessibility",
23
+ "a11y",
24
+ "napi-rs"
25
+ ],
26
+ "main": "index.js",
27
+ "types": "index.d.ts",
28
+ "bin": {
29
+ "rintenki": "bin/rintenki.js"
30
+ },
31
+ "files": [
32
+ "index.js",
33
+ "index.d.ts",
34
+ "bin/rintenki.js",
35
+ "rintenki.*.node"
36
+ ],
37
+ "napi": {
38
+ "binaryName": "rintenki",
39
+ "targets": [
40
+ "aarch64-apple-darwin",
41
+ "x86_64-apple-darwin",
42
+ "x86_64-unknown-linux-gnu",
43
+ "aarch64-unknown-linux-gnu",
44
+ "x86_64-pc-windows-msvc",
45
+ "aarch64-pc-windows-msvc"
46
+ ]
47
+ },
48
+ "dependencies": {
49
+ "tinyglobby": "0.2.15"
50
+ },
51
+ "devDependencies": {
52
+ "@napi-rs/cli": "3.5.1",
53
+ "@types/node": "25.5.0",
54
+ "typescript": "6.0.2",
55
+ "vitest": "4.1.2"
56
+ },
57
+ "scripts": {
58
+ "build": "napi build --release --platform --no-js --dts .napi-output.d.ts && rm -f .napi-output.d.ts",
59
+ "build:debug": "napi build --platform --no-js --dts .napi-output.d.ts && rm -f .napi-output.d.ts",
60
+ "test": "vitest run"
61
+ }
62
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file