eslint-plugin-sonarjs
Version:
42 lines (41 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getManifestFileInDir = getManifestFileInDir;
exports.getParentDirPath = getParentDirPath;
/*
* 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 files_js_1 = require("../../files.js");
const closest_js_1 = require("../../find-up/closest.js");
/**
* Returns the manifest file at exactly `dir` (not a parent directory), or `undefined` if absent.
*/
function getManifestFileInDir(manifestName, dir, topDir, fileSystem) {
const file = closest_js_1.closestPatternCache.get(manifestName, fileSystem).get(topDir).get(dir);
if (file && (0, files_js_1.dirnamePath)(file.filePath) === dir) {
return file;
}
return undefined;
}
/**
* Get the parent directory of the given path.
* @param path Path to get the parent directory of.
* @returns The parent directory or `null` if it is the root directory.
*/
function getParentDirPath(path) {
const parentDir = (0, files_js_1.dirnamePath)(path);
return parentDir === path ? null : parentDir;
}