-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsfmt maven plugin #553
Merged
Merged
tsfmt maven plugin #553
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ed9612b
Add Typescript Tsfmt to Maven Plugin
source-knights 0e429a5
Update README.md
source-knights bb72ebd
Update README to include tsfmt maven plugin
source-knights ae05010
Update CHANGES.md
source-knights 588990a
Update CHANGES.md
source-knights e973a2e
Fix unit test, correct xml end tag
source-knights 2ebe163
Spotless apply
source-knights 6a71794
Merge branch 'master' of https://github.com/source-knights/spotless
source-knights 588aa43
Spotless apply
source-knights 528e708
Merge branch 'master' into master
nedtwigg 811c661
Make the Typescript defaults a little less expensive to compute, and …
nedtwigg 90a1870
Condense the typescript docs for plugin-maven.
nedtwigg 97beb15
DRY on test files - reveals that tsfmtInline and tsconfig are both no…
nedtwigg 8c10f56
Make it easier to run single maven-plugin tests from the IDE.
nedtwigg 7bd2220
Fix warning about -color
nedtwigg e9da142
Fix types in the inline config.
nedtwigg 2641254
Fix buildDir going into Tsfmt
source-knights 9ac7a49
Fix tsconfig file
source-knights 33b13f6
spotless apply
source-knights 80cc770
Fix issue with FileLocator and tsconfig file
source-knights daff537
spotless apply
source-knights 839bcbd
spotless apply
source-knights 56ddfcb
add tsconfig test to plugin gradle
source-knights 5593769
Make the buildDir a non-optional part of FileLocator.
nedtwigg 5f4bbfa
Give FileLocator an in-place locator capability.
nedtwigg 6d21884
Make the gradle tests use the same test files as the maven and lib te…
nedtwigg 9567b07
Remove @Nullable from the maven plugin.
nedtwigg 2f77a77
Revert all ned's commits since the last good commit by @source-knights
nedtwigg 3d791da
Put the baseDir into FileLocator, and ensure that names match their "…
nedtwigg f5d9e07
Make the gradle tests use the same test files as the maven and lib te…
nedtwigg 7d21bf4
Extracted `Tsfmt.locateFile` into `Tsfmt.locateLocal`.
nedtwigg 1bb33d6
Remove maven-plugin info from the lib changelog.
nedtwigg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.typescript; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import com.diffplug.spotless.FormatterStep; | ||
import com.diffplug.spotless.maven.FormatterStepConfig; | ||
import com.diffplug.spotless.maven.FormatterStepFactory; | ||
import com.diffplug.spotless.npm.TsConfigFileType; | ||
import com.diffplug.spotless.npm.TsFmtFormatterStep; | ||
import com.diffplug.spotless.npm.TypedTsFmtConfigFile; | ||
|
||
public class Tsfmt implements FormatterStepFactory { | ||
|
||
@Parameter | ||
private String tslintFile; | ||
|
||
@Parameter | ||
private String tsconfigFile; | ||
|
||
@Parameter | ||
private String vscodeFile; | ||
|
||
@Parameter | ||
private String tsfmtFile; | ||
|
||
@Parameter | ||
private String typescriptFormatterVersion; | ||
|
||
@Parameter | ||
private String typescriptVersion; | ||
|
||
@Parameter | ||
private String tslintVersion; | ||
|
||
@Parameter | ||
private String npmExecutable; | ||
|
||
@Parameter | ||
private Map<String, Object> config; | ||
|
||
@Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true) | ||
private File buildDir; | ||
|
||
@Override | ||
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { | ||
|
||
Map<String, String> devDependencies = TsFmtFormatterStep.defaultDevDependencies(); | ||
if (typescriptFormatterVersion != null) { | ||
devDependencies.put("typescript-formatter", typescriptFormatterVersion); | ||
} | ||
if (typescriptVersion != null) { | ||
devDependencies.put("typescript", typescriptVersion); | ||
} | ||
if (tslintVersion != null) { | ||
devDependencies.put("tslint", tslintVersion); | ||
} | ||
|
||
File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; | ||
|
||
TypedTsFmtConfigFile configFile = null; | ||
|
||
// check that there is only 1 config file or inline config | ||
if (this.tsconfigFile != null | ||
^ this.tsfmtFile != null | ||
^ this.tslintFile != null | ||
^ this.vscodeFile != null) { | ||
if (this.tsconfigFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSCONFIG, stepConfig.getFileLocator().locateFile(tsconfigFile)); | ||
} else if (this.tsfmtFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSFMT, stepConfig.getFileLocator().locateFile(tsfmtFile)); | ||
} else if (this.tslintFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSLINT, stepConfig.getFileLocator().locateFile(tslintFile)); | ||
} else if (this.vscodeFile != null) { | ||
configFile = new TypedTsFmtConfigFile(TsConfigFileType.VSCODE, stepConfig.getFileLocator().locateFile(vscodeFile)); | ||
} | ||
} else { | ||
if (config == null) { | ||
throw new IllegalArgumentException("must specify exactly one configFile or config"); | ||
} | ||
} | ||
|
||
if (buildDir == null) { | ||
buildDir = new File("."); | ||
} | ||
return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npm, configFile, config); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2016 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless.maven.typescript; | ||
|
||
import java.util.Set; | ||
|
||
import com.diffplug.common.collect.ImmutableSet; | ||
import com.diffplug.spotless.maven.FormatterFactory; | ||
|
||
/** | ||
* A {@link FormatterFactory} implementation that corresponds to {@code <typescript>...</typescript>} configuration element. | ||
* <p> | ||
* It defines a formatter for typescript source files. | ||
*/ | ||
public class Typescript extends FormatterFactory { | ||
|
||
private static final Set<String> DEFAULT_INCLUDES = ImmutableSet.of("src/**/*.ts"); | ||
|
||
private static final String LICENSE_HEADER_DELIMITER = null; | ||
|
||
@Override | ||
public Set<String> defaultIncludes() { | ||
return DEFAULT_INCLUDES; | ||
} | ||
|
||
@Override | ||
public String licenseHeaderDelimiter() { | ||
return LICENSE_HEADER_DELIMITER; | ||
} | ||
|
||
public void addTsfmt(Tsfmt tsfmt) { | ||
addStepFactory(tsfmt); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean by "buildDir" default. It appears to not actually be readonly, and it also appears that the default does not work. One solution is for the "buildDir" to be just a regular nullable parameter, since it seems that's how you're actually using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was put in due to the tsftmt step formatter wants to have the build dir. In the Gradle impl that seems to be easier, but here in the Maven this seems to be the way. At least that Parameter(defaultValue = "${project.build.directory}" is used somewhere else (and seems to work with all the tests, except maybe the tsconfig test).
I still think the error message with tsconfig is missleading, cause when I looked at it, it was actually mentioning the found file name of the test.ts, so it does not really seem to be an error with missing inputs.
No time to look at this right now, maybe tomorrow. Thx @nedtwigg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. My assertion is that
defaultValue
has no effect, because later on you say "if buildDir is null then set it to some default value". That logic, of setting a default value if it is null, is fine. My objection, perhaps mistaken, is that the parameter annotation is claiming to magically set a default value, but it isn't working. So if it isn't working, it shouldn't be there.If there are other instances like this in the codebase, then I think they are broken too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm skeptical that
new File(".")
will work well as a default value for multiproject setups, but I'm willing to merge and ship this and wait for someone to have a problem and then we can worry about fixing it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will get null if you start this without a maven/gradle setup (e.g. in a unit test straight in IDE). Therefore I set the ".". But might be wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried deleting it, and I saw failures in the maven integration tests, which run using "real maven".