UNPKG

eslint-plugin-sonarjs

Version:
59 lines (58 loc) • 2.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MinimatchCache = void 0; /* * SonarQube JavaScript Plugin * Copyright (C) SonarSource Sàrl * mailto:info AT sonarsource DOT com * * You can redistribute and/or modify this program under the terms of * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the Sonar Source-Available License for more details. * * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ const filesystem_js_1 = require("../filesystem.js"); const posix_1 = require("node:path/posix"); const files_js_1 = require("../files.js"); const node_fs_1 = __importDefault(require("node:fs")); const cache_js_1 = require("../cache.js"); exports.MinimatchCache = new cache_js_1.ComputedCache((matcher, filesystem = node_fs_1.default) => { return new cache_js_1.ComputedCache((from) => { const files = []; try { for (const entry of filesystem.readdirSync(from)) { const fullEntryPath = (0, files_js_1.joinPaths)(from, entry.toString()); if (matcher.match((0, posix_1.basename)(fullEntryPath))) { let stats; // the resource may not be available try { stats = filesystem.statSync(fullEntryPath); } catch (error) { // todo: this is testable and should be tested stats = { isFile: () => false, }; } if (stats.isFile()) { files.push({ filePath: fullEntryPath, fileContent: filesystem.readFileSync(fullEntryPath, 'utf8'), }); } } } } catch { } return files; }, new filesystem_js_1.FileSystemMap()); });