UNPKG

@sasjs/lint

Version:

Linting and formatting for SAS code

43 lines 2.21 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.isIgnored = void 0; const utils_1 = require("@sasjs/utils"); const path_1 = __importDefault(require("path")); const ignore_1 = __importDefault(require("ignore")); const _1 = require("."); /** * A function to check if file/folder path matches any pattern from .gitignore or ignoreList (.sasjsLint) * * @param {string} fPath - absolute path of file or folder * @returns {Promise<boolean>} true if path matches the patterns from .gitignore file otherwise false */ const isIgnored = (fPath, configuration) => __awaiter(void 0, void 0, void 0, function* () { const config = configuration || (yield (0, _1.getLintConfig)()); const projectRoot = yield (0, _1.getProjectRoot)(); const gitIgnoreFilePath = path_1.default.join(projectRoot, '.gitignore'); const rootPath = projectRoot + path_1.default.sep; const relativePath = fPath.replace(rootPath, ''); if (fPath === projectRoot) return false; let gitIgnoreFileContent = ''; if (yield (0, utils_1.fileExists)(gitIgnoreFilePath)) gitIgnoreFileContent = yield (0, utils_1.readFile)(gitIgnoreFilePath); return (0, ignore_1.default)() .add(gitIgnoreFileContent) .add(config.ignoreList) .ignores(relativePath); }); exports.isIgnored = isIgnored; //# sourceMappingURL=isIgnored.js.map