eslint-plugin: refactor to fix issues uncovered by more strict parsing
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -36,8 +36,10 @@ const manypkg = require('@manypkg/get-packages');
|
||||
|
||||
// Loads all packages in the monorepo once, and caches the result
|
||||
module.exports = (function () {
|
||||
/** @type {PackageMap | undefined} */
|
||||
let result = undefined;
|
||||
let lastLoadAt = undefined;
|
||||
/** @type {number} */
|
||||
let lastLoadAt = 0;
|
||||
|
||||
/** @returns {PackageMap | undefined} */
|
||||
return function getPackages(/** @type {string} */ dir) {
|
||||
@@ -58,11 +60,9 @@ module.exports = (function () {
|
||||
list: packages.packages,
|
||||
root: packages.root,
|
||||
byPath(filePath) {
|
||||
return packages.packages.find(pkg => {
|
||||
if (!path.relative(pkg.dir, filePath).startsWith('..')) {
|
||||
return pkg;
|
||||
}
|
||||
});
|
||||
return packages.packages.find(
|
||||
pkg => !path.relative(pkg.dir, filePath).startsWith('..'),
|
||||
);
|
||||
},
|
||||
};
|
||||
lastLoadAt = Date.now();
|
||||
|
||||
@@ -56,12 +56,17 @@ const getPackages = require('./getPackages');
|
||||
|
||||
/**
|
||||
* @callback ImportVisitor
|
||||
* @param {import('eslint').Rule.Node} node
|
||||
* @param {ConsideredNode} node
|
||||
* @param {LocalImport | InternalImport | ExternalImport | BuiltinImport} import
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('estree').ImportDeclaration | import('estree').ExportAllDeclaration | import('estree').ExportNamedDeclaration | import('estree').ImportExpression | import('estree').SimpleCallExpression} node
|
||||
* @typedef ConsideredNode
|
||||
* @type {import('estree').ImportDeclaration | import('estree').ExportAllDeclaration | import('estree').ExportNamedDeclaration | import('estree').ImportExpression | import('estree').SimpleCallExpression}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {ConsideredNode} node
|
||||
* @returns {undefined | {path: string, kind: 'type' | 'value'}}
|
||||
*/
|
||||
function getImportInfo(node) {
|
||||
@@ -103,6 +108,9 @@ module.exports = function visitImports(context, visitor) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ConsideredNode} node
|
||||
*/
|
||||
function visit(node) {
|
||||
const info = getImportInfo(node);
|
||||
if (!info) {
|
||||
|
||||
Reference in New Issue
Block a user