UNPKG

atom-nuclide

Version:

A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.

75 lines (61 loc) 2.7 kB
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); /* * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the license found in the LICENSE file in * the root directory of this source tree. */ function fileOfDiagnosticMessage(diagnostic) { if (diagnostic.filePath != null) { return diagnostic.filePath; } else { return ''; } } function getProjectRelativePathOfDiagnostic(diagnostic) { if (diagnostic.filePath != null) { var _atom$project$relativizePath = atom.project.relativizePath(diagnostic.filePath); var _atom$project$relativizePath2 = _slicedToArray(_atom$project$relativizePath, 2); var relativePath = _atom$project$relativizePath2[1]; return relativePath; } else { return ''; } } function fileColumnCellDataGetter(cellDataKey, diagnostic) { return getProjectRelativePathOfDiagnostic(diagnostic); } function compareMessagesByFile(a, b) { // This will sort by: // - errors before warnings // - local before remote // - Remote machine name/port // - full path // var compareVal = compareMessagesByLevel(a, b); if (compareVal !== 0) { return compareVal; } // We don't sort by project relative path as that will interleave diagnostics from // different projects. compareVal = fileOfDiagnosticMessage(a).localeCompare(fileOfDiagnosticMessage(b)); // If the messages are from the same file (`filePath` is equal and `localeCompare` // returns 0), compare the line numbers within the file to determine their sort order. if (compareVal === 0 && a.range !== undefined && b.range !== undefined) { compareVal = a.range.start.row - b.range.start.row; } return compareVal; } var messageLevelRank = { Error: 0, Warning: 1 }; function compareMessagesByLevel(a, b) { return messageLevelRank[a.type] - messageLevelRank[b.type]; } module.exports = { compareMessagesByFile: compareMessagesByFile, getProjectRelativePathOfDiagnostic: getProjectRelativePathOfDiagnostic, fileColumnCellDataGetter: fileColumnCellDataGetter };