@@ -186,6 +186,27 @@ function lintTSLanguageFile(file) {
186186 errors . push ( new Error ( "A root language import can only include imports and an export called 'lang' " ) ) ;
187187 }
188188
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+
189210 sourceFile . statements . forEach ( s => {
190211 if ( ! ts . isImportDeclaration ( s ) ) return
191212 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) {
196217 if ( ! allowed . includes ( specifier ) && ! specifier . startsWith ( '".' ) ) {
197218 errors . push ( new Error ( `The import ${ specifier } is not allowlisted ([${ allowed . join ( ", " ) } ]) nor relative` ) ) ;
198219 }
199-
200220 } )
201221
202222 } else {
@@ -211,6 +231,32 @@ function lintTSLanguageFile(file) {
211231 if ( notDeclarationList ) {
212232 errors . push ( new Error ( "TS files should only look like: `export const somethingCopy = { ... }` " ) )
213233 }
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+ }
214260 }
215261
216262
0 commit comments