Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_header rule should trigger on first line if there're no comments #1520

Closed
rjhodge opened this issue May 16, 2017 · 11 comments
Closed

file_header rule should trigger on first line if there're no comments #1520

rjhodge opened this issue May 16, 2017 · 11 comments
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@rjhodge
Copy link
Contributor

rjhodge commented May 16, 2017

So I have the file header rule working great with one small problem. One developer is notorious for not having a file header. How can I enforce requiring this?

@marcelofabri
Copy link
Collaborator

Do you want to enforce a certain header format? Take a look how SwiftLint itself does it: https://github.com/realm/SwiftLint/blob/master/.swiftlint.yml#L25-L33

@marcelofabri marcelofabri added the question Question or doubts that needs discussion and clarification. Can become a bug or proposal. label May 16, 2017
@rjhodge
Copy link
Contributor Author

rjhodge commented May 16, 2017

So I have the header format

file_header:
  required_pattern: |
                    \/\/
                    \/\/  .*?\.swift
                    \/\/  Project
                    \/\/
                    \/\/  Created by .*? on \d{1,2}\/\d{1,2}\/\d{2}\.
                    \/\/  Copyright © \d{4} Company\. All rights reserved\.
                    \/\/

But he will often put in the following for files

import MapKit
import UIKit

And this still passes the file_header rule.

@marcelofabri
Copy link
Collaborator

This rule is opt-in, are you sure you've enabled it as well? It should trigger a warning.

@rjhodge
Copy link
Contributor Author

rjhodge commented May 16, 2017

We are using the whitelist_rules and have it listed as one of the rules. And the rule works great at finding inconsistent headers but does nothing when there is no header.

@marcelofabri
Copy link
Collaborator

Can you provide a small example that triggers the issue? I couldn't reproduce it:

$ swiftlint      
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'file.swift' (1/1)
/Users/marcelofabri/Documents/file.swift: warning: File Header Violation: Files should have consistent header comments. (file_header)
Done linting! Found 1 violation, 0 serious in 1 file.

file.swift

import MapKit
import UIKit

.swiftlint.yml

opt_in_rules:
  - file_header

file_header:
  required_pattern: |
                    \/\/
                    \/\/  .*?\.swift
                    \/\/  Project
                    \/\/
                    \/\/  Created by .*? on \d{1,2}\/\d{1,2}\/\d{2}\.
                    \/\/  Copyright © \d{4} Company\. All rights reserved\.
                    \/\/

@marcelofabri
Copy link
Collaborator

marcelofabri commented May 16, 2017

Maybe the issue is that when there's a comment, the warning is triggered on that line. Otherwise, the warning is only on the file. That could make Xcode behave differently.

@rjhodge
Copy link
Contributor Author

rjhodge commented May 16, 2017

Ahhh that appears to be the issue. Xcode is ditching the warning. Running it from terminal the warning shows up properly.

Anyway to fix it for Xcode?

@marcelofabri
Copy link
Collaborator

Not that I'm aware of. But it'd be possible to change the violation to trigger on the first line of the file here: https://github.com/realm/SwiftLint/blob/master/Source/SwiftLintFramework/Rules/FileHeaderRule.swift#L86.

Do you want to try that? Otherwise I might be able to take a look later today.

@marcelofabri marcelofabri added bug Unexpected and reproducible misbehavior. and removed question Question or doubts that needs discussion and clarification. Can become a bug or proposal. labels May 16, 2017
@rjhodge
Copy link
Contributor Author

rjhodge commented May 16, 2017

I'll give it a shot.

@marcelofabri
Copy link
Collaborator

BTW, I just tried on Xcode and I see the warning on the issue navigator, but not on the file editor itself.

@marcelofabri marcelofabri added enhancement Ideas for improvements of existing features and rules. and removed bug Unexpected and reproducible misbehavior. labels May 16, 2017
@marcelofabri marcelofabri changed the title file_header how to enforce needing header file_header rule should trigger on first line if there're no comments May 16, 2017
@rjhodge
Copy link
Contributor Author

rjhodge commented May 16, 2017

Ok this is fixed in the pull request #1521 please review when you get a chance.

Thanks again for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

2 participants