xcop
.xcop file with defaults

此命令行工具验证您的XML文件以进行正确的格式。如果未正确格式化,它将打印差异并带有错误。您可以使用两种方法:1)如果任何XML-ish文件(例如,XML,XSD,XSL或XHTML)未正确格式化,则无法正确格式化,而2)则使用--fix选项正确格式化它们。
首先阅读此博客文章: XCOP - XML样式检查器。
确保已安装Ruby,然后安装该工具:
$ gem install xcop在本地运行并读取其输出:
$ xcop --help要验证XML文件的格式,只需将其名称作为参数传递:
$ xcop file1.xml file2.xml如果您的文件未正确格式并且xcop抱怨,您可以要求它“美化”它们,使用--fix选项:
$ xcop --fix broken-file.xml要修复目录中的所有文件(如果您的文件名称包含空格,则无法使用):
$ xcop --fix $( find . -name ' *.xml ' ) 您可以将命令行选项放入启动xcop目录中的.xcop文件中。每个选项都应在文件中使用一行。它们都将添加到您指定的选项列表中。例如,正如这篇博客文章所建议的那样:
--license=LICENSE.txt
--nocolor
--quiet
--include=**/*
--exclude=**/*.xsl
--exclude=**/*.html
您还可以创建~/.xcop文件(在您的个人主目录中),该文件也将被读取并添加到命令行选项中。
Rakefile中使用?这就是您需要的:
require 'xcop/rake_task'
desc 'Run XCop on all XML/XSL files in all directories'
Xcop :: RakeTask . new ( :xcop ) do | task |
task . license = 'LICENSE.txt' # no license by default
task . quiet = true # FALSE by default
task . includes = [ '**/*.xml' , '**/*.xsl' ] # xml|xsd|xhtml|xsl|html by default
task . excludes = [ 'target/**/*' ] # empty by default
end 在.github/workflows/xcop.yml下在存储库中创建新的工作流文件:
---
name : XCOP
" on " :
# run on push to master events
push :
branches :
- master
# run on pull requests to master
pull_request :
branches :
- master
jobs :
build :
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v2
- uses : g4s8/xcop-action@master自定义许可位置或文件模式使用操作输入license和files :
- uses : g4s8/xcop-action@master
with :
license : MY_LICENSE.txt
files : " src/*.xml " pom.xml中使用?您可以在Maven-Antrun-Plugin的帮助下集成:
< project >
[...]
< build >
[...]
< plugins >
[...]
< plugin >
< artifactId >maven-antrun-plugin</ artifactId >
< version >1.8</ version >
< executions >
< execution >
< phase >verify</ phase >
< configuration >
< target >
< apply executable = " xcop " failonerror = " true " >
< arg value = " --license " />
< arg value = " LICENSE.txt " />
< fileset dir = " . " >
< include name = " **/*.xml " />
< include name = " **/*.xsd " />
< exclude name = " target/**/* " />
< exclude name = " .idea/**/* " />
</ fileset >
</ apply >
</ target >
</ configuration >
< goals >
< goal >run</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >
</ project >project.xml中使用?这样的事情应该有效:
< project >
[...]
< target name = " xcop " >
< apply executable = " xcop " failonerror = " true " >
< arg value = " --license " />
< arg value = " LICENSE.txt " />
< fileset dir = " . " >
< include name = " **/*.xml " />
< include name = " **/*.xsd " />
< exclude name = " target/**/* " />
< exclude name = " .idea/**/* " />
</ fileset >
</ apply >
</ target >
</ project >阅读这些准则。在提出拉动请求之前,请确保建造是绿色的。您将需要安装Ruby 2.3+和Bundler。然后:
$ bundle update
$ bundle exec rake
如果干净并且您看不到任何错误消息,请提交您的拉请请求。