mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-05 16:42:58 +00:00
Added capp_lint to Tools
This commit is contained in:
1 parent
d9640aa205
commit
092cb01bb3
5 files changed
+1322
No files matched your search
@@ -0,0 +1,7 @@
|
||||
capp_lint is a formatting checker for Objective-J. It performs a number of checks that catch
|
||||
common formatting mistakes, as defined in the Cappuccino coding style guidelines:
|
||||
|
||||
http://cappuccino.org/contribute/coding-style.php
|
||||
|
||||
To install capp_lint and its man page, execute install.sh in Terminal. You must have sudo access
|
||||
to run the install script.
|
||||
Executable
+1012
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,181 @@
|
||||
.Dd April 20, 2012
|
||||
.Os "Cappuccino"
|
||||
.Dt CAPP_LINT 1 "PRM"
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh NAME
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Nm capp_lint
|
||||
.Nd check formatting of Objective-J files
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh SYNOPSIS
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Nm
|
||||
.Op options
|
||||
.Op Ar
|
||||
.Nm
|
||||
.Op --version | -h | --help
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh "DESCRIPTION"
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Nm
|
||||
is a formatting checker for Objective-J. It performs a number of checks that catch
|
||||
common formatting mistakes, as defined in the Cappuccino coding style guidelines:
|
||||
.Pp
|
||||
http://cappuccino.org/contribute/coding-style.php
|
||||
.Pp
|
||||
.Nm
|
||||
operates on a list of files and/or directory. You may pass one or more paths (relative to the
|
||||
current working directory) as arguments to
|
||||
.Nm ,
|
||||
or if the first path is "-", the
|
||||
list of paths is taken from stdin, in which case everything after the "-" is ignored.
|
||||
.Pp
|
||||
If a path is a directory, the directory is recursively scanned for *.j files to check. Symbolic links
|
||||
are not followed.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width 4n
|
||||
.It Fl b, \-basedir=BASEDIR
|
||||
The base directory relative to which filenames will be resolved. If not passed,
|
||||
it defaults to the current working directory.
|
||||
.It Fl d, \-var-declarations=[none|single|strict]
|
||||
Determines the policy in flagging consecutive var declarations. The choices are:
|
||||
.Bl -tag -indent -width 8n
|
||||
.It none
|
||||
No checking is done.
|
||||
.It single
|
||||
If two var blocks appear consecutively and one of them is
|
||||
a single variable, the second var block will be flagged.
|
||||
.It strict
|
||||
Any consecutive var declarations will be flagged.
|
||||
.El
|
||||
.Pp
|
||||
Given the following code:
|
||||
.Pp
|
||||
var foo = "bar",
|
||||
bar = "foo";
|
||||
|
||||
var bow = "foobar",
|
||||
wow = "woof";
|
||||
.Pp
|
||||
The
|
||||
.Ar none
|
||||
policy will obviously not flag this. The
|
||||
.Ar single
|
||||
policy will not flag
|
||||
this because both blocks contain more than one declaration. The
|
||||
.Ar strict
|
||||
policy will flag this. Given the following code:
|
||||
.Pp
|
||||
var foo = "bar",
|
||||
bar = "foo";
|
||||
|
||||
var bow = "foobar";
|
||||
.Pp
|
||||
The
|
||||
.Ar single
|
||||
policy will flag this because the second block is a single declaration.
|
||||
.It Fl f, \-format=[text|html]
|
||||
Determines the format of the error output. See the OUTPUT section below for more information
|
||||
on the different formats.
|
||||
.It Fl q, \-quiet
|
||||
Normally
|
||||
.Nm
|
||||
will print a list of the errors it finds. If this option is passed,
|
||||
the error list is suppressed. This option is mutually exclusive with the -v option.
|
||||
.It Fl v, \-verbose
|
||||
Displays each line as it is processed by
|
||||
.Nm
|
||||
with a line number, along with some information about syntactic information it finds.
|
||||
.It Fl \-version
|
||||
Displays the current version and exits.
|
||||
.It Fl h, \-help
|
||||
Shows a synopsis of usage and options and exits.
|
||||
.El
|
||||
.Ss Errors flagged
|
||||
The following formatting errors are flagged by
|
||||
.Nm :
|
||||
.Bl -bullet -width 0n
|
||||
.It
|
||||
Lines which contain one or more tabs.
|
||||
.It
|
||||
Lines which contain non-ASCII characters not within quoted strings.
|
||||
.It
|
||||
Lines which contain malformed UTF-8.
|
||||
.It
|
||||
Missing space between control statements and their opening parentheses.
|
||||
.It
|
||||
Trailing whitespace.
|
||||
.It
|
||||
Binary operators without surrounding space.
|
||||
.It
|
||||
Assignment operators without surrounding space.
|
||||
.It
|
||||
Comparison operators without surrounding space.
|
||||
.It
|
||||
Useless unary + operators.
|
||||
.It
|
||||
Extra or missing space in a method declaration.
|
||||
.It
|
||||
Superflous function names.
|
||||
.It
|
||||
Unterminated variable blocks.
|
||||
.It
|
||||
Consecutive var statements.
|
||||
.It
|
||||
Incorrect indentation in a var block.
|
||||
.It
|
||||
Missing statement separators in a var block.
|
||||
.It
|
||||
Inadvertent global variables in a var block.
|
||||
.It
|
||||
Unbalanced [, { or ( in a variable block.
|
||||
.It
|
||||
Opening braces on the same line as a statement.
|
||||
.It
|
||||
Code following a var block that is not outdented from the var block.
|
||||
.El
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh EXIT STATUS
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Nm
|
||||
exits with a return status of one if it finds any errors. If no errors are found,
|
||||
it exits with a return status of zero.
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh OUTPUT
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
For each error that
|
||||
.Nm
|
||||
finds, if the -q/--quiet option was not passed,
|
||||
.Nm
|
||||
will output an error like the following if the error format is text:
|
||||
.Pp
|
||||
Foo.j:482: assignment operator without surrounding spaces.
|
||||
.br
|
||||
+ for (var i=0, count=[_observationProxies count]; i<count; i++)
|
||||
.br
|
||||
^ ^
|
||||
.Pp
|
||||
The filename (relative to the working directory), line number, and type of error are displayed
|
||||
first, followed by the offending line of source code. When possible and necessary (as in this example),
|
||||
the location of the errors is indicated below the source line. If only a single file was checked,
|
||||
the filename is suppressed.
|
||||
.Pp
|
||||
If the error format is html, the output is similar, but instead of using markers to indicate where
|
||||
the errors occurred, the character at that position is highlighted. In addition, clicking on the
|
||||
error opens TextMate to the file and line number of the error.
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh WHITESPACE
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
Cappuccino coding standards stipulate that there should be no trailing whitespace, and that tabs
|
||||
should consist of 4 spaces, not tab characters.
|
||||
.Nm
|
||||
will report trailing whitespace and hard tabs. You should fix those errors before paying attention
|
||||
to any other errors, as the presence of hard tabs may cause some false positives.
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Sh AUTHORS
|
||||
.\"-----------------------------------------------------------------------------------------
|
||||
.Pp
|
||||
Aparajita Fishman, Victory-Heart Productions
|
||||
.br
|
||||
aparajita@aparajita.com
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
chmod +x capp_lint
|
||||
|
||||
if [[ ! -d /usr/local/bin ]]; then
|
||||
sudo mkdir -p /usr/local/bin
|
||||
fi
|
||||
|
||||
sudo cp capp_lint /usr/local/bin
|
||||
|
||||
if [[ ! -d /usr/local/share/man/man1 ]]; then
|
||||
sudo mkdir -p /usr/local/share/man/man1
|
||||
fi
|
||||
|
||||
sudo cp capp_lint.1 /usr/local/share/man/man1
|
||||
@@ -0,0 +1,107 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
die() {
|
||||
echo '-------------------------' 1>&2
|
||||
echo 'pre-commit check failure' 1>&2
|
||||
echo '-------------------------' 1>&2
|
||||
echo "$@" 1>&2
|
||||
|
||||
if [ -f /tmp/capp_lint.tmp ]; then
|
||||
rm -f /tmp/capp_lint.tmp
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check for committer identity.
|
||||
advice='
|
||||
Use the commands:
|
||||
|
||||
git config --global user.name '\''Your Name'\''
|
||||
git config --global user.email '\''you@yourdomain.com'\''
|
||||
|
||||
to introduce yourself to Git before committing.'
|
||||
|
||||
# Ensure name and email are available.
|
||||
git config --get user.name > /dev/null &&
|
||||
git config --get user.email > /dev/null ||
|
||||
die 'Identity not configured!' "$advice"
|
||||
|
||||
# Validate the name and email.
|
||||
git config --get user.name | grep ' ' > /dev/null ||
|
||||
die 'Please set user.name to your Real Name (with a space), not a userid.' "$advice"
|
||||
git config --get user.email | grep '^[^@]*@[^@]*$' > /dev/null ||
|
||||
die 'Please set user.email to an email address (userid@validdomain.com).' "$advice"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check content that will be added by this commit.
|
||||
|
||||
if git rev-parse --verify -q HEAD > /dev/null; then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
# Disallow non-ascii file names. The printable range starts at the
|
||||
# space character and ends with tilde.
|
||||
if test "$(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0')"; then
|
||||
die 'Non-ascii file names may not be added:
|
||||
'"$(git diff --cached --name-only --diff-filter=A $against)"
|
||||
fi
|
||||
|
||||
# Check for trailing whitespaces, indents that uses a space before a tab and leftover conflict markers
|
||||
if test "$(git diff-index --check --cached $against --)"; then
|
||||
die 'The following whitespace errors or unresolved conflicts have been found:
|
||||
'"$(git diff-index --check --cached $against --)"
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Check for inadvertent globals and dangling variable declarations.
|
||||
|
||||
fileCount=`git diff --cached --name-only --diff-filter=AM $against | wc -l`
|
||||
|
||||
if [[ fileCount -ne "0" ]]; then
|
||||
lintPath=''
|
||||
|
||||
if [[ `which capp_lint.py` ]]; then
|
||||
lintPath="`which capp_lint.py`"
|
||||
fi
|
||||
|
||||
if [[ -z "$lintPath" && `which capp_lint` ]]; then
|
||||
lintPath="`which capp_lint`"
|
||||
fi
|
||||
|
||||
if [[ -z "$lintPath" ]]; then
|
||||
path=`dirname $0`/capp_lint.py
|
||||
|
||||
if [[ -x "$path" ]]; then
|
||||
lintPath="$path"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$lintPath" ]]; then
|
||||
die 'Could not find capp_lint or capp_lint.py in your PATH or in .git/hooks.'
|
||||
fi
|
||||
|
||||
git diff --cached --name-only --diff-filter=AM $against | "$lintPath" - > /tmp/capp_lint.tmp
|
||||
|
||||
if [ -s /tmp/capp_lint.tmp ]; then
|
||||
die 'The following lint errors were found:
|
||||
|
||||
'"$(cat /tmp/capp_lint.tmp)"
|
||||
else
|
||||
rm -f /tmp/capp_lint.tmp
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user