0

I am using swiftlint in Build phase - Run script. Build is failed because of swiftlint error. How can I proceed successful build but still want to produce swiftlint comments (i.e. errors, warnings) in my project?

enter image description here

9
  • 1
    Could you please explain why do you have a line of code that is 1422 characters long? If it's some text data (e.g. json), you should put it to a file and load it.
    – Sulthan
    Commented May 3, 2019 at 7:33
  • You have bigger problems than linting if you have a single line that is 1400 characters in length. Make that line shorter.
    – Fogmeister
    Commented May 3, 2019 at 7:33
  • 1
    To really answer you question, you can either change your linting rules from error to warning in config, or you can process the output of swiftlint using some tool (e.g. sed) and convert error: to warning: automatically.
    – Sulthan
    Commented May 3, 2019 at 7:38
  • @Sulthan I know its a true violation, but currently I am building a legacy code and no time for refactoring but yet I want to know all the errors and warnings. Commented May 3, 2019 at 8:09
  • 1
    @JoakimDanielson I am sorry for my mistake. I don't know why people downvote without mentioning the reason. Please forgive for my misunderstanding. Commented May 3, 2019 at 11:33

3 Answers 3

11

You can either:

  1. Change your config and remove the error limits, keeping only the warning limits:

    line_length:
      - 120 # warning limit
      - 200 # error limit
    

    vs

    line_length: 120 # warning limit
    
  2. Change your build phases script to automatically convert errors to warnings, e.g.:

    swiftlint lint --quiet $@ | sed 's/error: /warning: /g'
    

You cannot have an error and still the build. Also I suppose that you don't have "treat errors as warnings" build setting turned on.

0
2
  1. You can modify the rules of swiftlint with your own custom .swiftlint.yml in your project to make the error into a warning or completely ignore it swiftlint custom rules.
  2. Or you disable the rule for this one time with // swiftlint:disable:next line_length above your 1422 char line.
1
  • 1
    Can I add disable rules as command line argument? i.e. swiflint -disable comma Commented May 3, 2019 at 8:06
1

Write this line above your error line.

// swiftlint:disable type_name

type_name will be your error name, in this case it will be

// swiftlint:disable line_length
2
  • 1
    That wont be feasible for too many changes and it also make the code dirty. Commented May 3, 2019 at 8:07
  • If you don't want to do this then you should make file name .swiftlint.yml and update line_length in it. Commented May 3, 2019 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.