當我運行 swiftlint 時,我得到一個列印輸出,說某些規則的配置無效。
Invalid configuration for custom rule 'commented_out_code'.
Invalid configuration for custom rule 'avoid_multiline_comment_markers'.
Invalid configuration for custom rule 'avoid_background_color'.
沒有其他自定義規則被標記為此類,并且規則本身在專案中仍然有效。這些是有問題的配置:
commented_out_code:
regex: '(?<!:|\/)\/\/\h*[a-z.](?!wiftlint)'
message: "Comment starting with lowercase letter - did you forget to delete old code?"
avoid_multiline_comment_markers:
regex: '*/'
message: "Avoid using multi-line comment markers like */ and /* - use // and /// instead."
avoid_background_color:
regex: '.background(Color.'
message: "Avoid using .background(Color), use .backgroundColor() instead."
最后一個是我自己的,另外 2 個是默認的自定義規則,但是它們包含在一個基本的 swiftlint 組態檔中。
這是顯示格式相同的“有效”規則:
use_int_zero_property_in_single_check:
regex: ' == 0[^( {)]'
message: "Avoid checking for '0' in single check, use '== .zero' instead."
這些有什么無效的?
我嘗試過的事情沒有結果:
- 交換單引號和雙引號
- 移動方塊
- 用空格和制表符重新縮進行
uj5u.com熱心網友回復:
這里的問題是不正確的正則運算式語法,主要是沒有正確轉義字符。
所以avoid_background_color它應該是
regex: '\.background\(Color\.'
而對于avoid_multiline_comment_markers
regex: '\*/'
commented_out_code我很難理解,但看起來你一=開始就錯過了
regex: '(?=<!:|\/)\/\/\h*[a-z.](?!wiftlint)'
我會推薦網站https://regex101.com來測驗和驗證您的正則運算式語法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/532668.html
標籤:迅速代码yaml快速林特
