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; }