CheckList { public static List<Class<? extends JavaScriptCheck>> getAllChecks() { return ImmutableList.of( AdjacentOverloadSignaturesCheck.class, AlertUseCheck.class, AlphabeticalSortCheck.class, AlwaysUseCurlyBracesCheck.class, AngleBracketTypeAssertionCheck.class, ArgumentsCallerCalleeUsageCheck.class, ArgumentsUsageCheck.class, ArgumentTypesCheck.class, ArithmeticOperationReturningNanCheck.class, ArrayConstructorsCheck.class, ArrayCallbackWithoutReturnCheck.class, ArrowFunctionConventionCheck.class, AssociativeArraysCheck.class, BackboneChangedIsUsedCheck.class, BitwiseOperatorsCheck.class, BooleanEqualityComparisonCheck.class, BoolParamDefaultCheck.class, BuiltInObjectOverriddenCheck.class, CallabilityCheck.class, ClassNameCheck.class, ClassPrototypeCheck.class, CognitiveComplexityFunctionCheck.class, CollapsibleIfStatementsCheck.class, CollectionSizeComparisonCheck.class, CommaOperatorInSwitchCaseCheck.class, CommaOperatorUseCheck.class, CommentedCodeCheck.class, CommentRegularExpressionCheck.class, ConditionalUnreachableCodeCheck.class, ContentLengthCheck.class, ConsistentReturnsCheck.class, ValuesNotConvertibleToNumbersCheck.class, ComparisonWithNaNCheck.class, ConditionalCommentCheck.class, ConditionalIndentationCheck.class, ConditionalOperatorCheck.class, ConsoleLoggingCheck.class, ConstructorFunctionsForSideEffectsCheck.class, ConstructorSuperCheck.class, ContinueStatementCheck.class, CookieNoHttpOnlyCheck.class, CookiesCheck.class, CorsCheck.class, CounterUpdatedInLoopCheck.class, CsrfCheck.class, CyclomaticComplexityJavaScriptCheck.class, CyclomaticComplexityTypeScriptCheck.class, DeadStoreCheck.class, DebuggerStatementCheck.class, DeclarationInGlobalScopeCheck.class, DefaultParameterSideEffectCheck.class, DefaultParametersNotLastCheck.class, DeleteNonPropertyCheck.class, DeprecatedJQueryAPICheck.class, DeprecationCheck.class, DestructuringAssignmentSyntaxCheck.class, DifferentTypesComparisonCheck.class, DuplicateAllBranchImplementationCheck.class, DuplicateBranchImplementationCheck.class, DuplicateConditionIfCheck.class, DuplicateFunctionArgumentCheck.class, DuplicatePropertyNameCheck.class, ElementTypeSelectorCheck.class, ElementUsedWithClassSelectorCheck.class, ElseIfWithoutElseCheck.class, EmptyBlockCheck.class, EmptyDestructuringPatternCheck.class, EmptyFunctionCheck.class, EmptyStatementCheck.class, EncryptionCheck.class, EncryptionSecureModeCheck.class, EqEqEqCheck.class, EqualInForLoopTerminationCheck.class, ErrorWithoutThrowCheck.class, EvalCheck.class, MaxParameterCheck.class, ExpressionComplexityCheck.class, FileHeaderCheck.class, FileNameDiffersFromClassCheck.class, FileUploadsCheck.class, FixmeTagPresenceCheck.class, ForHidingWhileCheck.class, ForInCheck.class, ForLoopConditionAndUpdateCheck.class, ForLoopIncrementSignCheck.class, FunctionCallArgumentsOnNewLineCheck.class, FunctionConstructorCheck.class, FunctionDeclarationsWithinBlocksCheck.class, FunctionDefinitionInsideLoopCheck.class, FunctionNameCheck.class, FutureReservedWordsCheck.class, FunctionReturnTypeCheck.class, GeneratorWithoutYieldCheck.class, GetterSetterCheck.class, GlobalThisCheck.class, HardcodedCredentialsCheck.class, HashingCheck.class, XPoweredByCheck.class, HiddenFilesCheck.class, HtmlCommentsCheck.class, IdChildrenSelectorCheck.class, IdenticalExpressionOnBinaryOperatorCheck.class, IdenticalFunctionsCheck.class, IfConditionalAlwaysTrueOrFalseCheck.class, ImmediatelyReturnedVariableCheck.class, ImplicitDependenciesCheck.class, InconsistentFunctionCallCheck.class, IncrementDecrementInSubExpressionCheck.class, IndexOfCompareToPositiveNumberCheck.class, InsecureCookieCheck.class, InsecureJwtTokenCheck.class, IgnoredReturnCheck.class, InOperatorTypeErrorCheck.class, InstanceofInMisuseCheck.class, InvariantReturnCheck.class, JQueryVarNameConventionCheck.class, JumpStatementInFinallyCheck.class, LabelledStatementCheck.class, LabelPlacementCheck.class, LineLengthCheck.class, LocalStorageCheck.class, LoopsShouldNotBeInfiniteCheck.class, MaxSwitchCasesCheck.class, MaxUnionSizeCheck.class, MisorderedParameterListCheck.class, MissingNewlineAtEndOfFileCheck.class, MissingTrailingCommaCheck.class, ModelDefaultsWithArrayOrObjectCheck.class, MultilineBlockCurlyBraceCheck.class, MultilineStringLiteralsCheck.class, NamedFunctionExpressionCheck.class, NestedAssignmentCheck.class, NestedConditionalOperatorsCheck.class, NestedControlFlowDepthCheck.class, NewOperatorMisuseCheck.class, NoAccessorFieldMismatchCheck.class, NoAnyCheck.class, NoArrayDeleteCheck.class, NoDuplicateImportsCheck.class, NoDuplicateInCompositeCheck.class, NoDuplicateStringCheck.class, NoElementOverwriteCheck.class, NoEmptyCollectionCheck.class, NoEmptyInterfaceCheck.class, NoForInArrayCheck.class, NoInferrableTypesCheck.class, NoInvalidAwaitCheck.class, NoInvertedBooleanCheckCheck.class, NoMisleadingArrayReverseCheck.class, NoNestedSwitchCheck.class, NoMagicNumbersCheck.class, NoRedundantJumpCheck.class, NoThisAliasCheck.class, NonCaseLabelInSwitchCheck.class, NonEmptyCaseWithoutBreakCheck.class, NonExistentAssignmentOperatorCheck.class, NonExistentPropertyAccessCheck.class, NoMisusedNewCheck.class, NonNumberInArithmeticExpressionCheck.class, NonStandardImportCheck.class, NoInMisuseCheck.class, NoSparseArraysCheck.class, NotStoredSelectionCheck.class, NoNonNullAssertionCheck.class, NoNestedTemplateLiteralsCheck.class, NoRedundantOptionalCheck.class, NoReturnAwaitCheck.class, NoReturnTypeAnyCheck.class, NoUnnecessaryTypeAssertionCheck.class, NoUselessCatchCheck.class, NoWeakKeysCheck.class, NullDereferenceCheck.class, NullDereferenceInConditionalCheck.class, ObjectLiteralShorthandCheck.class, OctalNumberCheck.class, OneStatementPerLineCheck.class, OpenCurlyBracesAtEOLCheck.class, OSCommandCheck.class, ParenthesesCheck.class, ParseIntCallWithoutBaseCheck.class, ParsingErrorCheck.class, PostMessageCheck.class, PreferForOfCheck.class, PreferNamespaceCheck.class, PreferObjectLiteralCheck.class, PreferPromiseShorthandCheck.class, PreferReadonlyCheck.class, PreferTypeGuardCheck.class, PrimitiveWrappersCheck.class, ProcessArgvCheck.class, PreferDefaultLastCheck.class, ProductionDebugCheck.class, PseudoRandomCheck.class, ReassignedParameterCheck.class, RedeclaredSymbolCheck.class, RestrictPlusOperandsCheck.class, GratuitousConditionCheck.class, RedundantAssignmentCheck.class, ReferenceErrorCheck.class, RegularExprCheck.class, ReturnInSetterCheck.class, ReturnOfBooleanExpressionCheck.class, SameLineConditionalCheck.class, SelectionTestedWithoutLengthCheck.class, SelfAssignmentCheck.class, SemicolonCheck.class, ShorthandPropertiesNotGroupedCheck.class, SocketsCheck.class, SpaceInModelPropertyNameCheck.class, SqlQueriesCheck.class, StandardInputCheck.class, StrictModeCheck.class, StringConcatenatedWithNonStringCheck.class, StringConcatenationCheck.class, StringLiteralsQuotesCheck.class, StringsComparisonCheck.class, SuperInvocationCheck.class, SwitchWithNotEnoughCaseCheck.class, SwitchWithoutDefaultCheck.class, SymbolUsedAsConstructorCheck.class, TabCharacterCheck.class, TemplateStringMisuseCheck.class, TodoTagPresenceCheck.class, TooManyArgumentsCheck.class, TooManyBreakOrContinueInLoopCheck.class, TooManyLinesInFileCheck.class, TooManyLinesInFunctionCheck.class, ThrowLiteralCheck.class, TrailingCommaCheck.class, TrailingCommentCheck.class, TrailingWhitespaceCheck.class, TryPromiseCheck.class, UnaryPlusMinusWithObjectCheck.class, UnchangedLetVariableCheck.class, NoOneIterationLoopCheck.class, UndefinedAssignmentCheck.class, GlobalsShadowingCheck.class, UndefinedArgumentCheck.class, UniversalSelectorCheck.class, UnnecessaryTypeArgumentsCheck.class, UnreachableCodeCheck.class, UntrustedContentCheck.class, UnusedCollectionCheck.class, UnusedFunctionArgumentCheck.class, UnusedImportCheck.class, UnusedVariableCheck.class, UnverifiedHostnameCheck.class, UpdatedConstVariableCheck.class, UselessExpressionStatementCheck.class, UselessIncrementCheck.class, UselessIntersectionCheck.class, UselessStringOperationCheck.class, UseOfEmptyReturnValueCheck.class, UseTypeAliasCheck.class, VarDeclarationCheck.class, VariableDeclarationAfterUsageCheck.class, VariableDeclarationWithoutVarCheck.class, VariableNameCheck.class, VariableShadowingCheck.class, VoidUseCheck.class, WebSQLDatabaseCheck.class, WildcardImportCheck.class, WithStatementCheck.class, WrongScopeDeclarationCheck.class, XMLParserXXEVulnerableCheck.class, XpathCheck.class, YieldOutsideGeneratorCheck.class); } private  CheckList(); static List<Class<? extends JavaScriptCheck>> getTypeScriptChecks(); static List<Class<? extends JavaScriptCheck>> getJavaScriptChecks(); static List<Class<? extends JavaScriptCheck>> getAllChecks(); static final String JS_REPOSITORY_KEY; static final String TS_REPOSITORY_KEY; static final String REPOSITORY_NAME; }
@Test public void count() { int count = 0; List<File> files = (List<File>) FileUtils.listFiles(new File("src/main/java/org/sonar/javascript/checks/"), new String[]{"java"}, false); for (File file : files) { String name = file.getName(); if (name.endsWith("Check.java") && !name.startsWith("Abstract")) { count++; } } assertThat(CheckList.getAllChecks().size()).isEqualTo(count); }
@Test public void test() { List<Class<? extends JavaScriptCheck>> checks = CheckList.getAllChecks(); for (Class<? extends JavaScriptCheck> cls : checks) { if (!cls.getSimpleName().equals("ParsingErrorCheck") && !isEslintBasedCheck(cls)) { String testName = '/' + cls.getName().replace('.', '/') + "Test.class"; assertThat(getClass().getResource(testName)) .overridingErrorMessage("No test for " + cls.getSimpleName()) .isNotNull(); } } List<String> keys = Lists.newArrayList(); List<Rule> rules = new AnnotationRuleParser().parse("repositoryKey", Collections.unmodifiableList(checks)); for (Rule rule : rules) { keys.add(rule.getKey()); assertThat(getClass().getResource("/org/sonar/l10n/javascript/rules/javascript/" + rule.getKey() + ".html")) .overridingErrorMessage("No description for " + rule.getKey()) .isNotNull(); assertThat(rule.getDescription()) .overridingErrorMessage("Description of " + rule.getKey() + " should be in separate file") .isNull(); } keys.remove("S3854"); keys.remove("S3402"); keys.remove("S3533"); keys.remove("S3863"); keys.remove("S1541"); assertThat(keys).doesNotHaveDuplicates(); }
@Test public void test_eslint_key() throws IllegalAccessException, InstantiationException { List<Class<? extends JavaScriptCheck>> checks = CheckList.getAllChecks(); List<String> keys = Lists.newArrayList(); for (Class<? extends JavaScriptCheck> cls : checks) { if (isEslintBasedCheck(cls)) { EslintBasedCheck eslintBasedCheck = (EslintBasedCheck) cls.newInstance(); keys.add(eslintBasedCheck.eslintKey()); assertThat(eslintBasedCheck.eslintKey()).matches("[a-z\\-]+"); } } keys.remove("cyclomatic-complexity"); assertThat(keys).doesNotHaveDuplicates(); }