
เครื่องมือบรรทัดคำสั่งนี้ตรวจสอบไฟล์ XML ของคุณสำหรับการจัดรูปแบบที่เหมาะสม หากมีการจัดรูปแบบไม่ถูกต้องจะพิมพ์ความแตกต่างและออกด้วยข้อผิดพลาด คุณสามารถใช้สองวิธี: 1) เพื่อล้มเหลวในการสร้างของคุณหากไฟล์ XML-ish ใด ๆ (ตัวอย่างเช่น XML, XSD, XSL หรือ XHTML) ไม่ถูกจัดรูปแบบอย่างถูกต้องและ 2) เพื่อจัดรูปแบบอย่างถูกต้องโดยใช้ตัวเลือก --fix
อ่านโพสต์บล็อกนี้ก่อน: XCOP - ตัวตรวจสอบสไตล์ xml
ตรวจสอบให้แน่ใจว่าคุณติดตั้งทับทิมแล้วติดตั้งเครื่องมือ:
$ 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
หากสะอาดและคุณไม่เห็นข้อความแสดงข้อผิดพลาดใด ๆ ให้ส่งคำขอดึงของคุณ