@@ -186,6 +186,27 @@ function lintTSLanguageFile(file) {
186
186
errors . push ( new Error ( "A root language import can only include imports and an export called 'lang' " ) ) ;
187
187
}
188
188
189
+ if ( lastStatementIsDeclaration ) {
190
+ /** @type {import("typescript").VariableDeclarationList } */
191
+ // @ts -ignore
192
+ const declarationList = notImportStatements [ 0 ] . declarationList
193
+
194
+ const declaration = declarationList . declarations [ 0 ]
195
+ if ( ! declaration . initializer ) errors . push ( new Error ( `Something is off with the export in this file` ) ) ;
196
+
197
+ /** @type {import("typescript").CallExpression } */
198
+ // @ts -ignore
199
+ const callExpression = declaration . initializer . expression
200
+ if ( callExpression . getText ( sourceFile ) !== "defineMessages" ) errors . push ( new Error ( `The export needs to call define messages` ) ) ;
201
+
202
+ /** @type {import("typescript").ObjectLiteralExpression } */
203
+ // @ts -ignore
204
+ const arg0 = declaration . initializer . arguments [ 0 ]
205
+ arg0 . properties . forEach ( p => {
206
+ if ( p . kind !== 290 ) errors . push ( new Error ( `You can only have spreads (...) in the export` ) ) ;
207
+ } )
208
+ }
209
+
189
210
sourceFile . statements . forEach ( s => {
190
211
if ( ! ts . isImportDeclaration ( s ) ) return
191
212
if ( ! s . importClause ) errors . push ( new Error ( `The import ${ s . moduleSpecifier . getText ( sourceFile ) } is not importing an object` ) ) ;
@@ -196,7 +217,6 @@ function lintTSLanguageFile(file) {
196
217
if ( ! allowed . includes ( specifier ) && ! specifier . startsWith ( '".' ) ) {
197
218
errors . push ( new Error ( `The import ${ specifier } is not allowlisted ([${ allowed . join ( ", " ) } ]) nor relative` ) ) ;
198
219
}
199
-
200
220
} )
201
221
202
222
} else {
@@ -211,6 +231,32 @@ function lintTSLanguageFile(file) {
211
231
if ( notDeclarationList ) {
212
232
errors . push ( new Error ( "TS files should only look like: `export const somethingCopy = { ... }` " ) )
213
233
}
234
+ // @ts -ignore
235
+ const lastStatement = sourceFile . statements [ 0 ] . declarationList
236
+ if ( ! ts . isVariableDeclarationList ( lastStatement ) ) {
237
+ errors . push ( new Error ( "TS files should only look like: `export const somethingCopy = { ... }` " ) )
238
+ } else {
239
+ /** @type {import("typescript").ObjectLiteralExpression } */
240
+ // @ts -ignore
241
+ const init = lastStatement . declarations [ 0 ] . initializer
242
+ if ( ! init ) {
243
+ errors . push ( new Error ( "Something is off in the const in that file" ) )
244
+ } else {
245
+ init . properties . forEach ( prop => {
246
+ /** @type {import("typescript").PropertyAssignment } */
247
+ // @ts -ignore
248
+ const init = prop . initializer
249
+ if ( init . kind !== 10 && init . kind !== 14 ) {
250
+ if ( init . kind === 218 ) {
251
+ errors . push ( new Error ( `The template string at ${ prop . name . getText ( sourceFile ) } can't have evaluated code ( no \${} allowed )` ) )
252
+ } else {
253
+ errors . push ( new Error ( `The value at ${ prop . name . getText ( sourceFile ) } isn't a string` ) )
254
+ }
255
+ }
256
+ } ) ;
257
+ }
258
+ // declarationList.declarations[0]
259
+ }
214
260
}
215
261
216
262
0 commit comments