首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swiftlint自动更正不修改文件

Swiftlint自动更正不修改文件
EN

Stack Overflow用户
提问于 2018-01-10 22:05:26
回答 1查看 4.2K关注 0票数 2

在运行swiftlint版本0.24.0时,报告了错误。运行autocorrect会指出文件已被更正。然而,正如随后运行的swiftlint证明的那样,没有进行任何修改。

请参阅尝试修改和更正两个文件Player.swiftPrize.swift

代码语言:javascript
复制
MacBook-Pro-5: Developer$ swiftlint 
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'Prize.swift' (1/2)
Linting 'Player.swift' (2/2)
Player.swift:26:19: warning: Operator Function Whitespace Violation: Operators should be surrounded by a single whitespace when defining them. (operator_whitespace)
Player.swift:27: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
Player.swift:39: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
Prize.swift:44:34: warning: Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
Prize.swift:44: error: Line Length Violation: Line should be 120 characters or less: currently 210 characters (line_length)
Done linting! Found 5 violations, 1 serious in 2 files.
MacBook-Pro-5: Developer$ swiftlint autocorrect
Loading configuration from '.swiftlint.yml'
Correcting Swift files in current working directory
Correcting 'Prize.swift' (1/2)
Correcting 'Player.swift' (2/2)
Done correcting 2 files!
MacBook-Pro-5: Developer$ swiftlint 
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'Prize.swift' (1/2)
Linting 'Player.swift' (2/2)
Prize.swift:44:34: warning: Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
Prize.swift:44: error: Line Length Violation: Line should be 120 characters or less: currently 210 characters (line_length)
Player.swift:26:19: warning: Operator Function Whitespace Violation: Operators should be surrounded by a single whitespace when defining them. (operator_whitespace)
Player.swift:27: warning: Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
Player.swift:39: warning: Line Length Violation: Line should be 120 characters or less: currently 147 characters (line_length)
Done linting! Found 5 violations, 1 serious in 2 files.
MacBook-Pro-5: Developer$

这是另一次运行,但这一次,一个文件Prize.swift只包含一个可纠正的违规。同样,autocorrect不会修改:

代码语言:javascript
复制
MacBook-Pro-5:P Developer$ swiftlint 
Linting Swift files in current working directory
Linting 'Prize.swift' (1/2)
Linting 'Player.swift' (2/2)
PPrize.swift:44:34: warning: Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
Done linting! Found 1 violation, 0 serious in 2 files.
MacBook-Pro-5:P Developer$ swiftlint autocorrect
Correcting Swift files in current working directory
Correcting 'Prize.swift' (1/2)
Correcting 'Player.swift' (2/2)
Done correcting 2 files!
MacBook-Pro-5:P Developer$ swiftlint 
Linting Swift files in current working directory
Linting 'Prize.swift' (1/2)
Linting 'Player.swift' (2/2)
PPrize.swift:44:34: warning: Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
Done linting! Found 1 violation, 0 serious in 2 files.
MacBook-Pro-5:P Developer$ 

请注意,.swiftlint.yml文件的存在与否对此没有影响。

缩写-即仅显示相关规则- swiftlint rules输出如下所示。请注意,在这三个违规中,colon绝对是可纠正的。

代码语言:javascript
复制
MacBook-Pro-5: Developer$ swiftlint rules
+------------------------------------------+--------+-------------+------------------------+-------------+---------------------------------------------------------------------------------------------------------------------------+
| identifier                               | opt-in | correctable | enabled in your config | kind        | configuration                                                                                                             |
+------------------------------------------+--------+-------------+------------------------+-------------+---------------------------------------------------------------------------------------------------------------------------+
| colon                                    | no     | yes         | yes                    | style       | warning, flexible_right_spacing: false, apply_to_dictionaries: true                                                       |
| line_length                              | no     | no          | yes                    | metrics     | warning: 120, error: 200, ignores urls: false, ignores function declarations: false, ignores comments: false              |
| operator_whitespace                      | no     | no          | yes                    | style       | warning                                                                                                                   |
+------------------------------------------+--------+-------------+------------------------+-------------+---------------------------------------------------------------------------------------------------------------------------+

swiftlint autocorrect如何成功运行有什么想法吗?是否有一些明显的配置或参数我遗漏了?我已经咨询了https://github.com/realm/SwiftLint,但没有用。

EN

回答 1

Stack Overflow用户

发布于 2018-01-10 22:14:39

并非所有的SwiftLint规则都是可更正的,这意味着在您运行swiftlint autocorrect之后,它们仍将保留。如果运行swiftlint rules,您可以看到一个表,其中显示了哪些规则是可更正的。

我不确定您使用的是什么版本的SwiftLint,但我不认为line_lengthoperator_whitespace是可纠正的。你将不得不自己处理这些问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48189186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档