某软不给力,正在做的UWP项目停工了。官方说法是要等到RS2发布新的VOIP架构,再看看是不是给某软面子。虽然Beta用户中发出了几点愤怒的声音,但是木有用。有用的只能是某软的Skype for business UWP版拿下几个大订单,才有说服力。像现在这样鶸的表现,真是让人心寒……

  当然UWP开发入门还会继续写下去,本篇只是偷个懒,把工作中整理的资料放上来。蜀黍我可不是叛徒,我没发过誓不给水果开发APP,某软现在就是最大的果蛆。无奈混口饭吃,让写Swift就写呗,水果一套加上Xcode,咋用咋不爽,跟太阳系最强IDE比实在差距有点大,不得已还得额外安装代码格式检查的工具,安装过程也是学习使用MacOS,Terminal一系列陌生玩意的痛苦经历,风格迥异让我生不如死。特地写此一篇备忘,及供和我一样的iOS鶸参考。

What can SwiftLint do?

  1. Give code style warnings and errors
  2. Auto format swift code file

Installation

  • You can also install SwiftLint by downloading SwiftLint.pkg from the latest GitHub release and running it.

Integrate SwiftLint into an Xcode scheme to get warnings and errors displayed in the IDE.

In project file, just add a new "Run Script Phase" with:

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

Warnings and errors

Build project , swiftlint will display warnings and errors in Xcode.

We can disable or create some rules in configuration file.

Swiftlint Auto Correct

For formatting code files, you need to input "swiftlint autocorrect" in terminal.

cd documents/projects/MyProject/SomeFolder
swiftlint autocorrect

If you want to lint only one file:

cd documents/projects/MyProject/SomeFolder
swiftlint autocorrect --path SampleCode.swift

Unformatted:

Formatted:

Download Swift Configuration File

You can download swift configuration file in any folder. But the file which name starts with "." will be hidden on MacOS.

So I suggest you create an new file ".swiftlint.yml" in Xcode, under your project root folder.

Input below in terminal

cd documents/projects/yourProjectName
curl https://raw.githubusercontent.com/kevindelord/swift-style-guide/master/.swiftlint.yml > .swiftlint.yml

Press enter button and download. Then you can get lateset .swiftlint.yml and edit in Xcode.

Disable, included or create custom rule in .swiftlint.yml file

  • Disable rules

Add "- rule name" below "disabled_rules:"

disabled_rules:

- trailing_whitespace

  • Included folder

Only check child foder with SwiftLint

included:

- MyProject/NeedCheckFolder

  • Create custom rules

Use Regular Expression (regex) create custom rules

custom_rules:

comments_space:

name: "Space After Comment"

regex: "(^ *//\w+)"

message: "There should be a space after //"

severity: error

multiple_empty_lines:

name: "Multiple Empty Lines"

regex: ".\n(\s*\n){2,}"

message: "There are too many line breaks"

References

https://github.com/realm/SwiftLint

http://kevindelord.io/2016/04/06/integrate-swiftlint/

https://swifting.io/blog/2016/03/29/11-swiftlint/

SwiftLint——Swift代码检查及自动格式化工具的更多相关文章

  1. swiftlint swift代码规范检查神器

    一大堆的你为什么要用swiftlint,你为什么要codereview,swiftlint到底在做什么,就不多说了,没意义,他就是帮助你写出规范漂亮代码的神器! 安装 官方提供了三种安装的方式 hom ...

  2. SwiftLint:代码规范检查工具介绍

    Swift-CodeStyle Checker:SwiftLint 介绍: SwiftLint 是一个用于强制检查 Swift 代码风格和规定的一个工具,基本上以 GitHub's Swift 代码风 ...

  3. 使用Xcode HeaderDoc和Doxygen文档化你的Objective-C和Swift代码

    在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...

  4. [原创]Java静态代码检查工具介绍

    [原创]Java静态代码检查工具介绍 一  什么是静态代码检查? 静态代码分析是指无需运行被测代码,仅通过分析或检查源程序的语法.结构.过程.接口等来检查程序的正确性,找出代码隐藏的错误和缺陷,如参数 ...

  5. Cocos2D-ObjC:在RPG游戏中混合Swift代码

    我之前写过一个RPG游戏<<熊猫之魂 SoulOfPanda>> 编译器使用的是SpriteBuilder,很好很强大!全部代码都由Objc完成,现在想尝试一下在其中混入Swi ...

  6. 在Jenkins中使用sonar进行静态代码检查

    要解决的问题 jenkins自动构建完成后,希望能通过sonar静态代码检查生成一份报告,给与开发人员对当前代码的做一个质量评估和修改意见 1.安装并配置sonar服务器 懒得说,跟着官方文档走就行, ...

  7. CSS代码检查工具stylelint

    前面的话 CSS不能算是严格意义的编程语言,但是在前端体系中却不能小觑. CSS 是以描述为主的样式表,如果描述得混乱.没有规则,对于其他开发者一定是一个定时炸弹,特别是有强迫症的人群.CSS 看似简 ...

  8. C#静态代码检查工具StyleCode

    C#静态代码检查工具StyleCode -- 初探 最近我们Advent Data Service (ADS) 在项目上需要按照代码规范进行代码的编写工作,以方便将来代码的阅读与维护. 但是人工检查起 ...

  9. 在 OC 中调用 Swift 代码

    1.在 Objective-C 项目中使用 Swift 代码 1)在 OC 项目中创建 .Swift 文件,文件中的格式为其本有的格式. 2)Xcode 提示是否创建 Objective-C brid ...

随机推荐

  1. Oracle常见授权与回收权限(grant和revoke)学习记录

      1.GRANT 赋于权限常用的系统权限集合有以下三个:CONNECT(基本的连接), RESOURCE(程序开发), DBA(数据库管理) 常用的数据对象权限有以下五个:ALL ON 数据对象名, ...

  2. git 本地库提交至远程服务器

    1. git init 2. git add . 3. git commit -am "###"      -------以上3步只是本地提交 4.git remote add o ...

  3. 【CefSharp】 禁用右键菜单 与 控制弹出窗口的方式(限版本39.0.0.1)

    这周没什么时间,一开始就在忙一些CefSharp的事情,Win10的研究就放了下来,CefSharp的资料挺少的,但好在是开源的,可以我们便宜的折腾.因为两个的内容都不多,我就合成一篇文章啦. 这还里 ...

  4. 【腾讯bugly干货分享】Android自绘动画实现与优化实战——以Tencent OS录音机波形动

    前言 本文为腾讯bugly的原创内容,非经过本文作者同意禁止转载,原文地址为:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1180 ...

  5. [.net 面向对象编程基础] (2) 关于面向对象编程

    [.net 面向对象编程基础]  (2)  关于面向对象编程 首先是,面向对象编程英文 Object-Oriented Programming 简称 OOP 通俗来说,就是 针对对象编程的意思 那么问 ...

  6. java提高篇(六)-----使用序列化实现对象的拷贝

    我们知道在Java中存在这个接口Cloneable,实现该接口的类都会具备被拷贝的能力,同时拷贝是在内存中进行,在性能方面比我们直接通过new生成对象来的快,特别是在大对象的生成上,使得性能的提升非常 ...

  7. video.js html5 视频播放器

    我个人感觉很不错 https://github.com/videojs/video.js <head> <title>Video.js | HTML5 Video Player ...

  8. How to install java and eclipse on linux

    First of all, download from the website of java. I download 'jdk-8u102-linux-i586.tar.gz' unzip it t ...

  9. 当pageIndex遇上pageNo

    我们的项目程序里,由于赶项目进度,同时,大家缺乏相应的沟通,在服务层提供的接口里,涉及到分页查询的,有如下三种情形: l  List<OrderInfo> GetOrderList(Ord ...

  10. 我心中的核心组件(可插拔的AOP)~消息组件~完善篇

    回到目录 为什么要有本篇文章 本篇文章主要实现了RTX消息生产者,并且完成了整体的设计方式,之前在设计时消息生产者全局使用单一的生产方式,即一个项目里使用了Email就不能使用SMS,这种设计方法和实 ...