Three20 Lint Tool

32 visninger
Gå til det første ulæste opslag

Jeff Verkoeyen

ulæst,
27. feb. 2011, 19.42.2727.02.2011
til thr...@googlegroups.com

https://github.com/facebook/three20/pull/441

This was a fun weekend project for me. The script can be run from the command line, but works especially well in Xcode as a build target.

Basically it's an extra build target in all of the Three20 libs that goes through the source code and raises warnings when it detects any stylistic faux-pas. For example, if a line is over 100 characters long, it will raise a warning. You can then click that warning in the build output and jump straight to that line to fix it.

Other warnings:

  • @property spacing
  • copy instead of retain for NSMutable* objects
  • if/for/while space after the word
  • Empty lines before } else { statements
  • Divider lines before methods

Where this script really gets cool, though, is in the "delinting" aspect of it. If you run lint -d mysource.m, it will attempt to fix all of the linter warnings that are found and write the file back out to disk.

It gets better! I've put together an Xcode script that allows you to run the delinter from Xcode with a single key. I've mapped it to Option-D.


#! /usr/bin/perl -w
# 
# three20Delinter.pl - Delints the active file in Xcode.
#
# Expected use: Bind to a key like Option-D and use the hot
# key when you are in a Three20 source file. This will delint
# the file and save the results to disk. The results won't
# immediately be visible, but if you switch to a different app
# and back again, Xcode will load the changes.
#
# Author: Jeff Verkoeyen (jver...@gmail.com)
# Created: February 27, 2010
#

use strict;
use File::Basename;
use File::Path;

# get path to document
my $headerPath = <<'HEADERPATH';
%%%{PBXFilePath}%%%
HEADERPATH
chomp $headerPath;

if (length($headerPath)) {
    my $path = $headerPath;
    my @pathParts = split (m'/', $path);
    my $filename = pop (@pathParts);
    my $rootFileName = "$filename";
    $rootFileName =~ s/\.h|m$//;
    my $deepestFolder = pop (@pathParts);
    my $deepestFolderParent = pop (@pathParts);

    if (lc($deepestFolderParent) =~ /three20/) {
      my $lint = dirname($headerPath)."/../../scripts/lint";

      `\"$lint\" -d \"$headerPath\"`;
      `open \"$headerPath\"`;
    }
}

exit 0;

As for this pull request, the first commit is where the juicy bits are that definitely need review. The second commit is just me making Three20 compliant to the linter.

Svar alle
Svar til forfatter
Videresend
0 nye opslag