Skip to content

Commit

Permalink
fix: specify config file correctly
Browse files Browse the repository at this point in the history
`overrides` field in config file  did not work in the original implementation

BREAKING CHANGE:

- specify config file via filepath instead of directory
  • Loading branch information
ikatyang committed Sep 16, 2018
1 parent bd50395 commit a46bb9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<cwd>/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 `<cwd>/configs/.prettierrc`:

```json
{
"extends": ["tslint-plugin-prettier"],
"rules": {
"prettier": [true, "configs"]
"prettier": [true, "configs/.prettierrc"]
}
}
```
Expand Down
13 changes: 10 additions & 3 deletions src/prettierRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ class Walker extends tslint.AbstractWalker<any[]> {
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;
Expand Down
2 changes: 1 addition & 1 deletion tests/prettier/specified-config/tslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"rulesDirectory": ["../../../rules"],
"rules": {
"prettier": [true, "./fixtures/no-semi"]
"prettier": [true, "./fixtures/no-semi/.prettierrc"]
}
}

0 comments on commit a46bb9f

Please sign in to comment.