Skip to content

Commit

Permalink
Initial linting efforts.
Browse files Browse the repository at this point in the history
Summary:
Install node:
  http://nodejs.org/

Install npm:
  curl https://npmjs.org/install.sh | sudo sh

Install jshint:
  sudo npm install -g jshint

Install pep8 and pylint:
  pip install pep8 pylint

Test Plan: modify a .js or .py file

Reviewers: bogdan2412

Reviewed By: bogdan2412

Differential Revision: http://phab.code4fun.de/D2
  • Loading branch information
bmatican committed Feb 23, 2013
1 parent af52e28 commit 67bf578
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .arcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"project_id": "CodeStreak",
"conduit_uri": "http://phab.code4fun.de/"
"conduit_uri": "http://phab.code4fun.de/",
"load": [
"libcustom/src"
],
"lint.engine": "DefaultLintEngine",

"lint.jshint.prefix": "/usr/local/bin",
"lint.jshint.bin": "jshint",
"lint.jshint.config": ".jshintconfig",

"lint.pylint.codes.error": "^(E|F).*",
"lint.pylint.codes.warning": "^(W|R|C).*",
"lint.pylint.codes.advice" : ""
}
13 changes: 13 additions & 0 deletions .jshintconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"browser": true,
"devel": true,
"jquery": true,

"indent" : 2,
"bitwise" : true,
"trailing" : true,
"curly" : true,
"eqeqeq" : true,
"undef" : true,
"immed" : true
}
1 change: 1 addition & 0 deletions libcustom/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phutil_module_cache
3 changes: 3 additions & 0 deletions libcustom/src/__phutil_library_init__.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phutil_register_library('libcustom', __FILE__);
22 changes: 22 additions & 0 deletions libcustom/src/__phutil_library_map__.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* This file is automatically generated. Use 'arc liberate' to rebuild it.
* @generated
* @phutil-library-version 2
*/

phutil_register_library_map(array(
'__library_version__' => 2,
'class' =>
array(
'DefaultLintEngine' => 'lint/DefaultLintEngine.php',
),
'function' =>
array(
),
'xmap' =>
array(
'DefaultLintEngine' => 'ArcanistLintEngine',
),
));
74 changes: 74 additions & 0 deletions libcustom/src/lint/DefaultLintEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

final class DefaultLintEngine extends ArcanistLintEngine {
private $static_file_regexp = array(
"^(M|m)akefile$",
"\.min\.(js|css)$",
"\.json$",
"^db.sqlite3$",
);
public function buildLinters() {

// This is a list of paths which the user wants to lint. Either they
// provided them explicitly, or arc figured them out from a commit or set
// of changes. The engine needs to return a list of ArcanistLinter objects,
// representing the linters which should be run on these files.
$paths = $this->getPaths();

// Linters are responsible for actually analyzing the contents of a file
// and raising warnings and errors.
$python_linter = new ArcanistPyLintLinter();
$js_linter = new ArcanistJSHintLinter();
$file_linter = new ArcanistTextLinter();

// Remove any paths that don't exist before we add paths to linters. We want
// to do this for linters that operate on file contents because the
// generated list of paths will include deleted paths when a file is
// removed.
foreach ($paths as $key => $path) {
if (!$this->pathExists($path)) {
unset($paths[$key]);
}
}

/*
$file_linter->setPaths($paths);
$python_linter->setPaths(preg_grep('/\.py$/', $paths));
$js_linter->setPaths(preg_grep('/\.js$/', $paths));
*/

foreach ($paths as $path) {
if (preg_match('@/static/.*/img/@', $path)) {
continue;
}
if (preg_match('@/externals/@', $path)) {
continue;
}

// whitespace
$match = "/(" . implode("|",$this->static_file_regexp) . ")/";
if (!preg_match($match, $path)) {
$file_linter->addPath($path);
}

// python
if (preg_match('/\.py$/', $path)
&& !preg_match('/\/xhpy\//', $path)
&& !preg_match('/views.py$/', $path)) {
$python_linter->addPath($path);
}

// javascript
if (preg_match('/\.js$/', $path) && !preg_match('/\.min\.js$/', $path)) {
$js_linter->addPath($path);
}
}

return array(
$python_linter,
$js_linter,
$file_linter,
);
}

}

0 comments on commit 67bf578

Please sign in to comment.