Skip to content

Commit

Permalink
fix(linter): update circular file path message to wrap onto multiple …
Browse files Browse the repository at this point in the history
…lines (#9033)
  • Loading branch information
rpd10 committed Mar 4, 2022
1 parent c1ebe80 commit ecf6675
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -1198,7 +1198,10 @@ Circular file chain:
Circular file chain:
- libs/mylib/src/main.ts
- libs/badcirclelib/src/main.ts
- [libs/anotherlib/src/main.ts,libs/anotherlib/src/index.ts]`;
- [
libs/anotherlib/src/main.ts,
libs/anotherlib/src/index.ts
]`;
expect(failures.length).toEqual(2);
expect(failures[0].message).toEqual(message);
expect(failures[1].message).toEqual(message);
Expand Down
Expand Up @@ -302,6 +302,10 @@ export default createESLintRule<Options, MessageIds>({
if (circularPath.length !== 0) {
const circularFilePath = findFilesInCircularPath(circularPath);

// spacer text used for indirect dependencies when printing one line per file.
// without this, we can end up with a very long line that does not display well in the terminal.
const spacer = '\n ';

context.report({
node,
messageId: 'noCircularDependencies',
Expand All @@ -314,7 +318,9 @@ export default createESLintRule<Options, MessageIds>({
),
filePaths: circularFilePath
.map((files) =>
files.length > 1 ? `[${files.join(',')}]` : files[0]
files.length > 1
? `[${spacer}${files.join(`,${spacer}`)}\n ]`
: files[0]
)
.reduce(
(acc, files) => `${acc}\n- ${files}`,
Expand Down

0 comments on commit ecf6675

Please sign in to comment.