From e5a2baf30f5f56ecc8d9f58954d9db59e96e384e Mon Sep 17 00:00:00 2001 From: Casey Vega Date: Tue, 21 Jul 2020 12:25:42 -0700 Subject: [PATCH 1/5] add dart template --- TEMPLATES/analysis_options.yaml | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 TEMPLATES/analysis_options.yaml diff --git a/TEMPLATES/analysis_options.yaml b/TEMPLATES/analysis_options.yaml new file mode 100644 index 00000000..0c444f44 --- /dev/null +++ b/TEMPLATES/analysis_options.yaml @@ -0,0 +1,57 @@ +--- +########################## +########################## +## Dart Linter rules ## +########################## +########################## + +# Pedantic Rules +# https://github.com/dart-lang/pedantic + +linter: + rules: + - always_declare_return_types + - always_require_non_null_named_parameters + - annotate_overrides + - avoid_empty_else + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_relative_lib_imports + - avoid_return_types_on_setters + - avoid_shadowing_type_parameters + - avoid_types_as_parameter_names + - camel_case_extensions + - curly_braces_in_flow_control_structures + - empty_catches + - empty_constructor_bodies + - library_names + - library_prefixes + - no_duplicate_case_values + - null_closures + - omit_local_variable_types + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_contains + - prefer_equal_for_default_values + - prefer_final_fields + - prefer_for_elements_to_map_fromIterable + - prefer_generic_function_type_aliases + - prefer_if_null_operators + - prefer_is_empty + - prefer_is_not_empty + - prefer_iterable_whereType + - prefer_single_quotes + - prefer_spread_collections + - recursive_getters + - slash_for_doc_comments + - type_init_formals + - unawaited_futures + - unnecessary_const + - unnecessary_new + - unnecessary_null_in_if_null_operators + - unnecessary_this + - unrelated_type_equality_checks + - use_function_type_syntax_for_parameters + - use_rethrow_when_possible + - valid_regexps From daba819f8592eafe96eb30ebe94d89fe6096a06f Mon Sep 17 00:00:00 2001 From: Casey Vega Date: Tue, 21 Jul 2020 12:33:36 -0700 Subject: [PATCH 2/5] update linter.sh - remove pub On second thought, I do not like this approach because it's asking `pub` questions it has already answered for each file, coupled with the fact that `|| true` means pub can fail for whatever reason. Looking at the other linters, and looking at the recent bug report in #120 I think it's safe to assume that pub, or any package manager can be called as a first step and then proceed to super lint. --- lib/linter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index a4310c38..78092223 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1388,7 +1388,7 @@ if [ "${VALIDATE_DART}" == "true" ]; then # Lint the Dart files # ####################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "DART" "dart" "pub get || true && dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" + LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" fi ################## From af7101fd92d832d6a4ef13098a28a69670b34868 Mon Sep 17 00:00:00 2001 From: Casey Vega Date: Tue, 21 Jul 2020 12:37:47 -0700 Subject: [PATCH 3/5] update dart section - clean up invalid references - modified invalid file names (changed to anaylsis_options.yaml) --- docs/disabling-linters.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 858966a0..d625eef1 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -35,6 +35,7 @@ For some linters it is also possible to override rules on a case by case level w - [Dockerfile](#dockerfile) - [Terraform](#terraform) - [CSS](#css) +- [DART](#dart) - [ENV](#dotenv-linter) - [Kotlin](#kotlin) - [OpenAPI](#openapi) @@ -826,7 +827,7 @@ import package.b.* - `.github/linters/.dart-lint.yml` - You can pass multiple rules and overwrite default rules -- File should be located at: `.github/linters/.dart-lint.yml` +- File should be located at: `.github/linters/anaylsis_options.yaml` ### dartanalyzer disable single line @@ -844,7 +845,7 @@ int x = ''; // ignore: invalid_assignment ### dartanalyzer disable entire file -- You can disable entire files with the `analyzer.exclude` property in `.dart-lint.yml` +- You can disable entire files with the `analyzer.exclude` property in `anaylsis_options.yaml` ```dart analyzer: From c596ef11de805dbe85d0f2c024bd090520703f55 Mon Sep 17 00:00:00 2001 From: Casey Vega Date: Tue, 21 Jul 2020 13:32:34 -0700 Subject: [PATCH 4/5] Update Dockerfile - clean up glibc pkg for dart Noticed `glibc-${GLIBC_VERSION}.apk` was getting purged after and laying around in `/`. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4f56d321..8aa3c5b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -174,7 +174,7 @@ RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktli #################### RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk -RUN apk add --no-cache glibc-${GLIBC_VERSION}.apk +RUN apk add --no-cache glibc-${GLIBC_VERSION}.apk && rm glibc-${GLIBC_VERSION}.apk RUN wget https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-x64-release.zip -O - -q | unzip -q - \ && chmod +x dart-sdk/bin/dart* \ && mv dart-sdk/bin/* /usr/bin/ && mv dart-sdk/lib/* /usr/lib/ && mv dart-sdk/include/* /usr/include/ \ From b15fa8c738e98c33b5597841e58ed0d453f1d1a4 Mon Sep 17 00:00:00 2001 From: Gabo Date: Thu, 23 Jul 2020 00:30:12 -0500 Subject: [PATCH 5/5] Added case for special types like open api --- lib/linter.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index c489a260..1ade97b7 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1188,11 +1188,31 @@ fi # CFN LINTING # ############### if [ "${VALIDATE_CFN}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every yml/json file is an CFN file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectCloudFormationFile "${FILE}"; then + FILE_ARRAY_CFN+=("${FILE}") + fi + done + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + ################################# # Lint the CloudFormation files # ################################# # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "CFN" "cfn-lint" "cfn-lint --config-file ${CFN_LINTER_RULES}" ".*\.\(json\|yml\|yaml\)\$" "${FILE_ARRAY_CFN[@]}" + LintCodebase "CFN" "cfn-lint" "cfn-lint --config-file ${CFN_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CFN[@]}" fi ################ @@ -1475,11 +1495,31 @@ fi # ARM Template LINTING # ######################## if [ "${VALIDATE_ARM}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every json file is an ARM file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectARMFile "${FILE}"; then + FILE_ARRAY_ARM+=("${FILE}") + fi + done + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + ############################### # Lint the ARM Template files # ############################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" ".*\.\(json\)\$" "${FILE_ARRAY_ARM[@]}" + LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" fi ################### @@ -1531,10 +1571,30 @@ fi # AWS STATES LINTING # ###################### if [ "${VALIDATE_STATES}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every json file is an aws states file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectAWSStatesFIle "${FILE}"; then + FILE_ARRAY_STATES+=("${FILE}") + fi + done + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + ######################### # Lint the STATES files # ######################### - LintCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "${FILE_ARRAY_STATES[@]}" + LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" fi ##########