Skip to content

Commit

Permalink
Implement --vim switch
Browse files Browse the repository at this point in the history
  • Loading branch information
geekq committed Apr 19, 2011
1 parent d6e3247 commit 3c97138
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
15 changes: 11 additions & 4 deletions README.markdown
@@ -1,5 +1,5 @@

Run jslint on command line fast (with v8 engine)
Run jslint on the command line fast (with v8 engine)
================================================

jslint-v8 is a modern and extreamly fast runner for the popular jslint
Expand All @@ -10,7 +10,7 @@ Credits
--------
* this work was inspired by [jsbeautify][] implementation.
* original jslint-v8 implementation by [jlbfalcao][]
* vim support and Rakefile by [Vladimir Dobriakov][]
* vim support and Rakefile by [Vladimir Dobriakov][] AKA [geekQ][]


Build
Expand All @@ -35,6 +35,10 @@ Run on console

jslint --browser file.js

checks the style for `file.js`. You can provide all the known jslint
switches on the command line. Here `--browser` indicates that e.g.
XMLHttpRequest object should be allowed.


Run from vim
------------
Expand All @@ -43,11 +47,14 @@ Set up `jslint` as make program in .vimrc:

autocmd BufRead,BufNewFile *.js,*.json setlocal makeprg=jslint\ --vim\ \%

`--vim` provides error message formatting suitable for parsing in vim
(TODO)
`--vim` provides error message formatting suitable for parsing in vim.

Now you can check your JavaScript easily with `:make` or even
automatically on every file save or load.

[v8 doc]: http://code.google.com/apis/v8/build.html
[jsbeautify]: http://blog.slashpoundbang.com/post/2488598258/running-javascript-from-the-command-line-with-v8
[jlbfalcao]: https://github.com/jlbfalcao/jslint-v8
[Vladimir Dobriakov]: http://www.mobile-web-consulting.de
[jslint]: http://www.jslint.com/
[geekQ]: http://www.geekQ.net/
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -5,4 +5,5 @@ end

task :convert_js_to_h do
sh "ruby convert_to_h.rb print_vim.js > print_vim.h"
sh "ruby convert_to_h.rb print_human.js > print_human.h"
end
12 changes: 10 additions & 2 deletions jslint.cpp
Expand Up @@ -7,7 +7,7 @@
#include <string.h>

#include "jslint.h"
#include "v8.h"
#include "print_human.h"
#include "print_vim.h"

using namespace v8;
Expand Down Expand Up @@ -71,6 +71,7 @@ static void usage(char* progname)
printf("See: http://www.JSLint.com/lint.html\n");
printf("default selected: --bitwise --eqeqeq --immed --newcap --nomen --onevar --regexp --undef --white\n");
printf("[options]\n");
printf(" --vim : produce output in a form suitable for vim editor.\n");
printf(" --adsafe : ADsafe\n");
printf(" --bitwise : Disallow bitwise operator.\n");
printf(" --browser : Assume a browser.\n");
Expand Down Expand Up @@ -117,6 +118,7 @@ int main(int argc, char* argv[])
bool overwrite = false;
const char* output = 0;
bool some_parameter = false;
bool vim_mode = false;

for (int argpos = 1; argpos < argc; ++argpos) {
if (argv[argpos][0] != '-') {
Expand All @@ -128,6 +130,8 @@ int main(int argc, char* argv[])
strcmp(argv[argpos], "-h") == 0) {
usage(argv[0]);
return -1;
} else if (strcmp(argv[argpos], "--vim") == 0) {
vim_mode = true;
} else if (strncmp(argv[argpos], "--", 2) == 0) {
// TODO: check if is valid.
some_parameter = true;
Expand Down Expand Up @@ -167,7 +171,11 @@ int main(int argc, char* argv[])
Handle<Script> runnerScript = Script::Compile(String::New("JSLINT(source, options);"));
Handle<Value> result = runnerScript->Run();

Handle<Script> printScript = Script::Compile(String::New(print_vim_code));
Handle<Script> printScript;
if (vim_mode)
printScript = Script::Compile(String::New(print_vim_code));
else
printScript = Script::Compile(String::New(print_human_code));
printScript->Run();

return 0;
Expand Down
2 changes: 1 addition & 1 deletion v8.h → print_human.h
@@ -1,4 +1,4 @@
const char v8_code[] = {0xA,
const char print_human_code[] = {0xA,
0x66,0x6F,0x72,0x20,0x28,0x69,0x20,0x3D,0x20,0x30,0x3B,0x20,0x69,0x20,0x3C,0x20,
0x4A,0x53,0x4C,0x49,0x4E,0x54,0x2E,0x65,0x72,0x72,0x6F,0x72,0x73,0x2E,0x6C,0x65,
0x6E,0x67,0x74,0x68,0x3B,0x20,0x69,0x20,0x2B,0x3D,0x20,0x31,0x29,0x20,0x7B,0xA,
Expand Down
File renamed without changes.

0 comments on commit 3c97138

Please sign in to comment.