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?
Asked
Active
Viewed 3,840 times
0
-
1Could 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 May 03 '19 at 07:33
-
You have bigger problems than linting if you have a single line that is 1400 characters in length. Make that line shorter. – Fogmeister May 03 '19 at 07:33
-
1To 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 May 03 '19 at 07: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. – Sazzad Hissain Khan May 03 '19 at 08:09
-
Isn't the real question here why the same rule generates both a warning for one line and then an error for another line? This isn't something that can be configured as far as I understand it. – Joakim Danielson May 03 '19 at 08:18
-
@JoakimDanielson It can be your question but not mine for the time being, I want to know how to make build successful even after reporting warnings and errors. If you cant help at least don't put a downvote without reason. – Sazzad Hissain Khan May 03 '19 at 08:21
-
@JoakimDanielson That can be configured easily. There is a warning limit and an error limit. – Sulthan May 03 '19 at 08:21
-
@Sulthan, Thanks. Now I found it in the documentation as well. I guess the easy solution then for OP is to raise the error limit. – Joakim Danielson May 03 '19 at 08:25
-
1@JoakimDanielson I am sorry for my mistake. I don't know why people downvote without mentioning the reason. Please forgive for my misunderstanding. – Sazzad Hissain Khan May 03 '19 at 11:33
3 Answers
10
You can either:
Change your config and remove the
error
limits, keeping only thewarning
limits:line_length: - 120 # warning limit - 200 # error limit
vs
line_length: 120 # warning limit
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.

Sulthan
- 128,090
- 22
- 218
- 270
2
- 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.
- Or you disable the rule for this one time with
// swiftlint:disable:next line_length
above your 1422 char line.

zero3nna
- 2,770
- 30
- 28
-
1Can I add disable rules as command line argument? i.e. `swiflint -disable comma` – Sazzad Hissain Khan May 03 '19 at 08:06
0
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

Muhammad Danish Qureshi
- 329
- 1
- 7
- 27
-
1That wont be feasible for too many changes and it also make the code dirty. – Sazzad Hissain Khan May 03 '19 at 08:07
-
If you don't want to do this then you should make file name .swiftlint.yml and update line_length in it. – Muhammad Danish Qureshi May 03 '19 at 09:57