Skip to content

Commit bf16cab

Browse files
committed
update documentation for tsfmt config file part
and fix implementation to handle special case `editorconfig`.
1 parent f817309 commit bf16cab

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

plugin-gradle/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,18 @@ set the `target` parameter as described in the [Custom rules](#custom) section.
307307
spotless {
308308
typescript {
309309
// using existing config files
310-
tsfmt().configFile(['basedir': '/path/to/repo', 'tslint': true, 'tslintFile', '/path/to/repo/tslint.json'])
310+
tsfmt().configFile('tslint', '/path/to/repo/tslint.json')
311311
}
312312
}
313313
```
314-
*Please note:* The auto-discovery of config files (up the file tree) will not work when using prettier within spotless,
314+
Supported config file types are the ones supported by [tsfmt config options](https://github.com/vvakame/typescript-formatter/blob/7764258ad42ac65071399840d1b8701868510ca7/lib/index.ts#L26).
315+
Use the option names of type boolean in the tsfmt config object: `tsconfig`, `tslint`, `editorconfig`, `vscode` or `tsfmt`. For the option `editorconfig`, no path is supported.
316+
317+
*Please note:*
318+
- The auto-discovery of config files (up the file tree) will not work when using prettier within spotless,
315319
hence you are required to provide absolute file paths for config files.
320+
- The config file type `editorconfig` is only read from its default location (the user'home).
321+
Any value you pass for the path will be ignored.
316322

317323
... or alternatively provide the configuration inline ...
318324

@@ -387,7 +393,7 @@ spotless {
387393
```
388394

389395
Supported config file variants are documented on [prettier.io](https://prettier.io/docs/en/configuration.html).
390-
Please note:
396+
*Please note:*
391397
- The auto-discovery of config files (up the file tree) will not work when using prettier within spotless.
392398
- Prettier's override syntax is not supported when using prettier within spotless.
393399

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public TypescriptFormatExtension config(Map<String, Object> config) {
5858

5959
public TypescriptFormatExtension configFile(String filetype, String path) {
6060
this.configFileType = requireNonNull(filetype);
61-
this.configFilePath = requireNonNull(path);
61+
this.configFilePath = path; // might be null for 'editorconfig'
6262
replaceStep(createStep());
6363
return this;
6464
}
6565

6666
public FormatterStep createStep() {
6767
final Project project = getProject();
6868

69-
Map<String, Object> tsFmtCliOptions = craeateTsFmtCliOptions();
69+
Map<String, Object> tsFmtCliOptions = createTsFmtCliOptions();
7070

7171
return TsFmtFormatterStep.create(
7272
GradleProvisioner.fromProject(project),
@@ -76,11 +76,13 @@ public FormatterStep createStep() {
7676
config);
7777
}
7878

79-
private Map<String, Object> craeateTsFmtCliOptions() {
79+
private Map<String, Object> createTsFmtCliOptions() {
8080
Map<String, Object> tsFmtConfig = new TreeMap<>();
81-
if (!Strings.isNullOrEmpty(this.configFileType) && !Strings.isNullOrEmpty(this.configFilePath)) {
81+
if (!Strings.isNullOrEmpty(this.configFileType)) {
8282
tsFmtConfig.put(this.configFileType, Boolean.TRUE);
83-
tsFmtConfig.put(this.configFileType + "File", this.configFilePath);
83+
if (!Strings.isNullOrEmpty(this.configFilePath) && !this.configFileType.equals("editorconfig")) {
84+
tsFmtConfig.put(this.configFileType + "File", this.configFilePath);
85+
}
8486
}
8587
tsFmtConfig.put("basedir", getProject().getRootDir().getAbsolutePath()); //by default we use our project dir
8688
return tsFmtConfig;

0 commit comments

Comments
 (0)