From da8144f443f62510063a158b2204b5c285a69daa Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Tue, 18 Apr 2023 17:32:55 +0200 Subject: [PATCH] fix(linter): fix files --- .../src/utils/module-federation/share.ts | 2 +- .../src/utils/module-federation/typescript.ts | 2 +- .../src/rules/enforce-module-boundaries.ts | 10 ++++---- .../eslint-plugin-nx/src/utils/ast-utils.ts | 2 +- .../eslint-rules/rules/restrict-nx-imports.ts | 24 +++++++------------ 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/devkit/src/utils/module-federation/share.ts b/packages/devkit/src/utils/module-federation/share.ts index 0c91a911665acb..4bcad24c1112c0 100644 --- a/packages/devkit/src/utils/module-federation/share.ts +++ b/packages/devkit/src/utils/module-federation/share.ts @@ -11,7 +11,7 @@ import { collectPackageSecondaryEntryPoints, collectWorkspaceLibrarySecondaryEntryPoints, } from './secondary-entry-points'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports +// eslint-disable-next-line @typescript-eslint/no-restricted-imports, @nrwl/nx/workspace/restrict-nx-imports import { getRootTsConfigPath } from 'nx/src/plugins/js/utils/typescript'; import type { ProjectGraph } from 'nx/src/config/project-graph'; import { requireNx } from '../../../nx'; diff --git a/packages/devkit/src/utils/module-federation/typescript.ts b/packages/devkit/src/utils/module-federation/typescript.ts index 8868312aee1eb2..9ed48e7c3e44dd 100644 --- a/packages/devkit/src/utils/module-federation/typescript.ts +++ b/packages/devkit/src/utils/module-federation/typescript.ts @@ -1,6 +1,6 @@ import { existsSync } from 'fs'; import { ParsedCommandLine } from 'typescript'; -// eslint-disable-next-line @typescript-eslint/no-restricted-imports +// eslint-disable-next-line @typescript-eslint/no-restricted-imports, @nrwl/nx/workspace/restrict-nx-imports import { getRootTsConfigPath } from 'nx/src/plugins/js/utils/typescript'; import { dirname } from 'path'; diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts index 7325d313c76f7b..9da65a2cc84aa9 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts @@ -360,9 +360,9 @@ export default createESLintRule({ relativePath === '' ? `./${basename(importPath)}` : joinPathFragments( - relativePath, - basename(importPath) - ); + relativePath, + basename(importPath) + ); importsToRemap.push({ member: importMember, @@ -445,8 +445,8 @@ export default createESLintRule({ .map((files) => files.length > 1 ? `[${files - .map((f) => `\n${spacer}${spacer}${f}`) - .join(',')}\n${spacer}]` + .map((f) => `\n${spacer}${spacer}${f}`) + .join(',')}\n${spacer}]` : files[0] ) .reduce( diff --git a/packages/eslint-plugin-nx/src/utils/ast-utils.ts b/packages/eslint-plugin-nx/src/utils/ast-utils.ts index 36f3d25ee439af..f3fe1d4d4e3ed4 100644 --- a/packages/eslint-plugin-nx/src/utils/ast-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/ast-utils.ts @@ -3,7 +3,7 @@ import { ProjectGraphProjectNode, readJsonFile, } from '@nx/devkit'; -import { findNodes } from 'nx/src/plugins/js/utils/typescript'; +import { findNodes } from '@nx/js'; import { existsSync, readFileSync } from 'fs'; import { dirname } from 'path'; import ts = require('typescript'); diff --git a/tools/eslint-rules/rules/restrict-nx-imports.ts b/tools/eslint-rules/rules/restrict-nx-imports.ts index 5a7b95eabac846..9646a2e2a403fe 100644 --- a/tools/eslint-rules/rules/restrict-nx-imports.ts +++ b/tools/eslint-rules/rules/restrict-nx-imports.ts @@ -36,10 +36,10 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({ messages: { noCircularNx: 'Functions within "nx" should be imported with relative path. Alias import found: {{imp}}', - noDeepImport: - 'Functions from "nx/src/plugins/js" should be imported via barrel import. Deep import found: {{imp}}', - noDeepRelativeImport: - 'Functions from "./plugins/js" should be imported via relative barrel import. Deep import found: {{imp}}', + noJsImport: + 'Functions from "nx/src/plugins/js" should be imported from "@nrwl/js". Direct import found: {{imp}}', + + // TODO add deep import check from non js to nx/src/plugins/js }, }, defaultOptions: [], @@ -62,25 +62,17 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({ return; } const imp = node.source.value as string; - if (imp.includes('nx/src/plugins/js/')) { - context.report({ - node, - messageId: 'noDeepImport', - data: { - imp, - }, - }); - } const fileName = normalizePath(context.getFilename()).slice( workspaceRoot.length + 1 ); + if ( - imp.includes('./plugins/js/') && - fileName.startsWith('packages/nx/') + imp.includes('nx/src/plugins/js/') && + !fileName.startsWith('packages/js/') ) { context.report({ node, - messageId: 'noDeepRelativeImport', + messageId: 'noJsImport', data: { imp, },