@ryuugg/stanza 0.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/LICENSE.md +21 -0
- package/README.md +163 -0
- package/package.json +63 -0
- package/src/cli.ts +820 -0
- package/src/compile/darwin-arm64.ts +3 -0
- package/src/compile/darwin-x64.ts +3 -0
- package/src/compile/linux-arm64-musl.ts +3 -0
- package/src/compile/linux-arm64.ts +3 -0
- package/src/compile/linux-x64-musl.ts +3 -0
- package/src/compile/linux-x64.ts +3 -0
- package/src/compiled.ts +6 -0
- package/src/engine/attach.ts +62 -0
- package/src/engine/directives.ts +154 -0
- package/src/engine/doc.ts +93 -0
- package/src/engine/edits.ts +79 -0
- package/src/engine/explain.ts +333 -0
- package/src/engine/gaps.ts +329 -0
- package/src/engine/hunks.ts +320 -0
- package/src/engine/index.ts +254 -0
- package/src/engine/model.ts +102 -0
- package/src/engine/rules.ts +103 -0
- package/src/engine/types.ts +37 -0
- package/src/files.ts +822 -0
- package/src/gitignore.ts +279 -0
- package/src/hook.ts +282 -0
- package/src/languages/index.ts +32 -0
- package/src/languages/javascript/ast.ts +199 -0
- package/src/languages/javascript/braces.ts +374 -0
- package/src/languages/javascript/config/biome.ts +112 -0
- package/src/languages/javascript/config/eslint.ts +128 -0
- package/src/languages/javascript/config/evaluate.ts +278 -0
- package/src/languages/javascript/config/find.ts +108 -0
- package/src/languages/javascript/config/glob.ts +150 -0
- package/src/languages/javascript/config/index.ts +48 -0
- package/src/languages/javascript/config/layers.ts +425 -0
- package/src/languages/javascript/config/module.ts +326 -0
- package/src/languages/javascript/config/oxlint.ts +170 -0
- package/src/languages/javascript/config/width.ts +715 -0
- package/src/languages/javascript/entry.ts +39 -0
- package/src/languages/javascript/facts.ts +268 -0
- package/src/languages/javascript/index.ts +20 -0
- package/src/languages/javascript/lists.ts +49 -0
- package/src/languages/javascript/oracle.ts +191 -0
- package/src/languages/javascript/parse.ts +58 -0
- package/src/languages/javascript/scan.ts +68 -0
- package/src/languages/language.ts +109 -0
- package/src/launcher +21 -0
- package/src/native-file.d.ts +4 -0
- package/src/step.ts +108 -0
- package/src/usage.ts +30 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
type Rule = { summary: string; message: (...args: never[]) => string } & (
|
|
2
|
+
| { fixable: true; gap: "none" | "at-least-one" | null }
|
|
3
|
+
| { fixable: false; gap: null }
|
|
4
|
+
);
|
|
5
|
+
|
|
6
|
+
const joinMessage = (name: string, reader: string) =>
|
|
7
|
+
`keep \`${name}\` next to the \`${reader}\` that reads it (remove the blank line)`;
|
|
8
|
+
|
|
9
|
+
export const RULES = {
|
|
10
|
+
"after-multiline": {
|
|
11
|
+
fixable: true,
|
|
12
|
+
gap: "at-least-one",
|
|
13
|
+
summary: "a statement that spans several lines is followed by a blank line",
|
|
14
|
+
message: () => "blank line expected after the multi-line statement above",
|
|
15
|
+
},
|
|
16
|
+
"switch-clauses": {
|
|
17
|
+
fixable: true,
|
|
18
|
+
gap: "at-least-one",
|
|
19
|
+
summary:
|
|
20
|
+
"a blank line goes in between switch clauses and none is ever removed; the gap under a fall through label with an empty body is left as it is",
|
|
21
|
+
message: () => "blank line expected between switch clauses",
|
|
22
|
+
},
|
|
23
|
+
"edge-blank": {
|
|
24
|
+
fixable: true,
|
|
25
|
+
gap: null,
|
|
26
|
+
summary: "a block has no blank line right after `{` or right before `}`",
|
|
27
|
+
message: (side: "after {" | "before }") => `no blank line right ${side}`,
|
|
28
|
+
},
|
|
29
|
+
"guard-join": {
|
|
30
|
+
fixable: true,
|
|
31
|
+
gap: "none",
|
|
32
|
+
summary:
|
|
33
|
+
"a single-line declaration or assignment is followed directly by an `if` that references what it binds, whatever the body size and with or without `else`",
|
|
34
|
+
message: joinMessage,
|
|
35
|
+
},
|
|
36
|
+
"consume-join": {
|
|
37
|
+
fixable: true,
|
|
38
|
+
gap: "none",
|
|
39
|
+
summary:
|
|
40
|
+
"a single-line declaration or assignment is followed directly by a `return` or `switch` that references what it binds",
|
|
41
|
+
message: joinMessage,
|
|
42
|
+
},
|
|
43
|
+
"use-join": {
|
|
44
|
+
fixable: true,
|
|
45
|
+
gap: "none",
|
|
46
|
+
summary:
|
|
47
|
+
"a single-line declaration is followed directly by a loop, `try` or function declaration that references what it binds",
|
|
48
|
+
message: joinMessage,
|
|
49
|
+
},
|
|
50
|
+
"guard-chain": {
|
|
51
|
+
fixable: true,
|
|
52
|
+
gap: "none",
|
|
53
|
+
summary:
|
|
54
|
+
"consecutive compact guards (`if` with a one statement body and no `else`) have no blank line between them",
|
|
55
|
+
message: () => "no blank line between consecutive compact guards",
|
|
56
|
+
},
|
|
57
|
+
"let-step": {
|
|
58
|
+
fixable: true,
|
|
59
|
+
gap: "at-least-one",
|
|
60
|
+
summary:
|
|
61
|
+
"a `let` that joins the block below it gets a blank line above it, so it starts its own step",
|
|
62
|
+
message: () => "blank line expected above a let that the block below assigns or uses",
|
|
63
|
+
},
|
|
64
|
+
"after-guard": {
|
|
65
|
+
fixable: true,
|
|
66
|
+
gap: "at-least-one",
|
|
67
|
+
summary:
|
|
68
|
+
"a single-line guard that returns, throws, continues or breaks is followed by a blank line, unless the next statement is an `if` or a jump (`return`, `throw`, `break`, `continue`)",
|
|
69
|
+
message: () =>
|
|
70
|
+
"blank line expected after the guard above, the next statement starts a new step",
|
|
71
|
+
},
|
|
72
|
+
"short-body": {
|
|
73
|
+
fixable: true,
|
|
74
|
+
gap: "none",
|
|
75
|
+
summary:
|
|
76
|
+
"a block of two or three compact statements has no blank lines, whether it is a function body, an arrow body, a method, a nested block or a switch clause body",
|
|
77
|
+
message: () => "no blank lines between 2 or 3 compact statements",
|
|
78
|
+
},
|
|
79
|
+
braces: {
|
|
80
|
+
fixable: true,
|
|
81
|
+
gap: null,
|
|
82
|
+
summary: "a control flow body that is a single statement has no braces",
|
|
83
|
+
message: () => "braces around a single statement body",
|
|
84
|
+
},
|
|
85
|
+
"block-spacing": {
|
|
86
|
+
fixable: false,
|
|
87
|
+
gap: null,
|
|
88
|
+
summary: "a multi-line block directly under a statement, when no join rule explains it",
|
|
89
|
+
message: () => "blank line expected before this block, or join it to the step above",
|
|
90
|
+
},
|
|
91
|
+
wall: {
|
|
92
|
+
fixable: false,
|
|
93
|
+
gap: null,
|
|
94
|
+
summary: "six or more consecutive single-line statements with no blank line",
|
|
95
|
+
message: () => "6 or more statements with no blank line between them; separate the steps",
|
|
96
|
+
},
|
|
97
|
+
} as const satisfies Record<string, Rule>;
|
|
98
|
+
|
|
99
|
+
export type RuleId = keyof typeof RULES;
|
|
100
|
+
|
|
101
|
+
export type GapRule<W extends Rule["gap"]> = {
|
|
102
|
+
[K in RuleId]: (typeof RULES)[K]["gap"] extends W ? K : never;
|
|
103
|
+
}[RuleId];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Layout } from "../languages/language.ts";
|
|
2
|
+
import type { Changed } from "./model.ts";
|
|
3
|
+
import type { RuleId } from "./rules.ts";
|
|
4
|
+
|
|
5
|
+
export type Braces = "on" | "off";
|
|
6
|
+
|
|
7
|
+
export type Mode = "fix" | "check";
|
|
8
|
+
|
|
9
|
+
export interface Options {
|
|
10
|
+
keepBraces: boolean;
|
|
11
|
+
width: Layout;
|
|
12
|
+
changedLines?: Changed;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Finding {
|
|
16
|
+
path: string;
|
|
17
|
+
line: number;
|
|
18
|
+
col: number;
|
|
19
|
+
rule: RuleId | "parse" | "error" | "write";
|
|
20
|
+
message: string;
|
|
21
|
+
fixable: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function compareFindings(left: Finding, right: Finding): number {
|
|
25
|
+
return (
|
|
26
|
+
left.path.localeCompare(right.path) ||
|
|
27
|
+
left.line - right.line ||
|
|
28
|
+
left.col - right.col ||
|
|
29
|
+
left.rule.localeCompare(right.rule)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FileResult {
|
|
34
|
+
text: string;
|
|
35
|
+
findings: Finding[];
|
|
36
|
+
parseError: boolean;
|
|
37
|
+
}
|