@konvert7/klint 1.2.0 → 1.3.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 +29 -0
- package/klint.schema.json +55 -1
- package/klint.schema.yaml +45 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -734,6 +734,7 @@ doc-comments alongside `/** */`.
|
|
|
734
734
|
| `blank-line-before-control-flow` | Blank line above a control-flow statement that follows another statement; autofix |
|
|
735
735
|
| `blank-line-after-block` | Blank line below a block statement when another statement follows; autofix |
|
|
736
736
|
| `cognitive-complexity` | Function whose cognitive complexity (Biome / SonarSource model) is above `max`, in all five languages; opt-in, no autofix |
|
|
737
|
+
| `function-length` | Function whose body has more lines than `max` (counted like Biome's `noExcessiveLinesPerFunction`), in all five languages; opt-in, no autofix |
|
|
737
738
|
|
|
738
739
|
Rules that needed TypeScript's type checker were removed in 1.0; see [Upgrading from klint 0.x](#upgrading-from-klint-0x).
|
|
739
740
|
|
|
@@ -839,6 +840,34 @@ It adds nothing for `try` itself, `return`, `throw`, recursion, Rust `?`, Python
|
|
|
839
840
|
|
|
840
841
|
**Not checked.** Rust macro bodies are opaque token trees, so code inside a macro call is not scored. Code inside a Python decorator does not count toward the decorated function; a lambda there is scored on its own. A file with a syntax error gets no diagnostic. A Swift computed property without an explicit `get` is not a function. Bodyless declarations are never reported: TypeScript method signatures, Swift protocol requirements and Rust trait signatures are not functions at all, and C# interface and abstract members have nothing to score, so they score 0, which can never exceed `max`.
|
|
841
842
|
|
|
843
|
+
### Function length
|
|
844
|
+
|
|
845
|
+
`function-length` reports every function whose body has more than `max` lines, in TypeScript/JavaScript, Python, Swift, Rust and C#. It is opt-in and has no fix. It counts with Biome 2.6.5's `noExcessiveLinesPerFunction` algorithm in every language, so a TypeScript function gets the same count as in Biome.
|
|
846
|
+
|
|
847
|
+
```yaml
|
|
848
|
+
rules:
|
|
849
|
+
function-length: error
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
```yaml
|
|
853
|
+
rules:
|
|
854
|
+
function-length:
|
|
855
|
+
severity: warn
|
|
856
|
+
include: ["src/**", "!src/generated/**"]
|
|
857
|
+
max: 40
|
|
858
|
+
skipBlankLines: true
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
- `max` is an integer of at least 1, default 50. A function is reported when its count is **greater than** `max`. Any other value (0, a negative number, a fraction, a string) gives one `klint/config` warning naming the rule and the value, and the rule uses 50.
|
|
862
|
+
- `skipBlankLines` is a boolean, default `false`. Any other value gives one `klint/config` warning naming the rule and the value, and the rule uses `false`.
|
|
863
|
+
- The message has the form ``Function `big` has 51 lines (max 50) — split it into smaller functions.``. The name is the declared name, the same rule as `cognitive-complexity`. The line is the function's first line.
|
|
864
|
+
|
|
865
|
+
**Counting.** Only the body counts, not the signature line, decorators or attributes. Every line break before a token in the body counts, except a break before `{` or `}`, so lines that hold only braces (and `};`) do not count. Comment lines and blank lines count. With `skipBlankLines`, a run of blank lines adds nothing beyond the line it leads to. A multi-line string or template counts once. Blank lines before the closing brace do not count. A nested function's lines count toward its parent, and the nested function is also checked on its own. Python counts each statement's line (there are no braces), and docstrings count.
|
|
866
|
+
|
|
867
|
+
**What counts as a function.** The same list as `cognitive-complexity` (see above), but getters and setters are excluded in every language: TypeScript `get` and `set` methods, Swift computed getters and setters, and C# property and indexer accessors. `cognitive-complexity` does check those.
|
|
868
|
+
|
|
869
|
+
**Not checked.** Bodyless declarations, and files with a syntax error.
|
|
870
|
+
|
|
842
871
|
## Plugins
|
|
843
872
|
|
|
844
873
|
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.
|
|
2
|
+
"$id": "https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.3.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.",
|
|
@@ -774,6 +774,60 @@
|
|
|
774
774
|
"cognitive-complexity:\n severity: warn\n include: [\"src/**\", \"!src/generated/**\"]\n max: 14"
|
|
775
775
|
]
|
|
776
776
|
},
|
|
777
|
+
"function-length": {
|
|
778
|
+
"anyOf": [
|
|
779
|
+
{
|
|
780
|
+
"description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
|
|
781
|
+
"enum": [
|
|
782
|
+
"error",
|
|
783
|
+
"warn",
|
|
784
|
+
"off"
|
|
785
|
+
],
|
|
786
|
+
"type": "string"
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
"additionalProperties": false,
|
|
790
|
+
"description": "Rule options object. Omit severity to default to \"error\". Add include to scope the rule to specific files.",
|
|
791
|
+
"properties": {
|
|
792
|
+
"include": {
|
|
793
|
+
"description": "Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: [\"src/hooks/**\", \"!src/hooks/scripts/**\"]",
|
|
794
|
+
"items": {
|
|
795
|
+
"type": "string"
|
|
796
|
+
},
|
|
797
|
+
"type": "array"
|
|
798
|
+
},
|
|
799
|
+
"max": {
|
|
800
|
+
"default": 50,
|
|
801
|
+
"description": "Highest number of lines a function body may have; a function counting more is reported. An integer of at least 1. Defaults to 50.",
|
|
802
|
+
"format": "uint32",
|
|
803
|
+
"minimum": 1,
|
|
804
|
+
"type": "integer"
|
|
805
|
+
},
|
|
806
|
+
"severity": {
|
|
807
|
+
"description": "Rule severity. \"error\" exits with code 2; \"warn\" reports but exits 0; \"off\" silences.",
|
|
808
|
+
"enum": [
|
|
809
|
+
"error",
|
|
810
|
+
"warn",
|
|
811
|
+
"off",
|
|
812
|
+
null
|
|
813
|
+
],
|
|
814
|
+
"type": "string"
|
|
815
|
+
},
|
|
816
|
+
"skipBlankLines": {
|
|
817
|
+
"default": false,
|
|
818
|
+
"description": "Leave blank lines out of the count. Defaults to false.",
|
|
819
|
+
"type": "boolean"
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
"type": "object"
|
|
823
|
+
}
|
|
824
|
+
],
|
|
825
|
+
"description": "Reports every function whose body has more than `max` lines (default 50), counted like Biome 2.6.5's `noExcessiveLinesPerFunction`: brace lines do not count, comment and blank lines do (blank lines not with `skipBlankLines`), and a nested function's lines count toward its parent. Getters and setters are not checked. Works on TypeScript/JavaScript, Python, Swift, Rust and C#. Opt-in; no autofix.",
|
|
826
|
+
"examples": [
|
|
827
|
+
"function-length: error",
|
|
828
|
+
"function-length:\n severity: warn\n include: [\"src/**\", \"!src/generated/**\"]\n max: 40\n skipBlankLines: true"
|
|
829
|
+
]
|
|
830
|
+
},
|
|
777
831
|
"no-async-predicate": {
|
|
778
832
|
"anyOf": [
|
|
779
833
|
{
|
package/klint.schema.yaml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
$id: https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.
|
|
1
|
+
$id: https://raw.githubusercontent.com/konvert7/klint/refs/tags/v1.3.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.
|
|
@@ -591,6 +591,50 @@ properties:
|
|
|
591
591
|
severity: warn
|
|
592
592
|
include: ["src/**", "!src/generated/**"]
|
|
593
593
|
max: 14
|
|
594
|
+
function-length:
|
|
595
|
+
anyOf:
|
|
596
|
+
- description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
|
|
597
|
+
enum:
|
|
598
|
+
- error
|
|
599
|
+
- warn
|
|
600
|
+
- off
|
|
601
|
+
type: string
|
|
602
|
+
- additionalProperties: false
|
|
603
|
+
description: Rule options object. Omit severity to default to "error". Add include to scope the rule to specific files.
|
|
604
|
+
properties:
|
|
605
|
+
include:
|
|
606
|
+
description: 'Glob patterns scoping this rule to a subset of files. Prefix with ! to exclude. Example: ["src/hooks/**", "!src/hooks/scripts/**"]'
|
|
607
|
+
items:
|
|
608
|
+
type: string
|
|
609
|
+
type: array
|
|
610
|
+
max:
|
|
611
|
+
default: 50
|
|
612
|
+
description: Highest number of lines a function body may have; a function counting more is reported. An integer of at least 1. Defaults to 50.
|
|
613
|
+
format: uint32
|
|
614
|
+
minimum: 1
|
|
615
|
+
type: integer
|
|
616
|
+
severity:
|
|
617
|
+
description: Rule severity. "error" exits with code 2; "warn" reports but exits 0; "off" silences.
|
|
618
|
+
enum:
|
|
619
|
+
- error
|
|
620
|
+
- warn
|
|
621
|
+
- off
|
|
622
|
+
- null
|
|
623
|
+
type: string
|
|
624
|
+
skipBlankLines:
|
|
625
|
+
default: false
|
|
626
|
+
description: Leave blank lines out of the count. Defaults to false.
|
|
627
|
+
type: boolean
|
|
628
|
+
type: object
|
|
629
|
+
description: 'Reports every function whose body has more than `max` lines (default 50), counted like Biome 2.6.5''s `noExcessiveLinesPerFunction`: brace lines do not count, comment and blank lines do (blank lines not with `skipBlankLines`), and a nested function''s lines count toward its parent. Getters and setters are not checked. Works on TypeScript/JavaScript, Python, Swift, Rust and C#. Opt-in; no autofix.'
|
|
630
|
+
examples:
|
|
631
|
+
- 'function-length: error'
|
|
632
|
+
- |-
|
|
633
|
+
function-length:
|
|
634
|
+
severity: warn
|
|
635
|
+
include: ["src/**", "!src/generated/**"]
|
|
636
|
+
max: 40
|
|
637
|
+
skipBlankLines: true
|
|
594
638
|
no-async-predicate:
|
|
595
639
|
anyOf:
|
|
596
640
|
- 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.
|
|
3
|
+
"version": "1.3.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.
|
|
60
|
-
"@konvert7/klint-darwin-x64": "1.
|
|
61
|
-
"@konvert7/klint-linux-arm64": "1.
|
|
62
|
-
"@konvert7/klint-linux-x64": "1.
|
|
63
|
-
"@konvert7/klint-linux-x64-musl": "1.
|
|
64
|
-
"@konvert7/klint-win32-x64": "1.
|
|
59
|
+
"@konvert7/klint-darwin-arm64": "1.3.0",
|
|
60
|
+
"@konvert7/klint-darwin-x64": "1.3.0",
|
|
61
|
+
"@konvert7/klint-linux-arm64": "1.3.0",
|
|
62
|
+
"@konvert7/klint-linux-x64": "1.3.0",
|
|
63
|
+
"@konvert7/klint-linux-x64-musl": "1.3.0",
|
|
64
|
+
"@konvert7/klint-win32-x64": "1.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "2.6.5",
|