<commit_before>/* eslint-disable prefer-template */

import { isString } from 'lodash';
import stackTrace from 'stack-trace';
import isAbsolute from 'is-absolute';
import subdir from 'subdir';
import cc from 'cli-color';
import path from 'path';

const grey = cc.xtermSupported ? cc.xterm(241) : cc.blackBright;

export default function readableStack(error, options = { cwd: process.cwd() }) {
  const { cwd } = options;

  if (!(error instanceof Error)) return 'Not an error: ' + error;

  return stackTrace.parse(error).map(call => {
    const fileName = call.getFileName();
    const functionName = call.getFunctionName();
    const lineNumber = call.getLineNumber();
    const columnNumber = call.getColumnNumber();

    if (isString(fileName)) {
      const absolute = isAbsolute(fileName);

      if (
        absolute &&
        subdir(cwd, fileName) &&
        !subdir(path.join(cwd, 'node_modules'), fileName)) {
        // absolute and within CWD (but not in node_modules folder)
        // - highlight this line
        return (
          (functionName ? grey('  at ') + functionName : ' ') +
          grey(' in ') + path.join('./', path.relative(cwd, fileName)) +
          (lineNumber ? grey(':' + lineNumber + ':' + columnNumber) : '')<commit_msg>fix colours on stack trace<commit_after>import builtins from 'builtin-modules';
import pathExists from 'path-exists';
import { isString } from 'lodash';
import stackTrace from 'stack-trace';
import isAbsolute from 'is-absolute';
import subdir from 'subdir';
import cc from 'cli-color';
import path from 'path';

const grey = cc.xtermSupported ? cc.xterm(241) : cc.blackBright;

export default function readableStack(error, options = { cwd: process.cwd() }) {
  const { cwd } = options;

  if (!(error instanceof Error)) return 'Not an error: ' + error;

  return stackTrace.parse(error).map(call => {
    const fileName = call.getFileName();
    const functionName = call.getFunctionName();
    const lineNumber = call.getLineNumber();
    const columnNumber = call.getColumnNumber();

    if (isString(fileName)) {
      const absolute = isAbsolute(fileName);
      const resolvedFileName = path.resolve(cwd, fileName);

      if (
        subdir(cwd, fileName) &&
        !subdir(path.join(cwd, 'node_modules'), resolvedFileName) &&
        (absolute || (
          builtins.indexOf(path.basename(fileName, '.js')) === -1 &&
          pathExists.sync(resolvedFileName)
        ))
      ) {
        // absolute and within CWD (but not in node_modules folder)
        // - highlight this line
        return (
          (functionName ? grey('  at ') + functionName : ' ') +
          grey(' in ') + path.join('./', path.relative(cwd, fileName)) +
          (lineNumber ? grey(':' + lineNumber + ':' + columnNumber) : '')
{'fraction_non_alphanumeric': 0.1398274622573688, 'fraction_numerical': 0.0025161754133716753, 'mean_word_length': 3.1599402092675635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2610318', 'n_tokens_mistral': 806, 'n_tokens_neox': 803, 'n_words': 223}