@haltcase/style 9.0.0-canary.1 → 9.0.0-canary.3

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/README.md CHANGED
@@ -49,7 +49,7 @@ Additionally, it uses ESLint `jsPlugins` that require TypeScript 6. If you other
49
49
 
50
50
  ```js
51
51
  // oxlint.config.ts
52
- import createOxlintConfig from "@haltcase/style/oxlint";
52
+ import { createOxlintConfig } from "@haltcase/style/oxlint";
53
53
 
54
54
  export default createOxlintConfig({
55
55
  node: true
@@ -0,0 +1,28 @@
1
+ Vendored from gnkz/oxlint-rules at commit f55e306bd96e5066acb3a603d6daace164b56d16:
2
+
3
+ https://github.com/gnkz/oxlint-rules/tree/f55e306bd96e5066acb3a603d6daace164b56d16
4
+
5
+ - src/rules/padding-between-statements.ts
6
+ - src/padding.ts
7
+
8
+ MIT License
9
+
10
+ Copyright (c) 2026 gnkz
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
@@ -1,8 +1,8 @@
1
1
  import "node:path";
2
2
  import "node:url";
3
3
  import.meta.url;
4
- import { toMerged } from "es-toolkit";
5
4
  import { isPackageExists } from "local-pkg";
5
+ import { toMerged } from "es-toolkit";
6
6
  // src/oxfmt/index.ts
7
7
  const defaults = {
8
8
  arrowParens: "always",
@@ -22,8 +22,10 @@ export declare const baseConfig: {
22
22
  "import/no-default-export"?: undefined;
23
23
  };
24
24
  })[];
25
- plugins: ("promise" | "eslint" | "unicorn" | "oxc" | "import" | "jsdoc")[];
25
+ plugins: ("eslint" | "unicorn" | "oxc" | "import" | "jsdoc" | "promise")[];
26
+ jsPlugins: import("oxlint").ExternalPluginEntry[];
26
27
  rules: {
28
+ "haltcase/padding-between-statements": "error";
27
29
  "no-label-var": "error";
28
30
  "no-unused-vars": ["error", {
29
31
  args: "after-used";
@@ -451,7 +453,7 @@ export declare const baseConfig: {
451
453
  allowImplicit: true;
452
454
  }];
453
455
  "block-scoped-var": "error";
454
- curly: ["error", "multi-line"];
456
+ curly: ["error", "all"];
455
457
  "default-case-last": "error";
456
458
  "default-param-last": "error";
457
459
  eqeqeq: ["error", "always", {
@@ -9,6 +9,7 @@ import { possibleErrorsRules } from "../rules/possible-errors.js";
9
9
  import { restrictionRules } from "../rules/restriction.js";
10
10
  import { stylisticRules } from "../rules/stylistic.js";
11
11
  import { variablesRules } from "../rules/variables.js";
12
+ import { resolveJsPlugin } from "../utils/eslint-compat.js";
12
13
  // src/oxlint/configs/base.ts
13
14
  const baseConfig = [{
14
15
  categories: { ...sharedCategoryConfig },
@@ -27,6 +28,7 @@ const baseConfig = [{
27
28
  "promise",
28
29
  "unicorn"
29
30
  ],
31
+ jsPlugins: [resolveJsPlugin("haltcase", "@haltcase/style/oxlint/plugin")],
30
32
  rules: {
31
33
  ...typescriptDefaultRules,
32
34
  ...bestPracticeRules,
@@ -34,7 +36,8 @@ const baseConfig = [{
34
36
  ...possibleErrorsRules,
35
37
  ...stylisticRules,
36
38
  ...restrictionRules,
37
- ...variablesRules
39
+ ...variablesRules,
40
+ "haltcase/padding-between-statements": "error"
38
41
  }
39
42
  }];
40
43
  export { baseConfig };
@@ -1,8 +1,8 @@
1
1
  import "node:path";
2
2
  import "node:url";
3
3
  import.meta.url;
4
- import { jsxA11yRules } from "../rules/jsx-a11y.js";
5
4
  import { resolveJsPlugin, resolveRuleMap } from "../utils/eslint-compat.js";
5
+ import { jsxA11yRules } from "../rules/jsx-a11y.js";
6
6
  import { sharedCategoryConfig } from "@haltcase/style/oxlint/constants";
7
7
  import reactXPlugin from "@eslint-react/eslint-plugin";
8
8
  import { reactRules } from "@haltcase/style/oxlint/rules/react";
@@ -24,7 +24,7 @@ const tanstackPackages = [
24
24
  ];
25
25
  const typescriptPackages = ["@typescript/native-preview", "typescript"];
26
26
  const createOxlintConfig = (options = {}) => {
27
- const { env, extends: userExtends = [], globals, ignorePatterns: userIgnores = [], options: lintOptions, overrides = [], settings, typescript: isTypescriptEnabled = typescriptPackages.some((pkg) => isPackageExists(pkg)), react: isReactEnabled = reactPackages.some((pkg) => isPackageExists(pkg)), tanstackRouter: isTanstackRouterEnabled = tanstackPackages.filter((pkg) => pkg !== "@tanstack/react-start").every((pkg) => isPackageExists(pkg)), tanstackStart: isTanstackStartEnabled = tanstackPackages.every((pkg) => isPackageExists(pkg)), next: isNextEnabled = isPackageExists("next"), node: isNodeEnabled = false, testing: isTestingEnabled = false } = options;
27
+ const { env, extends: userExtends = [], globals, ignorePatterns: userIgnores = [], options: lintOptions, overrides = [], rules, settings, typescript: isTypescriptEnabled = typescriptPackages.some((pkg) => isPackageExists(pkg)), react: isReactEnabled = reactPackages.some((pkg) => isPackageExists(pkg)), tanstackRouter: isTanstackRouterEnabled = tanstackPackages.filter((pkg) => pkg !== "@tanstack/react-start").every((pkg) => isPackageExists(pkg)), tanstackStart: isTanstackStartEnabled = tanstackPackages.every((pkg) => isPackageExists(pkg)), next: isNextEnabled = isPackageExists("next"), node: isNodeEnabled = false, testing: isTestingEnabled = false } = options;
28
28
  const configs = [...userExtends, ...baseConfig];
29
29
  if (isTypescriptEnabled) configs.push(...typescriptConfig);
30
30
  if (isReactEnabled) configs.push(...reactConfig);
@@ -44,6 +44,7 @@ const createOxlintConfig = (options = {}) => {
44
44
  typeCheck: isTypescriptEnabled,
45
45
  ...lintOptions
46
46
  },
47
+ rules,
47
48
  settings
48
49
  };
49
50
  };
@@ -0,0 +1,4 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ declare const plugin: import("@oxlint/plugins").Plugin;
4
+ export { plugin as default };
@@ -0,0 +1,11 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { paddingBetweenStatements } from "./vendor/gnkz/rules/padding-between-statements.js";
5
+ import { definePlugin } from "@oxlint/plugins";
6
+ // src/oxlint/plugin.ts
7
+ const plugin = definePlugin({
8
+ meta: { name: "haltcase" },
9
+ rules: { "padding-between-statements": paddingBetweenStatements }
10
+ });
11
+ export { plugin as default };
@@ -90,9 +90,9 @@ export declare const bestPracticeRules: {
90
90
  */
91
91
  "block-scoped-var": "error";
92
92
  /**
93
- * Require curly braces for multiline blocks.
93
+ * Require curly braces around control statement bodies.
94
94
  */
95
- curly: ["error", "multi-line"];
95
+ curly: ["error", "all"];
96
96
  /**
97
97
  * Require default clauses in switch statements to be last (if used).
98
98
  */
@@ -90,9 +90,9 @@ const bestPracticeRules = {
90
90
  */
91
91
  "block-scoped-var": "error",
92
92
  /**
93
- * Require curly braces for multiline blocks.
93
+ * Require curly braces around control statement bodies.
94
94
  */
95
- curly: ["error", "multi-line"],
95
+ curly: ["error", "all"],
96
96
  /**
97
97
  * Require default clauses in switch statements to be last (if used).
98
98
  */
@@ -0,0 +1,12 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ import { Context, Span } from "@oxlint/plugins";
4
+ export declare function isMultiline(node: Span): boolean;
5
+ /** Each element paired with the one after it. */
6
+ export declare function adjacentPairs<T>(items: readonly T[]): Array<readonly [T, T]>;
7
+ export interface PaddingViolation {
8
+ readonly previous: Span;
9
+ readonly next: Span;
10
+ readonly messageId: string;
11
+ }
12
+ export declare function reportMissingBlankLine(context: Context, violation: PaddingViolation): void;
@@ -0,0 +1,54 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ // src/oxlint/vendor/gnkz/padding.ts
5
+ function isMultiline(node) {
6
+ return node.loc.start.line !== node.loc.end.line;
7
+ }
8
+ /** Each element paired with the one after it. */
9
+ function adjacentPairs(items) {
10
+ return items.slice(1).flatMap((next, index) => {
11
+ const previous = items[index];
12
+ return previous === void 0 ? [] : [[previous, next]];
13
+ });
14
+ }
15
+ function commentsBetween(sourceCode, previous, next) {
16
+ return sourceCode.getCommentsBefore(next).filter((comment) => comment.range[0] >= previous.range[1]);
17
+ }
18
+ /**
19
+ * The comments between two siblings that belong to `next`. A comment on the same line as the end
20
+ * of `previous` is a trailing comment of `previous`, so the blank line goes after it.
21
+ */
22
+ function leadingItems(sourceCode, previous, next) {
23
+ return [...commentsBetween(sourceCode, previous, next).filter((comment) => comment.loc.start.line > previous.loc.end.line), next];
24
+ }
25
+ function hasBlankLineBetween(sourceCode, previous, next) {
26
+ return adjacentPairs([
27
+ previous,
28
+ ...commentsBetween(sourceCode, previous, next),
29
+ next
30
+ ]).some(([before, after]) => after.loc.start.line - before.loc.end.line > 1);
31
+ }
32
+ /**
33
+ * Inserts the blank line above `next` and its leading comments, so a comment stays attached to
34
+ * the code it describes.
35
+ */
36
+ function insertBlankLine(sourceCode, previous, next) {
37
+ const [first = next] = leadingItems(sourceCode, previous, next);
38
+ if (first.loc.start.line === previous.loc.end.line) return (fixer) => fixer.insertTextBeforeRange(first.range, "\n\n");
39
+ const lineStart = sourceCode.getIndexFromLoc({
40
+ line: first.loc.start.line,
41
+ column: 0
42
+ });
43
+ return (fixer) => fixer.insertTextBeforeRange([lineStart, lineStart], "\n");
44
+ }
45
+ function reportMissingBlankLine(context, violation) {
46
+ const { previous, next, messageId } = violation;
47
+ if (hasBlankLineBetween(context.sourceCode, previous, next)) return;
48
+ context.report({
49
+ node: next,
50
+ messageId,
51
+ fix: insertBlankLine(context.sourceCode, previous, next)
52
+ });
53
+ }
54
+ export { adjacentPairs, isMultiline, reportMissingBlankLine };
@@ -0,0 +1,14 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ /**
4
+ * Requires a blank line between statements that belong to different groups. Blank lines split a
5
+ * body into paragraphs: a run of declarations, a run of calls, a control-flow block, the final
6
+ * `return`. Without them every line reads with the same weight and the reader has to find the
7
+ * structure on their own.
8
+ *
9
+ * A blank line is required around block-like statements (`if`, loops, `try`, function and class
10
+ * declarations) and around any statement that spans several lines. Single-line statements may be
11
+ * grouped only with statements of the same kind: imports, re-exports, variable declarations, type
12
+ * declarations, `return`/`throw`, or other statements.
13
+ */
14
+ export declare const paddingBetweenStatements: import("@oxlint/plugins").Rule;
@@ -0,0 +1,111 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { adjacentPairs, isMultiline, reportMissingBlankLine } from "../padding.js";
5
+ import { defineRule } from "@oxlint/plugins";
6
+ // src/oxlint/vendor/gnkz/rules/padding-between-statements.ts
7
+ const BLOCK_LIKE = /* @__PURE__ */ new Set([
8
+ "BlockStatement",
9
+ "ClassDeclaration",
10
+ "DoWhileStatement",
11
+ "ForInStatement",
12
+ "ForOfStatement",
13
+ "ForStatement",
14
+ "FunctionDeclaration",
15
+ "IfStatement",
16
+ "LabeledStatement",
17
+ "SwitchStatement",
18
+ "TryStatement",
19
+ "TSEnumDeclaration",
20
+ "TSModuleDeclaration",
21
+ "WhileStatement"
22
+ ]);
23
+ const KIND_BY_TYPE = /* @__PURE__ */ new Map([
24
+ ["ImportDeclaration", "import"],
25
+ ["TSImportEqualsDeclaration", "import"],
26
+ ["ExportAllDeclaration", "reexport"],
27
+ ["VariableDeclaration", "variable"],
28
+ ["TSTypeAliasDeclaration", "type"],
29
+ ["TSInterfaceDeclaration", "type"],
30
+ ["ReturnStatement", "jump"],
31
+ ["ThrowStatement", "jump"]
32
+ ]);
33
+ /** The declaration an `export` wraps, so `export const` pads like `const`. */
34
+ function unwrapExport(node) {
35
+ if (node.type === "ExportNamedDeclaration") return node.declaration ?? node;
36
+ return node.type === "ExportDefaultDeclaration" ? node.declaration : node;
37
+ }
38
+ function kindOf(node) {
39
+ if (node.type === "ExportNamedDeclaration" && node.source !== null) return "reexport";
40
+ return KIND_BY_TYPE.get(unwrapExport(node).type) ?? "other";
41
+ }
42
+ function isBlockLike(node) {
43
+ return BLOCK_LIKE.has(unwrapExport(node).type);
44
+ }
45
+ /** Overload signatures sit directly above their implementation. */
46
+ function isOverloadPair(previous, next) {
47
+ return unwrapExport(previous).type === "TSDeclareFunction" && isBlockLike(next);
48
+ }
49
+ function paddingReason(previous, next) {
50
+ const previousKind = kindOf(previous);
51
+ const nextKind = kindOf(next);
52
+ if ((previousKind === "import" || previousKind === "reexport") && previousKind === nextKind) return;
53
+ if (isOverloadPair(previous, next)) return;
54
+ if (isBlockLike(previous) || isBlockLike(next)) return "blockLike";
55
+ if (isMultiline(previous) || isMultiline(next)) return "multiline";
56
+ return previousKind === nextKind ? void 0 : "kindChange";
57
+ }
58
+ /**
59
+ * Requires a blank line between statements that belong to different groups. Blank lines split a
60
+ * body into paragraphs: a run of declarations, a run of calls, a control-flow block, the final
61
+ * `return`. Without them every line reads with the same weight and the reader has to find the
62
+ * structure on their own.
63
+ *
64
+ * A blank line is required around block-like statements (`if`, loops, `try`, function and class
65
+ * declarations) and around any statement that spans several lines. Single-line statements may be
66
+ * grouped only with statements of the same kind: imports, re-exports, variable declarations, type
67
+ * declarations, `return`/`throw`, or other statements.
68
+ */
69
+ const paddingBetweenStatements = defineRule({
70
+ meta: {
71
+ type: "layout",
72
+ fixable: "whitespace",
73
+ docs: { description: "Require blank lines that separate statements into related groups." },
74
+ messages: {
75
+ blockLike: "Separate block statements and function or class declarations from their neighbours with a blank line.",
76
+ multiline: "Separate statements that span several lines from their neighbours with a blank line.",
77
+ kindChange: "Add a blank line where the statement kind changes (declarations, other statements, return or throw)."
78
+ },
79
+ schema: []
80
+ },
81
+ create(context) {
82
+ function checkBody(body) {
83
+ for (const [previous, next] of adjacentPairs(body)) {
84
+ const messageId = paddingReason(previous, next);
85
+ if (messageId !== void 0) reportMissingBlankLine(context, {
86
+ previous,
87
+ next,
88
+ messageId
89
+ });
90
+ }
91
+ }
92
+ return {
93
+ Program: (node) => {
94
+ checkBody(node.body);
95
+ },
96
+ BlockStatement: (node) => {
97
+ checkBody(node.body);
98
+ },
99
+ StaticBlock: (node) => {
100
+ checkBody(node.body);
101
+ },
102
+ TSModuleBlock: (node) => {
103
+ checkBody(node.body);
104
+ },
105
+ SwitchCase: (node) => {
106
+ checkBody(node.consequent);
107
+ }
108
+ };
109
+ }
110
+ });
111
+ export { paddingBetweenStatements };
@@ -1,8 +1,8 @@
1
1
  import "node:path";
2
2
  import "node:url";
3
3
  import.meta.url;
4
- import { createOxfmtConfig } from "../oxfmt/index.js";
5
4
  import { createOxlintConfig } from "../oxlint/index.js";
5
+ import { createOxfmtConfig } from "../oxfmt/index.js";
6
6
  // src/vite-plus/index.ts
7
7
  const createVitePlusConfig = (options) => ({
8
8
  ...options,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haltcase/style",
3
- "version": "9.0.0-canary.1",
3
+ "version": "9.0.0-canary.3",
4
4
  "description": "haltcase's web ecosystem style guide & configurations",
5
5
  "keywords": [
6
6
  "editorconfig",
@@ -20,7 +20,8 @@
20
20
  "url": "https://github.com/haltcase/style.git"
21
21
  },
22
22
  "files": [
23
- "dist"
23
+ "dist",
24
+ "THIRD-PARTY-NOTICES"
24
25
  ],
25
26
  "type": "module",
26
27
  "imports": {
@@ -42,6 +43,7 @@
42
43
  "./oxlint/configs/testing": "./dist/oxlint/configs/testing.js",
43
44
  "./oxlint/configs/typescript": "./dist/oxlint/configs/typescript.js",
44
45
  "./oxlint/constants": "./dist/oxlint/constants.js",
46
+ "./oxlint/plugin": "./dist/oxlint/plugin.js",
45
47
  "./oxlint/rules/best-practice": "./dist/oxlint/rules/best-practice.js",
46
48
  "./oxlint/rules/imports": "./dist/oxlint/rules/imports.js",
47
49
  "./oxlint/rules/jsx-a11y": "./dist/oxlint/rules/jsx-a11y.js",
@@ -71,6 +73,7 @@
71
73
  "dependencies": {
72
74
  "@dreamsicle.io/stylelint-config-tailwindcss": "1.2.2",
73
75
  "@eslint-react/eslint-plugin": "5.17.3",
76
+ "@oxlint/plugins": "1.89.0",
74
77
  "@semantic-release/exec": "7.1.0",
75
78
  "es-toolkit": "1.52.0",
76
79
  "eslint-plugin-react-you-might-not-need-an-effect": "1.0.1",
@@ -89,7 +92,7 @@
89
92
  "@commitlint/cli": "21.2.3",
90
93
  "@commitlint/config-conventional": "21.2.3",
91
94
  "@commitlint/types": "21.2.3",
92
- "@haltcase/style": "9.0.0-canary.1",
95
+ "@haltcase/style": "9.0.0-canary.3",
93
96
  "@octokit/types": "16.0.0",
94
97
  "@octokit/webhooks-types": "7.6.1",
95
98
  "@semantic-release/git": "11.0.1",