From 755f727df00612b9d268cf18f7ac312f53f79d0a Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Mon, 27 Jul 2020 07:52:26 -0700 Subject: [PATCH] Add sanity check for non-ASCII character and trailing spaces (#927) * add CI sanity check for non-ASCII encoding and trailing spaces * check TAB too * fix ordering * rename sanity to sanitycheck --- .../{spellcheck.yml => sanitycheck.yml} | 14 +++++- build/sanitycheck.py | 45 +++++++++++++++++++ examples/AspNet/Properties/AssemblyInfo.cs | 12 ++--- .../ApacheThrift/README.md | 2 +- .../Implementation/README.md | 2 +- .../README.md | 1 - test/Benchmarks/README.md | 2 +- ...ry.Instrumentation.AspNetCore.Tests.csproj | 2 +- 8 files changed, 67 insertions(+), 13 deletions(-) rename .github/workflows/{spellcheck.yml => sanitycheck.yml} (59%) create mode 100644 build/sanitycheck.py diff --git a/.github/workflows/spellcheck.yml b/.github/workflows/sanitycheck.yml similarity index 59% rename from .github/workflows/spellcheck.yml rename to .github/workflows/sanitycheck.yml index f762c2520..9f2e5e9fd 100644 --- a/.github/workflows/spellcheck.yml +++ b/.github/workflows/sanitycheck.yml @@ -1,11 +1,11 @@ -name: spellcheck +name: sanitycheck on: pull_request: branches: [ master ] jobs: - build: + misspell: runs-on: ubuntu-latest steps: @@ -19,3 +19,13 @@ jobs: - name: run misspell run: ./bin/misspell -error . + + encoding: + runs-on: ubuntu-latest + + steps: + - name: check out code + uses: actions/checkout@v2 + + - name: detect non-ASCII encoding and trailing space + run: python3 ./build/sanitycheck.py diff --git a/build/sanitycheck.py b/build/sanitycheck.py new file mode 100644 index 000000000..259cfd277 --- /dev/null +++ b/build/sanitycheck.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import glob +import os +import sys + +def sanitycheck(pattern, allow_utf8 = False): + error_count = 0 + + for filename in glob.glob(pattern, recursive=True): + if not os.path.isfile(filename): + continue + with open(filename, 'rb') as file: + content = file.read() + error = [] + lineno = 1 + for line in content.splitlines(): + if allow_utf8 and lineno == 1 and line.startswith(b'\xef\xbb\xbf'): + line = line[3:] + if any(b > 127 for b in line): + error.append(' Non-ASCII character found at Ln:{} {}'.format(lineno, line)) + if line[-1:] == b' ' or line[-1:] == b'\t': + error.append(' Trailing space found at Ln:{} {}'.format(lineno, line)) + lineno += 1 + if error: + error_count += 1 + print('{} [FAIL]'.format(filename), file=sys.stderr) + for msg in error: + print(msg, file=sys.stderr) + else: + # print('{} [PASS]'.format(filename)) + pass + + return error_count + +retval = 0 +retval += sanitycheck('**/*.cmd') +retval += sanitycheck('**/*.cs', allow_utf8 = True) +retval += sanitycheck('**/*.csproj', allow_utf8 = True) +retval += sanitycheck('**/*.md') +retval += sanitycheck('**/*.proj', allow_utf8 = True) +retval += sanitycheck('**/*.py') +retval += sanitycheck('**/*.xml', allow_utf8 = True) + +sys.exit(retval) diff --git a/examples/AspNet/Properties/AssemblyInfo.cs b/examples/AspNet/Properties/AssemblyInfo.cs index 48590a96e..c69f2834c 100644 --- a/examples/AspNet/Properties/AssemblyInfo.cs +++ b/examples/AspNet/Properties/AssemblyInfo.cs @@ -1,7 +1,7 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Examples.AspNet")] @@ -9,12 +9,12 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Examples.AspNet")] -[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyCopyright("Copyright @ 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] @@ -24,11 +24,11 @@ using System.Runtime.InteropServices; // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Revision and Build Numbers +// You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/OpenTelemetry.Exporter.Jaeger/ApacheThrift/README.md b/src/OpenTelemetry.Exporter.Jaeger/ApacheThrift/README.md index 5d5536b59..63b931244 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/ApacheThrift/README.md +++ b/src/OpenTelemetry.Exporter.Jaeger/ApacheThrift/README.md @@ -1,4 +1,4 @@ -# Open Telemetry - Jaeger Exporter - Apache Thrift +# Open Telemetry - Jaeger Exporter - Apache Thrift This folder contains a stripped-down fork of the [ApacheThrift 0.13.0.1](https://www.nuget.org/packages/ApacheThrift/0.13.0.1) library from diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/README.md index e9b8a3404..9e0484750 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/README.md @@ -1,4 +1,4 @@ -# OpenTelemetry Protocol Implementation +# OpenTelemetry Protocol Implementation `.proto` files under `Implementation\` are copied from the [`opentelemetry-proto`](https://github.com/open-telemetry/opentelemetry-proto/commit/1a931b4b57c34e7fd8f7dddcaa9b7587840e9c08) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 778b6f816..fa30d2837 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -35,4 +35,3 @@ for an example of how to use the exporter. * [OpenTelemetry Project](https://opentelemetry.io/) * [OpenTelemetry Protocol](https://github.com/open-telemetry/opentelemetry-proto) - \ No newline at end of file diff --git a/test/Benchmarks/README.md b/test/Benchmarks/README.md index 8fe02c322..24737da56 100644 --- a/test/Benchmarks/README.md +++ b/test/Benchmarks/README.md @@ -1,4 +1,4 @@ -# OpenTelemetry Benchmarks +# OpenTelemetry Benchmarks Use the following example to run Benchmarks from command line: (change parameters as necessary) diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj index 485202c70..2a536cad0 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/OpenTelemetry.Instrumentation.AspNetCore.Tests.csproj @@ -34,7 +34,7 @@ - +