Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove javascript comments from .jshintrc before loading #36

Open
santhoshtr opened this issue Feb 8, 2014 · 1 comment
Open

Remove javascript comments from .jshintrc before loading #36

santhoshtr opened this issue Feb 8, 2014 · 1 comment

Comments

@santhoshtr
Copy link
Contributor

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.

@cfjedimaster
Copy link
Owner

I don't mind the line endings changing - can you just submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants