<commit_before>/*
   Copyright 2017 <NAME>, LLC and the Yanagiba project contributors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

import Foundation

extension Issue {
  var jsonString: String {
    // TODO: as of today, swift-4-snapshot-2017-06-22-a,
    // awesome `Encodable` and `JSONEncoder` are not available on Linux yet
    // we will switch to that later when it is available
    // right now, just brutal string concatenation

    return """
    {
      "path": "\(location.normalizedFilePath)",
      "startLine": \(location.start.line),
      "startColumn": \(location.start.column),<commit_msg>Tried out Codable and JSONEncoder<commit_after>/*
   Copyright 2017 <NAME>, LLC and the Yanagiba project contributors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

// import Foundation

extension Issue {
  var jsonString: String {
    /*
    struct IssueEntry : Encodable { // Note: because `implementation of 'Encodable' cannot
                                    // be automatically synthesized in an extension yet`
      let path: String
      let startLine: Int
      let startColumn: Int
      let endLine: Int
      let endColumn: Int
      let rule: String
      let category: String
      let severity: String
      let description: String

      init(issue: Issue) {
        path = issue.location.normalizedFilePath
        startLine = issue.location.start.line
        startColumn = issue.location.start.column
        endLine = issue.location.end.line
        endColumn = issue.location.end.column
        rule = issue.ruleIdentifier
        category = issue.category.rawValue
        severity = issue.severity.rawValue
        description = issue.description
      }
    }

    let jsonEncoder = JSONEncoder()
    do {
        let jsonData = try jsonEncoder.encode(IssueEntry(issue: self))
        let jsonString = String(data: jsonData, encoding: .utf8)
        return jsonString ?? ""
    }
    catch {
      return ""
    }
    */

    // Note: for our use case, simply string concatenation seems to be better, don't want to overcomplicate things.

    return """
    {
      "path": "\(location.normalizedFilePath)",
      "startLine": \(location.start.line),
      "startColumn": \(location.start.column),
{'fraction_non_alphanumeric': 0.07846153846153846, 'fraction_numerical': 0.008, 'mean_word_length': 2.7324913892078073, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7475330', 'n_tokens_mistral': 849, 'n_tokens_neox': 818, 'n_words': 338}