katoikia-app/web-ui/web-react/node_modules/eslint-plugin-import/lib/rules/no-useless-path-segments.js

151 lines
16 KiB
JavaScript

'use strict';
var _ignore = require('eslint-module-utils/ignore');
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');
var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _resolve = require('eslint-module-utils/resolve');
var _resolve2 = _interopRequireDefault(_resolve);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* convert a potentially relative path from node utils into a true
* relative path.
*
* ../ -> ..
* ./ -> .
* .foo/bar -> ./.foo/bar
* ..foo/bar -> ./..foo/bar
* foo/bar -> ./foo/bar
*
* @param relativePath {string} relative posix path potentially missing leading './'
* @returns {string} relative posix path that always starts with a ./
**/
function toRelativePath(relativePath) {
const stripped = relativePath.replace(/\/$/g, ''); // Remove trailing /
return (/^((\.\.)|(\.))($|\/)/.test(stripped) ? stripped : `./${stripped}`
);
} /**
* @fileOverview Ensures that there are no useless path segments
* @author Thomas Grainger
*/
function normalize(fn) {
return toRelativePath(_path2.default.posix.normalize(fn));
}
function countRelativeParents(pathSegments) {
return pathSegments.reduce((sum, pathSegment) => pathSegment === '..' ? sum + 1 : sum, 0);
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-useless-path-segments')
},
fixable: 'code',
schema: [{
type: 'object',
properties: {
commonjs: { type: 'boolean' },
noUselessIndex: { type: 'boolean' }
},
additionalProperties: false
}]
},
create(context) {
const currentDir = _path2.default.dirname(context.getFilename());
const options = context.options[0];
function checkSourceValue(source) {
const importPath = source.value;
function reportWithProposedPath(proposedPath) {
context.report({
node: source,
// Note: Using messageIds is not possible due to the support for ESLint 2 and 3
message: `Useless path segments for "${importPath}", should be "${proposedPath}"`,
fix: fixer => proposedPath && fixer.replaceText(source, JSON.stringify(proposedPath))
});
}
// Only relative imports are relevant for this rule --> Skip checking
if (!importPath.startsWith('.')) {
return;
}
// Report rule violation if path is not the shortest possible
const resolvedPath = (0, _resolve2.default)(importPath, context);
const normedPath = normalize(importPath);
const resolvedNormedPath = (0, _resolve2.default)(normedPath, context);
if (normedPath !== importPath && resolvedPath === resolvedNormedPath) {
return reportWithProposedPath(normedPath);
}
const fileExtensions = (0, _ignore.getFileExtensions)(context.settings);
const regexUnnecessaryIndex = new RegExp(`.*\\/index(\\${Array.from(fileExtensions).join('|\\')})?$`);
// Check if path contains unnecessary index (including a configured extension)
if (options && options.noUselessIndex && regexUnnecessaryIndex.test(importPath)) {
const parentDirectory = _path2.default.dirname(importPath);
// Try to find ambiguous imports
if (parentDirectory !== '.' && parentDirectory !== '..') {
for (let fileExtension of fileExtensions) {
if ((0, _resolve2.default)(`${parentDirectory}${fileExtension}`, context)) {
return reportWithProposedPath(`${parentDirectory}/`);
}
}
}
return reportWithProposedPath(parentDirectory);
}
// Path is shortest possible + starts from the current directory --> Return directly
if (importPath.startsWith('./')) {
return;
}
// Path is not existing --> Return directly (following code requires path to be defined)
if (resolvedPath === undefined) {
return;
}
const expected = _path2.default.relative(currentDir, resolvedPath); // Expected import path
const expectedSplit = expected.split(_path2.default.sep); // Split by / or \ (depending on OS)
const importPathSplit = importPath.replace(/^\.\//, '').split('/');
const countImportPathRelativeParents = countRelativeParents(importPathSplit);
const countExpectedRelativeParents = countRelativeParents(expectedSplit);
const diff = countImportPathRelativeParents - countExpectedRelativeParents;
// Same number of relative parents --> Paths are the same --> Return directly
if (diff <= 0) {
return;
}
// Report and propose minimal number of required relative parents
return reportWithProposedPath(toRelativePath(importPathSplit.slice(0, countExpectedRelativeParents).concat(importPathSplit.slice(countImportPathRelativeParents + diff)).join('/')));
}
return (0, _moduleVisitor2.default)(checkSourceValue, options);
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyY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