@@ -11,6 +11,11 @@ export interface PluginOptions {
1111 cssFiles ?: string [ ] ;
1212 /** Patterns to ignore when searching for CSS files */
1313 ignore ?: string [ ] ;
14+ /**
15+ * Enable watcher? Defaults to "auto", which only runs if the script namae has "watch"
16+ * or "serve" in it (VSCode's extension is named eslintServer).
17+ */
18+ watch ?: boolean | 'auto' ;
1419}
1520
1621let cssWatcher : CssWatcher | null = null ;
@@ -20,6 +25,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
2025 classFunctions : [ 'clsx' , 'classNames' , 'cx' ] ,
2126 cssFiles : [ '**/*.css' ] ,
2227 ignore : [ '**/node_modules/**' , '**/dist/**' , '**/out/**' , '**/build/**' ] ,
28+ watch : 'auto' ,
2329} ;
2430
2531const rule : RuleModule < 'unknownClass' , [ PluginOptions ] > = {
@@ -68,7 +74,14 @@ const rule: RuleModule<'unknownClass', [PluginOptions]> = {
6874
6975 // Initialize watcher if not already done
7076 if ( ! cssWatcher ) {
71- cssWatcher = new CssWatcher ( options . cssFiles , options . ignore ) ;
77+ const shouldWatch = ( ( ) => {
78+ if ( options . watch === 'auto' ) {
79+ const script = process . argv [ 1 ] ?. toLowerCase ( ) ?? '' ;
80+ return script . includes ( 'watch' ) || script . includes ( 'serve' ) ;
81+ }
82+ return options . watch ;
83+ } ) ( ) ;
84+ cssWatcher = new CssWatcher ( options . cssFiles , options . ignore , shouldWatch ) ;
7285 }
7386
7487 /** Helper to check if a class exists in our CSS files */
0 commit comments