• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.buildtools.checkstyle;
17 
18 import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
19 import com.puppycrawl.tools.checkstyle.api.DetailAST;
20 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
21 import com.puppycrawl.tools.checkstyle.utils.AnnotationUtil;
22 
23 /**
24  * Checks if a class uses the @Ignore annotation. Avoid disabling tests and work to
25  * resolve issues with the test instead.
26  *
27  * For manual tests and exceptional circumstances, use the commentation feature CHECKSTYLE: OFF
28  * to mark a test as ignored.
29  */
30 public class NoIgnoreAnnotationsCheck extends AbstractCheck {
31 
32     private static final String IGNORE_ANNOTATION = "Ignore";
33 
34     @Override
getDefaultTokens()35     public int[] getDefaultTokens() {
36         return getRequiredTokens();
37     }
38 
39     @Override
getAcceptableTokens()40     public int[] getAcceptableTokens() {
41         return getRequiredTokens();
42     }
43 
44     @Override
getRequiredTokens()45     public int[] getRequiredTokens() {
46         return new int[] {TokenTypes.CLASS_DEF, TokenTypes.METHOD_DEF};
47     }
48 
49     @Override
visitToken(DetailAST ast)50     public void visitToken(DetailAST ast) {
51         if (!AnnotationUtil.containsAnnotation(ast, IGNORE_ANNOTATION)) {
52             return;
53         }
54 
55         log(ast, "@Ignore annotation is not allowed");
56     }
57 }
58