8

I use swiftlint in my project. The project name is ABC xx and it works fine with swiftlint. Now I decided to include Unitest in my application and I have to import @testable import ABC_xx into the swift test file which is class ABC_xxTests: XCTestCase { not I get an error with Swiftlinter which says Type Name Violation: Type name should only contain alphanumeric characters: 'ABC_xxTests' (type_name) how do I sort this error

King
  • 1,885
  • 3
  • 27
  • 84

4 Answers4

19

The following swiftlint rule enable the use of underscore in your Swift class names:

type_name:
  allowed_symbols: "_"

EDIT: If you want to enable the use of underscore also for variable names use:

identifier_name:
  allowed_symbols: "_"
carmine
  • 1,597
  • 2
  • 24
  • 33
2

In addition to @carmine's answer, keep the below two things in mind while adding attributes to any rule in .swiftlint.yml:

  • it should be listed in a new line
  • and should be preceded with a white space.

In my case I overlooked the white space before allowed_symbols. So the linting was not working. When I added white space, it was successful.

Rishi
  • 743
  • 8
  • 17
1

Use of underscore for variable names add in .swiftlint.yml:

variable_name:
     allowed_symbols: "_"
Rahul Panzade
  • 1,302
  • 15
  • 12
  • 3
    Tested with SwiftLint 0.39.2 : `'variable_name' rule has been renamed to 'identifier_name' and will be completely removed in a future release.` – frouo Dec 02 '20 at 15:18
0

You can disable rule for specified folder, in your case its an ABC_xxTests folder. Inside .swiftlint.yml configuration file you can use 'excluded' property. If you haven't yet create swiftlint configuration file, you can create one with name .swiftlint.yml and place it in your project root folder.

Add this lines:

excluded:
    - ABC_xxTests
axunic
  • 2,256
  • 18
  • 18