Permalink
Browse files

Use node runtime instead of jsc.

Contrary to jsc, node handles utf-8 encoded source files correctly. The patch is in a very rough state, but it works (given node is installed in /usr/local/bin/node).
  • Loading branch information...
1 parent 38ec6fd commit 1d33be26c9baeccc98e23cdead4cb3b0bc2390b8 @noniq noniq committed Apr 4, 2012
Showing with 16 additions and 17 deletions.
  1. +12 −12 Support/lib/jsc.js
  2. +2 −3 Support/lib/jslintmate/linter.rb
  3. +2 −2 Support/lib/jslintmate/linter/options_files.rb
View
24 Support/lib/jsc.js
@@ -26,10 +26,10 @@ Copyright (c) 2009 Apple Inc.
white: false */
/*global JSLINT, JSHINT */
-
+JSHINT = require("jshint").JSHINT;
(function(args) {
- var filename = args[0],
+ var filename = args[2],
linter = (typeof JSHINT !== 'undefined' ? JSHINT : JSLINT),
options = args.slice(1), // Array; all but first
linterOptions = {},
@@ -146,13 +146,13 @@ Copyright (c) 2009 Apple Inc.
// Check for JS code
if (!filename) {
- print('Usage: jsc (jslint|jshint).js jsc.js -- "$(cat myFile.js)"' +
+ console.log('Usage: jsc (jslint|jshint).js jsc.js -- "$(cat myFile.js)"' +
' [--linter-options-from-bundle=\'a:1,b:[2,3]\']' +
' [--linter-options-from-options-file=\'c:4,d:{e:5,f:6}\']' +
' [--linter-options-from-defaults=\'g:7\']' +
' [--warn-about-unused-vars=true|false]'
);
- quit(1);
+ process.exit(1);
}
// Run linter and fetch data
@@ -190,23 +190,23 @@ Copyright (c) 2009 Apple Inc.
error = errors[i];
if (error) {
if (error.name) {
- print('Unused variable at line ' + error.line + ': ' +
+ console.log('Unused variable at line ' + error.line + ': ' +
error.name);
} else {
- print('Lint at line ' + error.line + ' character ' +
+ console.log('Lint at line ' + error.line + ' character ' +
error.character + ': ' + error.reason);
- print(error.evidence ?
+ console.log(error.evidence ?
error.evidence.replace(stripRegexp, "$1") : '');
}
- print('');
+ console.log('');
}
}
}());
- quit(2);
+ process.exit(2);
} else {
- print('No problems found.');
- quit();
+ console.log('No problems found.');
+ process.exit();
}
-}(arguments));
+}(process.argv));
View
5 Support/lib/jslintmate/linter.rb
@@ -11,8 +11,7 @@ class Linter
'undef' => false # `true` if variables and functions need not be
# declared before use.
}
- JSC_PATH = '/System/Library/Frameworks/' <<
- 'JavaScriptCore.framework/Versions/A/Resources/jsc'
+ JSC_PATH = '/usr/local/bin/node'
LINT_REGEXP = /^(Lint at line )(\d+)(.+?:)(.+?)\n(?:(.+?))?$/
UNUSED_VAR_REGEXP = /^Unused variable at line (\d+): (.+?)$/
@@ -125,7 +124,7 @@ def jsc_adapter_command(filepath)
adapter_options['--warn-about-unused-vars'] = true
end
- %{#{JSC_PATH} "#{self.path}" "#{adapter_path}" -- } <<
+ %{NODE_PATH="#{JSLintMate.lib_path}" #{JSC_PATH} "#{adapter_path}" } <<
%{"$(cat "#{filepath}")" } <<
jsc_adapter_command_options(adapter_options)
end
View
4 Support/lib/jslintmate/linter/options_files.rb
@@ -101,8 +101,8 @@ def read_options_from_json_file
# Convert JS file (containing valid JSON or JS, including comments) to
# a JSON string
- cmd = %{#{JSC_PATH} -e 'print(JSON.stringify(eval(arguments[0])))' } <<
- %{-- "($(cat "#{options_file_path}"))"}
+ cmd = %{#{JSC_PATH} -e 'console.log(JSON.stringify(eval(process.argv[1])))' } <<
+ %{ "($(cat "#{options_file_path}"))"}
# => `./jsc -e 'print(...)' -- "path/to/options.json"`
options_string = `#{cmd}`
cmd_status = $?

0 comments on commit 1d33be2

Please sign in to comment.