Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SNOW-921048] Add Linter as mandatory github action #954

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .EditorConfig

This file was deleted.

73 changes: 73 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
root = true
# yml files
[*.yml]
indent_style = space
indent_size = 2

# All files
[*.*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
max_line_length = 150

## Interfaces should start with I and PascalCase
dotnet_naming_style.prefix_and_pascal_case.required_prefix = I
dotnet_naming_style.prefix_and_pascal_case.capitalization = pascal_case
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_rule.interfaces_begin_with_I.severity = error
dotnet_naming_rule.interfaces_begin_with_I.symbols = interfaces
dotnet_naming_rule.interfaces_begin_with_I.style = prefix_and_pascal_case
dotnet_diagnostic.interfaces_begin_with_I.enabled = true

## Static fields should start with _s
dotnet_naming_style.prefix_s.required_prefix = s_
dotnet_naming_style.prefix_s.capitalization = camel_case
dotnet_naming_rule.static_fields_begin_with_s.style = prefix_s
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.applicable_accessibilities = public, internal, private, protected, protected_internal
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_rule.static_fields_begin_with_s.severity = error
dotnet_naming_rule.static_fields_begin_with_s.symbols = static_fields
dotnet_diagnostic.static_fields_begin_with_s.enabled = true

## Internal or private member should prefixed with _
dotnet_naming_style.internal_prefix_.required_prefix = _
dotnet_naming_style.internal_prefix_.capitalization = camel_case
dotnet_naming_rule.private_internal_prefix_.style = internal_prefix_
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = internal, private, protected_internal
dotnet_naming_rule.private_internal_prefix_.severity = error
dotnet_naming_rule.private_internal_prefix_.symbols = private_internal_fields
dotnet_diagnostic.private_internal_prefix_.enabled = true

# Enforce use of Pascal case in enums, classes, const and methods
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_rule.enforce_pascal_case.style = pascal_case_style
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.enums.applicable_kinds = enum
dotnet_naming_symbols.consts.applicable_kinds = field
dotnet_naming_symbols.consts.applicable_modifiers = const
dotnet_naming_symbols.public_methods.applicable_kinds = method
dotnet_naming_symbols.public_methods.applicable_accessibilities = public
dotnet_naming_symbols.public_classes.applicable_kinds = class
dotnet_naming_symbols.public_classes.applicable_accessibilities = public
dotnet_naming_symbols.enum_members.applicable_kinds = enum_member
dotnet_naming_symbols.enum_members.applicable_accessibilities = *
dotnet_naming_rule.enforce_pascal_case.severity = error
dotnet_naming_rule.enforce_pascal_case.symbols = methods, enums, consts, public_methods, public_classes, enum_members
dotnet_diagnostic.enforce_pascal_case.enabled = true


# Naming styles for different symbol kinds
dotnet_naming_style.camel_case_style.capitalization = camel_case
dotnet_naming_rule.method_parameters_should_be_camel_case.symbols = method_parameters
dotnet_naming_rule.method_parameters_should_be_camel_case.style = camel_case_style
dotnet_naming_symbols.method_parameters.applicable_kinds = parameter
dotnet_naming_symbols.method_parameters.applicable_accessibilities = *
dotnet_naming_symbols.method_parameters.required_modifiers = *
dotnet_naming_rule.method_parameters_should_be_camel_case.severity = error
dotnet_naming_rule.enforce_pascal_case.symbols = method_parameters
dotnet_diagnostic.method_parameters_should_be_camel_case.enabled = true
25 changes: 16 additions & 9 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
tags:
description: "Linter"
required: false
permissions: { }

concurrency:
# older builds for the same pull request number or branch should be cancelled
Expand All @@ -26,14 +27,20 @@ jobs:
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
dotnet-quality: 'ga'
- name: Run linters
uses: wearerequired/lint-action@v2
depth: 0

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet_format: true
continue_on_error: true
check_name: ${linter} run
dotnet-version: '6.0.103'

- name: Install dotnet format
run: dotnet tool install -g dotnet-format

- name: Add dotnet tools to PATH
run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH

- name: Run Linter Bash Script
run: |
bash ci/scripts/linter.sh
18 changes: 9 additions & 9 deletions Snowflake.Data.Tests/UnitTests/SFDbCommandTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

Expand All @@ -13,12 +13,12 @@ namespace Snowflake.Data.Tests.UnitTests
[TestFixture]
class SFDbCommandTest
{
SnowflakeDbCommand command;
SnowflakeDbCommand _command;

[SetUp]
public void BeforeTest()
{
command = new SnowflakeDbCommand();
_command = new SnowflakeDbCommand();
}

[Test]
Expand All @@ -29,18 +29,18 @@ public void TestCommandWithConnectionAndCommandText()
string commandText = "select 1";

// Act
command = new SnowflakeDbCommand(conn, commandText);
_command = new SnowflakeDbCommand(conn, commandText);

// Assert
Assert.AreEqual(conn, command.Connection);
Assert.AreEqual(commandText, command.CommandText);
Assert.AreEqual(conn, _command.Connection);
Assert.AreEqual(commandText, _command.CommandText);
}

[Test]
public void TestCommandExecuteThrowsExceptionWhenCommandTextIsNotSet()
{
// Act
var thrown = Assert.Throws<Exception>(() => command.ExecuteScalar());
var thrown = Assert.Throws<Exception>(() => _command.ExecuteScalar());

// Assert
Assert.AreEqual(thrown.Message, "Unable to execute command due to command text not being set");
Expand All @@ -50,7 +50,7 @@ public void TestCommandExecuteThrowsExceptionWhenCommandTextIsNotSet()
public void TestCommandExecuteAsyncThrowsExceptionWhenCommandTextIsNotSet()
{
// Arrange
Task<object> commandTask = command.ExecuteScalarAsync(CancellationToken.None);
Task<object> commandTask = _command.ExecuteScalarAsync(CancellationToken.None);

// Act
var thrown = Assert.Throws<AggregateException>(() => commandTask.Wait());
Expand All @@ -62,7 +62,7 @@ public void TestCommandExecuteAsyncThrowsExceptionWhenCommandTextIsNotSet()
[Test]
public void TestCommandPrepareShouldNotThrowsException()
{
Assert.DoesNotThrow(() => command.Prepare());
Assert.DoesNotThrow(() => _command.Prepare());
}
}
}
Loading
Loading