UNPKG

@sasjs/lint

Version:

Linting and formatting for SAS code

48 lines 2.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProjectRoot = void 0; const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const file_1 = require("@sasjs/utils/file"); /** * Returns the absolute path to the location of the .sasjslint file. * Traverses the folder tree until the .sasjslint file is found. * @returns {Promise<string>} the path to the folder containing the lint config. */ function getProjectRoot() { return __awaiter(this, void 0, void 0, function* () { let root = ''; let rootFound = false; let i = 1; let currentLocation = process.cwd(); const homeDir = os_1.default.homedir(); const maxLevels = currentLocation.split(path_1.default.sep).length; while (i <= maxLevels && !rootFound && currentLocation !== homeDir) { const isRoot = yield (0, file_1.fileExists)(path_1.default.join(currentLocation, '.sasjslint')); if (isRoot) { rootFound = true; root = currentLocation; break; } else { currentLocation = path_1.default.join(currentLocation, '..'); i++; } } return root; }); } exports.getProjectRoot = getProjectRoot; //# sourceMappingURL=getProjectRoot.js.map