Skip to content
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
120 changes: 120 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

# Code files
[*.{cs,csx,vb,vbx}]
indent_style = space
indent_size = 4
end_of_line = crlf

# Project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_style = space
indent_size = 2

# JSON files
[*.json]
indent_style = space
indent_size = 2

# Razor files
[*.{cshtml,razor}]
indent_style = space
indent_size = 4

# YAML files
[*.{yml,yaml}]
indent_style = space
indent_size = 2

# Markdown files
[*.md]
trim_trailing_whitespace = false

# C# Code Style Rules
[*.cs]

# Code style rules
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# Language rules
csharp_prefer_braces = true:warning
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_static_local_functions = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion

# Formatting rules
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Naming conventions
dotnet_naming_rule.interfaces_should_be_prefixed_with_i.severity = warning
dotnet_naming_rule.interfaces_should_be_prefixed_with_i.symbols = interface
dotnet_naming_rule.interfaces_should_be_prefixed_with_i.style = prefix_interface_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.prefix_interface_with_i.required_prefix = I
dotnet_naming_style.prefix_interface_with_i.required_suffix =
dotnet_naming_style.prefix_interface_with_i.word_separator =
dotnet_naming_style.prefix_interface_with_i.capitalization = pascal_case

# Code quality rules
dotnet_analyzer_diagnostic.category-security.severity = warning
dotnet_analyzer_diagnostic.category-reliability.severity = warning
dotnet_analyzer_diagnostic.category-performance.severity = suggestion
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ jobs:
if: matrix.language == 'csharp' && matrix.build-mode == 'manual'
run: dotnet build RazorPagesMovie.sln --configuration Release --no-restore

- name: Run Code Analysis and Linting
if: matrix.language == 'csharp' && matrix.build-mode == 'manual'
run: |
echo "Running static analysis and linting checks..."
dotnet build RazorPagesMovie.sln --configuration Release --verbosity normal --no-restore | tee build-output.log

# Count warnings from our static analysis tools
ANALYZER_WARNINGS=$(grep -c "warning SA\|warning CA" build-output.log || true)
echo "Static analysis warnings found: $ANALYZER_WARNINGS"

# For now, we'll log the count but not fail the build to avoid breaking existing CI
# In a production environment, you might want to set thresholds or fail on new warnings
if [ "$ANALYZER_WARNINGS" -gt 0 ]; then
echo "::notice title=Static Analysis::Found $ANALYZER_WARNINGS static analysis warnings. Consider addressing them to improve code quality."
fi

# - name: Set runtime
# if: matrix.language == 'csharp'
# id: set-runtime
Expand Down
9 changes: 9 additions & 0 deletions src/Data/RazorPagesMovieContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public RazorPagesMovieContext(DbContextOptions<RazorPagesMovieContext> options)
public DbSet<User> Users { get; set; } = default!;
public DbSet<Director> Directors { get; set; } = default!;
public DbSet<Review> Reviews { get; set; } = default!;
public DbSet<Artist> Artists { get; set; } = default!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand All @@ -27,6 +28,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.Name).IsRequired().HasMaxLength(100);
entity.Property(e => e.BirthDate).IsRequired();
});

// Artist configuration
modelBuilder.Entity<Artist>(entity =>
{
entity.Property(e => e.Name).IsRequired().HasMaxLength(100);
entity.Property(e => e.BirthDate).IsRequired();
entity.Property(e => e.Nationality).HasMaxLength(50);
});

// User configuration
modelBuilder.Entity<User>(entity =>
Expand Down
35 changes: 35 additions & 0 deletions src/Migrations/20241216230000_AddArtistTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace RazorPagesMovie.Migrations
{
public partial class AddArtistTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Artists",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
BirthDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Nationality = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
Timestamp = table.Column<byte[]>(type: "rowversion", rowVersion: true, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Artists", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Artists");
}
}
}
23 changes: 23 additions & 0 deletions src/Models/Artist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace RazorPagesMovie.Models
{
public class Artist
{
public int Id { get; set; }

[Required]
public string Name { get; set; } = string.Empty;

[Required]
[DataType(DataType.Date)]
public DateTime BirthDate { get; set; }

public string? Nationality { get; set; }

[Timestamp]
public byte[]? Timestamp { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/RazorPagesMovie.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateProgramFile>false</GenerateProgramFile>

<!-- Code Analysis properties for CI/CD best practices -->
<WarningsAsErrors />
<WarningsNotAsErrors />
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<AnalysisMode>Recommended</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,6 +36,16 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="3.1.24" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />

<!-- Static Analysis and Code Quality packages -->
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- <ItemGroup>
Expand All @@ -35,4 +54,8 @@
</None>
</ItemGroup> -->

<ItemGroup>
<AdditionalFiles Include="../stylecop.json" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"documentExposedElements": false,
"documentInternalElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false,
"documentInterfaces": false,
"documentExposedElements": false,
"companyName": "RazorPagesMovie",
"copyrightText": "Copyright (c) RazorPagesMovie. All rights reserved.\nLicensed under the MIT license."
},
"orderingRules": {
"systemUsingDirectivesFirst": true,
"usingDirectivesPlacement": "insideNamespace"
},
"namingRules": {
"allowCommonHungarianPrefixes": false,
"allowedHungarianPrefixes": []
},
"maintainabilityRules": {
"topLevelTypes": []
},
"layoutRules": {
"newlineAtEndOfFile": "require",
"allowConsecutiveUsings": true
},
"readabilityRules": {
"allowBuiltInTypeAliases": true
}
}
}
Loading