How can I check JavaScript code for syntax errors ONLY from the command line?

后端 未结 5 1832
栀梦
栀梦 2021-02-01 13:40

JavaScript programs can be checked for errors in IDEs or using online web apps but I\'m looking for a way to detect syntax errors alone.

I\'ve tried JSLint and

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 13:59

    Here is an answer for a Continuous Integration scenario.

    1- Checks all the JavaScript files with exclude folder, subfolder and file features.

    2- Exit if there is an error.

    esvalidate --version || npm install -g esprima;
    find ./ -not \( -path ./exclude_folder_1 -prune \) -not \( -path ./exclude/sub_folder -prune \) -not \( -path ./exclude/sub_folder_2 -prune \) ! -name exclude_specified_file.js  -name \*.js -exec esvalidate '{}' \; | grep -v "No syntax errors detected" && echo "Javascript Syntax error(s) detected" && exit 1;
    

提交回复
热议问题