From 6785ef870430eac993a8c1849cd9683bc062554a Mon Sep 17 00:00:00 2001 From: Stefano Pongelli Date: Thu, 17 Aug 2023 10:53:48 +0200 Subject: [PATCH] fix(misc): format must exclude ignored patterns (#18568) `nx format` commands will now correctly ignore patterns defined in `.gitignore` or `.nxignore` --- packages/nx/src/command-line/format/format.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/command-line/format/format.ts b/packages/nx/src/command-line/format/format.ts index efa7c63a50ac6..540f91ffa2b41 100644 --- a/packages/nx/src/command-line/format/format.ts +++ b/packages/nx/src/command-line/format/format.ts @@ -6,6 +6,7 @@ import { parseFiles, splitArgsIntoNxArgsAndOverrides, } from '../../utils/command-line-utils'; +import { getIgnoreObject } from '../../utils/ignore'; import { fileExists, readJsonFile, writeJsonFile } from '../../utils/fileutils'; import { calculateFileChanges, FileData } from '../../project-graph/file-utils'; import * as yargs from 'yargs'; @@ -94,9 +95,16 @@ async function getPatterns( (f) => fileExists(f) && supportedExtensions.includes(path.extname(f)) ); + // exclude patterns in .nxignore or .gitignore + const nonIgnoredPatterns = getIgnoreObject().filter(patterns); + return args.libsAndApps - ? await getPatternsFromApps(patterns, await allFileData(), graph) - : patterns; + ? await getPatternsFromApps( + nonIgnoredPatterns, + await allFileData(), + graph + ) + : nonIgnoredPatterns; } catch { return allFilesPattern; }