<commit_before>/*
  Copyright 2019 Google LLC

  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

      https://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.
*/

var Flow = require("./Flow.js"),
  RouteRule = require("./RouteRule.js"),
  FaultRule = require("./FaultRule.js"),
  xpath = require("xpath"),
  myUtil = require("./myUtil.js"),
  async = require("async"),
  debug = require("debug")("bundlelinter:Endpoint"),
  fs = require("fs"),
  HTTPProxyConnection = require("./HTTPProxyConnection.js"),
  HTTPTargetConnection = require("./HTTPTargetConnection.js"),
  bundleTypes = require('./BundleTypes.js');

function Endpoint(element, parent, fname, bundletype) {
  this.bundleType = bundletype ? bundletype : "apiproxy" //default to apiproxy if bundletype not passed
  this.fileName = fname;
  this.parent = parent;
  this.element = element;
  this.report = {
    filePath: fname.substring(fname.indexOf("/" + this.bundleType)),
    errorCount: 0,
    warningCount: 0,
    fixableErrorCount: 0,
    fixableWarningCount: 0,
    messages: []
  };
}

Endpoint.prototype.getName = function() {
  if (!this.name) {
    this.name = xpath.select("string(./@name)", this.element);
  }
  return this.name;
};

Endpoint.prototype.getReport = function() {
  return this.report;
};

Endpoint.prototype.getFileName = function() {
  return this.fileName;
};

Endpoint.prototype.getLines = function(start, stop) {
  //actually parse the source into lines if we haven't already and return the requested subset
  var result = "";
  if (!this.lines) {
    this.lines = fs.readFileSync(this.getFileName()).toString().split("\n");
  }<commit_msg>sort messages on an endpoint by line, column<commit_after>/*
  Copyright 2019 Google LLC

  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

      https://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.
*/

var Flow = require("./Flow.js"),
  RouteRule = require("./RouteRule.js"),
  FaultRule = require("./FaultRule.js"),
  xpath = require("xpath"),
  myUtil = require("./myUtil.js"),
  async = require("async"),
  debug = require("debug")("bundlelinter:Endpoint"),
  fs = require("fs"),
  HTTPProxyConnection = require("./HTTPProxyConnection.js"),
  HTTPTargetConnection = require("./HTTPTargetConnection.js"),
  bundleTypes = require('./BundleTypes.js');

function Endpoint(element, parent, fname, bundletype) {
  this.bundleType = bundletype ? bundletype : "apiproxy" //default to apiproxy if bundletype not passed
  this.fileName = fname;
  this.parent = parent;
  this.element = element;
  this.report = {
    filePath: fname.substring(fname.indexOf("/" + this.bundleType)),
    errorCount: 0,
    warningCount: 0,
    fixableErrorCount: 0,
    fixableWarningCount: 0,
    messages: []
  };
}

Endpoint.prototype.getName = function() {
  if (!this.name) {
    this.name = xpath.select("string(./@name)", this.element);
  }
  return this.name;
};

Endpoint.prototype.getReport = function() {
  // sort messages by line, column
  this.report.messages.sort((a, b) => {
    if (a.line && !b.line)
      return -1;
    if (b.line && !a.line)
      return 1;
    if (a.line == b.line) {
      if (a.column && !b.column)
        return -1;
      if (b.column && !a.column)
        return 1;
      return a.column - b.column;
    }
    return a.line - b.line;
  });
  return this.report;
};

Endpoint.prototype.getFileName = function() {
  return this.fileName;
};

Endpoint.prototype.getLines = function(start, stop) {
  //actually parse the source into lines if we haven't already and return the requested subset
  var result = "";
  if (!this.lines) {
    this.lines = fs.readFileSync(this.getFileName()).toString().split("\n");
  }
{'fraction_non_alphanumeric': 0.13190455148033584, 'fraction_numerical': 0.0061864781263809105, 'mean_word_length': 3.6383196721311477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6138251', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1345, 'n_words': 407}