diff --git a/src/jslint.cpp b/src/jslint.cpp index 6f14e7a..515fea7 100644 --- a/src/jslint.cpp +++ b/src/jslint.cpp @@ -31,56 +31,62 @@ THE SOFTWARE. using namespace v8; namespace jslint { -std::string find_and_replace(std::string tInput, std::string tFind, std::string tReplace) { - int uPos = 0; - int uFindLen = tFind.length(); - int uReplaceLen = tReplace.length(); - - if( uFindLen == 0 ) - { - return tInput; + std::string default_options() { + std::string options = "{passfail: true, white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true}"; + return options; } - for( ;(uPos = tInput.find( tFind, uPos )) != std::string::npos; ) - { - tInput.replace( uPos, uFindLen, tReplace ); - uPos += uReplaceLen; - } - return tInput; -}; - -Handle load_source_js (char* src_file) { - std::string result; - std::string line; - std::string jsline; - std::ifstream myfile (src_file); - if (myfile.is_open()) { - //std::cout << jslint::native_fulljslint << std::endl; - result = std::string(jslint::native_jslint) + "\nvar file_to_lint = [];\n"; - while (! myfile.eof() ) { - std::getline (myfile, line); - jsline = "file_to_lint.push(\"" + jslint::find_and_replace(line,"\"", "\\\"") + "\");"; - result.append(jsline); + std::string find_and_replace(std::string tInput, std::string tFind, std::string tReplace) { + int uPos = 0; + int uFindLen = tFind.length(); + int uReplaceLen = tReplace.length(); + + if( uFindLen == 0 ) + { + return tInput; } - myfile.close(); - result.append("(function () { " - "if (!JSLINT(file_to_lint, " - "{passfail: true, white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true}" - ")) {" - "var results = [];" - "for(var i=0; i load_source_js (char* src_file, std::string lint_options) { + std::string result; + std::string line; + std::string jsline; + std::ifstream myfile (src_file); + if (myfile.is_open()) { + //std::cout << jslint::native_fulljslint << std::endl; + result = std::string(jslint::native_jslint) + "\nvar file_to_lint = [];\n"; + while (! myfile.eof() ) { + std::getline (myfile, line); + jsline = "file_to_lint.push(\"" + jslint::find_and_replace(line,"\"", "\\\"") + "\");"; + result.append(jsline); + } + myfile.close(); + result.append("(function () { " + "if (!JSLINT(file_to_lint, "); + result.append(lint_options); + result.append( + ")) {" + "var results = [];" + "for(var i=0; i optionsArg("o", "options", "JSLint options", false, "", "string", cmd); + TCLAP::ValueArg optionsArg("o", "options", "JSLint options", false, jslint::default_options(), "string", cmd); TCLAP::UnlabeledMultiArg filesArg("files", "file names", true, "string", cmd); cmd.parse( argc, argv ); - std::string options = optionsArg.getValue(); + std::string lint_options = optionsArg.getValue(); std::vector files = filesArg.getValue(); for (int i=0; i < files.size(); i++) { @@ -113,7 +119,7 @@ int main(int argc, char* argv[]) { try { // Create a string containing the JavaScript source code. - Handle source = jslint::load_source_js(const_cast(fileName.c_str())); + Handle source = jslint::load_source_js(const_cast(fileName.c_str()), lint_options); // Compile the source code. Handle