Skip to content

barbosa/clorox

Repository files navigation

Build PyPI Version

Motivation

//
// TableViewController.m
// MyProject
//
// Created by My Name on 3/13/16.
// Copyright (c) 2016 My Company. All rights reserved.
//

I've never liked these 8 lines above (7 comment lines + 1 blank one). It does nothing but puts a lot of unuseful information in the beginning of your Objective-C/Swift files. If it is an open source project or if it is gonna be distributed, then ok, it makes sense to have it. Otherwise, it's just a waste of LOC. I'll tell you why, line by line:

Line Explanation
1️⃣ Blank comment
2️⃣ File name: static. Xcode does not change it if you rename the file
3️⃣ Project name: static. Xcode does not change it if you rename the project
4️⃣ Blank comment
5️⃣ File's creator and date: It just says who created the file (even if that person never touches it again) and when. Both infos are easily fetched with a simple git log or a git blame (which would be much more valuable)
6️⃣ Copyright, year and company: static. Xcode does not update the copyright with its current year. And also, it does not update the company name if changed (ok, maybe this is an uncommon case)
7️⃣ Blank comment
8️⃣ Blank line

Installation

clorox was written in python 🐍 and distributed via pypi. As your MacOS already comes with python installed, you can easily install it using the commands below:

sudo easy_install pip  # in case you don't have it already installed
sudo pip install clorox

Usage

⚠️ WARNING: Make sure that your project is backed up through source control before doing anything.

In its basic usage, the command takes only one argument, which is the root path you want to run the cleaning:

clorox --path MyProject

The following screenshots show the execution output and the diff of some modified files:

clorox in action screen shot 2016-03-29 at 11 10 12 pm

Advanced Usage

Inspection

If you are not comfortable running the command and want to see which files would be affected by its execution, simply add the option --inspection or -i, like this:

clorox --path MyProject --inspection

Report

By default, clorox prints out a colored tree indicating which files were modified (or inspected). If you're using clorox as a step of your development process, you might consider passing a --report argument. Currently, the only type of report that clorox supports is json. So you would do something like:

clorox --path MyProject --report json

Note

clorox only removes already existent file comment headers from existent source files. So it is useful when you have a project with a bunch of files and then decide to get rid of them all. For new files, Xcode will still add the cruft. To change that, you need to modify the file templates you want.

First, check which templates you have installed under your Xcode directory:

ls -al /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source/

It should print something like:

drwxr-xr-x  15 root  wheel  510 Mar 15 18:56 .
drwxr-xr-x   7 root  wheel  238 Mar 15 20:19 ..
drwxr-xr-x   7 root  wheel  238 Mar 15 18:56 C File.xctemplate
drwxr-xr-x   7 root  wheel  238 Mar 15 18:56 C++ File.xctemplate
drwxr-xr-x  21 root  wheel  714 Mar 15 18:56 Cocoa Class.xctemplate
drwxr-xr-x   6 root  wheel  204 Mar 15 18:56 Header File.xctemplate
drwxr-xr-x   9 root  wheel  306 Mar 15 18:56 Objective-C File.xctemplate
drwxr-xr-x   5 root  wheel  170 Mar 15 18:56 Objective-C new superclass.xctemplate
drwxr-xr-x   4 root  wheel  136 Mar 15 18:56 Playground Page.xctemplate
drwxr-xr-x   8 root  wheel  272 Mar 15 20:40 Playground with Platform Choice.xctemplate
drwxr-xr-x   6 root  wheel  204 Mar 15 20:40 Playground.xctemplate
drwxr-xr-x   4 root  wheel  136 Mar 15 18:56 Sources Folder Swift File.xctemplate
drwxr-xr-x   6 root  wheel  204 Mar 15 18:56 Swift File.xctemplate
drwxr-xr-x   7 root  wheel  238 Mar 15 18:56 UI Test Case Class.xctemplate
drwxr-xr-x   7 root  wheel  238 Mar 15 18:56 Unit Test Case Class.xctemplate

Then look for files named ___FILEBASENAME___.* inside the folder you want and clean its content.

Acknowlegdements

Author

Gustavo Barbosa. :octocat: GitHub 🐦 Twitter

License

This project is distributed under the MIT License.

About

Remove all the cruft from Xcode's file headers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published