UNPKG

@sasjs/lint

Version:

Linting and formatting for SAS code

62 lines 3.03 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.getLintConfig = exports.DefaultLintConfiguration = exports.getDefaultHeader = void 0; const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const LintConfig_1 = require("../types/LintConfig"); const file_1 = require("@sasjs/utils/file"); const getProjectRoot_1 = require("./getProjectRoot"); const LineEndings_1 = require("../types/LineEndings"); const getDefaultHeader = () => `/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`; exports.getDefaultHeader = getDefaultHeader; /** * Default configuration that is used when a .sasjslint file is not found */ exports.DefaultLintConfiguration = { lineEndings: LineEndings_1.LineEndings.OFF, noTrailingSpaces: true, noEncodedPasswords: true, hasDoxygenHeader: true, noSpacesInFileNames: true, lowerCaseFileNames: true, maxLineLength: 80, maxHeaderLineLength: 80, maxDataLineLength: 80, noTabIndentation: true, indentationMultiple: 2, hasMacroNameInMend: true, noNestedMacros: true, hasMacroParentheses: true, strictMacroDefinition: true, noGremlins: true, defaultHeader: (0, exports.getDefaultHeader)() }; /** * Fetches the config from the .sasjslint file (at project root or home directory) and creates a LintConfig object. * Returns the default configuration when a .sasjslint file is unavailable. * @returns {Promise<LintConfig>} resolves with an object representing the current lint configuration. */ function getLintConfig() { return __awaiter(this, void 0, void 0, function* () { const projectRoot = yield (0, getProjectRoot_1.getProjectRoot)(); const lintFileLocation = projectRoot || os_1.default.homedir(); const configuration = yield (0, file_1.readFile)(path_1.default.join(lintFileLocation, '.sasjslint')).catch((_) => { return JSON.stringify(exports.DefaultLintConfiguration); }); return new LintConfig_1.LintConfig(JSON.parse(configuration)); }); } exports.getLintConfig = getLintConfig; //# sourceMappingURL=getLintConfig.js.map