mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-22 07:12:11 -05:00
adding dart support
This commit is contained in:
parent
f948639bf1
commit
407f411e21
11 changed files with 175 additions and 4 deletions
13
.automation/test/dart/README.md
Normal file
13
.automation/test/dart/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Dart Test Cases
|
||||
This folder holds the test cases for **Dart**.
|
||||
|
||||
## 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.
|
6
.automation/test/dart/dart_bad_1.dart
Normal file
6
.automation/test/dart/dart_bad_1.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
// empty_constructor_bodies bad {}
|
||||
|
||||
class Point {
|
||||
int x, y;
|
||||
Point(this.x, this.y) {}
|
||||
}
|
6
.automation/test/dart/dart_good_1.dart
Normal file
6
.automation/test/dart/dart_good_1.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
// empty_constructor_bodies good ;
|
||||
|
||||
class Point {
|
||||
int x, y;
|
||||
Point(this.x, this.y);
|
||||
}
|
57
.github/linters/.dart-lint.yml
vendored
Normal file
57
.github/linters/.dart-lint.yml
vendored
Normal file
|
@ -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
|
|
@ -159,6 +159,14 @@ RUN curl -sLO https://github.com/borkdude/clj-kondo/releases/download/v${CLJ_KON
|
|||
RUN curl -sSLO https://github.com/pinterest/ktlint/releases/latest/download/ktlint && chmod a+x ktlint \
|
||||
&& mv "ktlint" /usr/bin/
|
||||
|
||||
####################
|
||||
# Install dart-sdk #
|
||||
####################
|
||||
ARG DART_VERSION='2.8.4'
|
||||
RUN wget https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-x64-release.zip -O - -q | unzip - \
|
||||
&& mv dart-sdk/bin/* /usr/bin \
|
||||
&& rm -r "dart-sdk"
|
||||
|
||||
###########################################
|
||||
# Load GitHub Env Vars for GitHub Actions #
|
||||
###########################################
|
||||
|
@ -190,6 +198,7 @@ ENV GITHUB_SHA=${GITHUB_SHA} \
|
|||
VALIDATE_ENV=${VALIDATE_ENV} \
|
||||
VALIDATE_CLOJURE=${VALIDATE_CLOJURE} \
|
||||
VALIDATE_KOTLIN=${VALIDATE_KOTLIN} \
|
||||
VALIDATE_DART=${VALIDATE_DART} \
|
||||
VALIDATE_POWERSHELL=${VALIDATE_POWERSHELL} \
|
||||
VALIDATE_OPENAPI=${VALIDATE_OPENAPI} \
|
||||
VALIDATE_PROTOBUF=${VALIDATE_PROTOBUF} \
|
||||
|
|
|
@ -38,6 +38,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base
|
|||
| **CSS** | [stylelint](https://stylelint.io/) |
|
||||
| **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) |
|
||||
| **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) |
|
||||
| **Dart** | [dartanalyzer](https://dart.dev/tools/dartanalyzer) |
|
||||
| **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) |
|
||||
| **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) |
|
||||
| **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) |
|
||||
|
@ -176,6 +177,7 @@ and won't run anything unexpected.
|
|||
| **VALIDATE_ENV** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_CLOJURE** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_KOTLIN** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_DART** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_OPENAPI** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_CLOUDFORMATION** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
| **VALIDATE_PROTOBUF** | `true` | Flag to enable or disable the linting process of the language. |
|
||||
|
|
|
@ -658,6 +658,35 @@ import package.b.*
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Dart
|
||||
- [dartanalyzer](https://dart.dev/tools/dartanalyzer)
|
||||
|
||||
### dartanalyzer standard Config file
|
||||
- `.github/linters/.dart-lint.yml`
|
||||
- You can pass multiple rules and overwrite default rules
|
||||
- File should be located at: `.github/linters/.dart-lint.yml`
|
||||
|
||||
### dartanalyzer disable single line
|
||||
```dart
|
||||
int x = ''; // ignore: invalid_assignment
|
||||
```
|
||||
|
||||
### dartanalyzer disable code block
|
||||
- You can make [rule exceptions](https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis) for the entire file.
|
||||
```dart
|
||||
// ignore_for_file: unused_import, unused_local_variable
|
||||
```
|
||||
|
||||
### dartanalyzer disable entire file
|
||||
- You can disable entire files with the `analyzer.exclude` property in `.dart-lint.yml`
|
||||
```dart
|
||||
analyzer:
|
||||
exclude:
|
||||
- file
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## OpenAPI
|
||||
- [spectral](https://github.com/stoplightio/spectral)
|
||||
|
||||
|
|
|
@ -336,6 +336,15 @@ function BuildFileList() {
|
|||
############################
|
||||
# Get the Protocol Buffers files #
|
||||
############################
|
||||
elif [ "$FILE_TYPE" == "dart" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
################################
|
||||
FILE_ARRAY_DART+=("$FILE")
|
||||
##########################################################
|
||||
# Set the READ_ONLY_CHANGE_FLAG since this could be exec #
|
||||
##########################################################
|
||||
READ_ONLY_CHANGE_FLAG=1
|
||||
elif [ "$FILE_TYPE" == "proto" ]; then
|
||||
################################
|
||||
# Append the file to the array #
|
||||
|
|
|
@ -77,6 +77,9 @@ PROTOBUF_LINTER_RULES="$DEFAULT_RULES_LOCATION/$PROTOBUF_FILE_NAME" # Path to th
|
|||
# Clojure Vars
|
||||
CLOJURE_FILE_NAME='.clj-kondo/config.edn'
|
||||
CLOJURE_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CLOJURE_FILE_NAME"
|
||||
# Dart Vars
|
||||
DART_FILE_NAME='.dart-lint.yml'
|
||||
DART_LINTER_RULES="$DEFAULT_RULES_LOCATION/$DART_FILE_NAME"
|
||||
|
||||
#######################################
|
||||
# Linter array for information prints #
|
||||
|
@ -85,7 +88,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
|||
"pylint" "perl" "rubocop" "coffeelint" "eslint" "standard"
|
||||
"ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint"
|
||||
"stylelint" "dotenv-linter" "pwsh" "ktlint" "protolint" "clj-kondo"
|
||||
"spectral" "cfn-lint")
|
||||
"spectral" "cfn-lint" "dart")
|
||||
|
||||
#############################
|
||||
# Language array for prints #
|
||||
|
@ -93,7 +96,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck"
|
|||
LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON'
|
||||
'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES'
|
||||
'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM'
|
||||
'CSS' 'ENV' 'POWERSHELL' 'KOTLIN' 'PROTOBUF' 'CLOJURE' 'OPENAPI' 'CFN')
|
||||
'CSS' 'ENV' 'POWERSHELL' 'KOTLIN' 'PROTOBUF' 'CLOJURE' 'OPENAPI' 'CFN' 'DART')
|
||||
|
||||
###################
|
||||
# GitHub ENV Vars #
|
||||
|
@ -129,6 +132,7 @@ VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to vali
|
|||
VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language
|
||||
VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language
|
||||
VALIDATE_OPENAPI="${VALIDATE_OPENAPI}" # Boolean to validate language
|
||||
VALIDATE_DART="${VALIDATE_DART}" # Boolean to validate language
|
||||
TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases
|
||||
DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors
|
||||
|
||||
|
@ -219,6 +223,7 @@ ERRORS_FOUND_CLOJURE=0 # Count of errors found
|
|||
ERRORS_FOUND_KOTLIN=0 # Count of errors found
|
||||
ERRORS_FOUND_PROTOBUF=0 # Count of errors found
|
||||
ERRORS_FOUND_OPENAPI=0 # Count of errors found
|
||||
ERRORS_FOUND_DART=0 # Count of errors found
|
||||
|
||||
################################################################################
|
||||
########################## FUNCTIONS BELOW #####################################
|
||||
|
@ -727,7 +732,8 @@ Footer() {
|
|||
[ "$ERRORS_FOUND_OPENAPI" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_PROTOBUF" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_CLOJURE" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then
|
||||
[ "$ERRORS_FOUND_KOTLIN" -ne 0 ] ||
|
||||
[ "$ERRORS_FOUND_DART" -ne 0 ]; then
|
||||
# Failed exit
|
||||
echo -e "${NC}${F[R]}Exiting with errors found!${NC}"
|
||||
exit 1
|
||||
|
@ -795,6 +801,8 @@ GetLinterRules "POWERSHELL"
|
|||
GetLinterRules "CSS"
|
||||
# Get CFN rules
|
||||
GetLinterRules "CFN"
|
||||
# Get DART rules
|
||||
GetLinterRules "DART"
|
||||
|
||||
#################################
|
||||
# Check if were in verbose mode #
|
||||
|
@ -1069,6 +1077,17 @@ if [ "$VALIDATE_KOTLIN" == "true" ]; then
|
|||
LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_KOTLIN[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# DART LINTING #
|
||||
##################
|
||||
if [ "$VALIDATE_DART" == "true" ]; then
|
||||
#######################
|
||||
# Lint the Dart files #
|
||||
#######################
|
||||
# LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY"
|
||||
LintCodebase "DART" "dart" "dartanalyzer --options $DART_LINTER_RULES" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}"
|
||||
fi
|
||||
|
||||
##################
|
||||
# DOCKER LINTING #
|
||||
##################
|
||||
|
|
|
@ -100,7 +100,8 @@ function GetValidationInfo() {
|
|||
$VALIDATE_CLOJURE || -n \
|
||||
$VALIDATE_PROTOBUF || -n \
|
||||
$VALIDATE_OPENAPI || -n \
|
||||
$VALIDATE_KOTLIN ]]; then
|
||||
$VALIDATE_KOTLIN || -n \
|
||||
$VALIDATE_DART ]]; then
|
||||
ANY_SET="true"
|
||||
fi
|
||||
|
||||
|
@ -412,6 +413,20 @@ function GetValidationInfo() {
|
|||
VALIDATE_KOTLIN="true"
|
||||
fi
|
||||
|
||||
####################################
|
||||
# Validate if we should check DART #
|
||||
####################################
|
||||
if [[ $ANY_SET == "true" ]]; then
|
||||
# Some linter flags were set - only run those set to true
|
||||
if [[ -z $VALIDATE_DART ]]; then
|
||||
# ENV flag was not set - default to false
|
||||
VALIDATE_DART="false"
|
||||
fi
|
||||
else
|
||||
# No linter flags were set - default all to true
|
||||
VALIDATE_DART="true"
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# Validate if we should check OPENAPI #
|
||||
#######################################
|
||||
|
@ -582,6 +597,11 @@ function GetValidationInfo() {
|
|||
else
|
||||
PRINT_ARRAY+=("- Excluding [PROTOBUF] files in code base...")
|
||||
fi
|
||||
if [[ $VALIDATE_DART == "true" ]]; then
|
||||
PRINT_ARRAY+=("- Validating [DART] files in code base...")
|
||||
else
|
||||
PRINT_ARRAY+=("- Excluding [DART] files in code base...")
|
||||
fi
|
||||
|
||||
##############################
|
||||
# Validate Ansible Directory #
|
||||
|
|
|
@ -477,6 +477,7 @@ function RunTestCases() {
|
|||
TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "kotlin"
|
||||
TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path $PROTOBUF_LINTER_RULES" ".*\.\(proto\)\$" "protobuf"
|
||||
TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi"
|
||||
TestCodebase "DART" "dart" "dartanalyzer --options $DART_LINTER_RULES" ".*\.\(dart\)\$" "dart"
|
||||
|
||||
#################
|
||||
# Footer prints #
|
||||
|
|
Loading…
Reference in a new issue