-1

I am using SwiftLint to clean up my code formatting of the project. I met a File Name Violation warning. I tried many ways but I can't fix it.

Those are what I did:

  1. Create a class -> LoginPageViewController.
  2. Got a warning -> Length of class name should be between 3 and 20 characters long.
  3. Refactor the name of this class as LoginController everywhere.
  4. Run and got a warning: File Name Violation. Seems like the name still keeps the original one.
  5. Try to clean build folder, still doesn't work.
  6. Try to delete the file and recreate a new file with a totally different name, but the same warning with the same name LoginPageViewController is still showing.

enter image description here

The filename has already been changed to LoginController.

enter image description here

Please help me out. How can I fix it?

LightOwlGG
  • 139
  • 10
  • 1
    Why have you created such a rule? 20 isn't that much for a filename when you want to include the type in the file namne, like viewController. Change the rule instead of your code. – Joakim Danielson Aug 14 '20 at 15:04

4 Answers4

2

If for whatever reason you don't want to change the file name or the class name you can deactivate the "file_name"-rule in your .swiftlint.yml for defined files like this:

file_name: 
  excluded: ["MyClass1.swift", "MyClass2.swift", "MyClass3.swift"]
Jochen Holzer
  • 1,598
  • 19
  • 25
0

The file name remains as LoginPageViewController.swift. Rename it to LoginController.swift as the class.

Then, do Cmd + Shift + K to clean the build folder and try again.

Sergio
  • 1,610
  • 14
  • 28
0

Update: Seems this issue has occurred due to unsuccessful rename. Copy all the code in this file and delete this file. Create a new Swift file named LoginController and paste the copied code into it.

A simple solution to avoid this warning is to create an empty declaration for LoginPageViewController. Like this:

enum LoginPageViewController { }
Frankenstein
  • 15,732
  • 4
  • 22
  • 47
0

To disable the warning in the any file, below code can be added in the first line of the file.

// swiftlint:disable:this file_name