gpt4 book ai didi

javascript - 使用 jshint 和 jenkins checkstyle-plugin 配置特定警告以报告错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:12 24 4
gpt4 key购买 nike

我正在使用 Jenkins 和 checkstyle-plugin和 JSHint。

我希望能够配置将特定警告报告为错误。显然我需要为 checkstyle 使用配置 xml 文件,但我已经搜索了这个文件但找不到它。

我已经完成了 source code但仍然不知道我需要把它放在哪里。

这是正确的做法吗?如果是这样,文件位置应该在哪里?

最佳答案

Checkstyle 不会由 Jenkins 本身启动 - Jenkins checkstyle 插件只会获取 checkstyle 运行的结果并将其集成到 Jenkins 显示的项目结果中。

在使用 Jenkins 时,大多数人会使用 maven、gradle、ant 等工具。对于 Maven(例如),您可以按如下方式定义 checkstyle 插件:

<reporting>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>checkstyle-config.xml</configLocation>
<checkstyleXmlOutput>true</checkstyleXmlOutput>
<checkstyleXmlOutputDirectory>target/site</checkstyleXmlOutputDirectory>
<xmlOutput>true</xmlOutput>
<failsOnError>false</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<excludes>**/module-info.java,**/package-info.java</excludes>
</configuration>
</plugin>

</plugins>
<//reporting>

我个人的 checkstyle-config.xml 看起来像(取决于我的个人需求):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning"/>

<module name="TreeWalker">
<!-- Annotations -->
<module name="AnnotationLocation"/>
<!-- <module name="AnnotationOnSameLine"/> -->
<module name="AnnotationUseStyle"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>
<module name="SuppressWarnings"/>
<module name="SuppressWarningsHolder"/>

<!-- Block Checks -->
<module name="AvoidNestedBlocks">
<property name="severity" value="warning"/>
</module>
<module name="EmptyBlock">
<property name="severity" value="warning"/>
<property name="option" value="text"/>
</module>
<module name="EmptyCatchBlock"/>
<module name="LeftCurly">
<property name="severity" value="warning"/>
<property name="option" value="nl"/>
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF"/>
</module>
<module name="NeedBraces">
<property name="severity" value="warning"/>
</module>
<module name="RightCurly">
<property name="severity" value="warning"/>
<property name="option" value="alone"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
</module>

<!-- Class Design -->
<module name="DesignForExtension"/>
<module name="FinalClass">
<property name="severity" value="warning"/>
</module>
<module name="HideUtilityClassConstructor">
<property name="severity" value="warning"/>
</module>
<module name="InnerTypeLast"/>
<module name="InterfaceIsType">
<property name="severity" value="warning"/>
</module>
<module name="MutableException"/>
<module name="OneTopLevelClass"/>
<module name="ThrowsCount">
<property name="max" value="6"/>
</module>
<module name="VisibilityModifier">
<property name="severity" value="warning"/>
</module>

<!-- Coding -->
<!-- <module name="ArrayTrailingComma"/> -->
<!-- <module name="AvoidInlineConditionals"/> -->
<module name="CovariantEquals"/>
<module name="DeclarationOrder"/>
<module name="DefaultComesLast"/>
<module name="EmptyStatement">
<property name="severity" value="warning"/>
</module>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode">
<property name="severity" value="warning"/>
</module>
<module name="ExplicitInitialization"/>
<module name="FallThrough"/>
<module name="FinalLocalVariable"/>
<module name="HiddenField">
<property name="severity" value="warning"/>
<property name="ignoreConstructorParameter" value="true"/>
<property name="ignoreSetter" value="true"/>
<property name="setterCanReturnItsClass" value="true"/>
</module>
<!-- TODO Enable later
<module name="IllegalCatch"/>
-->
<module name="IllegalInstantiation">
<property name="classes" value="java.lang.Boolean"/>
</module>
<module name="IllegalThrows"/>
<module name="IllegalToken"/>
<module name="IllegalTokenText"/>
<module name="IllegalType"/>
<module name="InnerAssignment">
<property name="severity" value="warning"/>
</module>
<!-- TODO Enable later
<module name="MagicNumber">
<property name="severity" value="warning"/>
</module>
-->
<!-- <module name="MissingCtor"/> -->
<module name="MissingSwitchDefault">
<property name="severity" value="warning"/>
</module>
<module name="ModifiedControlVariable"/>
<!-- TODO Enable later
<module name="MultipleStringLiterals"/>
-->
<module name="MultipleVariableDeclarations"/>
<module name="NestedForDepth">
<property name="max" value="3"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="4"/>
</module>
<module name="NestedTryDepth">
<property name="max" value="2"/>
</module>
<module name="NoClone"/>
<module name="NoFinalizer"/>
<module name="OneStatementPerLine"/>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="PackageDeclaration"/>
<module name="ParameterAssignment"/>
<!-- <module name="RequireThis"/> -->
<module name="ReturnCount">
<property name="max" value="7"/>
<!-- <property name="maxForVoid" value="2"/> -->
</module>
<module name="SimplifyBooleanExpression">
<property name="severity" value="warning"/>
</module>
<module name="SimplifyBooleanReturn">
<property name="severity" value="warning"/>
</module>
<module name="StringLiteralEquality"/>
<module name="SuperClone"/>
<module name="SuperFinalize"/>
<!-- <module name="UnnecessaryParentheses"/> -->
<module name="VariableDeclarationUsageDistance"/>

<!-- Imports -->
<module name="AvoidStarImport">
<property name="severity" value="warning"/>
</module>
<!-- <module name="AvoidStaticImport"/> -->
<!-- <module name="CustomImportOrder"/> -->
<module name="IllegalImport">
<property name="severity" value="warning"/>
</module>
<!-- <module name="ImportControl"/> -->
<!-- <module name="ImportOrder"/> -->
<module name="RedundantImport">
<property name="severity" value="warning"/>
</module>
<module name="UnusedImports">
<property name="severity" value="warning"/>
</module>

<!-- Javadoc Comments -->
<module name="AtclauseOrder"/>
<module name="JavadocMethod">
<property name="severity" value="warning"/>
</module>
<!-- <module name="JavadocParagraph"/> -->
<!-- <module name="JavadocStyle"/> -->
<!-- <module name="JavadocTagContinuationIndentation"/> -->
<module name="JavadocType">
<property name="severity" value="warning"/>
</module>
<module name="JavadocVariable">
<property name="severity" value="warning"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="SingleLineJavadoc"/>
<module name="SummaryJavadocCheck"/>
<!-- <module name="WriteTag"/> -->

<!-- Metrics -->
<!-- <module name="BooleanExpressionComplexity"/> -->
<!-- <module name="ClassDataAbstractionCoupling"/> -->
<!-- <module name="ClassFanOutComplexity"/> -->
<!-- <module name="CyclomaticComplexity"/> -->
<!-- <module name="JavaNCSS"/> -->
<!-- <module name="NPathComplexity"/> -->

<!-- Miscellaneous -->
<module name="ArrayTypeStyle">
<property name="severity" value="warning"/>
</module>
<module name="AvoidEscapedUnicodeCharacters"/>
<module name="CommentsIndentation"/>
<!-- <module name="DescendantToken"/> -->
<module name="FinalParameters">
<property name="tokens" value="METHOD_DEF,CTOR_DEF,LITERAL_CATCH"/>
</module>
<!-- TODO
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="1"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="2"/>
<property name="arrayInitIndent" value="2"/>
<property name="lineWrappingIndentation" value="2"/>
</module>
-->
<module name="OuterTypeFilename"/>
<!--
<module name="TodoComment">
<property name="severity" value="warning"/>
</module>
-->
<!--
<module name="TrailingComment"/>
-->
<module name="UncommentedMain"/>
<module name="UpperEll">
<property name="severity" value="warning"/>
</module>

<!-- Modifiers -->
<module name="ModifierOrder">
<property name="severity" value="warning"/>
</module>
<module name="RedundantModifier">
<property name="severity" value="warning"/>
</module>

<!-- Naming Conventions -->
<!-- <module name="AbbreviationAsWordInName"/> -->
<module name="AbstractClassName"/>
<module name="CatchParameterName"/>
<module name="ClassTypeParameterName"/>
<module name="ConstantName">
<property name="severity" value="warning"/>
</module>
<module name="InterfaceTypeParameterName"/>
<module name="LocalFinalVariableName">
<property name="severity" value="warning"/>
</module>
<module name="LocalVariableName">
<property name="severity" value="warning"/>
</module>
<module name="MemberName">
<property name="severity" value="warning"/>
</module>
<module name="MethodName">
<property name="severity" value="warning"/>
</module>
<module name="MethodTypeParameterName"/>
<module name="PackageName">
<property name="severity" value="warning"/>
</module>
<module name="ParameterName">
<property name="severity" value="warning"/>
</module>
<module name="StaticVariableName">
<property name="severity" value="warning"/>
</module>
<module name="TypeName">
<property name="severity" value="warning"/>
</module>

<!-- Regexp -->
<!-- <module name="Regexp"/> -->
<!-- <module name="RegexpSinglelineJava"/> -->

<!-- Size Violations -->
<module name="AnonInnerLength">
<property name="max" value="100"/>
</module>
<!-- <module name="ExecutableStatementCount"/> -->
<module name="LineLength">
<property name="severity" value="warning"/>
<property name="max" value="3100"/>
</module>
<module name="MethodCount">
<property name="maxTotal" value="110"/>
<property name="maxPublic" value="110"/>
</module>
<module name="MethodLength">
<property name="severity" value="warning"/>
<property name="max" value="260"/>
</module>
<module name="OuterTypeNumber"/>
<module name="ParameterNumber">
<property name="severity" value="warning"/>
<property name="max" value="31"/>
</module>

<!-- Whitespace -->
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad">
<property name="severity" value="warning"/>
</module>
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
<property name="tokens" value="IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoLineWrap">
<property name="tokens" value="IMPORT, PACKAGE_DEF"/> <!-- TODO , STATIC_IMPORT -->
</module>
<module name="NoWhitespaceAfter">
<property name="severity" value="warning"/>
<property name="tokens" value="ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, TYPECAST, ARRAY_DECLARATOR, INDEX_OP"/> <!-- TODO , AT, METHOD_REF -->
</module>
<module name="NoWhitespaceBefore">
<property name="severity" value="warning"/>
<property name="tokens" value="COMMA, SEMI, POST_INC, POST_DEC, DOT, GENERIC_START, GENERIC_END"/> <!-- TODO , ELLIPSIS, METHOD_REF -->
</module>
<module name="OperatorWrap">
<property name="severity" value="warning"/>
<property name="tokens" value=""/>
</module>
<module name="ParenPad">
<property name="severity" value="warning"/>
<property name="tokens" value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL"/> <!-- TODO , LAMBDA, DOT -->
</module>
<module name="SeparatorWrap">
<property name="option" value="eol"/>
<property name="tokens" value=""/>
</module>
<!-- TODO
<module name="SingleSpaceSeparator"/>
-->
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter">
<property name="severity" value="warning"/>
</module>
<module name="WhitespaceAround">
<property name="severity" value="warning"/>
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,TYPE_EXTENSION_AND"/>
</module>

</module>

<!-- Headers -->
<module name="RegexpHeader">
<property name="header" value="^/\*\n \* Copyright \(C\) (\d\d\d\d)(-(\d\d\d\d))?(,(\d\d\d\d)(-(\d\d\d\d))?)* Dipl.-Inform. Kai Hofmann. All rights reserved!\n \*/$"/>
<property name="fileExtensions" value="java"/>
</module>

<!-- Javadocs -->
<!-- <module name="JavadocPackage"/> -->

<!-- Misc -->
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
<property name="fileExtensions" value="java,xml,dtd,properties,txt"/>
</module>
<module name="Translation"/>
<module name="UniqueProperties"/>

<!-- Regexp -->
<!-- <module name="RegexpMultiline"/> -->
<!-- <module name="RegexpOnFilename"/> -->
<!-- <module name="RegexpSingleline"/> -->

<!-- Size violations -->
<module name="FileLength">
<property name="severity" value="warning"/>
<property name="max" value="20000"/>
</module>

<!-- Whitespace -->
<module name="FileTabCharacter">
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java,xml,dtd"/>
</module>

</module>

此外,我正在使用具有以下阶段的 Jenkinsfile(声明性管道)通过 Maven 启动检查样式:

stage('Sanity check')
{
steps
{
script
{
if (isUnix())
{
sh 'mvn --batch-mode checkstyle:checkstyle'
}
else
{
bat 'mvn --batch-mode checkstyle:checkstyle'
}
}
}
}

要嵌入 JSHint,请查看 How to configure JSHint with maven

关于javascript - 使用 jshint 和 jenkins checkstyle-plugin 配置特定警告以报告错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30089047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com