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
This commit is contained in:
Reiley Yang 2020-07-27 07:52:26 -07:00 committed by GitHub
parent 14255acb6d
commit 755f727df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 13 deletions

View File

@ -1,11 +1,11 @@
name: spellcheck name: sanitycheck
on: on:
pull_request: pull_request:
branches: [ master ] branches: [ master ]
jobs: jobs:
build: misspell:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -19,3 +19,13 @@ jobs:
- name: run misspell - name: run misspell
run: ./bin/misspell -error . 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

45
build/sanitycheck.py Normal file
View File

@ -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)

View File

@ -1,7 +1,7 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; 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 // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Examples.AspNet")] [assembly: AssemblyTitle("Examples.AspNet")]
@ -9,12 +9,12 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Examples.AspNet")] [assembly: AssemblyProduct("Examples.AspNet")]
[assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyCopyright("Copyright @ 2020")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -24,11 +24,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // 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: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -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 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 0.13.0.1](https://www.nuget.org/packages/ApacheThrift/0.13.0.1) library from

View File

@ -1,4 +1,4 @@
# OpenTelemetry Protocol Implementation # OpenTelemetry Protocol Implementation
`.proto` files under `Implementation\` are copied from the `.proto` files under `Implementation\` are copied from the
[`opentelemetry-proto`](https://github.com/open-telemetry/opentelemetry-proto/commit/1a931b4b57c34e7fd8f7dddcaa9b7587840e9c08) [`opentelemetry-proto`](https://github.com/open-telemetry/opentelemetry-proto/commit/1a931b4b57c34e7fd8f7dddcaa9b7587840e9c08)

View File

@ -35,4 +35,3 @@ for an example of how to use the exporter.
* [OpenTelemetry Project](https://opentelemetry.io/) * [OpenTelemetry Project](https://opentelemetry.io/)
* [OpenTelemetry * [OpenTelemetry
Protocol](https://github.com/open-telemetry/opentelemetry-proto) Protocol](https://github.com/open-telemetry/opentelemetry-proto)

View File

@ -1,4 +1,4 @@
# OpenTelemetry Benchmarks # OpenTelemetry Benchmarks
Use the following example to run Benchmarks from command line: Use the following example to run Benchmarks from command line:
(change parameters as necessary) (change parameters as necessary)

View File

@ -34,7 +34,7 @@
<ProjectReference Include="..\TestApp.AspNetCore.3.1\TestApp.AspNetCore.3.1.csproj" /> <ProjectReference Include="..\TestApp.AspNetCore.3.1\TestApp.AspNetCore.3.1.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.1" />