@@ -36,6 +36,46 @@ export function activate(context: vscode.ExtensionContext) {
36
36
const missingKeysInDotEnv = configTsKeys . filter (
37
37
x => ! parsedDotEnvKeys . includes ( x )
38
38
)
39
+ const hiddenPattern = / h i d d e n \( [ \n \r \s ] * ( ' | " ) .* ( " | ' ) [ \n \r \s ] * \) / g
40
+ const hiddenTsKeys =
41
+ text
42
+ . match ( hiddenPattern )
43
+ ?. map ( x => x . slice ( 7 , - 1 ) . trim ( ) . slice ( 1 , - 1 ) ) ?? [ ]
44
+
45
+ const diagnostics : vscode . Diagnostic [ ] = [ ]
46
+
47
+ // ============== Underline keys with unsafe default values in config.ts file ==============
48
+ for ( const hiddenKey of hiddenTsKeys ) {
49
+ const safeDefaultValue =
50
+ parsedDotEnv [ hiddenKey ] === '' ||
51
+ parsedDotEnv [ hiddenKey ] === `__${ hiddenKey } __`
52
+ if ( ! safeDefaultValue ) {
53
+ const startPos = file . document . getText ( ) . indexOf ( `'${ hiddenKey } '` )
54
+ const endPos = startPos + hiddenKey . length + 2
55
+ const keyRange = new vscode . Range (
56
+ file . document . positionAt ( startPos ) ,
57
+ file . document . positionAt ( endPos )
58
+ )
59
+ const warningMessage = new vscode . Diagnostic (
60
+ keyRange ,
61
+ `Key '${ hiddenKey } ' should have a safe default value. Use empty string or '__${ hiddenKey } __' in .env.jsonc.` ,
62
+ vscode . DiagnosticSeverity . Warning
63
+ )
64
+ warningMessage . relatedInformation = [
65
+ {
66
+ location : new vscode . Location ( file . document . uri , keyRange ) ,
67
+ message : 'Unsafe default value in .env' ,
68
+ } ,
69
+ ]
70
+ warningMessage . code = {
71
+ value : 'key-unsafe-default-value' ,
72
+ target : fileUri ,
73
+ }
74
+ warningMessage . source = 'configuru'
75
+
76
+ diagnostics . push ( warningMessage )
77
+ }
78
+ }
39
79
40
80
// ============== Underline missing keys in config.ts file ==============
41
81
// Get all comments in the file in order to not underline missing keys in comments
@@ -52,7 +92,6 @@ export function activate(context: vscode.ExtensionContext) {
52
92
} ) ?? [ ]
53
93
54
94
// Underline missing keys in config.ts file
55
- const diagnostics : vscode . Diagnostic [ ] = [ ]
56
95
for ( const key of missingKeysInDotEnv ) {
57
96
const startPos = file . document . getText ( ) . indexOf ( `'${ key } '` )
58
97
const endPos = startPos + key . length + 2
0 commit comments