diff --git a/README.md b/README.md index 9cd86034..a13b67c9 100644 --- a/README.md +++ b/README.md @@ -82,13 +82,13 @@ If there is no option provided, it'll try to load [config file](https://prettier } ``` -If you'd like to specify where to find the config file, just put the search path (relative to `process.cwd()`) in the second argument, the following example shows how to use the config file from `/configs/.prettierrc`: +If you'd like to specify which config file to use, just put its path (relative to `process.cwd()`) in the second argument, the following example shows how to load the config file from `/configs/.prettierrc`: ```json { "extends": ["tslint-plugin-prettier"], "rules": { - "prettier": [true, "configs"] + "prettier": [true, "configs/.prettierrc"] } } ``` diff --git a/src/prettierRule.ts b/src/prettierRule.ts index 9462f1b8..cdaa428e 100644 --- a/src/prettierRule.ts +++ b/src/prettierRule.ts @@ -23,12 +23,19 @@ class Walker extends tslint.AbstractWalker { options = ruleArgument1 as prettier.Options; break; case 'string': { - const filePath = path.resolve(process.cwd(), ruleArgument1 as string); - const resolvedConfig = prettier.resolveConfig.sync(filePath); + const configFilePath = path.resolve( + process.cwd(), + ruleArgument1 as string, + ); + + const resolvedConfig = prettier.resolveConfig.sync( + sourceFile.fileName, + { config: configFilePath }, + ); // istanbul ignore next if (resolvedConfig === null) { - throw new Error(`Config file not found: ${filePath}`); + throw new Error(`Config file not found: ${configFilePath}`); } options = resolvedConfig; diff --git a/tests/prettier/specified-config/tslint.json b/tests/prettier/specified-config/tslint.json index 78098054..ae3a31db 100644 --- a/tests/prettier/specified-config/tslint.json +++ b/tests/prettier/specified-config/tslint.json @@ -1,6 +1,6 @@ { "rulesDirectory": ["../../../rules"], "rules": { - "prettier": [true, "./fixtures/no-semi"] + "prettier": [true, "./fixtures/no-semi/.prettierrc"] } }