otakuProgrammer
otakuProgrammer

Reputation: 298

How can I use swiftlint to enforce that every swift file must include a specified header values?

I wanted that every *.swift files must have the required texts. Like so.. Required header text on swift file

If the developer forgets to add it or has inputted the wrong values swiftlint will give an error or warning upon compiling.

I have searched about file_header but somehow it doesnt work properly. Here is my swiftlint.yml configuration Swiftlint configuration yml file

Upvotes: 4

Views: 1294

Answers (1)

Amir Khorsandi
Amir Khorsandi

Reputation: 3708

You can use: required_pattern

    file_header:
      required_pattern: |
                        \/\/
                        \/\/  .*?\.swift
                        \/\/  (PROJECT_NAME.*?|Unit Tests)
                        \/\/
                        \/\/  (Created by .*? on .*?)
                        \/\/  Copyright © \d{4} COPY_RIGHT_NAME\. All rights reserved\.
                        \/\/

replace PROJECT_NAME and COPY_RIGHT_NAME with your values or change the pattern

Upvotes: 3

Related Questions