@@ -48,11 +48,18 @@ module.exports = async function codeMod(file, api, options) {
4848 const ruleIdWhitelist = ( options . rules || '' ) . split ( ',' ) . filter ( ( x ) => x ) ;
4949 const ruleIdWhitelistSet = ruleIdWhitelist . length ? new Set ( ruleIdWhitelist ) : null ;
5050
51+ let hasMaxLinesRule = false ;
52+
5153 for ( const { targetLine, ruleId } of targets ) {
5254 if ( ruleIdWhitelistSet && ! ruleIdWhitelistSet . has ( ruleId ) ) {
5355 continue ;
5456 }
5557
58+ if ( ruleId === 'max-lines' ) {
59+ hasMaxLinesRule = true ;
60+ continue ;
61+ }
62+
5663 const pathsStartingOnLine = result
5764 . find ( 'Node' , ( node ) => node . loc && node . loc . start . line === targetLine )
5865 . paths ( ) ;
@@ -72,6 +79,27 @@ module.exports = async function codeMod(file, api, options) {
7279 addDisableComment ( file . path , api , commentText , targetLine , ruleId , firstPathOnLine ) ;
7380 }
7481
82+ // Gotta put the disable max-lines comment near the top of the file
83+ if ( hasMaxLinesRule ) {
84+ const disableComment = `/* eslint-disable max-lines */\n` ;
85+ const todoComment = `/* ${ commentText } */\n` ;
86+
87+ const useClientMatch = file . source . match ( / ^ ( \s * [ ' " ] u s e c l i e n t [ ' " ] ; ? \s * ) / ) ;
88+
89+ let updatedSource ;
90+ if ( useClientMatch ) {
91+ // If 'use client' exists, insert comments just after it
92+ const [ fullMatch , useClientDirective ] = useClientMatch ;
93+ updatedSource =
94+ useClientDirective + todoComment + disableComment + file . source . slice ( fullMatch . length ) ;
95+ } else {
96+ // If 'use client' doesn't exist, insert comments at the beginning
97+ updatedSource = todoComment + disableComment + file . source ;
98+ }
99+
100+ return api . j ( updatedSource ) . toSource ( ) ;
101+ }
102+
75103 return result . toSource ( ) ;
76104} ;
77105
0 commit comments