From c9ef1fcb66f2653b7ed3f4469aa20472425d69f7 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Thu, 6 Aug 2020 12:01:36 -0500 Subject: [PATCH] Saving it --- .automation/test/sql/README.md | 19 +++++++++++++++++++ .automation/test/sql/sql_bad_1.sql | 1 + .automation/test/sql/sql_good_1.sql | 1 + Dockerfile | 1 + README.md | 2 ++ docs/disabling-linters.md | 23 +++++++++++++++++++++++ lib/buildFileList.sh | 9 +++++++++ lib/linter.sh | 19 +++++++++++++++++-- lib/worker.sh | 1 + 9 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 .automation/test/sql/README.md create mode 100644 .automation/test/sql/sql_bad_1.sql create mode 100644 .automation/test/sql/sql_good_1.sql diff --git a/.automation/test/sql/README.md b/.automation/test/sql/README.md new file mode 100644 index 00000000..dcf9d73b --- /dev/null +++ b/.automation/test/sql/README.md @@ -0,0 +1,19 @@ +# SQL Test Cases + +This folder holds the test cases for **SQL**. + +## Additional Docs + +No Additional information is needed for this test case. + +## Good Test Cases + +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. + +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases + +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. + +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/sql/sql_bad_1.sql b/.automation/test/sql/sql_bad_1.sql new file mode 100644 index 00000000..82e1f3eb --- /dev/null +++ b/.automation/test/sql/sql_bad_1.sql @@ -0,0 +1 @@ +DELETE from person; diff --git a/.automation/test/sql/sql_good_1.sql b/.automation/test/sql/sql_good_1.sql new file mode 100644 index 00000000..2e54affa --- /dev/null +++ b/.automation/test/sql/sql_good_1.sql @@ -0,0 +1 @@ +DELETE from person WHERE 1=1; diff --git a/Dockerfile b/Dockerfile index 5adfa969..3ebe7199 100644 --- a/Dockerfile +++ b/Dockerfile @@ -291,6 +291,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_RAKU=${VALIDATE_RAKU} \ VALIDATE_RUBY=${VALIDATE_RUBY} \ VALIDATE_STATES=${VALIDATE_STATES} \ + VALIDATE_SQL=${VALIDATE_SQL} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ VALIDATE_TERRAFORM_TERRASCAN=${VALIDATE_TERRAFORM_TERRASCAN} \ VALIDATE_TYPESCRIPT_ES=${VALIDATE_TYPESCRIPT_ES} \ diff --git a/README.md b/README.md index 66fffc84..39fce71e 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **Raku** | [raku](https://raku.org) | | **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | | **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) | +| **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) | | **Terraform** | [tflint](https://github.com/terraform-linters/tflint) [terrascan](https://github.com/accurics/terrascan) | | **TypeScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **XML** | [LibXML](http://xmlsoft.org/) | @@ -226,6 +227,7 @@ and won't run anything unexpected. | **VALIDATE_RAKU** | `true` | Flag to enable or disable the linting process of the Raku language. | | **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the Ruby language. | | **VALIDATE_STATES** | `true` | Flag to enable or disable the linting process for AWS States Language. | +| **VALIDATE_SQL** | `true` | Flag to enable or disable the linting process of the SQL language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the Terraform language. | | **VALIDATE_TERRAFORM_TERRASCAN** | `false` | Flag to enable or disable the linting process of the Terraform language for security related issues. | | **VALIDATE_TSX** | `true` | Flag to enable or disable the linting process for tsx files (Utilizing: eslint) | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 7a3c9b33..c1d76476 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -45,6 +45,7 @@ For some linters it is also possible to override rules on a case by case level w - [Raku](#raku) - [Ruby](#ruby) - [Shell](#shell) + - [SQL](#sql) - [Terraform](#terraform) - [Typescript eslint](#typescript-eslint) - [Typescript standard](#typescript-standard) @@ -1010,6 +1011,28 @@ moreThings() --- +## SQL + +- [SQL](https://www.npmjs.com/package/sql-lint) + +### SQL Config file + +- There is no top level _configuration file_ available at this time + +### SQL disable single line + +- There is currently **No** way to disable rules inline of the file(s) + +### SQL disable code block + +- There is currently **No** way to disable rules inline of the file(s) + +### SQL disable entire file + +- There is currently **No** way to disable rules inline of the file(s) + +--- + ## Terraform - [tflint](https://github.com/terraform-linters/tflint) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index c878a3be..9dd5502c 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -457,6 +457,15 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "${FILE_TYPE}" == "sql" ]; then + ################################ + # Append the file to the array # + ##############################p## + FILE_ARRAY_SQL+=("${FILE}") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then ################################ # Append the file to the array # diff --git a/lib/linter.sh b/lib/linter.sh index e0768e2b..6c689b85 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -127,7 +127,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the ya LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'cfn-lint' 'checkstyle' 'clj-kondo' 'coffeelint' 'dart' 'dockerfilelint' 'dotenv-linter' 'eslint' 'flake8' 'golangci-lint' 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' 'pwsh' - 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'terrascan' + 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'sql-lint' 'terrascan' 'tflint' 'xmllint' 'yamllint') ############################# @@ -137,7 +137,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' - 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'TERRAFORM' + 'PROTOBUF' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'RAKU' 'RUBY' 'STATES' 'SQL' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ############################################ @@ -197,6 +197,7 @@ VALIDATE_PYTHON_FLAKE8="${VALIDATE_PYTHON_FLAKE8}" # Boolean t VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language +VALIDATE_SQL="${VALIDATE_SQL}" # Boolean to validate language VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language VALIDATE_TSX="${VALIDATE_TSX}" # Boolean to validate language @@ -294,6 +295,7 @@ FILE_ARRAY_PYTHON_FLAKE8=() # Array of files to check FILE_ARRAY_RAKU=() # Array of files to check FILE_ARRAY_RUBY=() # Array of files to check FILE_ARRAY_STATES=() # Array of files to check +FILE_ARRAY_SQL=() # Array of files to check FILE_ARRAY_TERRAFORM=() # Array of files to check FILE_ARRAY_TSX=() # Array of files to check FILE_ARRAY_TYPESCRIPT_ES=() # Array of files to check @@ -376,6 +378,8 @@ ERRORS_FOUND_RUBY=0 # Count of errors found export ERRORS_FOUND_RUBY # Workaround SC2034 ERRORS_FOUND_STATES=0 # Count of errors found export ERRORS_FOUND_STATES # Workaround SC2034 +ERRORS_FOUND_SQL=0 # Count of errors found +export ERRORS_FOUND_SQL # Workaround SC2034 ERRORS_FOUND_TERRAFORM=0 # Count of errors found export ERRORS_FOUND_TERRAFORM # Workaround SC2034 ERRORS_FOUND_TERRAFORM_TERRASCAN=0 # Count of errors found @@ -1724,6 +1728,17 @@ if [ "${VALIDATE_STATES}" == "true" ]; then LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" fi +############### +# SQL LINTING # +############### +if [ "${VALIDATE_SQL}" == "true" ]; then + ###################### + # Lint the SQL files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "SQL" "sql-lint" "sql-lint" ".*\.\(sql\)\$" "${FILE_ARRAY_SQL[@]}" +fi + ##################### # TERRAFORM LINTING # ##################### diff --git a/lib/worker.sh b/lib/worker.sh index 300355c9..434fe2f0 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -603,6 +603,7 @@ function RunTestCases() { TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" + TestCodebase "SQL" "sql-lint" "sql-lint" ".*\.\(sql\)\$" "sql" TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" TestCodebase "TERRAFORM_TERRASCAN" "terrascan" "terrascan -f " ".*\.\(tf\)\$" "terraform_terrascan" TestCodebase "TYPESCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${TYPESCRIPT_LINTER_RULES}" ".*\.\(ts\)\$" "typescript"