brackets-jshint
brackets-jshint copied to clipboard
Remove javascript comments from .jshintrc before loading
trafficstars
JSHint supports javascript style comments in .jshintrc. When a project contains such config file and brackets opens it, brackets-jshint fails to parse it because of comments.
Please use the following method to strip comments before you do JSON.parse in main.js
/**
* Removes JavaScript comments from a string by replacing
* everything between block comments and everything after
* single-line comments in a non-greedy way.
*
* English version of the regex:
* match '/*'
* then match zero or more instances of any character (incl. \n)
* except for instances of '* /' (without a space, obv.)
* then match '* /' (again, without a space)
*
* @param {string} str a string with potential JavaScript comments.
* @returns {string} a string without JavaScript comments.
*/
function removeComments(str) {
str = str || "";
str = str.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\//g, "");
str = str.replace(/\/\/[^\n\r]*/g, ""); // Everything after '//'
return str;
}
This is the same approach jshint uses with its command line interface.
I considered giving a pull request, but somehow you are using non consistent line endings in main.js and it mess up the patch. So I did not bother.
I don't mind the line endings changing - can you just submit a PR?