From 0c870f6fb6bf4f35033afabc4dbd44eeafdc2e97 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 18 Jun 2021 18:41:02 +0100 Subject: [PATCH] feat(project): support ignore files for eslint and prettier (#1577) --- internal/project/constants.ts | 5 +++++ internal/project/load.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/project/constants.ts b/internal/project/constants.ts index 81596441df4..7ebd4e7512e 100644 --- a/internal/project/constants.ts +++ b/internal/project/constants.ts @@ -23,6 +23,11 @@ export const PRETTIER_CONFIG_FILESNAMES: string[] = [ ".prettierr.json5", ]; +export const INTEGRATIONS_IGNORE_FILES: string[] = [ + ".prettierignore", + ".eslintignore", +]; + export const PROJECT_CONFIG_PACKAGE_JSON_FIELD = "rome"; export const PROJECT_CONFIG_DIRECTORY = ".config"; export const PROJECT_CONFIG_FILENAMES: string[] = []; diff --git a/internal/project/load.ts b/internal/project/load.ts index 482d7a158bd..7fdf67388d5 100644 --- a/internal/project/load.ts +++ b/internal/project/load.ts @@ -31,6 +31,7 @@ import {CachedFileReader} from "@internal/fs"; import {parseSemverRange} from "@internal/codec-semver"; import {descriptions} from "@internal/diagnostics"; import { + INTEGRATIONS_IGNORE_FILES, PRETTIER_CONFIG_FILESNAMES, PROJECT_CONFIG_PACKAGE_JSON_FIELD, VCS_IGNORE_FILENAMES, @@ -119,6 +120,7 @@ export async function loadCompleteProjectConfig( // Load extensions configuration of prettier for (const prettierFile of PRETTIER_CONFIG_FILESNAMES) { const possiblePath = projectDirectory.append(prettierFile); + meta.configDependencies.add(possiblePath); if (await possiblePath.exists()) { const file = await reader.readFileText(possiblePath); const prettierConfig = loadPrettier(file, possiblePath.getExtensions()); @@ -129,6 +131,24 @@ export async function loadCompleteProjectConfig( } } + // read ignore files + for (const fileToIgnore of INTEGRATIONS_IGNORE_FILES) { + const possiblePath = projectDirectory.append(fileToIgnore); + meta.configDependencies.add(possiblePath); + if (await possiblePath.exists()) { + const file = await reader.readFileText(possiblePath); + + consumer.handleThrownDiagnostics(() => { + const patterns = parsePathPatternsFile({ + input: file, + path: possiblePath, + }); + + config.lint.ignore = [...config.lint.ignore, ...patterns]; + }); + } + } + // Calculate config hash keys await Promise.all( Array.from(