Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1/**2 * @fileoverview Main CLI object.3 * @author Nicholas C. Zakas4 */5 6"use strict";7 8/*9 * NOTE: The CLI object should *not* call process.exit() directly. It should only return10 * exit codes. This allows other programs to use the CLI object and still control11 * when the program exits.12 */13 14//------------------------------------------------------------------------------15// Requirements16//------------------------------------------------------------------------------17 18const fs = require("node:fs"),19 { mkdir, stat, writeFile } = require("node:fs/promises"),20 path = require("node:path"),21 { pathToFileURL } = require("node:url"),22 { LegacyESLint } = require("./eslint"),23 {24 ESLint,25 shouldUseFlatConfig,26 locateConfigFileToUse,27 } = require("./eslint/eslint"),28 createCLIOptions = require("./options"),29 log = require("./shared/logging"),30 RuntimeInfo = require("./shared/runtime-info"),31 translateOptions = require("./shared/translate-cli-options");32const { getCacheFile } = require("./eslint/eslint-helpers");33const { SuppressionsService } = require("./services/suppressions-service");34const debug = require("debug")("eslint:cli");35 36//------------------------------------------------------------------------------37// Types38//------------------------------------------------------------------------------39 40/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */41/** @typedef {import("./types").ESLint.LintResult} LintResult */42/** @typedef {import("./types").ESLint.ResultsMeta} ResultsMeta */43 44//------------------------------------------------------------------------------45// Helpers46//------------------------------------------------------------------------------47 48/**49 * Count error messages.50 * @param {LintResult[]} results The lint results.51 * @returns {{errorCount:number;fatalErrorCount:number,warningCount:number}} The number of error messages.52 */53function countErrors(results) {54 let errorCount = 0;55 let fatalErrorCount = 0;56 let warningCount = 0;57 58 for (const result of results) {59 errorCount += result.errorCount;60 fatalErrorCount += result.fatalErrorCount;61 warningCount += result.warningCount;62 }63 64 return { errorCount, fatalErrorCount, warningCount };65}66 67/**68 * Creates an options module from the provided CLI options and encodes it as a data URL.69 * @param {ParsedCLIOptions} options The CLI options.70 * @returns {URL} The URL of the options module.71 */72function createOptionsModule(options) {73 const translateOptionsFileURL = new URL(74 "./shared/translate-cli-options.js",75 pathToFileURL(__filename),76 ).href;77 const optionsSrc =78 `import translateOptions from ${JSON.stringify(translateOptionsFileURL)};\n` +79 `export default await translateOptions(${JSON.stringify(options)}, "flat");\n`;80 81 // Base64 encoding is typically shorter than URL encoding82 return new URL(83 `data:text/javascript;base64,${Buffer.from(optionsSrc).toString("base64")}`,84 );85}86 87/**88 * Check if a given file path is a directory or not.89 * @param {string} filePath The path to a file to check.90 * @returns {Promise<boolean>} `true` if the given path is a directory.91 */92async function isDirectory(filePath) {93 try {94 return (await stat(filePath)).isDirectory();95 } catch (error) {96 if (error.code === "ENOENT" || error.code === "ENOTDIR") {97 return false;98 }99 throw error;100 }101}102 103/**104 * Outputs the results of the linting.105 * @param {ESLint} engine The ESLint instance to use.106 * @param {LintResult[]} results The results to print.107 * @param {string} format The name of the formatter to use or the path to the formatter.108 * @param {string} outputFile The path for the output file.109 * @param {ResultsMeta} resultsMeta Warning count and max threshold.110 * @returns {Promise<boolean>} True if the printing succeeds, false if not.111 * @private112 */113async function printResults(engine, results, format, outputFile, resultsMeta) {114 let formatter;115 116 try {117 formatter = await engine.loadFormatter(format);118 } catch (e) {119 log.error(e.message);120 return false;121 }122 123 const output = await formatter.format(results, resultsMeta);124 125 if (outputFile) {126 const filePath = path.resolve(process.cwd(), outputFile);127 128 if (await isDirectory(filePath)) {129 log.error(130 "Cannot write to output file path, it is a directory: %s",131 outputFile,132 );133 return false;134 }135 136 try {137 await mkdir(path.dirname(filePath), { recursive: true });138 await writeFile(filePath, output);139 } catch (ex) {140 log.error("There was a problem writing the output file:\n%s", ex);141 return false;142 }143 } else if (output) {144 log.info(output);145 }146 147 return true;148}149 150/**151 * Validates the `--concurrency` flag value.152 * @param {string} concurrency The `--concurrency` flag value to validate.153 * @returns {void}154 * @throws {Error} If the `--concurrency` flag value is invalid.155 */156function validateConcurrency(concurrency) {157 if (158 concurrency === void 0 ||159 concurrency === "auto" ||160 concurrency === "off"161 ) {162 return;163 }164 165 const concurrencyValue = Number(concurrency);166 167 if (!Number.isInteger(concurrencyValue) || concurrencyValue < 1) {168 throw new Error(169 `Option concurrency: '${concurrency}' is not a positive integer, 'auto' or 'off'.`,170 );171 }172}173 174//------------------------------------------------------------------------------175// Public Interface176//------------------------------------------------------------------------------177 178/**179 * Encapsulates all CLI behavior for eslint. Makes it easier to test as well as180 * for other Node.js programs to effectively run the CLI.181 */182const cli = {183 /**184 * Calculates the command string for the --inspect-config operation.185 * @param {string} configFile The path to the config file to inspect.186 * @returns {Promise<string>} The command string to execute.187 */188 async calculateInspectConfigFlags(configFile) {189 // find the config file190 const { configFilePath, basePath } = await locateConfigFileToUse({191 cwd: process.cwd(),192 configFile,193 });194 195 return ["--config", configFilePath, "--basePath", basePath];196 },197 198 /**199 * Executes the CLI based on an array of arguments that is passed in.200 * @param {string|Array|Object} args The arguments to process.201 * @param {string} [text] The text to lint (used for TTY).202 * @param {boolean} [allowFlatConfig=true] Whether or not to allow flat config.203 * @returns {Promise<number>} The exit code for the operation.204 */205 async execute(args, text, allowFlatConfig = true) {206 if (Array.isArray(args)) {207 debug("CLI args: %o", args.slice(2));208 }209 210 /*211 * Before doing anything, we need to see if we are using a212 * flat config file. If so, then we need to change the way command213 * line args are parsed. This is temporary, and when we fully214 * switch to flat config we can remove this logic.215 */216 217 const usingFlatConfig =218 allowFlatConfig && (await shouldUseFlatConfig());219 220 debug("Using flat config?", usingFlatConfig);221 222 if (allowFlatConfig && !usingFlatConfig) {223 const { WarningService } = require("./services/warning-service");224 new WarningService().emitESLintRCWarning();225 }226 227 const CLIOptions = createCLIOptions(usingFlatConfig);228 229 /** @type {ParsedCLIOptions} */230 let options;231 232 try {233 options = CLIOptions.parse(args);234 validateConcurrency(options.concurrency);235 } catch (error) {236 debug("Error parsing CLI options:", error.message);237 238 let errorMessage = error.message;239 240 if (usingFlatConfig) {241 errorMessage +=242 "\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details.";243 }244 245 log.error(errorMessage);246 return 2;247 }248 249 const files = options._;250 const useStdin = typeof text === "string";251 252 if (options.help) {253 log.info(CLIOptions.generateHelp());254 return 0;255 }256 if (options.version) {257 log.info(RuntimeInfo.version());258 return 0;259 }260 if (options.envInfo) {261 try {262 log.info(RuntimeInfo.environment());263 return 0;264 } catch (err) {265 debug("Error retrieving environment info");266 log.error(err.message);267 return 2;268 }269 }270 271 if (options.printConfig) {272 if (files.length) {273 log.error(274 "The --print-config option must be used with exactly one file name.",275 );276 return 2;277 }278 if (useStdin) {279 log.error(280 "The --print-config option is not available for piped-in code.",281 );282 return 2;283 }284 285 const engine = usingFlatConfig286 ? new ESLint(await translateOptions(options, "flat"))287 : new LegacyESLint(await translateOptions(options));288 const fileConfig = await engine.calculateConfigForFile(289 options.printConfig,290 );291 292 log.info(JSON.stringify(fileConfig, null, " "));293 return 0;294 }295 296 if (options.inspectConfig) {297 log.info(298 "You can also run this command directly using 'npx @eslint/config-inspector@latest' in the same directory as your configuration file.",299 );300 301 try {302 const flatOptions = await translateOptions(options, "flat");303 const spawn = require("cross-spawn");304 const flags = await cli.calculateInspectConfigFlags(305 flatOptions.overrideConfigFile,306 );307 308 spawn.sync(309 "npx",310 ["@eslint/config-inspector@latest", ...flags],311 { encoding: "utf8", stdio: "inherit" },312 );313 } catch (error) {314 log.error(error);315 return 2;316 }317 318 return 0;319 }320 321 debug(`Running on ${useStdin ? "text" : "files"}`);322 323 if (options.fix && options.fixDryRun) {324 log.error(325 "The --fix option and the --fix-dry-run option cannot be used together.",326 );327 return 2;328 }329 if (useStdin && options.fix) {330 log.error(331 "The --fix option is not available for piped-in code; use --fix-dry-run instead.",332 );333 return 2;334 }335 if (options.fixType && !options.fix && !options.fixDryRun) {336 log.error(337 "The --fix-type option requires either --fix or --fix-dry-run.",338 );339 return 2;340 }341 342 if (343 options.reportUnusedDisableDirectives &&344 options.reportUnusedDisableDirectivesSeverity !== void 0345 ) {346 log.error(347 "The --report-unused-disable-directives option and the --report-unused-disable-directives-severity option cannot be used together.",348 );349 return 2;350 }351 352 if (usingFlatConfig && options.ext) {353 // Passing `--ext ""` results in `options.ext` being an empty array.354 if (options.ext.length === 0) {355 log.error("The --ext option value cannot be empty.");356 return 2;357 }358 359 // Passing `--ext ,ts` results in an empty string at index 0. Passing `--ext ts,,tsx` results in an empty string at index 1.360 const emptyStringIndex = options.ext.indexOf("");361 362 if (emptyStringIndex >= 0) {363 log.error(364 `The --ext option arguments cannot be empty strings. Found an empty string at index ${emptyStringIndex}.`,365 );366 return 2;367 }368 }369 370 if (options.suppressAll && options.suppressRule) {371 log.error(372 "The --suppress-all option and the --suppress-rule option cannot be used together.",373 );374 return 2;375 }376 377 if (options.suppressAll && options.pruneSuppressions) {378 log.error(379 "The --suppress-all option and the --prune-suppressions option cannot be used together.",380 );381 return 2;382 }383 384 if (options.suppressRule && options.pruneSuppressions) {385 log.error(386 "The --suppress-rule option and the --prune-suppressions option cannot be used together.",387 );388 return 2;389 }390 391 if (392 useStdin &&393 (options.suppressAll ||394 options.suppressRule ||395 options.pruneSuppressions)396 ) {397 log.error(398 "The --suppress-all, --suppress-rule, and --prune-suppressions options cannot be used with piped-in code.",399 );400 return 2;401 }402 403 const ActiveESLint = usingFlatConfig ? ESLint : LegacyESLint;404 405 /** @type {ESLint|LegacyESLint} */406 let engine;407 408 if (options.concurrency && options.concurrency !== "off") {409 const optionsURL = createOptionsModule(options);410 engine = await ESLint.fromOptionsModule(optionsURL);411 } else {412 const eslintOptions = await translateOptions(413 options,414 usingFlatConfig ? "flat" : "eslintrc",415 );416 engine = new ActiveESLint(eslintOptions);417 }418 let results;419 420 if (useStdin) {421 results = await engine.lintText(text, {422 filePath: options.stdinFilename,423 424 // flatConfig respects CLI flag and constructor warnIgnored, eslintrc forces true for backwards compatibility425 warnIgnored: usingFlatConfig ? void 0 : true,426 });427 } else {428 results = await engine.lintFiles(files);429 }430 431 if (options.fix) {432 debug("Fix mode enabled - applying fixes");433 await ActiveESLint.outputFixes(results);434 }435 436 let unusedSuppressions = {};437 438 if (!useStdin) {439 const suppressionsFileLocation = getCacheFile(440 options.suppressionsLocation || "eslint-suppressions.json",441 process.cwd(),442 {443 prefix: "suppressions_",444 },445 );446 447 if (448 options.suppressionsLocation &&449 !fs.existsSync(suppressionsFileLocation) &&450 !options.suppressAll &&451 !options.suppressRule452 ) {453 log.error(454 "The suppressions file does not exist. Please run the command with `--suppress-all` or `--suppress-rule` to create it.",455 );456 return 2;457 }458 459 if (460 options.suppressAll ||461 options.suppressRule ||462 options.pruneSuppressions ||463 fs.existsSync(suppressionsFileLocation)464 ) {465 const suppressions = new SuppressionsService({466 filePath: suppressionsFileLocation,467 cwd: process.cwd(),468 });469 470 if (options.suppressAll || options.suppressRule) {471 await suppressions.suppress(results, options.suppressRule);472 }473 474 if (options.pruneSuppressions) {475 await suppressions.prune(results);476 }477 478 const suppressionResults = suppressions.applySuppressions(479 results,480 await suppressions.load(),481 );482 483 results = suppressionResults.results;484 unusedSuppressions = suppressionResults.unused;485 }486 }487 488 let resultsToPrint = results;489 490 if (options.quiet) {491 debug("Quiet mode enabled - filtering out warnings");492 resultsToPrint = ActiveESLint.getErrorResults(resultsToPrint);493 }494 495 const resultCounts = countErrors(results);496 const tooManyWarnings =497 options.maxWarnings >= 0 &&498 resultCounts.warningCount > options.maxWarnings;499 const resultsMeta = tooManyWarnings500 ? {501 maxWarningsExceeded: {502 maxWarnings: options.maxWarnings,503 foundWarnings: resultCounts.warningCount,504 },505 }506 : {};507 508 if (509 await printResults(510 engine,511 resultsToPrint,512 options.format,513 options.outputFile,514 resultsMeta,515 )516 ) {517 // Errors and warnings from the original unfiltered results should determine the exit code518 const shouldExitForFatalErrors =519 options.exitOnFatalError && resultCounts.fatalErrorCount > 0;520 521 if (!resultCounts.errorCount && tooManyWarnings) {522 log.error(523 "ESLint found too many warnings (maximum: %s).",524 options.maxWarnings,525 );526 }527 528 if (!options.passOnUnprunedSuppressions) {529 const unusedSuppressionsCount =530 Object.keys(unusedSuppressions).length;531 532 if (unusedSuppressionsCount > 0) {533 log.error(534 "There are suppressions left that do not occur anymore. Consider re-running the command with `--prune-suppressions`.",535 );536 debug(JSON.stringify(unusedSuppressions, null, 2));537 538 return 2;539 }540 }541 542 if (shouldExitForFatalErrors) {543 return 2;544 }545 546 return resultCounts.errorCount || tooManyWarnings ? 1 : 0;547 }548 549 return 2;550 },551};552 553module.exports = cli;554 