• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

HubSpot/prettier-maven-plugin

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

HubSpot/prettier-maven-plugin

开源软件地址(OpenSource Url):

https://github.com/HubSpot/prettier-maven-plugin

开源编程语言(OpenSource Language):

Java 99.9%

开源软件介绍(OpenSource Introduction):

prettier-maven-plugin

Maven plugin for running prettier-java during a build. Node, prettier, and prettier-java are bundled into the plugin.

There is a check goal which (optionally) fails the build if code isn't formatted correctly, and a write goal which rewrites the source code in place. A common setup might be to use the write goal during local builds, and the check goal during CI builds.

Example Usage

This example will run the check goal inside of Travis CI, and the write goal outside of Travis CI. You can update the profile activation conditions based on the CI tool you use.

<properties>
  <!-- By default just re-write code with prettier -->
  <plugin.prettier.goal>write</plugin.prettier.goal>
</properties>

<build>
  <plugins>
    <plugin>
      <groupId>com.hubspot.maven.plugins</groupId>
      <artifactId>prettier-maven-plugin</artifactId>
      <version>0.16</version>
      <configuration>
        <prettierJavaVersion>1.5.0</prettierJavaVersion>
        <printWidth>90</printWidth>
        <tabWidth>2</tabWidth>
        <useTabs>false</useTabs>
        <ignoreConfigFile>true</ignoreConfigFile>
        <ignoreEditorConfig>true</ignoreEditorConfig>
        <!-- Use <inputGlobs> to override the default input patterns -->
        <inputGlobs>
          <!-- These are the default patterns, you can omit <inputGlobs> entirely unless you want to override them -->
          <inputGlob>src/main/java/**/*.java</inputGlob>
          <inputGlob>src/test/java/**/*.java</inputGlob>
        </inputGlobs>
      </configuration>
      <executions>
        <execution>
          <phase>validate</phase>
          <goals>
            <goal>${plugin.prettier.goal}</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

<profiles>
  <profile>
    <id>travis</id>
    <activation>
      <property>
        <name>env.TRAVIS</name>
      </property>
    </activation>
    <properties>
      <!-- But in our CI environment we want to validate that code is formatted -->
      <plugin.prettier.goal>check</plugin.prettier.goal>
    </properties>
  </profile>
</profiles>

You can also run in a one-off fashion via the commandline:
mvn prettier:check
or
mvn prettier:write

You can also run mvn prettier:print-args in order to confirm the configuration values

To format additional directories or file types via the commandline, you can pass a comma-separated list of patterns, for example:
mvn prettier:write '-Dprettier.inputGlobs=src/main/java/**/*.java,src/test/java/**/*.java,src/main/js/**/*.js'

Configuration

If you want to customize the behavior of prettier, you can use a normal prettier configuration file. Alternatively, you can configure prettier directly via the Maven plugin using the following options:

Name -D property name Default Value Description
skip N/A false If set to true, plugin execution will be skipped
fail N/A true Only appplies to check goal. If set to true, the plugin execution will fail if any unformatted files are found
generateDiff N/A false Only appplies to check goal. Be sure to have to sh and diff in your PATH. If set to true, a diff will be generated between the current code and the prettier-formatted code.
diffGenerator prettier.diffGenerator _ Only appplies to check goal. Can be used to supply a custom implementation of DiffGenerator
nodeVersion prettier.nodeVersion 16.13.1 Controls version of Node used to run prettier-java.
nodePath prettier.nodePath - Can be used to supply your own node executable, rather than having the plugin download it. To use the version of node on your $PATH, you can simply set this option to node.
npmPath prettier.npmPath - Can be used to supply your own npm executable, rather than having the plugin download it. To use the version of npm on your $PATH, you can simply set this option to npm.
prettierJavaVersion prettier.prettierJavaVersion 0.7.0 Controls version of prettier-java that is used.
printWidth prettier.printWidth null If set, will be passed to prettier as --print-width. More information here
tabWidth prettier.tabWidth null If set, will be passed to prettier as --tab-width. More information here
useTabs prettier.useTabs null If set, will be passed to prettier as --use-tabs. More information here
endOfLine prettier.endOfLine null If set, will be passed to prettier as --end-of-line. More information here
ignoreConfigFile prettier.ignoreConfigFile false If set to true, pretter will be invoked with --no-config. More information here
ignoreEditorConfig prettier.ignoreEditorConfig false If set to true, pretter will be invoked with --no-editorconfig. More information here
inputGlobs prettier.inputGlobs src/{main,test}/java/**/*.java Controls the input paths passed to prettier, useful for formatting additional directories or file types. More information here

Note

For convenience, this plugin downloads Node, prettier, and prettier-java as needed. Node is downloaded from https://nodejs.org/dist/ and prettier-plugin-java is downloaded via npm




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap