1313import  SwiftSyntax
1414
1515/// Imports must be lexicographically ordered and logically grouped at the top of each source file.
16- /// The order of the import groups is 1) regular imports, 2) declaration imports, 3) @_implementationOnly 
17- /// imports, and 4) @testable imports . These groups are separated by a single blank line. Blank lines in
18- /// between the import  declarations are removed.
16+ /// The order of the import groups is 1) regular imports, 2) declaration imports, and  3) @testable 
17+ /// imports. These groups are separated by a single blank line. Blank lines in between the import 
18+ /// declarations are removed.
1919///
2020/// Lint: If an import appears anywhere other than the beginning of the file it resides in,
2121///       not lexicographically ordered, or  not in the appropriate import group, a lint error is
@@ -34,7 +34,6 @@ public final class OrderedImports: SyntaxFormatRule {
3434
3535    var  regularImports :  [ Line ]  =  [ ] 
3636    var  declImports :  [ Line ]  =  [ ] 
37-     var  implementationOnlyImports :  [ Line ]  =  [ ] 
3837    var  testableImports :  [ Line ]  =  [ ] 
3938    var  codeBlocks :  [ Line ]  =  [ ] 
4039    var  fileHeader :  [ Line ]  =  [ ] 
@@ -53,23 +52,14 @@ public final class OrderedImports: SyntaxFormatRule {
5352
5453      regularImports =  formatImports ( regularImports) 
5554      declImports =  formatImports ( declImports) 
56-       implementationOnlyImports =  formatImports ( implementationOnlyImports) 
5755      testableImports =  formatImports ( testableImports) 
5856      formatCodeblocks ( & codeBlocks) 
5957
60-       let  joined  =  joinLines ( 
61-         fileHeader, 
62-         regularImports, 
63-         declImports, 
64-         implementationOnlyImports, 
65-         testableImports, 
66-         codeBlocks
67-       ) 
58+       let  joined  =  joinLines ( fileHeader,  regularImports,  declImports,  testableImports,  codeBlocks) 
6859      formattedLines. append ( contentsOf:  joined) 
6960
7061      regularImports =  [ ] 
7162      declImports =  [ ] 
72-       implementationOnlyImports =  [ ] 
7363      testableImports =  [ ] 
7464      codeBlocks =  [ ] 
7565      fileHeader =  [ ] 
@@ -125,11 +115,6 @@ public final class OrderedImports: SyntaxFormatRule {
125115        regularImports. append ( line) 
126116        commentBuffer =  [ ] 
127117
128-       case  . implementationOnlyImport: 
129-         implementationOnlyImports. append ( contentsOf:  commentBuffer) 
130-         implementationOnlyImports. append ( line) 
131-         commentBuffer =  [ ] 
132- 
133118      case  . testableImport: 
134119        testableImports. append ( contentsOf:  commentBuffer) 
135120        testableImports. append ( line) 
@@ -163,7 +148,6 @@ public final class OrderedImports: SyntaxFormatRule {
163148  /// statements do not appear at the top of the file.
164149  private  func  checkGrouping< C:  Collection > ( _ lines:  C )  where  C. Element ==  Line  { 
165150    var  declGroup  =  false 
166-     var  implementationOnlyGroup  =  false 
167151    var  testableGroup  =  false 
168152    var  codeGroup  =  false 
169153
@@ -173,8 +157,6 @@ public final class OrderedImports: SyntaxFormatRule {
173157      switch  lineType { 
174158      case  . declImport: 
175159        declGroup =  true 
176-       case  . implementationOnlyImport: 
177-         implementationOnlyGroup =  true 
178160      case  . testableImport: 
179161        testableGroup =  true 
180162      case  . codeBlock: 
@@ -184,28 +166,17 @@ public final class OrderedImports: SyntaxFormatRule {
184166
185167      if  codeGroup { 
186168        switch  lineType { 
187-         case  . regularImport,  . declImport,  . implementationOnlyImport ,   . testableImport: 
169+         case  . regularImport,  . declImport,  . testableImport: 
188170          diagnose ( . placeAtTopOfFile,  on:  line. firstToken) 
189171        default :  ( ) 
190172        } 
191173      } 
192174
193175      if  testableGroup { 
194-         switch  lineType { 
195-         case  . regularImport,  . declImport,  . implementationOnlyImport: 
196-           diagnose ( 
197-             . groupImports( before:  lineType,  after:  LineType . testableImport) , 
198-             on:  line. firstToken
199-           ) 
200-         default :  ( ) 
201-         } 
202-       } 
203- 
204-       if  implementationOnlyGroup { 
205176        switch  lineType { 
206177        case  . regularImport,  . declImport: 
207178          diagnose ( 
208-             . groupImports( before:  lineType,  after:  LineType . implementationOnlyImport ) , 
179+             . groupImports( before:  lineType,  after:  LineType . testableImport ) , 
209180            on:  line. firstToken
210181          ) 
211182        default :  ( ) 
@@ -237,7 +208,7 @@ public final class OrderedImports: SyntaxFormatRule {
237208
238209    for  line  in  imports { 
239210      switch  line. type { 
240-       case  . regularImport,  . declImport,  . implementationOnlyImport ,   . testableImport: 
211+       case  . regularImport,  . declImport,  . testableImport: 
241212        let  fullyQualifiedImport  =  line. fullyQualifiedImport
242213        // Check for duplicate imports and potentially remove them.
243214        if  let  previousMatchingImportIndex =  visitedImports [ fullyQualifiedImport]  { 
@@ -419,7 +390,6 @@ fileprivate func convertToCodeBlockItems(lines: [Line]) -> [CodeBlockItemSyntax]
419390public  enum  LineType :  CustomStringConvertible  { 
420391  case  regularImport
421392  case  declImport
422-   case  implementationOnlyImport
423393  case  testableImport
424394  case  codeBlock
425395  case  comment
@@ -431,8 +401,6 @@ public enum LineType: CustomStringConvertible {
431401      return  " regular " 
432402    case  . declImport: 
433403      return  " declaration " 
434-     case  . implementationOnlyImport: 
435-       return  " implementationOnly " 
436404    case  . testableImport: 
437405      return  " testable " 
438406    case  . codeBlock: 
@@ -547,16 +515,12 @@ fileprivate class Line {
547515
548516  /// Returns a `LineType` the represents the type of import from the given import decl.
549517  private  func  importType( of importDecl:  ImportDeclSyntax )  ->  LineType  { 
550- 
551-     let  importIdentifierTypes  =  importDecl. attributes. compactMap  {  $0. as ( AttributeSyntax . self) ? . attributeName } 
552-     let  importAttributeNames  =  importIdentifierTypes. compactMap  {  $0. as ( IdentifierTypeSyntax . self) ? . name. text } 
553- 
554-     if  importAttributeNames. contains ( " testable " )  { 
518+     if  let  attr =  importDecl. attributes. firstToken ( viewMode:  . sourceAccurate) , 
519+       attr. tokenKind ==  . atSign, 
520+       attr. nextToken ( viewMode:  . sourceAccurate) ? . text ==  " testable " 
521+     { 
555522      return  . testableImport
556523    } 
557-     if  importAttributeNames. contains ( " _implementationOnly " )  { 
558-       return  . implementationOnlyImport
559-     } 
560524    if  importDecl. importKindSpecifier !=  nil  { 
561525      return  . declImport
562526    } 
0 commit comments