@@ -42,27 +42,13 @@ export const enum PaddingType {
4242 Always ,
4343}
4444
45- type PaddingTester = (
46- prevNode : Node ,
47- nextNode : Node ,
48- paddingContext : PaddingContext ,
49- ) => void ;
50-
5145// A configuration object for padding type and the two statement types
5246export interface Config {
5347 paddingType : PaddingType ;
5448 prevStatementType : StatementTypes ;
5549 nextStatementType : StatementTypes ;
5650}
5751
58- // Tracks position in scope and prevNode. Used to compare current and prev node
59- // and then to walk back up to the parent scope or down into the next one.
60- // And so on...
61- interface Scope {
62- upper : Scope | null ;
63- prevNode : Node | null ;
64- }
65-
6652interface ScopeInfo {
6753 prevNode : Node | null ;
6854 enter : ( ) => void ;
@@ -76,6 +62,20 @@ interface PaddingContext {
7662 configs : Config [ ] ;
7763}
7864
65+ type PaddingTester = (
66+ prevNode : Node ,
67+ nextNode : Node ,
68+ paddingContext : PaddingContext ,
69+ ) => void ;
70+
71+ // Tracks position in scope and prevNode. Used to compare current and prev node
72+ // and then to walk back up to the parent scope or down into the next one.
73+ // And so on...
74+ interface Scope {
75+ upper : Scope | null ;
76+ prevNode : Node | null ;
77+ }
78+
7979// Creates a StatementTester to test an ExpressionStatement's first token name
8080const createTokenTester = ( tokenName : string ) : StatementTester => {
8181 return ( node : Node , sourceCode : SourceCode ) : boolean => {
@@ -143,35 +143,34 @@ const paddingAlwaysTester = (
143143 message : 'Expected blank line before this statement.' ,
144144 fix ( fixer : Rule . RuleFixer ) : Rule . Fix {
145145 let prevToken = astUtils . getActualLastToken ( sourceCode , prevNode ) ;
146- const nextToken =
147- sourceCode . getFirstTokenBetween ( prevToken , nextNode , {
148- includeComments : true ,
149- /**
150- * Skip the trailing comments of the previous node.
151- * This inserts a blank line after the last trailing comment.
152- *
153- * For example:
154- *
155- * foo(); // trailing comment.
156- * // comment.
157- * bar();
158- *
159- * Get fixed to:
160- *
161- * foo(); // trailing comment.
162- *
163- * // comment.
164- * bar();
165- */
166- filter ( token : AST . Token ) : boolean {
167- if ( astUtils . areTokensOnSameLine ( prevToken , token ) ) {
168- prevToken = token ;
169- return false ;
170- }
171-
172- return true ;
173- } ,
174- } ) || nextNode ;
146+ const nextToken = ( sourceCode . getFirstTokenBetween ( prevToken , nextNode , {
147+ includeComments : true ,
148+ /**
149+ * Skip the trailing comments of the previous node.
150+ * This inserts a blank line after the last trailing comment.
151+ *
152+ * For example:
153+ *
154+ * foo(); // trailing comment.
155+ * // comment.
156+ * bar();
157+ *
158+ * Get fixed to:
159+ *
160+ * foo(); // trailing comment.
161+ *
162+ * // comment.
163+ * bar();
164+ */
165+ filter ( token : AST . Token ) : boolean {
166+ if ( astUtils . areTokensOnSameLine ( prevToken , token ) ) {
167+ prevToken = token ;
168+ return false ;
169+ }
170+
171+ return true ;
172+ } ,
173+ } ) || nextNode ) as AST . Token ;
175174
176175 const insertText = astUtils . areTokensOnSameLine ( prevToken , nextToken )
177176 ? '\n\n'
0 commit comments