Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies and typescript version to latest #51

Merged
merged 11 commits into from
Feb 6, 2024
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "pnpm test",
"name": "Run tests and Debug",
"request": "launch",
"type": "node-terminal"
}
]
}
76 changes: 44 additions & 32 deletions dist/rules/no-internal-barrel-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ const rule = {
const { ignoredBarrelModules = [], requiredBarrelModules = [] } =
typeof maybeTsConfig === "string" && extraOpts
? {
ignoredBarrelModules:
extraOpts[OPTION_IGNORED_BARREL_MODULES] &&
resolvePathsOption(
extraOpts[OPTION_IGNORED_BARREL_MODULES],
maybeTsConfig
),
requiredBarrelModules:
extraOpts[OPTION_REQUIRED_BARREL_MODULES] &&
resolvePathsOption(
extraOpts[OPTION_REQUIRED_BARREL_MODULES],
maybeTsConfig
),
}
ignoredBarrelModules:
anmolshres98 marked this conversation as resolved.
Show resolved Hide resolved
extraOpts[OPTION_IGNORED_BARREL_MODULES] &&
resolvePathsOption(
extraOpts[OPTION_IGNORED_BARREL_MODULES],
maybeTsConfig
),
requiredBarrelModules:
extraOpts[OPTION_REQUIRED_BARREL_MODULES] &&
resolvePathsOption(
extraOpts[OPTION_REQUIRED_BARREL_MODULES],
maybeTsConfig
),
}
: {};

return {
Expand All @@ -141,6 +141,24 @@ const rule = {
return fileToImportPath(thisModule.fileName, fileOfExport.fileName);
}

/**
* @param {ts.SourceFile} sourceFile
* @param {string} moduleSpecifierText
* @returns {ts.ResolvedModuleFull | undefined}
*/
function getImportInfo(sourceFile, moduleSpecifierText) {
// For ts v5.3.0 and up `ts.getResolvedModule` was removed in https://github.com/microsoft/TypeScript/pull/55790 but was added to `ts.program` in https://github.com/microsoft/TypeScript/pull/55818
// Hence this check is needed to support all ts versions
return ts.getResolvedModule ? ts.getResolvedModule(
sourceFile,
moduleSpecifierText
) :
program.getResolvedModule(
sourceFile,
moduleSpecifierText
).resolvedModule;
}

if (typeof node.source.value !== "string")
throw Error("Invalid input source");

Expand All @@ -154,10 +172,7 @@ const rule = {

const thisModule = importNodeTs.getSourceFile();

const importInfo = ts.getResolvedModule(
thisModule,
importNodeTs.moduleSpecifier.text
);
const importInfo = getImportInfo(thisModule, importNodeTs.moduleSpecifier.text);

const importIsPackage =
importInfo === undefined || importInfo.isExternalLibraryImport;
Expand Down Expand Up @@ -224,10 +239,7 @@ const rule = {
child.moduleSpecifier !== undefined &&
!child.isTypeOnly;
if (!potentialReExport) return;
const transitiveImportInfo = ts.getResolvedModule(
importedModule,
child.moduleSpecifier.text
);
const transitiveImportInfo = getImportInfo(importedModule, child.moduleSpecifier.text);
const reExportsExternalPackage =
transitiveImportInfo === undefined ||
transitiveImportInfo.isExternalLibraryImport;
Expand All @@ -239,7 +251,7 @@ const rule = {
importNodeTs.importClause &&
importNodeTs.importClause.namedBindings &&
importNodeTs.importClause.namedBindings.kind ===
ts.SyntaxKind.NamespaceImport;
ts.SyntaxKind.NamespaceImport;

// there may be some situations where not reporting this is preferable
const isSideEffectImport =
Expand All @@ -256,8 +268,8 @@ const rule = {

const namedImports =
importNodeTs.importClause &&
importNodeTs.importClause.namedBindings &&
ts.isNamedImports(importNodeTs.importClause.namedBindings)
importNodeTs.importClause.namedBindings &&
ts.isNamedImports(importNodeTs.importClause.namedBindings)
? importNodeTs.importClause.namedBindings.elements
: [];

Expand Down Expand Up @@ -295,14 +307,14 @@ const rule = {
.map(
([importPath, namedImports], i) =>
// prettier-ignore
`${ i === 0 ? "" : "\n" /* separate all imported modules with a new line*/
}import { ${namedImports
.map(({ namedImport }) =>
namedImport.propertyName !== undefined
? `${namedImport.propertyName.escapedText} as ${namedImport.name.escapedText}`
: namedImport.name.escapedText
)
.join(", ")} } from "${importPath}";`
`${i === 0 ? "" : "\n" /* separate all imported modules with a new line*/
}import { ${namedImports
.map(({ namedImport }) =>
namedImport.propertyName !== undefined
? `${namedImport.propertyName.escapedText} as ${namedImport.name.escapedText}`
: namedImport.name.escapedText
)
.join(", ")} } from "${importPath}";`
)
.join("");
return fixer.replaceText(node, newImportStmtsText);
Expand Down
34 changes: 15 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,29 @@
"url": "http://www.bentley.com"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "~5.55.0",
"@typescript-eslint/parser": "~5.55.0",
"eslint-import-resolver-node": "0.3.4",
paulius-valiunas marked this conversation as resolved.
Show resolved Hide resolved
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-deprecation": "^1.4.1",
"eslint-plugin-import": "^2.27.5",
"@typescript-eslint/eslint-plugin": "~6.19.1",
"@typescript-eslint/parser": "~6.19.1",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jam3": "^0.2.3",
"eslint-plugin-jsdoc": "^43.2.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-jsdoc": "^48.0.3",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"workspace-tools": "^0.34.6"
"workspace-tools": "^0.36.4"
},
"peerDependencies": {
"eslint": "^8.36.0",
"eslint": "^8.56.0",
"typescript": "^3.7.0 || ^4.0.0 || ^5.0.0"
},
"devDependencies": {
"@types/eslint": "~7.2.14",
"@types/estree": "~0.0.52",
"@types/node": "^18.16.6",
aruniverse marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/typescript-estree": "~5.55.0",
"beachball": "^2.32.2",
"eslint": "^8.40.0",
"husky": "^8.0.3",
"@types/eslint": "~8.56.2",
"@types/node": "20.11.16",
"beachball": "^2.39.0",
"eslint": "^8.56.0",
"husky": "^9.0.5",
"mocha": "^10.2.0",
"typescript": "~5.0.4"
"typescript": "~5.3.3"
}
}
Loading
Loading