From 67bf578c60c7e2ca02933442bc21948a2921aa69 Mon Sep 17 00:00:00 2001 From: Bogdan Matican Date: Sat, 23 Feb 2013 13:31:19 +0000 Subject: [PATCH] Initial linting efforts. 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 --- .arcconfig | 14 ++++- .jshintconfig | 13 ++++ libcustom/src/.gitignore | 1 + libcustom/src/__phutil_library_init__.php | 3 + libcustom/src/__phutil_library_map__.php | 22 +++++++ libcustom/src/lint/DefaultLintEngine.php | 74 +++++++++++++++++++++++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 .jshintconfig create mode 100644 libcustom/src/.gitignore create mode 100644 libcustom/src/__phutil_library_init__.php create mode 100644 libcustom/src/__phutil_library_map__.php create mode 100644 libcustom/src/lint/DefaultLintEngine.php diff --git a/.arcconfig b/.arcconfig index d4c45f9..82f8f2a 100644 --- a/.arcconfig +++ b/.arcconfig @@ -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" : "" } diff --git a/.jshintconfig b/.jshintconfig new file mode 100644 index 0000000..e852c56 --- /dev/null +++ b/.jshintconfig @@ -0,0 +1,13 @@ +{ + "browser": true, + "devel": true, + "jquery": true, + + "indent" : 2, + "bitwise" : true, + "trailing" : true, + "curly" : true, + "eqeqeq" : true, + "undef" : true, + "immed" : true +} diff --git a/libcustom/src/.gitignore b/libcustom/src/.gitignore new file mode 100644 index 0000000..6b193c3 --- /dev/null +++ b/libcustom/src/.gitignore @@ -0,0 +1 @@ +.phutil_module_cache diff --git a/libcustom/src/__phutil_library_init__.php b/libcustom/src/__phutil_library_init__.php new file mode 100644 index 0000000..8fe246e --- /dev/null +++ b/libcustom/src/__phutil_library_init__.php @@ -0,0 +1,3 @@ + 2, + 'class' => + array( + 'DefaultLintEngine' => 'lint/DefaultLintEngine.php', + ), + 'function' => + array( + ), + 'xmap' => + array( + 'DefaultLintEngine' => 'ArcanistLintEngine', + ), +)); diff --git a/libcustom/src/lint/DefaultLintEngine.php b/libcustom/src/lint/DefaultLintEngine.php new file mode 100644 index 0000000..248945b --- /dev/null +++ b/libcustom/src/lint/DefaultLintEngine.php @@ -0,0 +1,74 @@ +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, + ); + } + +}