@@ -3,9 +3,7 @@ import { service } from '@ember/service';
33import {
44 isCardDocumentString ,
55 isCardErrorJSONAPI ,
6- SupportedMimeType ,
76 type CardErrorJSONAPI ,
8- type LintResult ,
97} from '@cardstack/runtime-common' ;
108
119import ENV from '@cardstack/host/config/environment' ;
@@ -16,7 +14,6 @@ import HostBaseCommand from '../lib/host-base-command';
1614
1715import type CardService from '../services/card-service' ;
1816import type CommandService from '../services/command-service' ;
19- import type NetworkService from '../services/network' ;
2017import type RealmService from '../services/realm' ;
2118import type RealmServerService from '../services/realm-server' ;
2219import type StoreService from '../services/store' ;
@@ -32,7 +29,6 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
3229 @service declare private commandService : CommandService ;
3330 @service declare private cardService : CardService ;
3431 @service declare private realmServer : RealmServerService ;
35- @service declare private network : NetworkService ;
3632
3733 description =
3834 'Run post-change correctness checks for a specific file or card instance.' ;
@@ -76,7 +72,7 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
7672 let commandModule = await this . loadCommandModule ( ) ;
7773 const { CorrectnessResultCard } = commandModule ;
7874 let errors : string [ ] = [ ] ;
79- let lintIssues : string [ ] = [ ] ;
75+ let lintIssues : string [ ] = input . lintIssues ?? [ ] ;
8076
8177 let sizeLimitError = this . cardService . getSizeLimitError ( input . targetRef ) ;
8278 if ( sizeLimitError ) {
@@ -100,9 +96,6 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
10096
10197 if ( targetType === 'file' && input . targetRef . endsWith ( '.gts' ) ) {
10298 errors = await this . collectModuleErrors ( input . targetRef , roomId ) ;
103- lintIssues = await this . collectLintIssues ( input . targetRef ) ;
104- } else if ( targetType === 'file' && this . isLintableFile ( input . targetRef ) ) {
105- lintIssues = await this . collectLintIssues ( input . targetRef ) ;
10699 } else if ( targetType === 'card' ) {
107100 if ( ! cardId ) {
108101 throw new Error ( 'Card correctness checks require a targetRef.' ) ;
@@ -268,81 +261,6 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
268261 }
269262 }
270263
271- private isLintableFile ( targetRef : string ) : boolean {
272- let path = targetRef ;
273- try {
274- path = new URL ( targetRef ) . pathname ;
275- } catch {
276- // fall back to original targetRef when it's not a URL
277- }
278- return / \. ( g t s | t s ) $ / . test ( path ) ;
279- }
280-
281- private async collectLintIssues ( targetRef : string ) : Promise < string [ ] > {
282- try {
283- if ( ! this . isLintableFile ( targetRef ) ) {
284- return [ ] ;
285- }
286-
287- let fileUrl = new URL ( targetRef ) ;
288- let realmURL = this . realm . realmOfURL ( fileUrl ) ;
289- if ( ! realmURL ) {
290- return [ ] ;
291- }
292-
293- let { status, content } = await this . cardService . getSource ( fileUrl ) ;
294- if ( status !== 200 || ! content . trim ( ) ) {
295- return [ ] ;
296- }
297-
298- let filename = fileUrl . pathname . split ( '/' ) . pop ( ) || 'input.gts' ;
299- let response = await this . network . authedFetch (
300- `${ realmURL . href } _lint?lintMode=lint` ,
301- {
302- method : 'POST' ,
303- body : content ,
304- headers : {
305- Accept : 'application/json' ,
306- 'Content-Type' : SupportedMimeType . CardSource ,
307- 'X-HTTP-Method-Override' : 'QUERY' ,
308- 'X-Filename' : filename ,
309- } ,
310- } ,
311- ) ;
312-
313- if ( ! response . ok ) {
314- console . warn (
315- `CheckCorrectnessCommand: lint request failed for ${ targetRef } (${ response . status } )` ,
316- ) ;
317- return [ ] ;
318- }
319-
320- let lintResult : LintResult ;
321- try {
322- lintResult = ( await response . json ( ) ) as LintResult ;
323- } catch ( error ) {
324- console . warn (
325- `CheckCorrectnessCommand: unable to parse lint response for ${ targetRef } ` ,
326- error ,
327- ) ;
328- return [ ] ;
329- }
330-
331- let messages = Array . isArray ( lintResult ?. messages )
332- ? lintResult . messages
333- : [ ] ;
334- return messages
335- . map ( ( message ) => this . formatLintIssue ( message ) )
336- . filter ( ( warning ) => warning . length > 0 ) ;
337- } catch ( error ) {
338- console . warn (
339- `CheckCorrectnessCommand: lint warning collection failed for ${ targetRef } ` ,
340- error ,
341- ) ;
342- return [ ] ;
343- }
344- }
345-
346264 private async isEmptyFileContent ( targetRef : string ) : Promise < boolean > {
347265 try {
348266 let fileUrl = new URL ( targetRef ) ;
@@ -353,31 +271,6 @@ export default class CheckCorrectnessCommand extends HostBaseCommand<
353271 }
354272 }
355273
356- private formatLintIssue ( message : LintResult [ 'messages' ] [ number ] ) : string {
357- if ( ! message || typeof message . message !== 'string' ) {
358- return '' ;
359- }
360- let trimmedMessage = message . message . trim ( ) ;
361- if ( ! trimmedMessage ) {
362- return '' ;
363- }
364-
365- let location = '' ;
366- if ( typeof message . line === 'number' ) {
367- if ( typeof message . column === 'number' ) {
368- location = `line ${ message . line } :${ message . column } ` ;
369- } else {
370- location = `line ${ message . line } ` ;
371- }
372- }
373-
374- let ruleId = message . ruleId ? ` (${ message . ruleId } )` : '' ;
375- if ( location ) {
376- return `${ location } ${ trimmedMessage } ${ ruleId } ` . trim ( ) ;
377- }
378- return `${ trimmedMessage } ${ ruleId } ` . trim ( ) ;
379- }
380-
381274 private describeCardError ( cardId : string , error : CardErrorJSONAPI ) : string {
382275 let pieces = [ error . title , error . message ]
383276 . filter ( ( part ) : part is string => typeof part === 'string' )
0 commit comments