UNPKG

textlint

Version:

The pluggable linting tool for natural language.

58 lines (56 loc) 2.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.showEmptyRuleWarning = void 0; exports.printResults = printResults; const logger_js_1 = require("./util/logger.js"); const node_path_1 = __importDefault(require("node:path")); const node_fs_1 = __importDefault(require("node:fs")); const showEmptyRuleWarning = () => { logger_js_1.Logger.log(` == No rules found, textlint hasn’t done anything == Possible reasons: * Your textlint config file has no rules. * You have no config file and you aren’t passing rules via command line. * Your textlint config has a syntax error. => How to set up rules? https://github.com/textlint/textlint/blob/master/docs/configuring.md `); }; exports.showEmptyRuleWarning = showEmptyRuleWarning; /** * Print results of lining text. * @param {string} output the output text which is formatted by {@link TextLintEngine.formatResults} * @param {object} options cli option object {@lint ./options.js} * @returns {boolean} does print result success? */ function printResults(output, options) { if (!output) { return true; } const outputFile = options.outputFile; if (outputFile) { const filePath = node_path_1.default.resolve(process.cwd(), outputFile); if (node_fs_1.default.existsSync(filePath) && node_fs_1.default.statSync(filePath).isDirectory()) { logger_js_1.Logger.error("Cannot write to output file path, it is a directory: %s", outputFile); return false; } try { node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true }); node_fs_1.default.writeFileSync(filePath, output); } catch (ex) { logger_js_1.Logger.error("There was a problem writing the output file:\n%s", ex); return false; } } else { logger_js_1.Logger.log(output); } return true; } //# sourceMappingURL=cli-util.js.map