{"action":"created","comment":{"url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/comments/24714160","id":24714160,"diff_hunk":"@@ -136,8 +150,87 @@ StringChecker.prototype = {\n \n             this._errorsFound += errors.getErrorCount();\n         }\n+    },\n \n-        return errors;\n+    /**\n+     * Adds parse error to the error list.\n+     *\n+     * @param {Errors} errors\n+     * @param {Error} parseError\n+     * @private\n+     */\n+    _addParseError: function(errors, parseError) {\n+        errors.setCurrentRule('parseError');\n+        errors.add(parseError.description, parseError.lineNumber, parseError.column);\n+    },\n+\n+    /**\n+     * Creates configured JsFile instance.\n+     *\n+     * @param {String} filename\n+     * @param {String} source\n+     * @param {Object} sourceTree\n+     * @private\n+     */\n+    _createJsFileInstance: function(filename, source, sourceTree) {\n+        return new JsFile(filename, source, sourceTree, {\n+            es3: this._configuration.isES3Enabled(),\n+            es6: this._configuration.isESNextEnabled()\n+        });\n+    },\n+\n+    /**\n+     * Checks file provided with a string.\n+     * @param {String} source\n+     * @param {String} [filename]\n+     * @returns {{output: String, errors: Errors}}\n+     */\n+    fixString: function(source, filename) {\n+        filename = filename || 'input';\n+\n+        var sourceTree;\n+        var parseError;\n+\n+        try {\n+            sourceTree = JsFile.parse(source, this._esprima, this._configuration.getEsprimaOptions());\n+        } catch (e) {\n+            parseError = e;\n+        }\n+\n+        if (parseError) {\n+            var parseErrors = new Errors(this._createJsFileInstance(filename, source, sourceTree), this._verbose);\n+            this._addParseError(parseErrors, parseError);\n+            return {output: source, errors: parseErrors};\n+        } else {\n+            var attempt = 0;\n+            var errors;\n+            var file;\n+\n+            do {\n+                file = this._createJsFileInstance(filename, source, sourceTree);\n+                errors = new Errors(file, this._verbose);\n+                this._checkJsFile(file, errors);\n+                var hasFixes = false;\n+                var errorList = errors.getErrorList();\n+                for (var i = 0; i < errorList.length; i++) {\n+                    if (errorList[i].fixed) {\n+                        hasFixes = true;\n+                        break;\n+                    }\n+                }\n+\n+                if (!hasFixes) {\n+                    break;\n+                }\n+\n+                source = file.render();\n+                sourceTree = JsFile.parse(source, this._esprima, this._configuration.getEsprimaOptions());","path":"lib/string-checker.js","position":151,"original_position":151,"commit_id":"b3fb19f891c48cf75e10aafe81801e9419436556","original_commit_id":"b3fb19f891c48cf75e10aafe81801e9419436556","user":{"login":"zxqfox","id":677518,"avatar_url":"https://avatars.githubusercontent.com/u/677518?v=3","gravatar_id":"","url":"https://api.github.com/users/zxqfox","html_url":"https://github.com/zxqfox","followers_url":"https://api.github.com/users/zxqfox/followers","following_url":"https://api.github.com/users/zxqfox/following{/other_user}","gists_url":"https://api.github.com/users/zxqfox/gists{/gist_id}","starred_url":"https://api.github.com/users/zxqfox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zxqfox/subscriptions","organizations_url":"https://api.github.com/users/zxqfox/orgs","repos_url":"https://api.github.com/users/zxqfox/repos","events_url":"https://api.github.com/users/zxqfox/events{/privacy}","received_events_url":"https://api.github.com/users/zxqfox/received_events","type":"User","site_admin":false},"body":"Oh, right. Thanks. But should we really reparse? Probably there is a way to just recheck fixed tree. It's much harder, yes. Ok, nvm ;-(","created_at":"2015-02-14T12:12:03Z","updated_at":"2015-02-14T12:12:03Z","html_url":"https://github.com/jscs-dev/node-jscs/pull/1058#discussion_r24714160","pull_request_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058","_links":{"self":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/comments/24714160"},"html":{"href":"https://github.com/jscs-dev/node-jscs/pull/1058#discussion_r24714160"},"pull_request":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058"}}},"pull_request":{"url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058","id":29315152,"html_url":"https://github.com/jscs-dev/node-jscs/pull/1058","diff_url":"https://github.com/jscs-dev/node-jscs/pull/1058.diff","patch_url":"https://github.com/jscs-dev/node-jscs/pull/1058.patch","issue_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/1058","number":1058,"state":"open","locked":false,"title":"Autofixing: initial implementation","user":{"login":"mdevils","id":176898,"avatar_url":"https://avatars.githubusercontent.com/u/176898?v=3","gravatar_id":"","url":"https://api.github.com/users/mdevils","html_url":"https://github.com/mdevils","followers_url":"https://api.github.com/users/mdevils/followers","following_url":"https://api.github.com/users/mdevils/following{/other_user}","gists_url":"https://api.github.com/users/mdevils/gists{/gist_id}","starred_url":"https://api.github.com/users/mdevils/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdevils/subscriptions","organizations_url":"https://api.github.com/users/mdevils/orgs","repos_url":"https://api.github.com/users/mdevils/repos","events_url":"https://api.github.com/users/mdevils/events{/privacy}","received_events_url":"https://api.github.com/users/mdevils/received_events","type":"User","site_admin":false},"body":"**Work in progress**\r\n\r\nIn this pull-request I have implemented autofixing mechanism:\r\n\r\n* Flag `-x, --fix` does autofixing.\r\n* In case of `stdin` input, autofixed content is written to the console.\r\n* I tried to keep everything as simple as possible.\r\n* I will write tests later.\r\n* I will cover other assertion methods soon.\r\n* All unfixed errors are printed.\r\n\r\n@mikesherov @markelog @mrjoelkemp @zxqfox please take a look!","created_at":"2015-02-14T03:52:24Z","updated_at":"2015-02-14T12:12:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"984d61e11cd3ede569a09b13f8ae170e133e6092","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058/commits","review_comments_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058/comments","review_comment_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/1058/comments","statuses_url":"https://api.github.com/repos/jscs-dev/node-jscs/statuses/b3fb19f891c48cf75e10aafe81801e9419436556","head":{"label":"jscs-dev:mdevils.autofixing","ref":"mdevils.autofixing","sha":"b3fb19f891c48cf75e10aafe81801e9419436556","user":{"login":"jscs-dev","id":8018201,"avatar_url":"https://avatars.githubusercontent.com/u/8018201?v=3","gravatar_id":"","url":"https://api.github.com/users/jscs-dev","html_url":"https://github.com/jscs-dev","followers_url":"https://api.github.com/users/jscs-dev/followers","following_url":"https://api.github.com/users/jscs-dev/following{/other_user}","gists_url":"https://api.github.com/users/jscs-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/jscs-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscs-dev/subscriptions","organizations_url":"https://api.github.com/users/jscs-dev/orgs","repos_url":"https://api.github.com/users/jscs-dev/repos","events_url":"https://api.github.com/users/jscs-dev/events{/privacy}","received_events_url":"https://api.github.com/users/jscs-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":10697582,"name":"node-jscs","full_name":"jscs-dev/node-jscs","owner":{"login":"jscs-dev","id":8018201,"avatar_url":"https://avatars.githubusercontent.com/u/8018201?v=3","gravatar_id":"","url":"https://api.github.com/users/jscs-dev","html_url":"https://github.com/jscs-dev","followers_url":"https://api.github.com/users/jscs-dev/followers","following_url":"https://api.github.com/users/jscs-dev/following{/other_user}","gists_url":"https://api.github.com/users/jscs-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/jscs-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscs-dev/subscriptions","organizations_url":"https://api.github.com/users/jscs-dev/orgs","repos_url":"https://api.github.com/users/jscs-dev/repos","events_url":"https://api.github.com/users/jscs-dev/events{/privacy}","received_events_url":"https://api.github.com/users/jscs-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jscs-dev/node-jscs","description":"JavaScript Code Style checker","fork":false,"url":"https://api.github.com/repos/jscs-dev/node-jscs","forks_url":"https://api.github.com/repos/jscs-dev/node-jscs/forks","keys_url":"https://api.github.com/repos/jscs-dev/node-jscs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jscs-dev/node-jscs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jscs-dev/node-jscs/teams","hooks_url":"https://api.github.com/repos/jscs-dev/node-jscs/hooks","issue_events_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/events{/number}","events_url":"https://api.github.com/repos/jscs-dev/node-jscs/events","assignees_url":"https://api.github.com/repos/jscs-dev/node-jscs/assignees{/user}","branches_url":"https://api.github.com/repos/jscs-dev/node-jscs/branches{/branch}","tags_url":"https://api.github.com/repos/jscs-dev/node-jscs/tags","blobs_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/refs{/sha}","trees_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jscs-dev/node-jscs/statuses/{sha}","languages_url":"https://api.github.com/repos/jscs-dev/node-jscs/languages","stargazers_url":"https://api.github.com/repos/jscs-dev/node-jscs/stargazers","contributors_url":"https://api.github.com/repos/jscs-dev/node-jscs/contributors","subscribers_url":"https://api.github.com/repos/jscs-dev/node-jscs/subscribers","subscription_url":"https://api.github.com/repos/jscs-dev/node-jscs/subscription","commits_url":"https://api.github.com/repos/jscs-dev/node-jscs/commits{/sha}","git_commits_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/commits{/sha}","comments_url":"https://api.github.com/repos/jscs-dev/node-jscs/comments{/number}","issue_comment_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/comments/{number}","contents_url":"https://api.github.com/repos/jscs-dev/node-jscs/contents/{+path}","compare_url":"https://api.github.com/repos/jscs-dev/node-jscs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jscs-dev/node-jscs/merges","archive_url":"https://api.github.com/repos/jscs-dev/node-jscs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jscs-dev/node-jscs/downloads","issues_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues{/number}","pulls_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls{/number}","milestones_url":"https://api.github.com/repos/jscs-dev/node-jscs/milestones{/number}","notifications_url":"https://api.github.com/repos/jscs-dev/node-jscs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jscs-dev/node-jscs/labels{/name}","releases_url":"https://api.github.com/repos/jscs-dev/node-jscs/releases{/id}","created_at":"2013-06-14T20:53:48Z","updated_at":"2015-02-14T12:09:27Z","pushed_at":"2015-02-14T03:50:01Z","git_url":"git://github.com/jscs-dev/node-jscs.git","ssh_url":"git@github.com:jscs-dev/node-jscs.git","clone_url":"https://github.com/jscs-dev/node-jscs.git","svn_url":"https://github.com/jscs-dev/node-jscs","homepage":"http://jscs.info/","size":8918,"stargazers_count":2511,"watchers_count":2511,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":252,"mirror_url":null,"open_issues_count":113,"forks":252,"open_issues":113,"watchers":2511,"default_branch":"master"}},"base":{"label":"jscs-dev:master","ref":"master","sha":"845a6b2a8d78e25c038fcb981c0334fe6f9c2d30","user":{"login":"jscs-dev","id":8018201,"avatar_url":"https://avatars.githubusercontent.com/u/8018201?v=3","gravatar_id":"","url":"https://api.github.com/users/jscs-dev","html_url":"https://github.com/jscs-dev","followers_url":"https://api.github.com/users/jscs-dev/followers","following_url":"https://api.github.com/users/jscs-dev/following{/other_user}","gists_url":"https://api.github.com/users/jscs-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/jscs-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscs-dev/subscriptions","organizations_url":"https://api.github.com/users/jscs-dev/orgs","repos_url":"https://api.github.com/users/jscs-dev/repos","events_url":"https://api.github.com/users/jscs-dev/events{/privacy}","received_events_url":"https://api.github.com/users/jscs-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":10697582,"name":"node-jscs","full_name":"jscs-dev/node-jscs","owner":{"login":"jscs-dev","id":8018201,"avatar_url":"https://avatars.githubusercontent.com/u/8018201?v=3","gravatar_id":"","url":"https://api.github.com/users/jscs-dev","html_url":"https://github.com/jscs-dev","followers_url":"https://api.github.com/users/jscs-dev/followers","following_url":"https://api.github.com/users/jscs-dev/following{/other_user}","gists_url":"https://api.github.com/users/jscs-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/jscs-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscs-dev/subscriptions","organizations_url":"https://api.github.com/users/jscs-dev/orgs","repos_url":"https://api.github.com/users/jscs-dev/repos","events_url":"https://api.github.com/users/jscs-dev/events{/privacy}","received_events_url":"https://api.github.com/users/jscs-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jscs-dev/node-jscs","description":"JavaScript Code Style checker","fork":false,"url":"https://api.github.com/repos/jscs-dev/node-jscs","forks_url":"https://api.github.com/repos/jscs-dev/node-jscs/forks","keys_url":"https://api.github.com/repos/jscs-dev/node-jscs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jscs-dev/node-jscs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jscs-dev/node-jscs/teams","hooks_url":"https://api.github.com/repos/jscs-dev/node-jscs/hooks","issue_events_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/events{/number}","events_url":"https://api.github.com/repos/jscs-dev/node-jscs/events","assignees_url":"https://api.github.com/repos/jscs-dev/node-jscs/assignees{/user}","branches_url":"https://api.github.com/repos/jscs-dev/node-jscs/branches{/branch}","tags_url":"https://api.github.com/repos/jscs-dev/node-jscs/tags","blobs_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/refs{/sha}","trees_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jscs-dev/node-jscs/statuses/{sha}","languages_url":"https://api.github.com/repos/jscs-dev/node-jscs/languages","stargazers_url":"https://api.github.com/repos/jscs-dev/node-jscs/stargazers","contributors_url":"https://api.github.com/repos/jscs-dev/node-jscs/contributors","subscribers_url":"https://api.github.com/repos/jscs-dev/node-jscs/subscribers","subscription_url":"https://api.github.com/repos/jscs-dev/node-jscs/subscription","commits_url":"https://api.github.com/repos/jscs-dev/node-jscs/commits{/sha}","git_commits_url":"https://api.github.com/repos/jscs-dev/node-jscs/git/commits{/sha}","comments_url":"https://api.github.com/repos/jscs-dev/node-jscs/comments{/number}","issue_comment_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues/comments/{number}","contents_url":"https://api.github.com/repos/jscs-dev/node-jscs/contents/{+path}","compare_url":"https://api.github.com/repos/jscs-dev/node-jscs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jscs-dev/node-jscs/merges","archive_url":"https://api.github.com/repos/jscs-dev/node-jscs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jscs-dev/node-jscs/downloads","issues_url":"https://api.github.com/repos/jscs-dev/node-jscs/issues{/number}","pulls_url":"https://api.github.com/repos/jscs-dev/node-jscs/pulls{/number}","milestones_url":"https://api.github.com/repos/jscs-dev/node-jscs/milestones{/number}","notifications_url":"https://api.github.com/repos/jscs-dev/node-jscs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jscs-dev/node-jscs/labels{/name}","releases_url":"https://api.github.com/repos/jscs-dev/node-jscs/releases{/id}","created_at":"2013-06-14T20:53:48Z","updated_at":"2015-02-14T12:09:27Z","pushed_at":"2015-02-14T03:50:01Z","git_url":"git://github.com/jscs-dev/node-jscs.git","ssh_url":"git@github.com:jscs-dev/node-jscs.git","clone_url":"https://github.com/jscs-dev/node-jscs.git","svn_url":"https://github.com/jscs-dev/node-jscs","homepage":"http://jscs.info/","size":8918,"stargazers_count":2511,"watchers_count":2511,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":252,"mirror_url":null,"open_issues_count":113,"forks":252,"open_issues":113,"watchers":2511,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058"},"html":{"href":"https://github.com/jscs-dev/node-jscs/pull/1058"},"issue":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/issues/1058"},"comments":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/issues/1058/comments"},"review_comments":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058/comments"},"review_comment":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/pulls/1058/commits"},"statuses":{"href":"https://api.github.com/repos/jscs-dev/node-jscs/statuses/b3fb19f891c48cf75e10aafe81801e9419436556"}}}}