@@ -62,6 +62,7 @@ export default createRule<RuleOptions, MessageIds>({
6262 if ( tokenOperator . range [ 0 ] <= right . parent ! . range [ 0 ] )
6363 return
6464 }
65+ const tokenBeforeAll = sourceCode . getTokenBefore ( node )
6566 const tokenLeft = sourceCode . getTokenBefore ( tokenOperator ) !
6667
6768 const isMultiline = tokenRight . loc . start . line !== tokenLeft . loc . start . line
@@ -73,9 +74,16 @@ export default createRule<RuleOptions, MessageIds>({
7374 // we bump the indentation level by one.
7475 const firstTokenOfLineLeft = firstTokenOfLine ( tokenLeft . loc . start . line )
7576 const lastTokenOfLineLeft = lastTokenOfLine ( tokenLeft . loc . start . line )
76- const needAdditionIndent = ( firstTokenOfLineLeft ?. type === 'Keyword' && ! [ 'typeof' , 'instanceof' , 'this' ] . includes ( firstTokenOfLineLeft . value ) )
77+ const needAdditionIndent = false
78+ // First line is a keyword (but exclude `typeof`, `instanceof`, `this`)
79+ || ( firstTokenOfLineLeft ?. type === 'Keyword' && ! [ 'typeof' , 'instanceof' , 'this' ] . includes ( firstTokenOfLineLeft . value ) )
80+ // First line is a `type` keyword in a type alias declaration
7781 || ( firstTokenOfLineLeft ?. type === 'Identifier' && firstTokenOfLineLeft . value === 'type' && node . parent ?. type === 'TSTypeAliasDeclaration' )
82+ // End of line is a opening bracket
7883 || [ ':' , '[' , '(' , '<' , '=' ] . includes ( lastTokenOfLineLeft ?. value || '' )
84+ // Before the left token is a opening bracket
85+ || ( [ '[' , '(' , '=>' , ':' ] . includes ( tokenBeforeAll ?. value || '' ) && firstTokenOfLineLeft ?. loc . start . line === tokenBeforeAll ?. loc . start . line )
86+ // Chain of `||` or `&&` operators
7987 || ( [ '||' , '&&' ] . includes ( lastTokenOfLineLeft ?. value || '' ) && node . loc . start . line === tokenLeft . loc . start . line && node . loc . start . column !== getIndentOfLine ( node . loc . start . line ) . length )
8088
8189 const indentTarget = getIndentOfLine ( tokenLeft . loc . start . line ) + ( needAdditionIndent ? indentStr : '' )
0 commit comments