oxlint-plugin-vize 0.443.0 → 0.457.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.
@@ -0,0 +1,7 @@
1
+ import { c as createVizeRuleConfig, s as configs } from "./configs-BuOTHAnm.mjs";
2
+
3
+ //#region src/eslint.d.ts
4
+ /** ESLint rules over the complete source supplied by the configured parser. */
5
+ declare const _default: import("@oxlint/plugins").Plugin;
6
+ //#endregion
7
+ export { configs, createVizeRuleConfig, _default as default };
@@ -0,0 +1,153 @@
1
+ import { a as getPatinaRules, c as isTypeAwareRuleName, d as getRuleOptions, i as formatPatinaMessage, l as createRuleSelection, n as createVizeRuleConfig, o as getActivePreset, r as plugin_default, s as getVizeSettings, t as configs } from "./configs-DY0BrbH2.mjs";
2
+ import { d as isPatinaFile, m as loadBinding } from "./workaround-CiQUFJw0.mjs";
3
+ import { definePlugin, defineRule, eslintCompatPlugin } from "@oxlint/plugins";
4
+ //#region src/eslint-source.ts
5
+ /** Native UTF-8 text cannot preserve an unpaired UTF-16 surrogate. */
6
+ function assertSourceText(source) {
7
+ if (/[\uD800-\uDFFF]/u.test(source)) throw new Error("Vize cannot lint source containing an unpaired UTF-16 surrogate");
8
+ }
9
+ /** Convert only requested UTF-8 boundaries, with one scan of the UTF-16 text. */
10
+ function mapSourceOffsets(source, offsets) {
11
+ const result = /* @__PURE__ */ new Map();
12
+ let index = 0;
13
+ let bytes = 0;
14
+ for (const offset of [...new Set(offsets)].sort((left, right) => left - right)) {
15
+ if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Vize returned an invalid source offset");
16
+ while (bytes < offset && index < source.length) {
17
+ const point = source.codePointAt(index);
18
+ bytes += point <= 127 ? 1 : point <= 2047 ? 2 : point <= 65535 ? 3 : 4;
19
+ index += point > 65535 ? 2 : 1;
20
+ }
21
+ if (bytes !== offset) throw new Error("Vize source offset is not a UTF-8 boundary");
22
+ result.set(offset, index);
23
+ }
24
+ return result;
25
+ }
26
+ /** Refuse invalid or overlapping native edits before handing them to a fixer. */
27
+ function mapTextEdits(edits, offsets) {
28
+ let previousEnd = -1;
29
+ let previousStart = -1;
30
+ return [...edits].sort((left, right) => left.start - right.start || left.end - right.end).map((edit) => {
31
+ const start = offsets.get(edit.start);
32
+ const end = offsets.get(edit.end);
33
+ if (start === void 0 || end === void 0 || start > end || start < previousEnd || start === previousStart || typeof edit.newText !== "string") throw new Error("Vize returned invalid or overlapping ESLint text edits");
34
+ previousStart = start;
35
+ previousEnd = end;
36
+ return {
37
+ range: [start, end],
38
+ text: edit.newText
39
+ };
40
+ });
41
+ }
42
+ //#endregion
43
+ //#region src/eslint.ts
44
+ const programs = /* @__PURE__ */ new WeakMap();
45
+ const metadata = getPatinaRules();
46
+ const byName = new Map(metadata.map((rule) => [rule.name, rule]));
47
+ function collect(context, program, name) {
48
+ const source = context.sourceCode.text;
49
+ let collected = programs.get(program);
50
+ if (!collected || collected.diagnostics) {
51
+ collected = {
52
+ source,
53
+ sourceCode: context.sourceCode,
54
+ filename: context.physicalFilename,
55
+ settings: structuredClone(getVizeSettings(context)),
56
+ options: /* @__PURE__ */ new Map()
57
+ };
58
+ programs.set(program, collected);
59
+ }
60
+ if (source !== collected.source || context.physicalFilename !== collected.filename) throw new Error("Vize source changed during ESLint rule collection");
61
+ collected.options.set(name, structuredClone(getRuleOptions(name, context.options)));
62
+ }
63
+ function run(collected) {
64
+ assertSourceText(collected.source);
65
+ const selection = createRuleSelection(collected.options);
66
+ const settings = collected.settings;
67
+ const result = loadBinding().lintPatinaSfc(collected.source, {
68
+ filename: collected.filename,
69
+ locale: settings.locale,
70
+ helpLevel: settings.helpLevel,
71
+ preset: getActivePreset(settings),
72
+ enabledRules: selection.names,
73
+ typeAware: settings.typeAware === true || selection.names.some(isTypeAwareRuleName),
74
+ corsaPath: settings.corsaPath,
75
+ ...selection.options,
76
+ includeFixes: true
77
+ });
78
+ if (result.filename !== collected.filename) throw new Error("Vize returned diagnostics for another ESLint source");
79
+ const diagnostics = /* @__PURE__ */ new Map();
80
+ const offsets = [];
81
+ for (const diagnostic of result.diagnostics) {
82
+ if (!selection.names.includes(diagnostic.rule)) throw new Error(`Vize returned an unselected ESLint rule: ${diagnostic.rule}`);
83
+ if (byName.get(diagnostic.rule)?.fixable && !Object.hasOwn(diagnostic, "fix")) throw new Error("The Vize native binding does not expose ESLint text edits; update it");
84
+ const current = diagnostics.get(diagnostic.rule) ?? [];
85
+ current.push(diagnostic);
86
+ diagnostics.set(diagnostic.rule, current);
87
+ offsets.push(diagnostic.location.start.offset, diagnostic.location.end.offset);
88
+ for (const edit of diagnostic.fix?.edits ?? []) offsets.push(edit.start, edit.end);
89
+ }
90
+ collected.offsets = mapSourceOffsets(collected.source, offsets);
91
+ collected.diagnostics = diagnostics;
92
+ }
93
+ /** ESLint rules over the complete source supplied by the configured parser. */
94
+ var eslint_default = eslintCompatPlugin(definePlugin({
95
+ meta: { name: "oxlint-plugin-vize" },
96
+ rules: Object.fromEntries(metadata.map((rule) => [rule.name, defineRule({
97
+ meta: {
98
+ ...plugin_default.rules[rule.name].meta,
99
+ ...rule.fixable ? { fixable: "code" } : {}
100
+ },
101
+ createOnce(context) {
102
+ let participated;
103
+ return {
104
+ before() {
105
+ participated = void 0;
106
+ },
107
+ after() {
108
+ if (participated) programs.delete(participated);
109
+ participated = void 0;
110
+ },
111
+ Program(program) {
112
+ if (!isPatinaFile(context.physicalFilename)) return;
113
+ const preset = getActivePreset(getVizeSettings(context));
114
+ if (preset !== "incremental" && rule.presets.length > 0 && !rule.presets.includes(preset)) return;
115
+ collect(context, program, rule.name);
116
+ participated = program;
117
+ },
118
+ "Program:exit"(program) {
119
+ if (participated !== program) return;
120
+ const collected = programs.get(program);
121
+ if (!collected?.options.has(rule.name)) return;
122
+ if (collected.source !== context.sourceCode.text || collected.sourceCode !== context.sourceCode || collected.filename !== context.physicalFilename || JSON.stringify(collected.settings) !== JSON.stringify(getVizeSettings(context))) throw new Error("Vize source changed before ESLint rule execution");
123
+ if (!collected.diagnostics) run(collected);
124
+ const sourceCode = context.sourceCode;
125
+ for (const diagnostic of collected.diagnostics.get(rule.name) ?? []) {
126
+ const start = collected.offsets.get(diagnostic.location.start.offset);
127
+ const end = collected.offsets.get(diagnostic.location.end.offset);
128
+ if (start > end) throw new Error("Vize returned a reversed diagnostic span");
129
+ const loc = {
130
+ start: sourceCode.getLocFromIndex(start),
131
+ end: sourceCode.getLocFromIndex(end)
132
+ };
133
+ if (loc.start.line !== diagnostic.location.start.line || loc.start.column + 1 !== diagnostic.location.start.column || loc.end.line !== diagnostic.location.end.line || loc.end.column + 1 !== diagnostic.location.end.column) throw new Error("Vize returned inconsistent ESLint location metadata");
134
+ const edits = diagnostic.fix ? mapTextEdits(diagnostic.fix.edits, collected.offsets) : void 0;
135
+ context.report({
136
+ loc,
137
+ message: formatPatinaMessage(diagnostic, {
138
+ hasMappedLocation: true,
139
+ blockLabel: null,
140
+ helpLevel: collected.settings.helpLevel ?? "full"
141
+ }),
142
+ ...edits ? { fix(fixer) {
143
+ return edits.map((edit) => fixer.replaceTextRange(edit.range, edit.text));
144
+ } } : {}
145
+ });
146
+ }
147
+ }
148
+ };
149
+ }
150
+ })]))
151
+ }));
152
+ //#endregion
153
+ export { configs, createVizeRuleConfig, eslint_default as default };
package/dist/index.d.mts CHANGED
@@ -1,45 +1,8 @@
1
+ import { a as VizeRuleConfigPreset, c as createVizeRuleConfig, i as VizeRuleConfigOptions, l as PatinaPreset, n as OxlintRuleEntry, o as VizeRuleConfigPresetInput, r as OxlintRuleSeverity, s as configs, t as OxlintRuleConfig, u as PatinaSettings } from "./configs-BuOTHAnm.mjs";
2
+
1
3
  //#region src/plugin.d.ts
2
4
  declare const _default: import("@oxlint/plugins").Plugin;
3
5
  //#endregion
4
- //#region src/model.d.ts
5
- type HelpLevel = "none" | "short" | "full";
6
- type PatinaPreset = "general-recommended" | "essential" | "ecosystem" | "incremental" | "opinionated" | "nuxt";
7
- interface PatinaSettings {
8
- locale?: string;
9
- helpLevel?: HelpLevel;
10
- preset?: PatinaPreset;
11
- typeAware?: boolean;
12
- corsaPath?: string;
13
- /** Rules to evaluate together. Oxlint's own rules still control reporting. */
14
- rules?: readonly string[] | Record<string, unknown>;
15
- }
16
- //#endregion
17
- //#region src/configs.d.ts
18
- type OxlintRuleSeverity = "error" | "warn" | "off";
19
- type OxlintRuleEntry = OxlintRuleSeverity | [OxlintRuleSeverity, ...unknown[]];
20
- type OxlintRuleConfig = Record<string, OxlintRuleEntry>;
21
- type VizeRuleConfigPreset = Exclude<PatinaPreset, "incremental"> | "happy-path" | "all";
22
- type VizeRuleConfigPresetInput = VizeRuleConfigPreset | readonly VizeRuleConfigPreset[];
23
- interface VizeRuleConfigOptions {
24
- includeTypeAware?: boolean;
25
- preset?: VizeRuleConfigPresetInput;
26
- presets?: readonly VizeRuleConfigPreset[];
27
- }
28
- declare function createVizeRuleConfig(options?: VizeRuleConfigOptions): OxlintRuleConfig;
29
- declare const configs: {
30
- readonly all: OxlintRuleConfig;
31
- readonly ecosystem: OxlintRuleConfig;
32
- readonly ecosystemWithTypeAware: OxlintRuleConfig;
33
- readonly essential: OxlintRuleConfig;
34
- readonly happyPath: OxlintRuleConfig;
35
- readonly happyPathWithTypeAware: OxlintRuleConfig;
36
- readonly nuxt: OxlintRuleConfig;
37
- readonly opinionated: OxlintRuleConfig;
38
- readonly opinionatedWithTypeAware: OxlintRuleConfig;
39
- readonly recommended: OxlintRuleConfig;
40
- readonly recommendedWithTypeAware: OxlintRuleConfig;
41
- };
42
- //#endregion
43
6
  //#region src/vite-plus.d.ts
44
7
  /**
45
8
  * Bare specifier Oxlint uses to load this bridge as a JS plugin.