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 #1291

Closed
arlovip opened this issue Feb 7, 2017 · 9 comments
Closed

file_header rule #1291

arlovip opened this issue Feb 7, 2017 · 9 comments
Labels
question Question or doubts that needs discussion and clarification. Can become a bug or proposal.

Comments

@arlovip
Copy link

arlovip commented Feb 7, 2017

I don't know why file_header rule has no any effects when the project was compiled in Xcode 8.2. I tried testing it so many times, but it still right all the time. And the filename is "ViewController.swift". But the rule name "Bar.swift" should violate the rule. is it configured or understood wrongly?

//
//  Bar.swift
//  MissU2
//
//  Created by Odom_Sheng on 2017/1/19.
//  Copyright © 2017年 Xinguang. All rights reserved.
//
@ghost
Copy link

ghost commented Feb 7, 2017

Would you please post (or link) to a copy of your .swiftlint.yml file so that we can check how it's configured?

@arlovip
Copy link
Author

arlovip commented Feb 7, 2017

Thanks for so quick reply. I configure .swiftlint.yml on terminal. And I want to make some rules generate error messages but not warnings. Some configurations in .swiftlint.yml as follows:

disabled_rules:
  - todo
  - valid_docs
  - first_where
excluded:
  - Pods
colon:
  severity: error
variable_name:
  min_length:
    error: 3
  excluded:
    - id
vertical_whitespace:
  severity: error
file_header: error --------------no effect?
empty_count: error ------------no effect?
explicit_init: error
...and so on

I know file_header rule just generate warning on terminal. Even though I don't configure it with error message, it still does not generate any warning or error?

@ghost
Copy link

ghost commented Feb 7, 2017

I believe that file_header requires either at least one of the following properties for it to be applied:

  • required_string
  • required_pattern
  • forbidden_string
  • forbidden_pattern

As an example, see:

SwiftLint/.swiftlint.yml

Lines 24 to 32 in ad10f81

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

@arlovip
Copy link
Author

arlovip commented Feb 7, 2017

Thank you so much. I will have a try.

@jpsim
Copy link
Collaborator

jpsim commented Feb 10, 2017

Correct, and error needs to be set as the severity, it can't just be implicitly the only value in the rule's YAML dictionary.

@marcelofabri
Copy link
Collaborator

@Jacklchen were you able to fix the issue?

@mgrebenets
Copy link
Contributor

mgrebenets commented Mar 8, 2017

The rule doesn't seem to work for me.

We have very simple copyright header - just one line:

// Copyright (c) 2015 Company. All rights reserved.

I tried a lot of combinations, for example:

file_header:
  required_string: //  Wrong

I just wanted the rule to fail, but nothing happens.
I tried all kinds of combinations I could think of:

  required_string: //  Wrong
  required_string: "//  Wrong"
  required_pattern: //  Wrong
  required_pattern: \/\/  Wrong
  required_pattern: \/\/  Wrong.*

and so on ... - no success either

I used the --no-cache option for lint command - same

I know that the linter works - I can see other rules being reported.

The SwiftLint version that I use is 0.16.1.

@mgrebenets
Copy link
Contributor

Actually, my bad.

I absolutely missed the fact that this is an opt-in rule.
So I had to add it as opt-in rule and it started working then 👍

I believe @Jacklchen hasn't added it to opt_in_rules either.

Probably it would make it helpful if SwiftLint could display some kind of warning, when a configuration for opt-in rule is present, but the rule itself is "opted-out" (not enabled).

To be honest, until today I couldn't clearly understand what did "opt-in rule" actually mean ...

@marcelofabri
Copy link
Collaborator

@mgrebenets I've filled #1350 to track your idea.

@Jacklchen I'm closing this since we haven't heard from you in a while. Feel free to reopen if you have more questions related to this issue.

@marcelofabri marcelofabri added the question Question or doubts that needs discussion and clarification. Can become a bug or proposal. label Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or doubts that needs discussion and clarification. Can become a bug or proposal.
Projects
None yet
Development

No branches or pull requests

4 participants