{"action":"created","comment":{"url":"https://api.github.com/repos/troessner/reek/pulls/comments/199078819","pull_request_review_id":133127377,"id":199078819,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5OTA3ODgxOQ==","diff_hunk":"@@ -0,0 +1,110 @@\n+# frozen_string_literal: true\n+\n+require_relative './configuration_validator'\n+\n+module Reek\n+  module Configuration\n+    # Responsible for converting marked strings coming from the outside world\n+    # into proper regexes.\n+    class ConfigurationConverter\n+      REGEXABLE_ATTRIBUTES = %w(accept reject exclude).freeze\n+      include ConfigurationValidator\n+      attr_reader :configuration\n+\n+      # @param configuration [Hash] e.g.\n+      #\n+      #   detectors => {\n+      #     \"UnusedPrivateMethod\" => {\"exclude\"=>[\"/exclude regexp/\"]},\n+      #     \"UncommunicativeMethodName\"=>{\"reject\"=>[\"reject name\"], \"accept\"=>[\"accept name\"]\n+      #   },\n+      #   directories => {\n+      #     \"app/controllers\" => {\n+      #       \"UnusedPrivateMethod\" => {\"exclude\"=>[\"/exclude regexp/\"]},\n+      #       \"UncommunicativeMethodName\"=>{\"reject\"=>[\"reject name\"], \"accept\"=>[\"accept name\"]}\n+      #     }\n+      #   }\n+      def initialize(configuration)\n+        @configuration = configuration\n+      end\n+\n+      # Converts all marked strings across the whole configuration to regexes.\n+      # @return [Hash]\n+      #\n+      def convert\n+        strings_to_regexes_for_detectors\n+        strings_to_regexes_for_directories\n+\n+        configuration\n+      end\n+\n+      private\n+\n+      # @param value [String] String that is potentially marked as regex, e.g. \"/foobar/\".\n+      # @return [Bool] if the string in question is marked as regex.\n+      #\n+      # @quality :reek:UtilityFunction\n+      def marked_as_regex?(value)\n+        value.start_with?('/') && value.end_with?('/')\n+      end\n+\n+      # @param value [value] String that is potentially marked as regex, e.g. \"/foobar/\".\n+      # @return [Regexp] e.g. /foobar/.\n+      #\n+      def to_regex(value)\n+        marked_as_regex?(value) ? Regexp.new(value[1..-2]) : value\n+      end\n+\n+      # @param detector_configuration [Hash] e.g.\n+      #   { \"UnusedPrivateMethod\" => {\"exclude\"=>[\"/exclude regexp/\"] }\n+      # @return [Array] all the attributes from the detector configuration that potentially contain regexes.\n+      #   Using this example above this would just be \"exclude\".\n+      #\n+      # @quality :reek:UtilityFunction\n+      def convertible_attributes(detector_configuration)\n+        detector_configuration.keys & REGEXABLE_ATTRIBUTES\n+      end\n+\n+      # Iterates over our detector configuration and converts all marked strings into regexes.\n+      # @return nil\n+      #\n+      # @quality :reek:DuplicateMethodCall { max_calls: 3 }\n+      # @quality :reek:NestedIterators { max_allowed_nesting: 3 }\n+      # @quality :reek:TooManyStatements { max_statements: 6 }\n+      def strings_to_regexes_for_detectors\n+        return unless configuration[AppConfiguration::DETECTORS_KEY]\n+\n+        configuration[AppConfiguration::DETECTORS_KEY].tap do |detectors|\n+          detectors.keys.each do |detector|\n+            convertible_attributes(detectors[detector]).each do |attribute|\n+              detectors[detector][attribute] = detectors[detector][attribute].map do |item|\n+                to_regex item\n+              end\n+            end\n+          end\n+        end\n+      end\n+\n+      # Iterates over our directory configuration and converts all marked strings into regexes.\n+      # @return nil\n+      #\n+      # @quality :reek:DuplicateMethodCall { max_calls: 3 }\n+      # @quality :reek:NestedIterators { max_allowed_nesting: 4 }\n+      # @quality :reek:TooManyStatements { max_statements: 7 }\n+      def strings_to_regexes_for_directories\n+        return unless configuration[AppConfiguration::DIRECTORIES_KEY]\n+\n+        configuration[AppConfiguration::DIRECTORIES_KEY].tap do |directories|\n+          directories.keys.each do |directory|\n+            directories[directory].each do |detector, configuration|\n+              convertible_attributes(configuration).each do |attribute|\n+                directories[directory][detector][attribute] = directories[directory][detector][attribute].map do |item|\n+                  to_regex item\n+                end","path":"lib/reek/configuration/configuration_converter.rb","position":102,"original_position":102,"commit_id":"72c9bfffa4d222ea8a1edb3057e67df682746dc4","original_commit_id":"72c9bfffa4d222ea8a1edb3057e67df682746dc4","user":{"login":"mvz","id":10898,"node_id":"MDQ6VXNlcjEwODk4","avatar_url":"https://avatars3.githubusercontent.com/u/10898?v=4","gravatar_id":"","url":"https://api.github.com/users/mvz","html_url":"https://github.com/mvz","followers_url":"https://api.github.com/users/mvz/followers","following_url":"https://api.github.com/users/mvz/following{/other_user}","gists_url":"https://api.github.com/users/mvz/gists{/gist_id}","starred_url":"https://api.github.com/users/mvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvz/subscriptions","organizations_url":"https://api.github.com/users/mvz/orgs","repos_url":"https://api.github.com/users/mvz/repos","events_url":"https://api.github.com/users/mvz/events{/privacy}","received_events_url":"https://api.github.com/users/mvz/received_events","type":"User","site_admin":false},"body":"Amazing nesting :laughing:.","created_at":"2018-06-29T07:44:57Z","updated_at":"2018-06-29T07:45:22Z","html_url":"https://github.com/troessner/reek/pull/1378#discussion_r199078819","pull_request_url":"https://api.github.com/repos/troessner/reek/pulls/1378","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/troessner/reek/pulls/comments/199078819"},"html":{"href":"https://github.com/troessner/reek/pull/1378#discussion_r199078819"},"pull_request":{"href":"https://api.github.com/repos/troessner/reek/pulls/1378"}}},"pull_request":{"url":"https://api.github.com/repos/troessner/reek/pulls/1378","id":198142289,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk4MTQyMjg5","html_url":"https://github.com/troessner/reek/pull/1378","diff_url":"https://github.com/troessner/reek/pull/1378.diff","patch_url":"https://github.com/troessner/reek/pull/1378.patch","issue_url":"https://api.github.com/repos/troessner/reek/issues/1378","number":1378,"state":"open","locked":false,"title":"Convert strings to regexes for directory directives.","user":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"body":"Fixes #1377 ","created_at":"2018-06-28T20:21:38Z","updated_at":"2018-06-29T07:45:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e38a1e195ca865755fe137ab35d62cce6d5da0d","assignee":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"assignees":[{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":2538,"node_id":"MDU6TGFiZWwyNTM4","url":"https://api.github.com/repos/troessner/reek/labels/defect","name":"defect","color":"e10c02","default":false},{"id":417002333,"node_id":"MDU6TGFiZWw0MTcwMDIzMzM=","url":"https://api.github.com/repos/troessner/reek/labels/ready-for-review","name":"ready-for-review","color":"0e8a16","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/troessner/reek/pulls/1378/commits","review_comments_url":"https://api.github.com/repos/troessner/reek/pulls/1378/comments","review_comment_url":"https://api.github.com/repos/troessner/reek/pulls/comments{/number}","comments_url":"https://api.github.com/repos/troessner/reek/issues/1378/comments","statuses_url":"https://api.github.com/repos/troessner/reek/statuses/72c9bfffa4d222ea8a1edb3057e67df682746dc4","head":{"label":"troessner:convert-strings-to-regexes-for-directory-directives","ref":"convert-strings-to-regexes-for-directory-directives","sha":"72c9bfffa4d222ea8a1edb3057e67df682746dc4","user":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"repo":{"id":49515,"node_id":"MDEwOlJlcG9zaXRvcnk0OTUxNQ==","name":"reek","full_name":"troessner/reek","owner":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/troessner/reek","description":"Code smell detector for Ruby","fork":false,"url":"https://api.github.com/repos/troessner/reek","forks_url":"https://api.github.com/repos/troessner/reek/forks","keys_url":"https://api.github.com/repos/troessner/reek/keys{/key_id}","collaborators_url":"https://api.github.com/repos/troessner/reek/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/troessner/reek/teams","hooks_url":"https://api.github.com/repos/troessner/reek/hooks","issue_events_url":"https://api.github.com/repos/troessner/reek/issues/events{/number}","events_url":"https://api.github.com/repos/troessner/reek/events","assignees_url":"https://api.github.com/repos/troessner/reek/assignees{/user}","branches_url":"https://api.github.com/repos/troessner/reek/branches{/branch}","tags_url":"https://api.github.com/repos/troessner/reek/tags","blobs_url":"https://api.github.com/repos/troessner/reek/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/troessner/reek/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/troessner/reek/git/refs{/sha}","trees_url":"https://api.github.com/repos/troessner/reek/git/trees{/sha}","statuses_url":"https://api.github.com/repos/troessner/reek/statuses/{sha}","languages_url":"https://api.github.com/repos/troessner/reek/languages","stargazers_url":"https://api.github.com/repos/troessner/reek/stargazers","contributors_url":"https://api.github.com/repos/troessner/reek/contributors","subscribers_url":"https://api.github.com/repos/troessner/reek/subscribers","subscription_url":"https://api.github.com/repos/troessner/reek/subscription","commits_url":"https://api.github.com/repos/troessner/reek/commits{/sha}","git_commits_url":"https://api.github.com/repos/troessner/reek/git/commits{/sha}","comments_url":"https://api.github.com/repos/troessner/reek/comments{/number}","issue_comment_url":"https://api.github.com/repos/troessner/reek/issues/comments{/number}","contents_url":"https://api.github.com/repos/troessner/reek/contents/{+path}","compare_url":"https://api.github.com/repos/troessner/reek/compare/{base}...{head}","merges_url":"https://api.github.com/repos/troessner/reek/merges","archive_url":"https://api.github.com/repos/troessner/reek/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/troessner/reek/downloads","issues_url":"https://api.github.com/repos/troessner/reek/issues{/number}","pulls_url":"https://api.github.com/repos/troessner/reek/pulls{/number}","milestones_url":"https://api.github.com/repos/troessner/reek/milestones{/number}","notifications_url":"https://api.github.com/repos/troessner/reek/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/troessner/reek/labels{/name}","releases_url":"https://api.github.com/repos/troessner/reek/releases{/id}","deployments_url":"https://api.github.com/repos/troessner/reek/deployments","created_at":"2008-09-05T10:48:33Z","updated_at":"2018-06-29T07:39:13Z","pushed_at":"2018-06-29T07:39:14Z","git_url":"git://github.com/troessner/reek.git","ssh_url":"git@github.com:troessner/reek.git","clone_url":"https://github.com/troessner/reek.git","svn_url":"https://github.com/troessner/reek","homepage":"https://github.com/troessner/reek","size":5201,"stargazers_count":2754,"watchers_count":2754,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":208,"mirror_url":null,"archived":false,"open_issues_count":38,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":208,"open_issues":38,"watchers":2754,"default_branch":"master"}},"base":{"label":"troessner:master","ref":"master","sha":"66da00d3a0f59c490f33aa4193591eed836ee3d4","user":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"repo":{"id":49515,"node_id":"MDEwOlJlcG9zaXRvcnk0OTUxNQ==","name":"reek","full_name":"troessner/reek","owner":{"login":"troessner","id":271109,"node_id":"MDQ6VXNlcjI3MTEwOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/271109?v=4","gravatar_id":"","url":"https://api.github.com/users/troessner","html_url":"https://github.com/troessner","followers_url":"https://api.github.com/users/troessner/followers","following_url":"https://api.github.com/users/troessner/following{/other_user}","gists_url":"https://api.github.com/users/troessner/gists{/gist_id}","starred_url":"https://api.github.com/users/troessner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troessner/subscriptions","organizations_url":"https://api.github.com/users/troessner/orgs","repos_url":"https://api.github.com/users/troessner/repos","events_url":"https://api.github.com/users/troessner/events{/privacy}","received_events_url":"https://api.github.com/users/troessner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/troessner/reek","description":"Code smell detector for Ruby","fork":false,"url":"https://api.github.com/repos/troessner/reek","forks_url":"https://api.github.com/repos/troessner/reek/forks","keys_url":"https://api.github.com/repos/troessner/reek/keys{/key_id}","collaborators_url":"https://api.github.com/repos/troessner/reek/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/troessner/reek/teams","hooks_url":"https://api.github.com/repos/troessner/reek/hooks","issue_events_url":"https://api.github.com/repos/troessner/reek/issues/events{/number}","events_url":"https://api.github.com/repos/troessner/reek/events","assignees_url":"https://api.github.com/repos/troessner/reek/assignees{/user}","branches_url":"https://api.github.com/repos/troessner/reek/branches{/branch}","tags_url":"https://api.github.com/repos/troessner/reek/tags","blobs_url":"https://api.github.com/repos/troessner/reek/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/troessner/reek/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/troessner/reek/git/refs{/sha}","trees_url":"https://api.github.com/repos/troessner/reek/git/trees{/sha}","statuses_url":"https://api.github.com/repos/troessner/reek/statuses/{sha}","languages_url":"https://api.github.com/repos/troessner/reek/languages","stargazers_url":"https://api.github.com/repos/troessner/reek/stargazers","contributors_url":"https://api.github.com/repos/troessner/reek/contributors","subscribers_url":"https://api.github.com/repos/troessner/reek/subscribers","subscription_url":"https://api.github.com/repos/troessner/reek/subscription","commits_url":"https://api.github.com/repos/troessner/reek/commits{/sha}","git_commits_url":"https://api.github.com/repos/troessner/reek/git/commits{/sha}","comments_url":"https://api.github.com/repos/troessner/reek/comments{/number}","issue_comment_url":"https://api.github.com/repos/troessner/reek/issues/comments{/number}","contents_url":"https://api.github.com/repos/troessner/reek/contents/{+path}","compare_url":"https://api.github.com/repos/troessner/reek/compare/{base}...{head}","merges_url":"https://api.github.com/repos/troessner/reek/merges","archive_url":"https://api.github.com/repos/troessner/reek/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/troessner/reek/downloads","issues_url":"https://api.github.com/repos/troessner/reek/issues{/number}","pulls_url":"https://api.github.com/repos/troessner/reek/pulls{/number}","milestones_url":"https://api.github.com/repos/troessner/reek/milestones{/number}","notifications_url":"https://api.github.com/repos/troessner/reek/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/troessner/reek/labels{/name}","releases_url":"https://api.github.com/repos/troessner/reek/releases{/id}","deployments_url":"https://api.github.com/repos/troessner/reek/deployments","created_at":"2008-09-05T10:48:33Z","updated_at":"2018-06-29T07:39:13Z","pushed_at":"2018-06-29T07:39:14Z","git_url":"git://github.com/troessner/reek.git","ssh_url":"git@github.com:troessner/reek.git","clone_url":"https://github.com/troessner/reek.git","svn_url":"https://github.com/troessner/reek","homepage":"https://github.com/troessner/reek","size":5201,"stargazers_count":2754,"watchers_count":2754,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":208,"mirror_url":null,"archived":false,"open_issues_count":38,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":208,"open_issues":38,"watchers":2754,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/troessner/reek/pulls/1378"},"html":{"href":"https://github.com/troessner/reek/pull/1378"},"issue":{"href":"https://api.github.com/repos/troessner/reek/issues/1378"},"comments":{"href":"https://api.github.com/repos/troessner/reek/issues/1378/comments"},"review_comments":{"href":"https://api.github.com/repos/troessner/reek/pulls/1378/comments"},"review_comment":{"href":"https://api.github.com/repos/troessner/reek/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/troessner/reek/pulls/1378/commits"},"statuses":{"href":"https://api.github.com/repos/troessner/reek/statuses/72c9bfffa4d222ea8a1edb3057e67df682746dc4"}},"author_association":"OWNER"}}
{"actor":{"display_login":"mvz"}}