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

- 1,885
- 3
- 27
- 84
-
You can do `//swiftlint:disable:this type_name` just for this one? – Larme Jan 11 '19 at 10:05
-
would this be included in my appDelegate or where? – King Jan 11 '19 at 10:05
-
https://github.com/realm/SwiftLint#disable-rules-in-code – Larme Jan 11 '19 at 10:06
-
`//swiftlint:disable:this type_name class ABC_xxTests: XCTestCase {` still shows the same error – King Jan 11 '19 at 10:09
4 Answers
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: "_"

- 1,597
- 2
- 24
- 33
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.

- 743
- 8
- 17
Use of underscore for variable names add in .swiftlint.yml:
variable_name:
allowed_symbols: "_"

- 1,302
- 15
- 12
-
3Tested 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
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

- 2,256
- 18
- 18