@jutaru-dev/envsonar 0.1.0 → 0.2.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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Parses dotenv text. Supports comments, `export KEY=...`, single/double/backtick quotes,
3
+ * multi-line quoted values and inline `#` comments after unquoted values.
4
+ * Never throws: malformed lines are reported in `errors`.
5
+ *
6
+ * @param {string} text
7
+ * @returns {ParsedEnv}
8
+ */
9
+ export function parseEnv(text: string): ParsedEnv;
10
+ export type Entry = {
11
+ value: string;
12
+ line: number;
13
+ endLine: number;
14
+ };
15
+ export type ParseIssue = {
16
+ line: number;
17
+ message: string;
18
+ };
19
+ export type ParsedEnv = {
20
+ entries: Map<string, Entry>;
21
+ duplicates: {
22
+ key: string;
23
+ lines: number[];
24
+ }[];
25
+ errors: ParseIssue[];
26
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Variables that SDKs, frameworks and container images read on their own, without a line of your code
3
+ * naming them. A key from this list in .env.example is never reported as unused once the matching
4
+ * dependency (or compose image) is found.
5
+ *
6
+ * markers: `npm:<pkg>`, `py:<pkg>`, `composer:<pkg>`, `nuget:<pkg>`, `image:<name>`, `dotnet`, `compose`;
7
+ * a trailing `*` matches a prefix.
8
+ *
9
+ * @type {{ source: string, markers: string[], keys: string[] }[]}
10
+ */
11
+ export const PROFILES: {
12
+ source: string;
13
+ markers: string[];
14
+ keys: string[];
15
+ }[];
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Blanks out comments (and Python docstrings) so reads inside them don't count. Strings are kept, so
3
+ * `"http://x"` isn't mistaken for a comment; newlines are kept, so line numbers don't move.
4
+ *
5
+ * @param {string} text
6
+ * @param {CommentStyle} style
7
+ */
8
+ export function stripComments(text: string, style: CommentStyle): string;
9
+ /**
10
+ * @param {string[]} patterns exact names or prefixes ending with `*`
11
+ * @returns {(key: string) => boolean}
12
+ */
13
+ export function keyMatcher(patterns: string[]): (key: string) => boolean;
14
+ /**
15
+ * Everything envsonar learns from one file.
16
+ *
17
+ * @param {string} text
18
+ * @param {string} file path used to pick the language
19
+ */
20
+ export function extractFile(text: string, file: string): {
21
+ found: {
22
+ ci?: true | undefined;
23
+ optional?: true | undefined;
24
+ key: string;
25
+ line: number;
26
+ }[];
27
+ sections: {
28
+ key: string;
29
+ line: number;
30
+ }[];
31
+ dynamic: {
32
+ expr: string;
33
+ line: number;
34
+ }[];
35
+ provided: Provided[];
36
+ markers: Set<string>;
37
+ bindings: Binding[];
38
+ optionClasses: Map<string, OptionClass>;
39
+ };
40
+ /**
41
+ * Every statically named environment variable read in one file.
42
+ *
43
+ * @param {string} text
44
+ * @param {string} file used to pick the language
45
+ * @returns {Found[]}
46
+ */
47
+ export function extractKeys(text: string, file: string): Found[];
48
+ /**
49
+ * Walks `root`: collects every environment variable the code reads, plus what frameworks,
50
+ * SDKs, compose files and appsettings.json provide or read on their own.
51
+ *
52
+ * @param {string} root
53
+ * @param {{ ignoreDirs?: string[], ignoreKeys?: string[], includeTests?: boolean }} [options]
54
+ * @returns {ScanResult}
55
+ */
56
+ export function scanProject(root: string, options?: {
57
+ ignoreDirs?: string[];
58
+ ignoreKeys?: string[];
59
+ includeTests?: boolean;
60
+ }): ScanResult;
61
+ /** @type {Record<string, CommentStyle>} */
62
+ export const COMMENT_STYLES: Record<string, CommentStyle>;
63
+ /** @type {Language[]} */
64
+ export const LANGUAGES: Language[];
65
+ export const DEFAULT_IGNORE_DIRS: string[];
66
+ /** Keys set by the OS, runtimes and CI — nobody documents them in .env.example. */
67
+ export const DEFAULT_IGNORE_KEYS: string[];
68
+ /** Test code sets and mocks variables; it isn't what the app needs at runtime. `--include-tests` scans it anyway. */
69
+ export const TEST_DIRS: string[];
70
+ /**
71
+ * optional — the code has a fallback value; ci — the name is matched case-insensitively (.NET config, pydantic)
72
+ */
73
+ export type Flags = {
74
+ optional?: boolean;
75
+ ci?: boolean;
76
+ schema?: boolean;
77
+ };
78
+ export type Usage = {
79
+ file: string;
80
+ line: number;
81
+ } & Flags;
82
+ export type Found = {
83
+ key: string;
84
+ line: number;
85
+ } & Flags;
86
+ export type DynamicRead = {
87
+ file: string;
88
+ line: number;
89
+ expr: string;
90
+ };
91
+ export type Implicit = {
92
+ source: string;
93
+ keys: string[];
94
+ };
95
+ /**
96
+ * base — the value applies in every environment (appsettings.json, compose); false for appsettings.<Environment>.json
97
+ */
98
+ export type Provided = {
99
+ key: string;
100
+ source: string;
101
+ base: boolean;
102
+ };
103
+ export type Binding = {
104
+ cls: string;
105
+ line: number;
106
+ section?: string;
107
+ sectionOf?: string;
108
+ };
109
+ export type OptionProp = {
110
+ name: string;
111
+ line: number;
112
+ optional: boolean;
113
+ };
114
+ export type OptionClass = {
115
+ props: OptionProp[];
116
+ sectionName?: string;
117
+ };
118
+ export type ScanResult = {
119
+ files: number;
120
+ usages: Map<string, Usage[]>;
121
+ sections: Map<string, Usage[]>;
122
+ dynamic: DynamicRead[];
123
+ provided: Map<string, Provided>;
124
+ implicit: Implicit[];
125
+ };
126
+ export type Sink = {
127
+ add: (key: string, line: number, flags?: Flags) => void;
128
+ section: (prefix: string, line: number) => void;
129
+ dynamic: (expr: string, line: number) => void;
130
+ provide: (key: string, source: string, base?: boolean) => void;
131
+ bind: (binding: Binding) => void;
132
+ optionClass: (name: string, cls: OptionClass) => void;
133
+ mark: (marker: string) => void;
134
+ lineAt: (offset: number) => number;
135
+ };
136
+ export type Pattern = {
137
+ re: RegExp;
138
+ call?: boolean;
139
+ member?: boolean;
140
+ optional?: boolean;
141
+ };
142
+ export type CommentStyle = {
143
+ line: string[];
144
+ block: [string, string][];
145
+ quotes: string;
146
+ multiline?: string;
147
+ triple?: boolean;
148
+ lineAfterSpace?: boolean;
149
+ };
150
+ export type Language = {
151
+ name: string;
152
+ test: (file: string) => boolean;
153
+ comments?: CommentStyle;
154
+ patterns: Pattern[];
155
+ extra?: (text: string, sink: Sink, file: string) => void;
156
+ };