From a7afab4b8aa92c32a05057047d42bcb6a91114aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 8 Dec 2020 12:56:37 +0100 Subject: [PATCH] Typescript: Fixing typescript strict error, and separate check from publishing (#29679) * Typescript: Fixing typescript string error, and seperate check from publishing * now should pass --- package.json | 2 +- public/app/plugins/panel/graph/graph.ts | 2 +- public/app/plugins/panel/singlestat/module.ts | 4 +-- scripts/ci-check-strict.sh | 13 +++++++++ scripts/ci-frontend-metrics.sh | 21 -------------- scripts/ci-metrics-publisher.sh | 28 ------------------- 6 files changed, 17 insertions(+), 53 deletions(-) create mode 100755 scripts/ci-check-strict.sh delete mode 100755 scripts/ci-metrics-publisher.sh diff --git a/package.json b/package.json index b70519ef8347..3f8b540d0d53 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "typecheck": "tsc --noEmit && yarn run packages:typecheck", "plugins:build-bundled": "grafana-toolkit plugin:bundle-managed", "watch": "yarn start -d watch,start core:start --watchTheme", - "ci:test-frontend": "yarn run prettier:check && yarn run typecheck && yarn run lint && yarn run test:ci && yarn grafana-toolkit node-version-check" + "ci:test-frontend": "yarn run prettier:check && yarn run typecheck && yarn run lint && yarn run test:ci && yarn grafana-toolkit node-version-check && ./scripts/ci-check-strict.sh" }, "grafana": { "whatsNewUrl": "https://grafana.com/docs/grafana/latest/guides/whats-new-in-v7-3/", diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index abd78aa5bca7..1c5d936e7d4a 100644 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -58,7 +58,7 @@ class GraphElement { annotations: object[]; panel: any; plot: any; - sortedSeries: any[]; + sortedSeries?: any[]; data: any[]; panelWidth: number; eventManager: EventManager; diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 6fe53bc743fb..cbd0239b358d 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -52,10 +52,10 @@ class SingleStatCtrl extends MetricsPanelCtrl { data: Partial = {}; - fontSizes: any[]; + fontSizes: any[] = []; fieldNames: string[] = []; - invalidGaugeRange: boolean; + invalidGaugeRange = false; panel: any; events: any; valueNameOptions: any[] = [ diff --git a/scripts/ci-check-strict.sh b/scripts/ci-check-strict.sh new file mode 100755 index 000000000000..56e48a8a2079 --- /dev/null +++ b/scripts/ci-check-strict.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +echo -e "Collecting code stats (typescript errors & more)" + +ERROR_COUNT_LIMIT=579 +ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')" + +if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then + echo -e "Typescript strict errors $ERROR_COUNT exceeded $ERROR_COUNT_LIMIT so failing build" + exit 1 +fi + diff --git a/scripts/ci-frontend-metrics.sh b/scripts/ci-frontend-metrics.sh index 7d0cdfec89c8..f56bb03c9091 100755 --- a/scripts/ci-frontend-metrics.sh +++ b/scripts/ci-frontend-metrics.sh @@ -1,12 +1,6 @@ #!/bin/bash set -e -echo -e "Collecting code stats (typescript errors & more)" - -ERROR_COUNT_LIMIT=580 -DIRECTIVES_LIMIT=172 -CONTROLLERS_LIMIT=139 - ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')" DIRECTIVES="$(grep -r -o directive public/app/ | wc -l)" CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/ | wc -l)" @@ -14,21 +8,6 @@ STORIES_COUNT="$(find ./packages/grafana-ui/src/components -name "*.story.tsx" | MDX_COUNT="$(find ./packages/grafana-ui/src/components -name "*.mdx" | wc -l)" LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app | wc -l)" -if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then - echo -e "Typescript strict errors $ERROR_COUNT exceeded $ERROR_COUNT_LIMIT so failing build" - exit 1 -fi - -if [ "$DIRECTIVES" -gt $DIRECTIVES_LIMIT ]; then - echo -e "Directive count $DIRECTIVES exceeded $DIRECTIVES_LIMIT so failing build" - exit 1 -fi - -if [ "$CONTROLLERS" -gt $CONTROLLERS_LIMIT ]; then - echo -e "Controllers count $CONTROLLERS exceeded $CONTROLLERS_LIMIT so failing build" - exit 1 -fi - echo -e "Typescript errors: $ERROR_COUNT" echo -e "Directives: $DIRECTIVES" echo -e "Controllers: $CONTROLLERS" diff --git a/scripts/ci-metrics-publisher.sh b/scripts/ci-metrics-publisher.sh deleted file mode 100755 index a2da5ef98cee..000000000000 --- a/scripts/ci-metrics-publisher.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -echo "Publishing CI Metrics" - -data="" - -for ((i = 1; i <= $#; i++ )); do - remainder="${!i}" - # Find everything until last = character (= is included in the result) - # This allows to add tags to metric names - metricName=$(grep -o "\(.*\)=" <<< "$remainder") - # Get the metric value - value=${remainder#"$metricName"} - # Remove remaining = character from metric name - metricName=${metricName%?}; - - - if [ -n "$data" ]; then - data="$data," - fi - data=''$data'{"name": "'${metricName}'", "value": '${value}', "interval": 60, "mtype": "gauge", "time": '$(date +%s)'}' -done - -echo "Publishing metrics:" -echo "$data" -curl "https://6371:$GRAFANA_MISC_STATS_API_KEY@graphite-us-central1.grafana.net/metrics" \ - -H 'Content-type: application/json' \ - -d "[$data]"