@konvert7/klint 0.37.1 → 1.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.
Files changed (56) hide show
  1. package/README.md +49 -166
  2. package/bin/klint.js +47 -0
  3. package/klint.schema.json +1 -1
  4. package/klint.schema.yaml +1 -1
  5. package/package.json +15 -25
  6. package/cli/command.ts +0 -189
  7. package/cli/commands.ts +0 -90
  8. package/cli/help.ts +0 -21
  9. package/cli/install-skill.ts +0 -260
  10. package/cli/output.ts +0 -178
  11. package/cli/paths.ts +0 -20
  12. package/cli/rust-config.ts +0 -145
  13. package/cli/rust-engine.ts +0 -323
  14. package/cli/stats.ts +0 -92
  15. package/cli.ts +0 -214
  16. package/core/arch-comments.ts +0 -125
  17. package/core/arch.ts +0 -470
  18. package/core/ast.ts +0 -63
  19. package/core/config.schema.ts +0 -413
  20. package/core/fixer.ts +0 -47
  21. package/core/native-binary.ts +0 -123
  22. package/core/paths.ts +0 -9
  23. package/core/rule-helpers.ts +0 -76
  24. package/core/runner.ts +0 -196
  25. package/core/schema-version.ts +0 -46
  26. package/core/skill.ts +0 -164
  27. package/core/stats.ts +0 -160
  28. package/core/types.ts +0 -146
  29. package/plugins/index.ts +0 -6
  30. package/plugins/sonar.ts +0 -27
  31. package/rules/index.ts +0 -26
  32. package/rules/no-async-predicate.ts +0 -51
  33. package/rules/no-consecutive-array-push.ts +0 -61
  34. package/rules/no-date-equality.ts +0 -35
  35. package/rules/no-floating-promise.ts +0 -37
  36. package/rules/no-misused-promises.ts +0 -59
  37. package/rules/no-nested-template-literals.ts +0 -47
  38. package/rules/no-object-in-template.ts +0 -95
  39. package/rules/no-optional-chain-on-non-nullable.ts +0 -47
  40. package/rules/no-single-char-class.ts +0 -113
  41. package/rules/no-string-match.ts +0 -63
  42. package/rules/no-sync-in-async.ts +0 -43
  43. package/rules/no-unguarded-json-parse.ts +0 -35
  44. package/rules/prefer-at.ts +0 -46
  45. package/rules/prefer-nullish-coalescing-assign.ts +0 -111
  46. package/rules/prefer-string-raw-regexp.ts +0 -93
  47. package/rules/prefer-string-raw.ts +0 -39
  48. package/rules/prefer-string-replaceall.ts +0 -67
  49. package/skill/klint-rules/SKILL.md +0 -264
  50. package/tools/generate-homebrew-formula.ts +0 -64
  51. package/tools/prepare-native-release.ts +0 -166
  52. package/tools/prepare-nuget-release.ts +0 -62
  53. package/tools/prepare-python-release.ts +0 -76
  54. package/tools/semantic-release-crates.js +0 -96
  55. package/tools/semantic-release-native-npm.js +0 -121
  56. package/tools/semantic-release-root-npm.js +0 -87
@@ -1,96 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
-
5
- const CRATE_NAME = "klint-rs";
6
- const MANIFEST = "crates/klint-rs/Cargo.toml";
7
- const WORKSPACE_SKILL = "skill/klint-rules/SKILL.md";
8
- const PACKAGED_SKILL = "crates/klint-rs/skill/SKILL.md";
9
-
10
- export async function verifyConditions(_, context) {
11
- const manifest = readManifest(cwdOf(context));
12
- if (crateNameOf(manifest) !== CRATE_NAME) {
13
- throw new Error(`${MANIFEST} declares ${crateNameOf(manifest)}, expected ${CRATE_NAME}`);
14
- }
15
- if (context.options?.dryRun) return;
16
- if (!process.env.CARGO_REGISTRY_TOKEN) {
17
- throw new Error(
18
- "CARGO_REGISTRY_TOKEN is unset; crates.io trusted publishing issued no token"
19
- );
20
- }
21
- }
22
-
23
- export async function prepare(pluginConfig = {}, context) {
24
- const cwd = cwdOf(context);
25
- const version = versionOf(context);
26
-
27
- writeManifest(cwd, stampVersion(readManifest(cwd), version));
28
- refreshLockfile(cwd, pluginConfig.spawnSync ?? spawnSync);
29
- bundleSkill(cwd);
30
-
31
- context.logger?.log(`Stamped ${CRATE_NAME} at ${version} and bundled its skill`);
32
- }
33
-
34
- export async function publish(pluginConfig = {}, context) {
35
- if (context.options?.dryRun) {
36
- context.logger?.log("Dry run: skipping the crates.io publish");
37
- return;
38
- }
39
-
40
- const spawn = pluginConfig.spawnSync ?? spawnSync;
41
- const result = spawn(
42
- "cargo",
43
- ["publish", "-p", CRATE_NAME, "--locked", "--allow-dirty"],
44
- { cwd: cwdOf(context), encoding: "utf-8", stdio: "inherit" }
45
- );
46
- if ((result.status ?? -1) !== 0) {
47
- throw new Error(`cargo publish failed with exit code ${result.status ?? -1}`);
48
- }
49
-
50
- context.logger?.log(`Published ${CRATE_NAME} ${versionOf(context)} to crates.io`);
51
- }
52
-
53
- function stampVersion(manifest, version) {
54
- return manifest.replace(/^version = ".*"$/m, `version = "${version}"`);
55
- }
56
-
57
- function refreshLockfile(cwd, spawn) {
58
- const result = spawn("cargo", ["update", "--workspace"], {
59
- cwd,
60
- encoding: "utf-8",
61
- stdio: ["ignore", "ignore", "pipe"],
62
- });
63
- if ((result.status ?? -1) !== 0) {
64
- throw new Error(
65
- `cargo update failed with exit code ${result.status ?? -1}\n${result.stderr ?? ""}`
66
- );
67
- }
68
- }
69
-
70
- function bundleSkill(cwd) {
71
- const target = join(cwd, PACKAGED_SKILL);
72
- mkdirSync(dirname(target), { recursive: true });
73
- copyFileSync(join(cwd, WORKSPACE_SKILL), target);
74
- }
75
-
76
- function crateNameOf(manifest) {
77
- return manifest.match(/^name = "(.*)"$/m)?.[1];
78
- }
79
-
80
- function readManifest(cwd) {
81
- return readFileSync(join(cwd, MANIFEST), "utf-8");
82
- }
83
-
84
- function writeManifest(cwd, manifest) {
85
- writeFileSync(join(cwd, MANIFEST), manifest);
86
- }
87
-
88
- function cwdOf(context) {
89
- return context.cwd ?? process.cwd();
90
- }
91
-
92
- function versionOf(context) {
93
- const version = context.nextRelease?.version;
94
- if (!version) throw new Error("semantic-release did not provide nextRelease.version");
95
- return version;
96
- }
@@ -1,121 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { spawnSync } from "node:child_process";
4
-
5
- const NATIVE_PACKAGES = [
6
- {
7
- dir: "darwin-arm64",
8
- name: "@konvert7/klint-darwin-arm64",
9
- binaryPath: "bin/klint-rs",
10
- },
11
- {
12
- dir: "darwin-x64",
13
- name: "@konvert7/klint-darwin-x64",
14
- binaryPath: "bin/klint-rs",
15
- },
16
- {
17
- dir: "linux-x64",
18
- name: "@konvert7/klint-linux-x64",
19
- binaryPath: "bin/klint-rs",
20
- },
21
- {
22
- dir: "win32-x64",
23
- name: "@konvert7/klint-win32-x64",
24
- binaryPath: "bin/klint-rs.exe",
25
- },
26
- ];
27
-
28
- export async function verifyConditions(_, context) {
29
- const cwd = context.cwd ?? process.cwd();
30
-
31
- for (const nativePackage of NATIVE_PACKAGES) {
32
- const packageJson = readPackageJson(packageDir(cwd, nativePackage));
33
- if (packageJson.name !== nativePackage.name) {
34
- throw new Error(
35
- `${nativePackage.dir} package name is ${packageJson.name}, expected ${nativePackage.name}`
36
- );
37
- }
38
- }
39
- }
40
-
41
- export async function prepare(_, context) {
42
- const cwd = context.cwd ?? process.cwd();
43
- const version = context.nextRelease?.version;
44
-
45
- if (!version) {
46
- throw new Error("semantic-release did not provide nextRelease.version");
47
- }
48
-
49
- for (const nativePackage of NATIVE_PACKAGES) {
50
- const dir = packageDir(cwd, nativePackage);
51
- const packageJson = readPackageJson(dir);
52
- packageJson.version = version;
53
- packageJson.private = false;
54
- writePackageJson(dir, packageJson);
55
-
56
- const binary = join(dir, nativePackage.binaryPath);
57
- if (!existsSync(binary)) {
58
- throw new Error(`Missing native binary for ${nativePackage.name}: ${binary}`);
59
- }
60
-
61
- writeFileSync(join(dirname(binary), "VERSION"), `${version}\n`);
62
- }
63
- }
64
-
65
- export async function publish(pluginConfig = {}, context) {
66
- const cwd = context.cwd ?? process.cwd();
67
- const spawn = pluginConfig.spawnSync ?? spawnSync;
68
-
69
- if (context.options?.dryRun) {
70
- context.logger?.log("Dry run: skipping native npm publishes");
71
- return;
72
- }
73
-
74
- for (const nativePackage of NATIVE_PACKAGES) {
75
- const result = spawn("npm", ["publish", "--access", "public"], {
76
- cwd: packageDir(cwd, nativePackage),
77
- encoding: "utf-8",
78
- stdio: ["ignore", "pipe", "pipe"],
79
- });
80
-
81
- if (result.stdout) process.stdout.write(result.stdout);
82
- if (result.stderr) process.stderr.write(result.stderr);
83
-
84
- if ((result.status ?? -1) !== 0) {
85
- if (shouldSkipMissingPackagePublish(result)) {
86
- context.logger?.log(
87
- `Skipping ${nativePackage.name}: npm package is not available to this trusted publisher yet`
88
- );
89
- continue;
90
- }
91
-
92
- throw new Error(
93
- `${nativePackage.name} npm publish failed with exit code ${result.status ?? -1}`
94
- );
95
- }
96
- }
97
- }
98
-
99
- function packageDir(cwd, nativePackage) {
100
- return join(cwd, "npm", "native", nativePackage.dir);
101
- }
102
-
103
- function readPackageJson(dir) {
104
- return JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
105
- }
106
-
107
- function writePackageJson(dir, packageJson) {
108
- writeFileSync(join(dir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`);
109
- }
110
-
111
- function shouldSkipMissingPackagePublish(result) {
112
- if (process.env.KLINT_SKIP_MISSING_NATIVE_PUBLISH !== "1") return false;
113
-
114
- const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
115
- return (
116
- output.includes("npm error code E404") ||
117
- output.includes("404 Not Found") ||
118
- output.includes("package not found") ||
119
- output.includes("could not be found or you do not have permission")
120
- );
121
- }
@@ -1,87 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { readFileSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
4
-
5
- const NATIVE_PACKAGE_NAMES = [
6
- "@konvert7/klint-darwin-arm64",
7
- "@konvert7/klint-darwin-x64",
8
- "@konvert7/klint-linux-x64",
9
- "@konvert7/klint-win32-x64",
10
- ];
11
-
12
- export async function verifyConditions(_, context) {
13
- const cwd = context.cwd ?? process.cwd();
14
- const packageJson = readPackageJson(cwd);
15
-
16
- if (!packageJson.name) {
17
- throw new Error("Root package.json must have a name before npm publish");
18
- }
19
- }
20
-
21
- export async function prepare(pluginConfig = {}, context) {
22
- const cwd = context.cwd ?? process.cwd();
23
- const version = context.nextRelease?.version;
24
-
25
- if (!version) {
26
- throw new Error("semantic-release did not provide nextRelease.version");
27
- }
28
-
29
- const packageJson = readPackageJson(cwd);
30
- packageJson.version = version;
31
- writePackageJson(cwd, packageJson);
32
-
33
- regenerateSchema(cwd, version, pluginConfig.spawnSync ?? spawnSync);
34
- }
35
-
36
- function regenerateSchema(cwd, version, spawn) {
37
- const args = ["run", "--quiet", "-p", "klint-rs", "--example", "generate_schema", "--", version];
38
- const result = spawn("cargo", args, {
39
- cwd,
40
- encoding: "utf-8",
41
- stdio: "inherit",
42
- });
43
-
44
- if ((result.status ?? -1) !== 0) {
45
- throw new Error(`Schema generation failed with exit code ${result.status ?? -1}`);
46
- }
47
- }
48
-
49
- export async function publish(pluginConfig = {}, context) {
50
- const cwd = context.cwd ?? process.cwd();
51
- const spawn = pluginConfig.spawnSync ?? spawnSync;
52
- const version = context.nextRelease?.version;
53
-
54
- if (context.options?.dryRun) {
55
- context.logger?.log("Dry run: skipping npm publish");
56
- return;
57
- }
58
-
59
- if (!version) {
60
- throw new Error("semantic-release did not provide nextRelease.version");
61
- }
62
-
63
- const packageJson = readPackageJson(cwd);
64
- packageJson.optionalDependencies ??= {};
65
- for (const packageName of NATIVE_PACKAGE_NAMES) {
66
- packageJson.optionalDependencies[packageName] = version;
67
- }
68
- writePackageJson(cwd, packageJson);
69
-
70
- const result = spawn("npm", ["publish", "--access", "public"], {
71
- cwd,
72
- encoding: "utf-8",
73
- stdio: "inherit",
74
- });
75
-
76
- if ((result.status ?? -1) !== 0) {
77
- throw new Error(`npm publish failed with exit code ${result.status ?? -1}`);
78
- }
79
- }
80
-
81
- function readPackageJson(cwd) {
82
- return JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
83
- }
84
-
85
- function writePackageJson(cwd, packageJson) {
86
- writeFileSync(join(cwd, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`);
87
- }