@konvert7/klint 1.0.2 → 1.1.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/README.md CHANGED
@@ -525,11 +525,13 @@ klint scans TypeScript/JavaScript, Python, Swift, Rust, and C#. Every architectu
525
525
  | `arch.forbidden` / `singleton` — `jsx-element` | ✅ | — | — | — | — |
526
526
  | `arch.maxLines` | ✅ | ✅ | ✅ | ✅ | ✅ |
527
527
  | `arch.maxCommentDensity` / `maxCommentBlock` | ✅ `//`, `/* */`, `/** */` docs | ✅ `#` | ✅ `//`, `/* */`, `///` and `/** */` docs | ✅ `//`, `/* */`, `///` and `//!` docs | ✅ `//`, `/* */`, `///` and `/** */` docs |
528
- | Built-in rules and plugins | ✅ | ✗ | ✗ | ✗ | ✗ |
528
+ | Built-in rules and plugins | ✅ | ✗ ¹ | ✗ ¹ | ✗ ¹ | ✗ ¹ |
529
529
 
530
530
  **✅** supported · **—** the language has no equivalent construct · **✗** not supported yet
531
531
 
532
- A dash is not a gap. Swift has no dynamic import expression, no `import type`, and one module per declaration; Rust has no dynamic import and no type-only import; C# has no dynamic `using`, no type-only import, and one namespace per `using`. Those rows can never be filled. The `✗` rows are real limits: the rule set and custom rules are written against the TypeScript AST, and type-aware rules need a type checker that only the TS engine has.
532
+ ¹ except `blank-line-before-control-flow` and `blank-line-after-block`, which run on all five languages.
533
+
534
+ A dash is not a gap. Swift has no dynamic import expression, no `import type`, and one module per declaration; Rust has no dynamic import and no type-only import; C# has no dynamic `using`, no type-only import, and one namespace per `using`. Those rows can never be filled. The `✗` rows are real limits: the rule set and custom rules are written against the TypeScript AST, and type-aware rules need a type checker that only the TS engine has. The one exception is the pair of blank-line rules, which read each language's own syntax tree and so run on all five.
533
535
 
534
536
  Imports are read off the AST in every language, so a specifier written inside a comment or a string is never an import — including nested Swift block comments.
535
537
 
@@ -729,9 +731,57 @@ doc-comments alongside `/** */`.
729
731
  | `no-nested-template-literals` | Template literals nested inside template literals |
730
732
  | `no-consecutive-array-push` | Multiple consecutive `push()` calls that should be grouped |
731
733
  | `no-string-match` | `String#match()` usage better expressed with clearer APIs |
734
+ | `blank-line-before-control-flow` | Blank line above a control-flow statement that follows another statement; autofix |
735
+ | `blank-line-after-block` | Blank line below a block statement when another statement follows; autofix |
732
736
 
733
737
  Rules that needed TypeScript's type checker were removed in 1.0; see [Upgrading from klint 0.x](#upgrading-from-klint-0x).
734
738
 
739
+ ### Blank lines around control flow
740
+
741
+ `blank-line-before-control-flow` asks for a blank line above a control-flow statement that follows another statement in its block. `blank-line-after-block` asks for a blank line below a block statement when another statement follows it in the same block. Both work on TypeScript/JavaScript, Python, Swift, Rust and C#. They are opt-in, and `klint --fix` inserts the missing line.
742
+
743
+ ```yaml
744
+ rules:
745
+ blank-line-before-control-flow: error
746
+ blank-line-after-block: warn
747
+ ```
748
+
749
+ ```yaml
750
+ rules:
751
+ blank-line-before-control-flow:
752
+ severity: error
753
+ include: ["src/**", "!src/generated/**"]
754
+ statements: [if, for, while, switch, try, return, guard, loop, with]
755
+ allowSetup: true
756
+ blank-line-after-block:
757
+ severity: warn
758
+ include: ["src/**"]
759
+ statements: [if, for, while, switch, try, guard, loop, with]
760
+ ```
761
+
762
+ - `statements` lists the statement kinds a rule targets. The default is every kind the rule supports. `statements: []` turns the rule off. `match` is an alias of `switch`. `return` is valid only for `blank-line-before-control-flow`. An unknown keyword, or `return` on the after rule, produces one `klint/config` warning, and the remaining keywords still apply.
763
+ - `allowSetup` (before rule only, default `true`) turns the setup exception on or off, described below.
764
+
765
+ | keyword | TypeScript / JavaScript | Python | Swift | Rust | C# |
766
+ |---|---|---|---|---|---|
767
+ | `if` | `if` | `if` | `if` | `if`, `if let` | `if` |
768
+ | `for` | `for`, `for…in`, `for…of` | `for` | `for…in` | `for` | `for`, `foreach` |
769
+ | `while` | `while`, `do…while` | `while` | `while`, `repeat…while` | `while`, `while let` | `while`, `do…while` |
770
+ | `switch` (alias `match`) | `switch` | `match` | `switch` | `match` | `switch` statement |
771
+ | `try` | `try` | `try` | `do` | — | `try` |
772
+ | `return` (before rule only) | `return` | `return` | `return` | `return` | `return` |
773
+ | `guard` | — | — | `guard` | — | — |
774
+ | `loop` | — | — | — | `loop` | — |
775
+ | `with` | — | `with` | — | — | — |
776
+
777
+ **Comments.** A comment that starts its own line directly above a statement belongs to that statement. The before rule puts the blank line above the comment. The after rule puts the blank line between the block and a comment that follows the block, so the comment stays with the statement below.
778
+
779
+ **Setup exception.** With `allowSetup: true`, the before rule skips an `if`, `guard` or `switch` whose condition uses a name assigned by the statement directly above it. For example, `x = f();` followed by `if (x) …` is not reported. Only the statement directly above counts (comment lines are skipped), only plain names count (`self.x = f()` does not), and only the condition is searched, not the body.
780
+
781
+ **Autofix.** `klint --fix` inserts one empty line with the line ending of the line above it, and changes nothing else. A second run changes nothing.
782
+
783
+ **Not checked.** A file with a syntax error gets no report and no fix. A braceless body (`if (a) return 1;`) is not a block for the after rule. `do…while` and `repeat…while` are never reported by the after rule. A statement that shares its line with the previous statement is not reported, because the fix would have to split that line. Expression forms are not statements: `let x = if …` and `let r = match …` in Rust, `let x = if …` in Swift, a C# switch expression, and control flow inside a call are never reported. A Python docstring is documentation, not a statement, so the statement after it counts as first in its block. A C# preprocessor line (`#region`, `#if`, `#pragma`, …) or a Swift `#if`/`#elseif`/`#else`/`#endif` line separates statements like a blank line, so neither rule inserts a line next to one.
784
+
735
785
  ## Plugins
736
786
 
737
787
  Enable plugin rules with `plugins: [sonar]`, then override individual severities in `rules` when needed.
package/klint.schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.0.2/klint.schema.json",
2
+ "$id": "https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.1.0/klint.schema.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "additionalProperties": false,
5
5
  "description": "klint configuration. Lives at klint.yaml (or klint.config.json) next to biome.json and knip.json.",
@@ -598,6 +598,133 @@
598
598
  },
599
599
  "description": "Map of rule name → severity or options. Example: { \"no-floating-promise\": \"error\", \"no-sync-in-async\": { \"severity\": \"warn\", \"include\": [\"src/hooks/**\"] } }.",
600
600
  "properties": {
601
+ "blank-line-after-block": {
602
+ "anyOf": [
603
+ {
604
+ "description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
605
+ "enum": [
606
+ "error",
607
+ "warn",
608
+ "off"
609
+ ],
610
+ "type": "string"
611
+ },
612
+ {
613
+ "additionalProperties": false,
614
+ "description": "Rule options object. Omit severity to default to \"error\". Add include to scope the rule to specific files.",
615
+ "properties": {
616
+ "include": {
617
+ "description": "Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: [\"src/hooks/**\", \"!src/hooks/scripts/**\"]",
618
+ "items": {
619
+ "type": "string"
620
+ },
621
+ "type": "array"
622
+ },
623
+ "severity": {
624
+ "description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
625
+ "enum": [
626
+ "error",
627
+ "warn",
628
+ "off",
629
+ null
630
+ ],
631
+ "type": "string"
632
+ },
633
+ "statements": {
634
+ "description": "Block statement kinds this rule targets. Defaults to every kind: if, for, while, switch, try, guard, loop, with. match is an alias of switch. return is not a block statement. An empty list turns the rule off.",
635
+ "items": {
636
+ "description": "A block statement kind the rule targets. match is an alias of switch.",
637
+ "enum": [
638
+ "if",
639
+ "for",
640
+ "while",
641
+ "switch",
642
+ "match",
643
+ "try",
644
+ "guard",
645
+ "loop",
646
+ "with"
647
+ ],
648
+ "type": "string"
649
+ },
650
+ "type": "array"
651
+ }
652
+ },
653
+ "type": "object"
654
+ }
655
+ ],
656
+ "description": "Requires a blank line below a block statement (if, for, while, switch/match, try, guard, loop, with) when another statement follows it in the same block, like C# IDE2003. Works on TypeScript/JavaScript, Python, Swift, Rust and C#; `klint --fix` inserts the line.",
657
+ "examples": [
658
+ "blank-line-after-block: warn",
659
+ "blank-line-after-block:\n severity: warn\n include: [\"src/**\"]\n statements: [if, for, while, switch, try, guard, loop, with]"
660
+ ]
661
+ },
662
+ "blank-line-before-control-flow": {
663
+ "anyOf": [
664
+ {
665
+ "description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
666
+ "enum": [
667
+ "error",
668
+ "warn",
669
+ "off"
670
+ ],
671
+ "type": "string"
672
+ },
673
+ {
674
+ "additionalProperties": false,
675
+ "description": "Rule options object. Omit severity to default to \"error\". Add include to scope the rule to specific files.",
676
+ "properties": {
677
+ "allowSetup": {
678
+ "description": "Skip an if, guard or switch statement whose condition uses a name assigned by the statement directly above it. Defaults to true.",
679
+ "type": "boolean"
680
+ },
681
+ "include": {
682
+ "description": "Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: [\"src/hooks/**\", \"!src/hooks/scripts/**\"]",
683
+ "items": {
684
+ "type": "string"
685
+ },
686
+ "type": "array"
687
+ },
688
+ "severity": {
689
+ "description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
690
+ "enum": [
691
+ "error",
692
+ "warn",
693
+ "off",
694
+ null
695
+ ],
696
+ "type": "string"
697
+ },
698
+ "statements": {
699
+ "description": "Statement kinds this rule targets. Defaults to every kind: if, for, while, switch, try, return, guard, loop, with. match is an alias of switch. An empty list turns the rule off.",
700
+ "items": {
701
+ "description": "A statement kind the rule targets. match is an alias of switch.",
702
+ "enum": [
703
+ "if",
704
+ "for",
705
+ "while",
706
+ "switch",
707
+ "match",
708
+ "try",
709
+ "return",
710
+ "guard",
711
+ "loop",
712
+ "with"
713
+ ],
714
+ "type": "string"
715
+ },
716
+ "type": "array"
717
+ }
718
+ },
719
+ "type": "object"
720
+ }
721
+ ],
722
+ "description": "Requires a blank line above a control-flow statement (if, for, while, switch/match, try, return, guard, loop, with) that follows another statement in the same block. Works on TypeScript/JavaScript, Python, Swift, Rust and C#; `klint --fix` inserts the line.",
723
+ "examples": [
724
+ "blank-line-before-control-flow: error",
725
+ "blank-line-before-control-flow:\n severity: error\n include: [\"src/**\", \"!src/generated/**\"]\n statements: [if, for, while, switch, try, return, guard, loop, with]\n allowSetup: true"
726
+ ]
727
+ },
601
728
  "no-async-predicate": {
602
729
  "anyOf": [
603
730
  {
package/klint.schema.yaml CHANGED
@@ -1,4 +1,4 @@
1
- $id: https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.0.2/klint.schema.json
1
+ $id: https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.1.0/klint.schema.json
2
2
  $schema: http://json-schema.org/draft-07/schema#
3
3
  additionalProperties: false
4
4
  description: klint configuration. Lives at klint.yaml (or klint.config.json) next to biome.json and knip.json.
@@ -449,6 +449,109 @@ properties:
449
449
  type: object
450
450
  description: 'Map of rule name → severity or options. Example: { "no-floating-promise": "error", "no-sync-in-async": { "severity": "warn", "include": ["src/hooks/**"] } }.'
451
451
  properties:
452
+ blank-line-after-block:
453
+ anyOf:
454
+ - description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
455
+ enum:
456
+ - error
457
+ - warn
458
+ - off
459
+ type: string
460
+ - additionalProperties: false
461
+ description: Rule options object. Omit severity to default to "error". Add include to scope the rule to specific files.
462
+ properties:
463
+ include:
464
+ description: 'Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: ["src/hooks/**", "!src/hooks/scripts/**"]'
465
+ items:
466
+ type: string
467
+ type: array
468
+ severity:
469
+ description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
470
+ enum:
471
+ - error
472
+ - warn
473
+ - off
474
+ - null
475
+ type: string
476
+ statements:
477
+ description: 'Block statement kinds this rule targets. Defaults to every kind: if, for, while, switch, try, guard, loop, with. match is an alias of switch. return is not a block statement. An empty list turns the rule off.'
478
+ items:
479
+ description: A block statement kind the rule targets. match is an alias of switch.
480
+ enum:
481
+ - if
482
+ - for
483
+ - while
484
+ - switch
485
+ - match
486
+ - try
487
+ - guard
488
+ - loop
489
+ - with
490
+ type: string
491
+ type: array
492
+ type: object
493
+ description: Requires a blank line below a block statement (if, for, while, switch/match, try, guard, loop, with) when another statement follows it in the same block, like C# IDE2003. Works on TypeScript/JavaScript, Python, Swift, Rust and C#; `klint --fix` inserts the line.
494
+ examples:
495
+ - 'blank-line-after-block: warn'
496
+ - |-
497
+ blank-line-after-block:
498
+ severity: warn
499
+ include: ["src/**"]
500
+ statements: [if, for, while, switch, try, guard, loop, with]
501
+ blank-line-before-control-flow:
502
+ anyOf:
503
+ - description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
504
+ enum:
505
+ - error
506
+ - warn
507
+ - off
508
+ type: string
509
+ - additionalProperties: false
510
+ description: Rule options object. Omit severity to default to "error". Add include to scope the rule to specific files.
511
+ properties:
512
+ allowSetup:
513
+ description: Skip an if, guard or switch statement whose condition uses a name assigned by the statement directly above it. Defaults to true.
514
+ type: boolean
515
+ include:
516
+ description: 'Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: ["src/hooks/**", "!src/hooks/scripts/**"]'
517
+ items:
518
+ type: string
519
+ type: array
520
+ severity:
521
+ description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
522
+ enum:
523
+ - error
524
+ - warn
525
+ - off
526
+ - null
527
+ type: string
528
+ statements:
529
+ description: 'Statement kinds this rule targets. Defaults to every kind: if, for, while, switch, try, return, guard, loop, with. match is an alias of switch. An empty list turns the rule off.'
530
+ items:
531
+ description: A statement kind the rule targets. match is an alias of switch.
532
+ enum:
533
+ - if
534
+ - for
535
+ - while
536
+ - switch
537
+ - match
538
+ - try
539
+ - return
540
+ - guard
541
+ - loop
542
+ - with
543
+ type: string
544
+ type: array
545
+ type: object
546
+ description: Requires a blank line above a control-flow statement (if, for, while, switch/match, try, return, guard, loop, with) that follows another statement in the same block. Works on TypeScript/JavaScript, Python, Swift, Rust and C#; `klint --fix` inserts the line.
547
+ examples:
548
+ - 'blank-line-before-control-flow: error'
549
+ - |-
550
+ blank-line-before-control-flow:
551
+ severity: error
552
+ include: ["src/**", "!src/generated/**"]
553
+ statements: [if, for, while, switch, try, return, guard, loop, with]
554
+ allowSetup: true
452
555
  no-async-predicate:
453
556
  anyOf:
454
557
  - description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konvert7/klint",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Architecture-as-Code linter for TypeScript. Enforce layer boundaries, import rules, and singleton patterns in YAML.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,12 +56,12 @@
56
56
  ]
57
57
  },
58
58
  "optionalDependencies": {
59
- "@konvert7/klint-darwin-arm64": "1.0.2",
60
- "@konvert7/klint-darwin-x64": "1.0.2",
61
- "@konvert7/klint-linux-arm64": "1.0.2",
62
- "@konvert7/klint-linux-x64": "1.0.2",
63
- "@konvert7/klint-linux-x64-musl": "1.0.2",
64
- "@konvert7/klint-win32-x64": "1.0.2"
59
+ "@konvert7/klint-darwin-arm64": "1.1.0",
60
+ "@konvert7/klint-darwin-x64": "1.1.0",
61
+ "@konvert7/klint-linux-arm64": "1.1.0",
62
+ "@konvert7/klint-linux-x64": "1.1.0",
63
+ "@konvert7/klint-linux-x64-musl": "1.1.0",
64
+ "@konvert7/klint-win32-x64": "1.1.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@biomejs/biome": "2.6.5",