Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swiftlint underscore name swift

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

like image 535
King Avatar asked Jan 11 '19 10:01

King


People also ask

What is swiftlint?

A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guide rules that are generally accepted by the Swift community.

How does swiftlint enforce swift style and conventions?

A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guide rules that are generally accepted by the Swift community. These rules are well described in popular style guides like Ray Wenderlich's Swift Style Guide.

How to reduce the number of warnings and errors in swiftlint?

Here the general .swiftlint.yml file, which I recommend you to use in your project. Now, Save configuration file and build, you will see that the number of warnings and errors are now so much lower. I recommend you to go to the Swiftlint rules file in their repository and see all of them. Or you can run swiftlint rules command to see all the rules.

Is there a swiftlint tool for Xcode?

Yes of course there is! SwiftLint is a swift code style analysis tool that helps you flag stylistic errors in your code. It can help you enforce these styles by marking build as failures or with warnings when the style is not followed. In this tutorial I will show you how to setup SwiftLint, configure it and use it within Xcode build process.


2 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: "_"
like image 109
carmine Avatar answered Sep 28 '22 09:09

carmine


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.

like image 41
Rishi Avatar answered Sep 28 '22 08:09

Rishi