UNPKG

@sasjs/lint

Version:

Linting and formatting for SAS code

53 lines 2.91 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.lintFolder = void 0; const file_1 = require("@sasjs/utils/file"); const path_1 = __importDefault(require("path")); const utils_1 = require("../utils"); const lintFile_1 = require("./lintFile"); const excludeFolders = [ '.git', '.github', '.vscode', 'node_modules', 'sasjsbuild', 'sasjsresults' ]; /** * Analyses and produces a set of diagnostics for the folder at the given path. * @param {string} folderPath - the path to the folder to be linted. * @param {LintConfig} configuration - an optional configuration. When not passed in, this is read from the .sasjslint file. * @returns {Promise<Map<string, Diagnostic[]>>} Resolves with a map with array of diagnostic objects, each containing a warning, line number and column number, and grouped by file path. */ const lintFolder = (folderPath, configuration) => __awaiter(void 0, void 0, void 0, function* () { const config = configuration || (yield (0, utils_1.getLintConfig)()); let diagnostics = new Map(); if (yield (0, utils_1.isIgnored)(folderPath, config)) return diagnostics; const fileNames = yield (0, utils_1.listSasFiles)(folderPath); yield (0, utils_1.asyncForEach)(fileNames, (fileName) => __awaiter(void 0, void 0, void 0, function* () { const filePath = path_1.default.join(folderPath, fileName); diagnostics.set(filePath, yield (0, lintFile_1.lintFile)(filePath, config)); })); const subFolders = (yield (0, file_1.listSubFoldersInFolder)(folderPath)).filter((f) => !excludeFolders.includes(f)); yield (0, utils_1.asyncForEach)(subFolders, (subFolder) => __awaiter(void 0, void 0, void 0, function* () { const subFolderPath = path_1.default.join(folderPath, subFolder); const subFolderDiagnostics = yield (0, exports.lintFolder)(subFolderPath, config); diagnostics = new Map([...diagnostics, ...subFolderDiagnostics]); })); return diagnostics; }); exports.lintFolder = lintFolder; //# sourceMappingURL=lintFolder.js.map