{"action":"created","comment":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/74007982","id":74007982,"diff_hunk":"@@ -0,0 +1,521 @@\n+External Bears\n+==============\n+\n+Welcome. This tutorial will teach you how to use the\n+``@external_bear_wrap`` decorator in order to write Bears in languages other\n+than Python.\n+\n+.. note::\n+\n+  This tutorial assumes that you already know the basics. If you are new, please\n+  refer to the\n+  :doc:`Writing Bears<Writing_Bears>` section.\n+\n+  If you are planning to create a bear that uses an already existing tool (aka\n+  linter), please refer to the\n+  :doc:`Linter Bears<Linter_Bears>` section.\n+\n+Why is This Useful?\n+-------------------\n+\n+coala is a great tool if you want to write static code analysis without having\n+to worry about the interaction with the user. That makes it an excellent choice\n+for researchers and other people who want to build new static analysis routines.\n+Enabling developers to write external Bears means that they do not need to waste\n+any time learning new languages and they can get faster to the interesting part,\n+**static code analysis**.\n+\n+How Does This Work?\n+-------------------\n+\n+By using the ``@external_bear_wrap`` decorator you will have all the necessary\n+data sent to your external executable (filename, lines, settings) as a JSON\n+string via ``stdin``. Afterwards the analysis takes place in your executable\n+that can be written in **literally** any language. In the end you will have to\n+provide the ``Results`` in a JSON string via stdout.\n+\n+In this tutorial we will go through 2 examples where we create a very simple\n+bear. The first example will use a **compiled** language that creates a\n+standalone binary, ``C++``, whilst in the second example we will take a look at\n+``JS`` that needs ``node`` in order to run out of the browser.\n+\n+External Bear Generation Tool\n+-----------------------------\n+\n+If you really do not want to write any Python code, there is a tool\n+`here <https://gitlab.com/coala/coala-bear-management>`__,\n+``coala-bears-create``, that will create the wrapper for you. We will be using\n+\n+::\n+\n+    $ coala-bears-create -ext\n+\n+in order to generate the wrapper for the bear.\n+\n+Writing a Bear in C++\n+---------------------\n+\n+The bear that will be created with this tutorial will check whether there is any\n+**coala** spelled with a capital ``C`` since that is a horrible mistake for one\n+to make.\n+\n+1. Create a new directory and make it your current working directory.\n+2. Run ``coala-bears-create`` as mentioned above in order to create the wrapper\n+   for our ``C++`` bear and hit ``Enter`` for the first question. You can skip\n+   this step and use the wrapper provided below.\n+3. Name the bear ``coalaCheckBear`` and the executable ``coalaCheck_cpp``.\n+4. Reply to the rest of the questions (hit ``Enter`` at settings). After the\n+   script is finished running there should be 2 files in your current directory:\n+   ``coalaCheckBear.py`` (the wrapper) and ``coalaCheckBearTest.py``.\n+5. This tutorial will not focus on testing so ignore the second file for now.\n+   The wrapper should look something like this (after some cleaning):\n+\n+::\n+\n+    import os\n+\n+    from coalib.bearlib.abstractions.ExternalBearWrap import external_bear_wrap\n+\n+\n+    @external_bear_wrap(executable='coalaCheck_cpp',\n+                        settings={})\n+    class coalaCheckBear:\n+        \"\"\"\n+        Checks for coala written with uppercase 'C'\n+        \"\"\"\n+        LANGUAGES = {'All'}\n+        REQUIREMENTS = {'coalaCheck_cpp'}\n+        AUTHORS = {'Me'}\n+        AUTHORS_EMAILS = {'me@mail.com'}\n+        LICENSE = 'GPLv3'\n+\n+        @staticmethod\n+        def create_arguments():\n+            return ()\n+\n+6. Since the input will be a JSON string some kind of JSON class is needed.\n+   `This one <https://github.com/nlohmann/json>`__ is a great choice because it\n+   is easy to integrate and is used in this tutorial.\n+7. Create ``coalaCheck.cpp`` and start by testing the input. The best thing\n+   about nlohmann's JSON library is that you can parse JSON directly\n+   from stdin like this:\n+\n+::\n+\n+    #include <iostream>\n+\n+    #include \"json.hpp\"\n+\n+    using json = nlohmann::json;\n+    using namespace std;\n+\n+    json in;\n+\n+    int main() {\n+\n+        cin >> in;\n+\n+        cout << in;\n+\n+    return 0;\n+\n+8. Create a ``Makefile``. The JSON library requires C++11 so a sample\n+   ``Makefile`` would look like this:\n+\n+::\n+\n+    build: coalaCheck.cpp\n+        g++ -std=c++11 -o coalaCheck_cpp coalaCheck.cpp\n+\n+9. Compile and test the binary by giving it a JSON string. It should print the\n+   JSON string back at ``stdout``.\n+\n+10. Read about the JSON Spec that the input uses(`The JSON Spec`_). The filename\n+    is found in ``in[\"filename\"]`` and the list of lines is found in\n+    ``in[\"file\"]``.\n+11. Create a result adding function, also an init function proves quite useful\n+    for initializing the output json.\n+\n+::\n+\n+    #include <iostream>\n+    #include <string>\n+\n+    #include \"json.hpp\"\n+\n+    using json = nlohmann::json;\n+    using namespace std;\n+\n+    json in;\n+    json out;","path":"docs/Users/Tutorials/External_Bears.rst","position":150,"original_position":150,"commit_id":"c11a45d5541a221dfc580034b8b73619584c5d4d","original_commit_id":"c11a45d5541a221dfc580034b8b73619584c5d4d","user":{"login":"Udayan12167","id":6421568,"avatar_url":"https://avatars.githubusercontent.com/u/6421568?v=3","gravatar_id":"","url":"https://api.github.com/users/Udayan12167","html_url":"https://github.com/Udayan12167","followers_url":"https://api.github.com/users/Udayan12167/followers","following_url":"https://api.github.com/users/Udayan12167/following{/other_user}","gists_url":"https://api.github.com/users/Udayan12167/gists{/gist_id}","starred_url":"https://api.github.com/users/Udayan12167/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Udayan12167/subscriptions","organizations_url":"https://api.github.com/users/Udayan12167/orgs","repos_url":"https://api.github.com/users/Udayan12167/repos","events_url":"https://api.github.com/users/Udayan12167/events{/privacy}","received_events_url":"https://api.github.com/users/Udayan12167/received_events","type":"User","site_admin":false},"body":"just to keep uniformity make this output.","created_at":"2016-08-09T07:12:26Z","updated_at":"2016-08-09T07:12:26Z","html_url":"https://github.com/coala-analyzer/coala/pull/2583#discussion_r74007982","pull_request_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583","_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments/74007982"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/2583#discussion_r74007982"},"pull_request":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583"}}},"pull_request":{"url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583","id":79999671,"html_url":"https://github.com/coala-analyzer/coala/pull/2583","diff_url":"https://github.com/coala-analyzer/coala/pull/2583.diff","patch_url":"https://github.com/coala-analyzer/coala/pull/2583.patch","issue_url":"https://api.github.com/repos/coala-analyzer/coala/issues/2583","number":2583,"state":"open","locked":false,"title":"docs: Add External Bears tutorial","user":{"login":"Redridge","id":8859650,"avatar_url":"https://avatars.githubusercontent.com/u/8859650?v=3","gravatar_id":"","url":"https://api.github.com/users/Redridge","html_url":"https://github.com/Redridge","followers_url":"https://api.github.com/users/Redridge/followers","following_url":"https://api.github.com/users/Redridge/following{/other_user}","gists_url":"https://api.github.com/users/Redridge/gists{/gist_id}","starred_url":"https://api.github.com/users/Redridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Redridge/subscriptions","organizations_url":"https://api.github.com/users/Redridge/orgs","repos_url":"https://api.github.com/users/Redridge/repos","events_url":"https://api.github.com/users/Redridge/events{/privacy}","received_events_url":"https://api.github.com/users/Redridge/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-04T00:07:42Z","updated_at":"2016-08-09T07:12:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7dcd212d784f89aa5b51b60e69a7dfe2a3a6af3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583/commits","review_comments_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583/comments","review_comment_url":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/issues/2583/comments","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/c11a45d5541a221dfc580034b8b73619584c5d4d","head":{"label":"coala-analyzer:red/externalBear-docs","ref":"red/externalBear-docs","sha":"c11a45d5541a221dfc580034b8b73619584c5d4d","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"coala provides a unified command-line interface for linting and fixing all your code, regardless of the programming languages you use.","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","deployments_url":"https://api.github.com/repos/coala-analyzer/coala/deployments","created_at":"2014-05-15T11:35:34Z","updated_at":"2016-08-09T05:44:48Z","pushed_at":"2016-08-09T05:18:49Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":12067,"stargazers_count":397,"watchers_count":397,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":263,"forks":172,"open_issues":263,"watchers":397,"default_branch":"master"}},"base":{"label":"coala-analyzer:master","ref":"master","sha":"e61ca50cdf4fa4b996b02b00c80c2d10e550a4df","user":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"repo":{"id":19816973,"name":"coala","full_name":"coala-analyzer/coala","owner":{"login":"coala-analyzer","id":10620750,"avatar_url":"https://avatars.githubusercontent.com/u/10620750?v=3","gravatar_id":"","url":"https://api.github.com/users/coala-analyzer","html_url":"https://github.com/coala-analyzer","followers_url":"https://api.github.com/users/coala-analyzer/followers","following_url":"https://api.github.com/users/coala-analyzer/following{/other_user}","gists_url":"https://api.github.com/users/coala-analyzer/gists{/gist_id}","starred_url":"https://api.github.com/users/coala-analyzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coala-analyzer/subscriptions","organizations_url":"https://api.github.com/users/coala-analyzer/orgs","repos_url":"https://api.github.com/users/coala-analyzer/repos","events_url":"https://api.github.com/users/coala-analyzer/events{/privacy}","received_events_url":"https://api.github.com/users/coala-analyzer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coala-analyzer/coala","description":"coala provides a unified command-line interface for linting and fixing all your code, regardless of the programming languages you use.","fork":false,"url":"https://api.github.com/repos/coala-analyzer/coala","forks_url":"https://api.github.com/repos/coala-analyzer/coala/forks","keys_url":"https://api.github.com/repos/coala-analyzer/coala/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coala-analyzer/coala/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coala-analyzer/coala/teams","hooks_url":"https://api.github.com/repos/coala-analyzer/coala/hooks","issue_events_url":"https://api.github.com/repos/coala-analyzer/coala/issues/events{/number}","events_url":"https://api.github.com/repos/coala-analyzer/coala/events","assignees_url":"https://api.github.com/repos/coala-analyzer/coala/assignees{/user}","branches_url":"https://api.github.com/repos/coala-analyzer/coala/branches{/branch}","tags_url":"https://api.github.com/repos/coala-analyzer/coala/tags","blobs_url":"https://api.github.com/repos/coala-analyzer/coala/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coala-analyzer/coala/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coala-analyzer/coala/git/refs{/sha}","trees_url":"https://api.github.com/repos/coala-analyzer/coala/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coala-analyzer/coala/statuses/{sha}","languages_url":"https://api.github.com/repos/coala-analyzer/coala/languages","stargazers_url":"https://api.github.com/repos/coala-analyzer/coala/stargazers","contributors_url":"https://api.github.com/repos/coala-analyzer/coala/contributors","subscribers_url":"https://api.github.com/repos/coala-analyzer/coala/subscribers","subscription_url":"https://api.github.com/repos/coala-analyzer/coala/subscription","commits_url":"https://api.github.com/repos/coala-analyzer/coala/commits{/sha}","git_commits_url":"https://api.github.com/repos/coala-analyzer/coala/git/commits{/sha}","comments_url":"https://api.github.com/repos/coala-analyzer/coala/comments{/number}","issue_comment_url":"https://api.github.com/repos/coala-analyzer/coala/issues/comments{/number}","contents_url":"https://api.github.com/repos/coala-analyzer/coala/contents/{+path}","compare_url":"https://api.github.com/repos/coala-analyzer/coala/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coala-analyzer/coala/merges","archive_url":"https://api.github.com/repos/coala-analyzer/coala/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coala-analyzer/coala/downloads","issues_url":"https://api.github.com/repos/coala-analyzer/coala/issues{/number}","pulls_url":"https://api.github.com/repos/coala-analyzer/coala/pulls{/number}","milestones_url":"https://api.github.com/repos/coala-analyzer/coala/milestones{/number}","notifications_url":"https://api.github.com/repos/coala-analyzer/coala/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coala-analyzer/coala/labels{/name}","releases_url":"https://api.github.com/repos/coala-analyzer/coala/releases{/id}","deployments_url":"https://api.github.com/repos/coala-analyzer/coala/deployments","created_at":"2014-05-15T11:35:34Z","updated_at":"2016-08-09T05:44:48Z","pushed_at":"2016-08-09T05:18:49Z","git_url":"git://github.com/coala-analyzer/coala.git","ssh_url":"git@github.com:coala-analyzer/coala.git","clone_url":"https://github.com/coala-analyzer/coala.git","svn_url":"https://github.com/coala-analyzer/coala","homepage":"http://coala-analyzer.org/","size":12067,"stargazers_count":397,"watchers_count":397,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":263,"forks":172,"open_issues":263,"watchers":397,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583"},"html":{"href":"https://github.com/coala-analyzer/coala/pull/2583"},"issue":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/2583"},"comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/issues/2583/comments"},"review_comments":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583/comments"},"review_comment":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coala-analyzer/coala/pulls/2583/commits"},"statuses":{"href":"https://api.github.com/repos/coala-analyzer/coala/statuses/c11a45d5541a221dfc580034b8b73619584c5d4d"}}}}
{"actor":{"display_login":"Udayan12167"}}