Skip to content

Commit

Permalink
fix(linter): fix files
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 18, 2023
1 parent da674ce commit de1816d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/module-federation/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/module-federation/typescript.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ export default createESLintRule<Options, MessageIds>({
relativePath === ''
? `./${basename(importPath)}`
: joinPathFragments(
relativePath,
basename(importPath)
);
relativePath,
basename(importPath)
);

importsToRemap.push({
member: importMember,
Expand Down Expand Up @@ -445,8 +445,8 @@ export default createESLintRule<Options, MessageIds>({
.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(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-nx/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 3 additions & 8 deletions tools/eslint-rules/rules/restrict-nx-imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ruleTester = new TSESLint.RuleTester({
});

jest.mock('@nrwl/devkit', () => ({
...jest.requireActual<any>('@nrwl/devkit'),
normalizePath: (path: string) => path,
workspaceRoot: '/root',
}));

Expand All @@ -27,14 +27,9 @@ ruleTester.run(RULE_NAME, rule, {
],
invalid: [
{
errors: [{ messageId: 'noDeepImport' }],
errors: [{ messageId: 'noJsImport' }],
code: `import { createLockFile } from 'nx/src/plugins/js/lock-file/lock-file';`,
filename: '/root/packages/devkit/src/path/to.ts',
},
{
errors: [{ messageId: 'noDeepRelativeImport' }],
code: `import { createLockFile } from '../plugins/js/lock-file/lock-file';`,
filename: '/root/packages/nx/src/path/to.ts',
filename: '/root/packages/storybook/src/path/to.ts',
},
{
errors: [{ messageId: 'noCircularNx' }],
Expand Down
24 changes: 8 additions & 16 deletions tools/eslint-rules/rules/restrict-nx-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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,
},
Expand Down

0 comments on commit de1816d

Please sign in to comment.