diff --git a/.editorconfig b/.editorconfig index 8195330..32e3ef9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,79 +2,373 @@ root = true [*] charset = utf-8 -indent_style = space +end_of_line = lf indent_size = 2 -trim_trailing_whitespace = true +indent_style = space insert_final_newline = true -end_of_line = lf +trim_trailing_whitespace = true -[*.cake] -indent_style = tab -indent_size = 4 +[*.json] +resharper_comment_typo_highlighting = none +resharper_identifier_typo_highlighting = none +resharper_string_literal_typo_highlighting = none -[*.csproj] +[Directory.Packages.props] +insert_final_newline = false + +[dotnet-tools.json] insert_final_newline = false [*.cs] +indent_size = tab indent_style = tab -indent_size = 4 - -[{Settings.*}] -charset = utf-8-bom -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset -end_of_line = unset - -# changes from VS2017 defaults -csharp_style_expression_bodied_methods = true:suggestion -csharp_style_expression_bodied_constructors = true:suggestion -csharp_style_expression_bodied_operators = true:suggestion -csharp_prefer_braces = false:none -csharp_indent_switch_labels = false -csharp_space_after_cast = true -csharp_preserve_single_line_statements = false - -# use VS2017 defaults, but make them warnings (instead of none) -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning -dotnet_style_predefined_type_for_locals_parameters_members = true:warning -dotnet_style_explicit_tuple_names = true:warning -dotnet_style_coalesce_expression = true:warning - -# use VS2017 defaults, but make them suggestions (instead of none) -csharp_style_var_for_built_in_types = true:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_style_var_elsewhere = true:suggestion -csharp_style_expression_bodied_properties = true:suggestion -csharp_style_expression_bodied_indexers = true:suggestion -csharp_style_expression_bodied_accessors = true:suggestion - -# explicitly use VS2017 defaults -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_null_propagation = true:suggestion -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_inlined_variable_declaration = true:suggestion -csharp_prefer_simple_default_expression = true:suggestion -csharp_style_throw_expression = true:suggestion -csharp_style_conditional_delegate_call = true:suggestion -dotnet_sort_system_directives_first = true -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true +tab_width = 4 +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true csharp_new_line_before_catch = true +csharp_new_line_before_else = 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_within_query_expression_clauses = true -csharp_indent_case_contents = true -csharp_indent_labels = one_less +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true +csharp_prefer_braces = when_multiline : suggestion +csharp_prefer_simple_default_expression = true : suggestion +csharp_prefer_simple_using_statement = true : suggestion +csharp_prefer_static_local_function = true : suggestion +csharp_preferred_modifier_order = public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async : warning +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true +csharp_space_after_cast = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false -csharp_preserve_single_line_blocks = true +csharp_space_between_square_brackets = false +csharp_style_conditional_delegate_call = true : suggestion +csharp_style_deconstructed_variable_declaration = true : suggestion +csharp_style_expression_bodied_accessors = true : suggestion +csharp_style_expression_bodied_constructors = false : suggestion +csharp_style_expression_bodied_indexers = true : suggestion +csharp_style_expression_bodied_lambdas = true : suggestion +csharp_style_expression_bodied_local_functions = true : suggestion +csharp_style_expression_bodied_methods = true : suggestion +csharp_style_expression_bodied_operators = true : suggestion +csharp_style_expression_bodied_properties = true : suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true : suggestion +csharp_style_inlined_variable_declaration = true : suggestion +csharp_style_namespace_declarations = file_scoped : suggestion +csharp_style_pattern_matching_over_as_with_null_check = true : suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion +csharp_style_prefer_extended_property_pattern = true : suggestion +csharp_style_prefer_index_operator = true : suggestion +csharp_style_prefer_local_over_anonymous_function = true : suggestion +csharp_style_prefer_not_pattern = true : suggestion +csharp_style_prefer_null_check_over_type_check = true : suggestion +csharp_style_prefer_pattern_matching = true : suggestion +csharp_style_prefer_primary_constructors = true : suggestion +csharp_style_prefer_range_operator = true : suggestion +csharp_style_prefer_switch_expression = true : suggestion +csharp_style_prefer_tuple_swap = true : warning +csharp_style_throw_expression = true : suggestion +csharp_style_unused_value_assignment_preference = discard_variable : warning +csharp_style_unused_value_expression_statement_preference = discard_variable : none +csharp_style_var_elsewhere = true : suggestion +csharp_style_var_for_built_in_types = true : suggestion +csharp_style_var_when_type_is_apparent = true : suggestion +csharp_using_directive_placement = outside_namespace : warning +dotnet_analyzer_diagnostic.severity = warning +dotnet_code_quality_unused_parameters = all : suggestion +dotnet_diagnostic.CA1014.severity = none +dotnet_diagnostic.CA1030.severity = none +dotnet_diagnostic.CA1031.severity = suggestion +dotnet_diagnostic.CA1032.severity = suggestion +dotnet_diagnostic.CA1054.severity = none +dotnet_diagnostic.CA1055.severity = none +dotnet_diagnostic.CA1056.severity = none +dotnet_diagnostic.CA1062.severity = suggestion +dotnet_diagnostic.CA1063.severity = none +dotnet_diagnostic.CA1303.severity = none +dotnet_diagnostic.CA1308.severity = suggestion +dotnet_diagnostic.CA1309.severity = suggestion +dotnet_diagnostic.CA1508.severity = suggestion +dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.CA1716.severity = none +dotnet_diagnostic.CA1720.severity = suggestion +dotnet_diagnostic.CA1812.severity = none +dotnet_diagnostic.CA1815.severity = suggestion +dotnet_diagnostic.CA1816.severity = none +dotnet_diagnostic.CA1819.severity = suggestion +dotnet_diagnostic.CA1822.severity = suggestion +dotnet_diagnostic.CA1826.severity = suggestion +dotnet_diagnostic.CA1848.severity = suggestion +dotnet_diagnostic.CA2000.severity = none +dotnet_diagnostic.CA2227.severity = none +dotnet_diagnostic.CA2234.severity = none +dotnet_diagnostic.CA2237.severity = none +dotnet_diagnostic.CA2254.severity = none +dotnet_diagnostic.CA5351.severity = none +dotnet_diagnostic.IDE0001.severity = warning +dotnet_diagnostic.IDE0002.severity = warning +dotnet_diagnostic.IDE0003.severity = warning +dotnet_diagnostic.IDE0004.severity = warning +dotnet_diagnostic.IDE0005.severity = warning +dotnet_diagnostic.IDE0007.severity = suggestion +dotnet_diagnostic.IDE0008.severity = suggestion +dotnet_diagnostic.IDE0009.severity = warning +dotnet_diagnostic.IDE0010.severity = suggestion +dotnet_diagnostic.IDE0011.severity = suggestion +dotnet_diagnostic.IDE0016.severity = suggestion +dotnet_diagnostic.IDE0017.severity = suggestion +dotnet_diagnostic.IDE0018.severity = suggestion +dotnet_diagnostic.IDE0019.severity = suggestion +dotnet_diagnostic.IDE0020.severity = suggestion +dotnet_diagnostic.IDE0021.severity = suggestion +dotnet_diagnostic.IDE0022.severity = suggestion +dotnet_diagnostic.IDE0023.severity = suggestion +dotnet_diagnostic.IDE0024.severity = suggestion +dotnet_diagnostic.IDE0025.severity = suggestion +dotnet_diagnostic.IDE0026.severity = suggestion +dotnet_diagnostic.IDE0027.severity = suggestion +dotnet_diagnostic.IDE0028.severity = suggestion +dotnet_diagnostic.IDE0029.severity = warning +dotnet_diagnostic.IDE0030.severity = warning +dotnet_diagnostic.IDE0031.severity = suggestion +dotnet_diagnostic.IDE0032.severity = suggestion +dotnet_diagnostic.IDE0033.severity = warning +dotnet_diagnostic.IDE0034.severity = suggestion +dotnet_diagnostic.IDE0035.severity = warning +dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.IDE0037.severity = suggestion +dotnet_diagnostic.IDE0038.severity = suggestion +dotnet_diagnostic.IDE0039.severity = suggestion +dotnet_diagnostic.IDE0040.severity = warning +dotnet_diagnostic.IDE0041.severity = suggestion +dotnet_diagnostic.IDE0042.severity = suggestion +dotnet_diagnostic.IDE0044.severity = warning +dotnet_diagnostic.IDE0045.severity = suggestion +dotnet_diagnostic.IDE0046.severity = none +dotnet_diagnostic.IDE0047.severity = suggestion +dotnet_diagnostic.IDE0048.severity = suggestion +dotnet_diagnostic.IDE0049.severity = warning +dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.IDE0053.severity = suggestion +dotnet_diagnostic.IDE0054.severity = suggestion +dotnet_diagnostic.IDE0056.severity = suggestion +dotnet_diagnostic.IDE0057.severity = suggestion +dotnet_diagnostic.IDE0058.severity = none +dotnet_diagnostic.IDE0059.severity = warning +dotnet_diagnostic.IDE0060.severity = suggestion +dotnet_diagnostic.IDE0061.severity = suggestion +dotnet_diagnostic.IDE0062.severity = suggestion +dotnet_diagnostic.IDE0063.severity = suggestion +dotnet_diagnostic.IDE0065.severity = warning +dotnet_diagnostic.IDE0066.severity = suggestion +dotnet_diagnostic.IDE0070.severity = suggestion +dotnet_diagnostic.IDE0071.severity = suggestion +dotnet_diagnostic.IDE0072.severity = suggestion +dotnet_diagnostic.IDE0074.severity = suggestion +dotnet_diagnostic.IDE0075.severity = warning +dotnet_diagnostic.IDE0078.severity = suggestion +dotnet_diagnostic.IDE0080.severity = suggestion +dotnet_diagnostic.IDE0082.severity = warning +dotnet_diagnostic.IDE0083.severity = suggestion +dotnet_diagnostic.IDE0090.severity = suggestion +dotnet_diagnostic.IDE0100.severity = warning +dotnet_diagnostic.IDE0110.severity = warning +dotnet_diagnostic.IDE0130.severity = warning +dotnet_diagnostic.IDE0150.severity = suggestion +dotnet_diagnostic.IDE0160.severity = suggestion +dotnet_diagnostic.IDE0161.severity = suggestion +dotnet_diagnostic.IDE0170.severity = suggestion +dotnet_diagnostic.IDE0180.severity = warning +dotnet_diagnostic.IDE0290.severity = suggestion +dotnet_diagnostic.IDE1005.severity = suggestion +dotnet_diagnostic.NUnit2045.severity = suggestion +dotnet_diagnostic.SA0001.severity = none +dotnet_diagnostic.SA1003.severity = none +dotnet_diagnostic.SA1008.severity = none +dotnet_diagnostic.SA1009.severity = none +dotnet_diagnostic.SA1011.severity = none +dotnet_diagnostic.SA1013.severity = none +dotnet_diagnostic.SA1027.severity = none +dotnet_diagnostic.SA1101.severity = none +dotnet_diagnostic.SA1116.severity = none +dotnet_diagnostic.SA1117.severity = none +dotnet_diagnostic.SA1118.severity = none +dotnet_diagnostic.SA1122.severity = none +dotnet_diagnostic.SA1133.severity = none +dotnet_diagnostic.SA1134.severity = none +dotnet_diagnostic.SA1200.severity = none +dotnet_diagnostic.SA1201.severity = none +dotnet_diagnostic.SA1202.severity = none +dotnet_diagnostic.SA1203.severity = none +dotnet_diagnostic.SA1204.severity = none +dotnet_diagnostic.SA1206.severity = none +dotnet_diagnostic.SA1214.severity = suggestion +dotnet_diagnostic.SA1300.severity = none +dotnet_diagnostic.SA1303.severity = none +dotnet_diagnostic.SA1308.severity = none +dotnet_diagnostic.SA1310.severity = none +dotnet_diagnostic.SA1311.severity = none +dotnet_diagnostic.SA1407.severity = none +dotnet_diagnostic.SA1408.severity = none +dotnet_diagnostic.SA1503.severity = none +dotnet_diagnostic.SA1504.severity = none +dotnet_diagnostic.SA1513.severity = none +dotnet_diagnostic.SA1516.severity = none +dotnet_diagnostic.SA1600.severity = none +dotnet_diagnostic.SA1601.severity = none +dotnet_diagnostic.SA1602.severity = none +dotnet_diagnostic.SA1604.severity = none +dotnet_diagnostic.SA1605.severity = none +dotnet_diagnostic.SA1611.severity = none +dotnet_diagnostic.SA1615.severity = none +dotnet_diagnostic.SA1618.severity = none +dotnet_diagnostic.SA1619.severity = none +dotnet_diagnostic.SA1623.severity = none +dotnet_diagnostic.SA1629.severity = none +dotnet_diagnostic.SA1633.severity = none +dotnet_diagnostic.SA1642.severity = none +dotnet_diagnostic.SA1643.severity = none +dotnet_diagnostic.SX1101.severity = warning +dotnet_diagnostic.SYSLIB1045.severity = suggestion +dotnet_diagnostic.SYSLIB1054.severity = none +dotnet_naming_rule.local_functions_rule.severity = warning +dotnet_naming_rule.local_functions_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_rule.symbols = local_functions_symbols +dotnet_naming_rule.private_constants_rule.severity = warning +dotnet_naming_rule.private_constants_rule.style = c_lower_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_instance_fields_rule.severity = warning +dotnet_naming_rule.private_instance_fields_rule.style = m_lower_camel_case_style +dotnet_naming_rule.private_instance_fields_rule.symbols = private_instance_fields_symbols +dotnet_naming_rule.private_static_fields_rule.severity = warning +dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.severity = warning +dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_style.c_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.c_lower_camel_case_style.required_prefix = c_ +dotnet_naming_style.m_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.m_lower_camel_case_style.required_prefix = m_ +dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.local_functions_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_functions_symbols.applicable_kinds = local_function +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static, readonly +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = true +dotnet_style_coalesce_expression = true : warning +dotnet_style_collection_initializer = true : suggestion +dotnet_style_explicit_tuple_names = true : warning +dotnet_style_namespace_match_folder = true : warning +dotnet_style_null_propagation = true : suggestion +dotnet_style_object_initializer = true : suggestion +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity : none +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : none +dotnet_style_parentheses_in_other_operators = never_if_unnecessary : suggestion +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary : suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true : warning +dotnet_style_predefined_type_for_member_access = true : warning +dotnet_style_prefer_auto_properties = true : suggestion +dotnet_style_prefer_compound_assignment = true : suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true : suggestion +dotnet_style_prefer_conditional_expression_over_return = true : none +dotnet_style_prefer_inferred_anonymous_type_member_names = true : suggestion +dotnet_style_prefer_inferred_tuple_names = true : suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true : suggestion +dotnet_style_prefer_simplified_boolean_expressions = true : warning +dotnet_style_prefer_simplified_interpolation = true : suggestion +dotnet_style_qualification_for_event = false : warning +dotnet_style_qualification_for_field = false : warning +dotnet_style_qualification_for_method = false : warning +dotnet_style_qualification_for_property = false : warning +dotnet_style_readonly_field = true : warning +dotnet_style_require_accessibility_modifiers = for_non_interface_members : warning +resharper_access_to_disposed_closure_highlighting = none +resharper_access_to_modified_closure_highlighting = none +resharper_apply_auto_detected_rules = false +resharper_arrange_constructor_or_destructor_body_highlighting = hint +resharper_arrange_method_or_operator_body_highlighting = hint +resharper_arrange_missing_parentheses_highlighting = hint +resharper_arrange_trailing_comma_in_multiline_lists_highlighting = warning +resharper_comment_typo_highlighting = none +resharper_compare_of_floats_by_equality_operator_highlighting = suggestion +resharper_convert_to_primary_constructor_highlighting = hint +resharper_csharp_align_first_arg_by_paren = false +resharper_csharp_align_linq_query = false +resharper_csharp_align_multiline_argument = false +resharper_csharp_align_multiline_array_and_object_initializer = false +resharper_csharp_align_multiline_binary_expressions_chain = false +resharper_csharp_align_multiline_calls_chain = false +resharper_csharp_align_multiline_expression = false +resharper_csharp_align_multiline_extends_list = false +resharper_csharp_align_multiline_for_stmt = false +resharper_csharp_align_multiline_parameter = false +resharper_csharp_align_multiline_statement_conditions = false +resharper_csharp_align_multiline_switch_expression = false +resharper_csharp_align_multiple_declaration = false +resharper_csharp_align_multline_type_parameter_constrains = false +resharper_csharp_align_multline_type_parameter_list = false +resharper_csharp_align_tuple_components = false +resharper_csharp_blank_lines_after_block_statements = 0 +resharper_csharp_indent_anonymous_method_block = false +resharper_csharp_indent_nested_for_stmt = true +resharper_csharp_indent_nested_foreach_stmt = true +resharper_csharp_indent_nested_while_stmt = true +resharper_csharp_int_align = false +resharper_csharp_keep_existing_arrangement = true +resharper_csharp_nested_ternary_style = simple_wrap +resharper_csharp_new_line_before_while = true +resharper_csharp_parentheses_group_non_obvious_operations = conditional +resharper_csharp_parentheses_non_obvious_operations = shift, bitwise +resharper_csharp_parentheses_redundancy_style = remove_if_not_clarifies_precedence +resharper_csharp_space_within_single_line_array_initializer_braces = true +resharper_csharp_trailing_comma_in_multiline_lists = true +resharper_csharp_wrap_before_ternary_opsigns = true +resharper_csharp_wrap_lines = false +resharper_csharp_wrap_ternary_expr_style = wrap_if_long +resharper_identifier_typo_highlighting = none +resharper_invert_if_highlighting = none +resharper_is_expression_always_true_highlighting = hint +resharper_localizable_element_highlighting = none +resharper_pattern_always_of_type_highlighting = none +resharper_string_literal_typo_highlighting = none +resharper_unused_auto_property_accessor_global_highlighting = none +resharper_unused_auto_property_accessor_local_highlighting = suggestion +resharper_unused_member_global_highlighting = none +resharper_unused_member_local_highlighting = suggestion diff --git a/.gitattributes b/.gitattributes index 1c07025..4092f8f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,4 @@ *.cs text diff=csharp *.csproj text merge=union -*.sln text eol=crlf merge=union +*.sln text merge=union diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..5e1e243 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,40 @@ +name: Build + +on: + push: + branches: [master] + tags-ignore: ['**'] + pull_request: + workflow_dispatch: + +env: + DOTNET_NOLOGO: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + +defaults: + run: + shell: pwsh + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Install .NET + uses: actions/setup-dotnet@v3 + - name: Check out code + uses: actions/checkout@v3 + - name: Restore + run: .\build.ps1 restore + - name: Build + run: .\build.ps1 build --skip restore + - name: Test + run: .\build.ps1 test --skip build + - name: Publish + if: runner.os == 'Windows' && github.repository_owner == 'Faithlife' && github.ref == 'refs/heads/master' + env: + BUILD_BOT_PASSWORD: ${{ secrets.BUILD_BOT_PASSWORD }} + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + run: .\build.ps1 publish --skip test diff --git a/.gitignore b/.gitignore index 0e44f7d..a2ad192 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,16 @@ -# ignore output folders +.vs/ +.idea/ +artifacts/ bin/ -build/ -cake/ obj/ -ipch/ release/ -tools/ -# ignore user-specific options/cache files -.vs/ -Thumbs.db *.cache -*.user -*.opensdf -*.sdf -*.suo -*.userprefs +*.log *.ncrunchproject *.ncrunchsolution +*.user +launchSettings.json nCrunchTemp* _ReSharper* -launchSettings.json +.DS_Store diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6c5c048..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: csharp -mono: latest -dotnet: 2.1.401 -dist: trusty -sudo: false - -script: -- ./build.sh --target=NuGetPackage diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 612bd0b..8ab1646 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,9 @@ -# Contributing to FindReplaceCode +# Contributing -## Prerequisites +## Publishing -* Install [Visual Studio 2017](https://www.visualstudio.com/downloads/) or [Visual Studio Code](https://code.visualstudio.com/) with the [editorconfig extension](https://github.com/editorconfig/editorconfig-vscode). -* Install [.NET Core 2.0](https://www.microsoft.com/net/core). +* To publish the library, update the `` in [`Directory.Build.props`](Directory.Build.props), add a corresponding section to the top of [`ReleaseNotes.md`](ReleaseNotes.md), commit, and push. -## Guidelines +## Template -* All new code **must** have complete unit tests. -* All public classes, methods, interfaces, enums, etc. **must** have correct XML documentation comments. -* Update [VersionHistory](VersionHistory.md) with a human-readable description of the change. - -## How to Build - -* Clone the repository: `git clone https://github.com/Faithlife/FindReplaceCode.git` -* `cd FindReplaceCode` -* `dotnet test tests/FindReplaceCode.Tests` +* This repository uses the [`faithlife-build`](https://github.com/Faithlife/CSharpTemplate/tree/faithlife-build) template of [`Faithlife/CSharpTemplate`](https://github.com/Faithlife/CSharpTemplate). diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..6c40d94 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,37 @@ + + + + 1.1.0 + 12.0 + enable + enable + true + $(NoWarn);1591;1998;NU1507;NU5105 + en-US + embedded + Faithlife + RepoName + MIT + https://github.com/$(GitHubOrganization)/$(RepositoryName) + https://github.com/$(GitHubOrganization)/$(RepositoryName)/blob/master/ReleaseNotes.md + https://github.com/$(GitHubOrganization)/$(RepositoryName).git + Faithlife + Copyright $(Authors) + true + true + true + latest-all + true + true + false + false + false + true + + + + $(VersionPrefix).$(BuildNumber) + true + + + diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..5c6392d --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,16 @@ + + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/FindReplaceCode.sln b/FindReplaceCode.sln index 18ca383..ce70dbd 100644 --- a/FindReplaceCode.sln +++ b/FindReplaceCode.sln @@ -1,23 +1,26 @@ + Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.2003 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FindReplaceCode", "src\FindReplaceCode\FindReplaceCode.csproj", "{4E2B87C2-B50A-4876-A1EC-118554B4B389}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FindReplaceCode", "src\FindReplaceCode\FindReplaceCode.csproj", "{1F75E8CE-F59A-4738-81EC-17B71C125A06}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C2B8692-C413-4D47-BBC5-046E63526F9D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "tools\Build\Build.csproj", "{9BB3C85C-100E-4128-A9AF-8F697D753538}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A21957E2-3EB8-4CA5-8537-04F60C9F98D5}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore - .travis.yml = .travis.yml - appveyor.yml = appveyor.yml - build.cake = build.cake build.ps1 = build.ps1 - build.sh = build.sh CONTRIBUTING.md = CONTRIBUTING.md + Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props + global.json = global.json LICENSE = LICENSE + nuget.config = nuget.config README.md = README.md - VersionHistory.md = VersionHistory.md + ReleaseNotes.md = ReleaseNotes.md EndProjectSection EndProject Global @@ -26,16 +29,19 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4E2B87C2-B50A-4876-A1EC-118554B4B389}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4E2B87C2-B50A-4876-A1EC-118554B4B389}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4E2B87C2-B50A-4876-A1EC-118554B4B389}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4E2B87C2-B50A-4876-A1EC-118554B4B389}.Release|Any CPU.Build.0 = Release|Any CPU + {1F75E8CE-F59A-4738-81EC-17B71C125A06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F75E8CE-F59A-4738-81EC-17B71C125A06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F75E8CE-F59A-4738-81EC-17B71C125A06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F75E8CE-F59A-4738-81EC-17B71C125A06}.Release|Any CPU.Build.0 = Release|Any CPU + {9BB3C85C-100E-4128-A9AF-8F697D753538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BB3C85C-100E-4128-A9AF-8F697D753538}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BB3C85C-100E-4128-A9AF-8F697D753538}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BB3C85C-100E-4128-A9AF-8F697D753538}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {61721187-4DC2-4A62-9B7A-93E34B4071E5} - SolutionGuid = {C2367BAD-9F87-4BED-8E58-C1D7E5C3FE51} + SolutionGuid = {28CD7BF1-0965-4088-8597-4C08C20C814C} EndGlobalSection EndGlobal diff --git a/FindReplaceCode.sln.DotSettings b/FindReplaceCode.sln.DotSettings new file mode 100644 index 0000000..6f09a21 --- /dev/null +++ b/FindReplaceCode.sln.DotSettings @@ -0,0 +1,2 @@ + + <?xml version="1.0" encoding="utf-16"?><Profile name="Build"><XAMLCollapseEmptyTags>False</XAMLCollapseEmptyTags><CppClangTidyCleanupDescriptor /><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="False" ArrangeBraces="False" ArrangeAttributes="False" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="False" ArrangeVarStyle="True" ArrangeTrailingCommas="True" /><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CSShortenReferences>True</CSShortenReferences><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly></Profile> diff --git a/LICENSE b/LICENSE index 1264693..5595acf 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright 2018 Faithlife Corporation +Copyright 2024 Faithlife Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 11ff144..b20e793 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ -# FindReplaceCode +# ProjectName Used to generate a new code project from a template. +[![Build](https://github.com/Faithlife/RepoName/workflows/Build/badge.svg)](https://github.com/Faithlife/RepoName/actions?query=workflow%3ABuild) [![NuGet](https://img.shields.io/nuget/v/ProjectName.svg)](https://www.nuget.org/packages/ProjectName) + +[Documentation](https://faithlife.github.io/FindReplaceCode/) | [Release Notes](https://github.com/Faithlife/FindReplaceCode/blob/master/ReleaseNotes.md) | [Contributing](https://github.com/Faithlife/FindReplaceCode/blob/master/CONTRIBUTING.md) + **WARNING:** This tool is recursively destructive. Please be extremely careful with it. This tool is installed as a dotnet tool: `dotnet tool install Faithlife.FindReplaceCode.Tool --global`. @@ -43,15 +47,3 @@ Any subfolder whose name starts with a period (e.g. `.git`) is automatically exc ## Issues Only [certain file extensions](src/FindReplaceCode/ProgramSettings.cs) are currently considered for content replacement. Please let us know if there are others that should be added. - -## Build Status - -Ubuntu | Windows | NuGet ---- | --- | --- -[![Travis CI](https://img.shields.io/travis/Faithlife/FindReplaceCode/master.svg)](https://travis-ci.org/Faithlife/FindReplaceCode) | [![AppVeyor](https://img.shields.io/appveyor/ci/Faithlife/findreplacecode/master.svg)](https://ci.appveyor.com/project/Faithlife/findreplacecode) | [![NuGet](https://img.shields.io/nuget/v/Faithlife.FindReplaceCode.Tool.svg)](https://www.nuget.org/packages/Faithlife.FindReplaceCode.Tool) - -## Documentation - -* License: [MIT](LICENSE) -* [Version History](VersionHistory.md) -* [Contributing Guidelines](CONTRIBUTING.md) diff --git a/ReleaseNotes.md b/ReleaseNotes.md new file mode 100644 index 0000000..378c37c --- /dev/null +++ b/ReleaseNotes.md @@ -0,0 +1,10 @@ +# Release Notes + +## 1.1.0 + +* Find and replace `.js`, `.py`, and `.ts` files. +* Support snake case and kebab case, i.e. when replacing `SourceText` with `TargetText`, replace `source_text` with `target_text` and `source-text` with `target-text`. + +## 1.0.0 + +* Initial release. diff --git a/VersionHistory.md b/VersionHistory.md deleted file mode 100644 index 46d5a7d..0000000 --- a/VersionHistory.md +++ /dev/null @@ -1,19 +0,0 @@ -# Version History - -## Pending - -Add changes here when they're committed to the `master` branch. Move them to "Released" once the version number -is updated in preparation for publishing an updated NuGet package. - -Prefix the description of the change with `[major]`, `[minor]` or `[patch]` in accordance with [SemVer](http://semver.org). - -## Released - -### 1.1.0 - -* Find and replace `.js`, `.py`, and `.ts` files. -* Support snake case and kebab case, i.e. when replacing `SourceText` with `TargetText`, replace `source_text` with `target_text` and `source-text` with `target-text`. - -### 1.0.0 - -* Initial release. diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d5677db..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '{build}' -image: Visual Studio 2017 -environment: - NUGETAPIKEY: - secure: Ev6JfzK7FYZzsR4ALWtJs95U98Pa9FxgMxECDA0LGNidWwULyKoQIKYQwMVZ1s0U - BUILD_BOT_PASSWORD: - secure: wJ9JVS5hSAp9ItYlHKxTPg== -build_script: -- ps: .\build.ps1 --target=NuGetPublish """--trigger=$env:APPVEYOR_REPO_TAG_NAME""" "--nugetApiKey=$env:NUGETAPIKEY" -test: off -artifacts: -- path: 'release\*.nupkg' diff --git a/build.cake b/build.cake deleted file mode 100644 index ace8b3a..0000000 --- a/build.cake +++ /dev/null @@ -1,99 +0,0 @@ -#addin Cake.Git -#addin Cake.XmlDocMarkdown&version=1.4.1 - -using System.Text.RegularExpressions; - -var target = Argument("target", "Default"); -var configuration = Argument("configuration", "Release"); -var nugetApiKey = Argument("nugetApiKey", ""); -var trigger = Argument("trigger", ""); -var versionSuffix = Argument("versionSuffix", ""); - -var solutionFileName = "FindReplaceCode.sln"; - -var nugetSource = "https://api.nuget.org/v3/index.json"; -var buildBotUserName = "faithlifebuildbot"; -var buildBotPassword = EnvironmentVariable("BUILD_BOT_PASSWORD"); - -Task("Clean") - .Does(() => - { - CleanDirectories("src/**/bin"); - CleanDirectories("src/**/obj"); - CleanDirectories("release"); - }); - -Task("Restore") - .Does(() => - { - DotNetCoreRestore(solutionFileName); - }); - -Task("Build") - .IsDependentOn("Restore") - .Does(() => - { - DotNetCoreBuild(solutionFileName, new DotNetCoreBuildSettings { Configuration = configuration, NoRestore = true, ArgumentCustomization = args => args.Append("--verbosity normal") }); - }); - -Task("Rebuild") - .IsDependentOn("Clean") - .IsDependentOn("Build"); - -Task("NuGetPackage") - .IsDependentOn("Rebuild") - .Does(() => - { - if (string.IsNullOrEmpty(versionSuffix) && !string.IsNullOrEmpty(trigger)) - versionSuffix = Regex.Match(trigger, @"^v[^\.]+\.[^\.]+\.[^\.]+-(.+)").Groups[1].ToString(); - foreach (var projectPath in GetFiles("src/**/*.csproj").Select(x => x.FullPath)) - DotNetCorePack(projectPath, new DotNetCorePackSettings { Configuration = configuration, NoBuild = true, NoRestore = true, OutputDirectory = "release", VersionSuffix = versionSuffix }); - }); - -Task("NuGetPublish") - .IsDependentOn("NuGetPackage") - .Does(() => - { - var nupkgPaths = GetFiles("release/*.nupkg").Select(x => x.FullPath).ToList(); - - string version = null; - foreach (var nupkgPath in nupkgPaths) - { - string nupkgVersion = Regex.Match(nupkgPath, @"\.([^\.]+\.[^\.]+\.[^\.]+)\.nupkg$").Groups[1].ToString(); - if (version == null) - version = nupkgVersion; - else if (version != nupkgVersion) - throw new InvalidOperationException($"Mismatched package versions '{version}' and '{nupkgVersion}'."); - } - - if (!string.IsNullOrEmpty(nugetApiKey) && (trigger == null || Regex.IsMatch(trigger, "^v[0-9]"))) - { - if (trigger != null && trigger != $"v{version}") - throw new InvalidOperationException($"Trigger '{trigger}' doesn't match package version '{version}'."); - - var pushSettings = new NuGetPushSettings { ApiKey = nugetApiKey, Source = nugetSource }; - foreach (var nupkgPath in nupkgPaths) - NuGetPush(nupkgPath, pushSettings); - } - else - { - Information("To publish this package, push this git tag: v" + version); - } - }); - -Task("Default") - .IsDependentOn("Build"); - -void ExecuteProcess(string exePath, string arguments) -{ - if (IsRunningOnUnix()) - { - arguments = exePath + " " + arguments; - exePath = "mono"; - } - int exitCode = StartProcess(exePath, arguments); - if (exitCode != 0) - throw new InvalidOperationException($"{exePath} failed with exit code {exitCode}."); -} - -RunTarget(target); diff --git a/build.ps1 b/build.ps1 old mode 100644 new mode 100755 index 67d3f25..21a0bb6 --- a/build.ps1 +++ b/build.ps1 @@ -1,55 +1,17 @@ -<# -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. - -.PARAMETER Target -The build script target to run. -#> - -[CmdletBinding()] -Param( - [string]$Target, - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs -) - -# create cake directory -$CakeDirPath = Join-Path $PSScriptRoot "cake" -New-Item -Path $CakeDirPath -Type Directory -ErrorAction SilentlyContinue | Out-Null - -# create packages.config -$PackagesConfigPath = Join-Path $CakeDirPath "packages.config" -If (!(Test-Path $PackagesConfigPath)) { - [System.IO.File]::WriteAllLines($PackagesConfigPath, @( - "", - "", - "`t", - "")) +#!/usr/bin/env pwsh +$ErrorActionPreference = 'Stop' +Push-Location $PSScriptRoot +try { + if (-not (Test-Path ./tools/bin/Build) -or + (Get-ChildItem ./tools/Build/* | Measure-Object LastWriteTime -Maximum).Maximum -gt + (Get-ChildItem ./tools/bin/Build/* | Measure-Object LastWriteTime -Maximum).Maximum) { + if (Test-Path ./tools/bin/Build) { Remove-Item ./tools/bin/Build -Recurse } + dotnet publish ./tools/Build/Build.csproj --output ./tools/bin/Build --nologo --verbosity quiet + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + dotnet ./tools/bin/Build/Build.dll $args + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } } - -# download nuget.exe if not in path and not already downloaded -$NuGetExe = Get-Command "nuget.exe" -ErrorAction SilentlyContinue -If ($NuGetExe -ne $null) { - $NuGetExePath = $NuGetExe.Path +finally { + Pop-Location } -Else { - $NuGetExePath = Join-Path $CakeDirPath "nuget.exe" - If (!(Test-Path $NuGetExePath)) { - Invoke-WebRequest -Uri http://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NuGetExePath - } -} - -# use NuGet to download Cake -Push-Location $CakeDirPath -Invoke-Expression "&`"$NuGetExePath`" install -ExcludeVersion -OutputDirectory ." -If ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet tools." -} -Pop-Location - -# run Cake with specified arguments -$CakeExePath = Join-Path $CakeDirPath "Cake/Cake.exe" -$ExtraArgs = "" -if ($Target) { $ExtraArgs += "--target=$Target" } -Invoke-Expression "& `"$CakeExePath`" --paths_tools=cake --experimental $ExtraArgs $ScriptArgs" -Exit $LASTEXITCODE diff --git a/build.sh b/build.sh deleted file mode 100755 index 52d3ce0..0000000 --- a/build.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/cake -NUGET_EXE=$TOOLS_DIR/nuget.exe -NUGET_URL=https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -CAKE_VERSION=0.30.0 -CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe - -# Define default arguments. -SCRIPT_ARGUMENTS=$@ - -# Make sure the tools folder exist. -if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" -fi - -########################################################################### -# INSTALL NUGET -########################################################################### - -# Download NuGet if it does not exist. -if [ ! -f "$NUGET_EXE" ]; then - echo "Downloading NuGet..." - curl -Lsfo "$NUGET_EXE" $NUGET_URL - if [ $? -ne 0 ]; then - echo "An error occurred while downloading nuget.exe." - exit 1 - fi -fi - -########################################################################### -# INSTALL CAKE -########################################################################### - -if [ ! -f "$CAKE_EXE" ]; then - mono "$NUGET_EXE" install Cake -Version $CAKE_VERSION -OutputDirectory "$TOOLS_DIR" - if [ $? -ne 0 ]; then - echo "An error occurred while installing Cake." - exit 1 - fi -fi - -# Make sure that Cake has been installed. -if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 -fi - -########################################################################### -# RUN BUILD SCRIPT -########################################################################### - -export MONO_ROOT=$(dirname $(which mono))/../ - -# Start Cake -exec mono "$CAKE_EXE" build.cake --paths_tools=cake --experimental ${SCRIPT_ARGUMENTS[@]} diff --git a/global.json b/global.json new file mode 100644 index 0000000..391ba3c --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "8.0.100", + "rollForward": "latestFeature" + } +} diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..6873eb9 --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props deleted file mode 100644 index 48aefe8..0000000 --- a/src/Directory.Build.props +++ /dev/null @@ -1,24 +0,0 @@ - - - - $(MONO_ROOT)/lib/mono/4.6.1-api/ - $(MONO_ROOT)/lib/mono/4.7-api/ - latest - true - true - $(NoWarn);1591 - portable - True - FindReplaceCode - https://raw.githubusercontent.com/Faithlife/$(RepositoryName)/master/LICENSE - https://github.com/Faithlife/$(RepositoryName) - https://github.com/Faithlife/$(RepositoryName)/blob/master/VersionHistory.md#released - https://github.com/Faithlife/$(RepositoryName).git - Faithlife Corporation - Copyright Faithlife Corporation - true - true - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - diff --git a/src/FindReplaceCode/FindReplaceCode.csproj b/src/FindReplaceCode/FindReplaceCode.csproj index f824656..2875262 100644 --- a/src/FindReplaceCode/FindReplaceCode.csproj +++ b/src/FindReplaceCode/FindReplaceCode.csproj @@ -1,10 +1,17 @@ + Exe - netcoreapp2.1 - 1.1.0 + net6.0;net7.0;net8.0 + true true findreplacecode Faithlife.FindReplaceCode.Tool + README.md - \ No newline at end of file + + + + + + diff --git a/src/FindReplaceCode/Program.cs b/src/FindReplaceCode/Program.cs index 68c00c7..51a65a9 100644 --- a/src/FindReplaceCode/Program.cs +++ b/src/FindReplaceCode/Program.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; -using System.IO; -using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -14,14 +10,14 @@ public sealed class Program public Program(string[] args) { if (args.Length < 3) - throw new ProgramException(s_fullUsageMessage); + throw new ProgramException(c_fullUsageMessage); if (args.Length % 2 != 1) throw new ProgramException("Missing , or the last is missing its ."); m_folderPath = Path.GetFullPath(args[0]); var searchReplaceArgs = new List>(); - for (int index = 1; index < args.Length; index += 2) + for (var index = 1; index < args.Length; index += 2) searchReplaceArgs.Add(new KeyValuePair(args[index], args[index + 1])); m_searchReplaceArgs = searchReplaceArgs.AsReadOnly(); } @@ -34,7 +30,7 @@ public void Run() if (m_searchReplaceArgs.Any(x => string.IsNullOrWhiteSpace(x.Key) || string.IsNullOrWhiteSpace(x.Value))) throw new ProgramException("Neither nor can be blank."); - DirectoryInfo folderInfo = new DirectoryInfo(m_folderPath); + var folderInfo = new DirectoryInfo(m_folderPath); var infos = folderInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories) .Where(x => !ShouldIgnoreFileSystemInfo(x)).ToList(); @@ -48,11 +44,11 @@ public void Run() // create new GUIDs for csproj files that will be renamed foreach (var csprojFile in infos.OfType().Where(x => x.Extension == ".csproj")) { - string oldName = csprojFile.Name; + var oldName = csprojFile.Name; if (oldName != ReplaceStrings(oldName)) { - string csprojFileText = File.ReadAllText(csprojFile.FullName); - var projectRegex = new Regex(@"^\s*(" + c_guidPattern + @")", RegexOptions.CultureInvariant | RegexOptions.Multiline); + var csprojFileText = File.ReadAllText(csprojFile.FullName); + var projectRegex = new Regex(@"^\s*(" + c_guidPattern + ")", RegexOptions.CultureInvariant | RegexOptions.Multiline); foreach (var oldGuid in projectRegex.Matches(csprojFileText).Cast().Select(x => Guid.Parse(x.Groups[1].ToString()))) oldGuids.Add(oldGuid); } @@ -67,7 +63,7 @@ public void Run() if (m_editCount != 0 || m_renameCount != 0) { string backupFolderPath; - int backupFolderSuffix = 0; + var backupFolderSuffix = 0; while (true) { backupFolderPath = Path.Combine(Path.GetTempPath(), Path.GetFileName(m_folderPath) + (backupFolderSuffix == 0 ? "" : ("-" + backupFolderSuffix))); @@ -80,7 +76,7 @@ public void Run() Console.WriteLine("The folder will first be backed up to: {0}", backupFolderPath); Console.Write("ARE YOU SURE you want to do this? Type yes if you dare: "); - string confirmation = Console.ReadLine(); + var confirmation = Console.ReadLine(); Console.WriteLine(); if (confirmation == "yes") @@ -92,7 +88,7 @@ public void Run() backupFolderInfo.Create(); CopyFilesRecursively(folderInfo, backupFolderInfo); - bool success = false; + var success = false; try { FindReplace(infos, doIt: true); @@ -117,9 +113,9 @@ public void Run() public static void CopyFilesRecursively(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory) { - foreach (DirectoryInfo directory in sourceDirectory.GetDirectories()) + foreach (var directory in sourceDirectory.GetDirectories()) CopyFilesRecursively(directory, targetDirectory.CreateSubdirectory(directory.Name)); - foreach (FileInfo file in sourceDirectory.GetFiles()) + foreach (var file in sourceDirectory.GetFiles()) file.CopyTo(Path.Combine(targetDirectory.FullName, file.Name)); } @@ -156,19 +152,13 @@ private IEnumerable> GetEnhancedFindReplacePairs(Ke private static KeyValuePair? TryGetEnhancedFindReplacePairs(KeyValuePair searchReplacePair, Func transform) { - string newKey = transform(searchReplacePair.Key); + var newKey = transform(searchReplacePair.Key); return newKey != searchReplacePair.Key ? new KeyValuePair(newKey, transform(searchReplacePair.Value)) : default(KeyValuePair?); } - private static string Capitalize(string text) - { - return text.Substring(0, 1).ToUpperInvariant() + text.Substring(1); - } + private static string Capitalize(string text) => string.Concat(text.Substring(0, 1).ToUpperInvariant(), text.AsSpan(1)); - private static string Uncapitalize(string text) - { - return text.Substring(0, 1).ToLowerInvariant() + text.Substring(1); - } + private static string Uncapitalize(string text) => string.Concat(text.Substring(0, 1).ToLowerInvariant(), text.AsSpan(1)); public static void Main(string[] args) { @@ -191,7 +181,7 @@ private void FindReplace(IReadOnlyCollection infos, bool doIt) m_editCount = 0; m_renameCount = 0; - foreach (FileInfo info in infos.OfType()) + foreach (var info in infos.OfType()) { if (ShouldFindReplaceFileContent(info)) { @@ -199,9 +189,9 @@ private void FindReplace(IReadOnlyCollection infos, bool doIt) using (var stream = File.OpenRead(info.FullName)) hasBOM = stream.ReadByte() == 0xEF && stream.ReadByte() == 0xBB && stream.ReadByte() == 0xBF; - string oldContent = File.ReadAllText(info.FullName); + var oldContent = File.ReadAllText(info.FullName); - string newContent = ReplaceGuids(ReplaceStrings(oldContent)); + var newContent = ReplaceGuids(ReplaceStrings(oldContent)); if (oldContent != newContent) { @@ -214,16 +204,16 @@ private void FindReplace(IReadOnlyCollection infos, bool doIt) } } - foreach (FileInfo info in infos.OfType()) + foreach (var info in infos.OfType()) { - string oldName = info.Name; - string newName = ReplaceStrings(oldName); + var oldName = info.Name; + var newName = ReplaceStrings(oldName); if (oldName != newName) { Console.WriteLine("{0} => {1}", info.FullName, Path.GetFileName(newName)); m_renameCount++; - string newPath = Path.Combine(Path.GetDirectoryName(info.FullName), newName); + var newPath = Path.Combine(Path.GetDirectoryName(info.FullName)!, newName); if (File.Exists(newPath) || Directory.Exists(newPath)) throw new ProgramException(string.Format(CultureInfo.InvariantCulture, "{0} already exists!", newPath)); @@ -232,16 +222,16 @@ private void FindReplace(IReadOnlyCollection infos, bool doIt) } } - foreach (DirectoryInfo info in infos.OfType()) + foreach (var info in infos.OfType()) { - string oldName = info.Name; - string newName = ReplaceStrings(oldName); + var oldName = info.Name; + var newName = ReplaceStrings(oldName); if (oldName != newName) { Console.WriteLine("{0} => {1}", info.FullName, Path.GetFileName(newName)); m_renameCount++; - string newPath = Path.Combine(Path.GetDirectoryName(info.FullName), newName); + var newPath = Path.Combine(Path.GetDirectoryName(info.FullName)!, newName); if (File.Exists(newPath) || Directory.Exists(newPath)) throw new ProgramException(string.Format(CultureInfo.InvariantCulture, "{0} already exists!", newPath)); @@ -262,22 +252,22 @@ private static bool ShouldFindReplaceFileContent(FileSystemInfo info) if (!(info is FileInfo)) return false; - string extension = Path.GetExtension(info.Name).ToLowerInvariant(); + var extension = Path.GetExtension(info.Name).ToLowerInvariant(); return ProgramSettings.FindReplaceFileContentExtensions.Contains(extension); } private string ReplaceStrings(string oldText) { - string newText = oldText; - foreach (var searchReplacePair in m_searchReplacePairs) - newText = newText.Replace(searchReplacePair.Key, searchReplacePair.Value); + var newText = oldText; + foreach (var searchReplacePair in m_searchReplacePairs!) + newText = newText.Replace(searchReplacePair.Key, searchReplacePair.Value, StringComparison.Ordinal); return newText; } private string ReplaceGuids(string oldText) { - string newText = oldText; - foreach (var projectGuid in m_searchReplaceGuids) + var newText = oldText; + foreach (var projectGuid in m_searchReplaceGuids!) newText = projectGuid.Key.Replace(newText, x => RenderMatchingGuid(x, projectGuid.Value)); return newText; } @@ -289,16 +279,15 @@ private static Regex CreateRegexForGuid(Guid guid) private static string RenderMatchingGuid(Match match, Guid value) { - string oldText = match.ToString(); - string newText = value.ToString(); + var oldText = match.ToString(); + var newText = value.ToString(); +#pragma warning disable CA1862 return oldText != oldText.ToUpperInvariant() ? newText : newText.ToUpperInvariant(); +#pragma warning restore CA1862 } private static string ToSnakeCase(string value, char separator) { - if (value == null) - return null; - var words = GetWords(value); return string.Join(separator.ToString(), words.Select(x => x.ToLowerInvariant())); } @@ -307,18 +296,15 @@ private static string ToSnakeCase(string value, char separator) private const string c_guidPattern = @"\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\}"; - private static readonly string s_fullUsageMessage = string.Join(Environment.NewLine, new[] - { - "Usage: FindReplaceCode.exe [ ...]" - }); + private const string c_fullUsageMessage = "Usage: FindReplaceCode.exe [ ...]"; private static readonly Regex s_hiddenDirectoryRegex = new Regex(@"[\\/]\..*[\\/]", RegexOptions.CultureInvariant); private static readonly Regex s_word = new Regex("[A-Z]([A-Z]*(?![a-z])|[a-z]*)|[a-z]+|[0-9]+", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture); private readonly string m_folderPath; private readonly ReadOnlyCollection> m_searchReplaceArgs; - private List> m_searchReplacePairs; - private List> m_searchReplaceGuids; + private List>? m_searchReplacePairs; + private List>? m_searchReplaceGuids; private int m_editCount; private int m_renameCount; } diff --git a/src/FindReplaceCode/ProgramException.cs b/src/FindReplaceCode/ProgramException.cs index b7b7833..4747002 100644 --- a/src/FindReplaceCode/ProgramException.cs +++ b/src/FindReplaceCode/ProgramException.cs @@ -1,5 +1,3 @@ -using System; - namespace FindReplaceCode { public sealed class ProgramException : Exception diff --git a/src/FindReplaceCode/ProgramSettings.cs b/src/FindReplaceCode/ProgramSettings.cs index 741a74c..796ca0d 100644 --- a/src/FindReplaceCode/ProgramSettings.cs +++ b/src/FindReplaceCode/ProgramSettings.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace FindReplaceCode { public static class ProgramSettings diff --git a/tools/Build/Build.cs b/tools/Build/Build.cs new file mode 100644 index 0000000..f1b5b76 --- /dev/null +++ b/tools/Build/Build.cs @@ -0,0 +1,15 @@ +return BuildRunner.Execute(args, build => +{ + var gitLogin = new GitLoginInfo("faithlifebuildbot", Environment.GetEnvironmentVariable("BUILD_BOT_PASSWORD") ?? ""); + + build.AddDotNetTargets( + new DotNetBuildSettings + { + NuGetApiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY"), + PackageSettings = new DotNetPackageSettings + { + GitLogin = gitLogin, + PushTagOnPublish = x => $"v{x.Version}", + }, + }); +}); diff --git a/tools/Build/Build.csproj b/tools/Build/Build.csproj new file mode 100644 index 0000000..94c9978 --- /dev/null +++ b/tools/Build/Build.csproj @@ -0,0 +1,12 @@ + + + + Exe + net8.0 + + + + + + +