@@ -8,6 +8,7 @@ import { createCodeMirrorEditor } from './modules/editor-codemirror.js'
88import { defaultCss , defaultJsx , defaultReactJsx } from './modules/defaults.js'
99import { createDiagnosticsUiController } from './modules/diagnostics-ui.js'
1010import { createLayoutThemeController } from './modules/layout-theme.js'
11+ import { createLintController } from './modules/lint/lint-controller.js'
1112import { createPreviewBackgroundController } from './modules/preview-background.js'
1213import { createRenderRuntimeController } from './modules/render-runtime.js'
1314import { createTypeDiagnosticsController } from './modules/type-diagnostics.js'
@@ -24,6 +25,8 @@ const previewPanel = document.getElementById('preview-panel')
2425const renderMode = document . getElementById ( 'render-mode' )
2526const autoRenderToggle = document . getElementById ( 'auto-render' )
2627const typecheckButton = document . getElementById ( 'typecheck-button' )
28+ const lintComponentButton = document . getElementById ( 'lint-component-button' )
29+ const lintStylesButton = document . getElementById ( 'lint-styles-button' )
2730const renderButton = document . getElementById ( 'render-button' )
2831const copyComponentButton = document . getElementById ( 'copy-component' )
2932const clearComponentButton = document . getElementById ( 'clear-component' )
@@ -369,6 +372,16 @@ const setTypecheckButtonLoading = isLoading => {
369372 typecheckButton . disabled = isLoading
370373}
371374
375+ const setLintButtonLoading = ( { button, isLoading } ) => {
376+ if ( ! ( button instanceof HTMLButtonElement ) ) {
377+ return
378+ }
379+
380+ button . classList . toggle ( 'render-button--loading' , isLoading )
381+ button . setAttribute ( 'aria-busy' , isLoading ? 'true' : 'false' )
382+ button . disabled = isLoading
383+ }
384+
372385const setCdnLoading = isLoading => {
373386 if ( ! cdnLoading ) return
374387 cdnLoading . hidden = ! isLoading
@@ -409,6 +422,49 @@ const typeDiagnostics = createTypeDiagnosticsController({
409422 getActiveTypeDiagnosticsRuns,
410423} )
411424
425+ const lintController = createLintController ( {
426+ getComponentSource : ( ) => getJsxSource ( ) ,
427+ getStylesSource : ( ) => getCssSource ( ) ,
428+ getRenderMode : ( ) => renderMode . value ,
429+ getStyleMode : ( ) => styleMode . value ,
430+ setComponentDiagnostics : setTypeDiagnosticsDetails ,
431+ setStyleDiagnostics : setStyleDiagnosticsDetails ,
432+ setStatus,
433+ } )
434+
435+ let activeComponentLintAbortController = null
436+ let activeStylesLintAbortController = null
437+
438+ const runComponentLint = async ( ) => {
439+ activeComponentLintAbortController ?. abort ( )
440+ activeComponentLintAbortController = new AbortController ( )
441+
442+ setLintButtonLoading ( { button : lintComponentButton , isLoading : true } )
443+
444+ try {
445+ await lintController . lintComponent ( {
446+ signal : activeComponentLintAbortController . signal ,
447+ } )
448+ } finally {
449+ setLintButtonLoading ( { button : lintComponentButton , isLoading : false } )
450+ }
451+ }
452+
453+ const runStylesLint = async ( ) => {
454+ activeStylesLintAbortController ?. abort ( )
455+ activeStylesLintAbortController = new AbortController ( )
456+
457+ setLintButtonLoading ( { button : lintStylesButton , isLoading : true } )
458+
459+ try {
460+ await lintController . lintStyles ( {
461+ signal : activeStylesLintAbortController . signal ,
462+ } )
463+ } finally {
464+ setLintButtonLoading ( { button : lintStylesButton , isLoading : false } )
465+ }
466+ }
467+
412468const markTypeDiagnosticsStale = ( ) => {
413469 typeDiagnostics . markTypeDiagnosticsStale ( )
414470}
@@ -607,6 +663,16 @@ if (typecheckButton) {
607663 typeDiagnostics . triggerTypeDiagnostics ( )
608664 } )
609665}
666+ if ( lintComponentButton ) {
667+ lintComponentButton . addEventListener ( 'click' , ( ) => {
668+ void runComponentLint ( )
669+ } )
670+ }
671+ if ( lintStylesButton ) {
672+ lintStylesButton . addEventListener ( 'click' , ( ) => {
673+ void runStylesLint ( )
674+ } )
675+ }
610676renderButton . addEventListener ( 'click' , renderPreview )
611677if ( clipboardSupported ) {
612678 copyComponentButton . addEventListener ( 'click' , ( ) => {
@@ -699,6 +765,10 @@ if (typeof compactViewportMediaQuery.addEventListener === 'function') {
699765 compactViewportMediaQuery . onchange = handleCompactViewportChange
700766}
701767
768+ window . addEventListener ( 'beforeunload' , ( ) => {
769+ lintController . dispose ( )
770+ } )
771+
702772applyAppGridLayout ( getInitialAppGridLayout ( ) , { persist : false } )
703773applyTheme ( getInitialTheme ( ) , { persist : false } )
704774applyEditorToolsVisibility ( )
0 commit comments