From cfe5961009e6645444f8e36d04deec6e874c7b86 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 29 Jul 2025 11:53:22 +0200 Subject: [PATCH] Bug 40541: Add missing new line at the end of files when missing We have insert_final_newline = true to ensure files will contain a new line at the end. However we have seen commits with "No new line" added in the git log. We should have a xt test to prevent more occurrences. We should also have a test at the QA script level: https://gitlab.com/koha-community/qa-test-tools/-/issues/96 Test plan: prove xt/find-missing-new-lines-at-the-end-of-file.t should return green. Remove the new line at the end of a file, eg. vim -b mainpage.pl :set noeol :wq Now prove xt/find-missing-new-lines-at-the-end-of-file.t is failing on mainpage.pl. Signed-off-by: Owen Leonard --- Koha/Devel/Files.pm | 52 +++++++++++++++++++ api/v1/swagger/definitions/basket.yaml | 2 +- .../definitions/circulation_rules.yaml | 2 +- api/v1/swagger/definitions/edifact_file.yaml | 2 +- .../swagger/definitions/erm_counter_file.yaml | 2 +- .../swagger/definitions/erm_counter_log.yaml | 2 +- .../definitions/erm_custom_report.yaml | 2 +- .../definitions/erm_default_usage_report.yaml | 2 +- api/v1/swagger/definitions/erm_license.yaml | 2 +- api/v1/swagger/definitions/erm_usage_mus.yaml | 2 +- api/v1/swagger/definitions/erm_usage_yus.yaml | 2 +- .../definitions/extended_attribute_value.yaml | 2 +- .../swagger/paths/acquisitions_baskets.yaml | 2 +- .../swagger/paths/acquisitions_edifiles.yaml | 2 +- api/v1/swagger/paths/article_requests.yaml | 2 +- api/v1/swagger/paths/biblios.yaml | 2 +- api/v1/swagger/paths/checkouts.yaml | 2 +- api/v1/swagger/paths/circulation_rules.yaml | 2 +- .../en/mandatory/account_credit_types.yml | 2 +- .../en/mandatory/account_debit_types.yml | 2 +- .../mysql/en/mandatory/illbatch_statuses.yml | 2 +- .../marc21_sample_fastadd_framework.yml | 2 +- .../mysql/en/optional/marc21_relatorterms.yml | 2 +- .../intranet-tmpl/prog/css/hierarchy.css | 2 +- koha-tmpl/intranet-tmpl/prog/css/print.css | 2 +- .../intranet-tmpl/prog/css/spinelabel.css | 2 +- koha-tmpl/intranet-tmpl/prog/css/tinymce.css | 2 +- .../opac-tmpl/bootstrap/css/hierarchy.css | 2 +- koha-tmpl/opac-tmpl/bootstrap/css/oai.css | 2 +- ...ind-missing-new-lines-at-the-end-of-file.t | 31 +++++++++++ 30 files changed, 111 insertions(+), 28 deletions(-) create mode 100755 xt/find-missing-new-lines-at-the-end-of-file.t diff --git a/Koha/Devel/Files.pm b/Koha/Devel/Files.pm index df1bba620bc..f6446414042 100644 --- a/Koha/Devel/Files.pm +++ b/Koha/Devel/Files.pm @@ -53,6 +53,7 @@ my $exceptions = { misc/cronjobs/build_browser_and_cloud.pl ) ], + all => [], }, js => { tidy => [ @@ -71,6 +72,12 @@ my $exceptions = { koha-tmpl/opac-tmpl/bootstrap/js/Gettext.js ) ], + all => [ + qw( + koha-tmpl/intranet-tmpl/lib + koha-tmpl/opac-tmpl/lib + ) + ], }, tt => { tidy => [ @@ -81,7 +88,20 @@ my $exceptions = { ) ], codespell => [], + all => [], + }, + yml => { + all => [], + }, + css => { + all => [ + qw( + koha-tmpl/intranet-tmpl/lib + koha-tmpl/opac-tmpl/lib + ) + ], }, + }; =head1 METHODS @@ -167,6 +187,38 @@ sub ls_tt_files { return @files; } +=head2 ls_yml_files + + my @yml_files = $file_manager->ls_yml_files(); + +Lists YAML files (with extensions .yml, .yaml) in the repository, excluding those specified in the exceptions. + +=cut + +sub ls_yml_files { + my ($self) = @_; + my $cmd = sprintf q{git ls-files '*.yml' '*.yaml' %s}, $self->build_git_exclude('yml'); + my @files = qx{$cmd}; + chomp for @files; + return @files; +} + +=head2 ls_css_files + + my @css_files = $file_manager->ls_css_files(); + +Lists CSS files (with extensions .css) in the repository, excluding those specified in the exceptions. + +=cut + +sub ls_css_files { + my ($self) = @_; + my $cmd = sprintf q{git ls-files '*.css' %s}, $self->build_git_exclude('css'); + my @files = qx{$cmd}; + chomp for @files; + return @files; +} + =head2 get_filetype my $filetype = $file_manager->get_filetype($filename); diff --git a/api/v1/swagger/definitions/basket.yaml b/api/v1/swagger/definitions/basket.yaml index 2006079fd7a..5b02068190a 100644 --- a/api/v1/swagger/definitions/basket.yaml +++ b/api/v1/swagger/definitions/basket.yaml @@ -84,4 +84,4 @@ properties: - null description: "When items should be created for orders in this basket (Options: 'ordering', 'receiving', 'cataloguing'. Null means system wide config)" -additionalProperties: false \ No newline at end of file +additionalProperties: false diff --git a/api/v1/swagger/definitions/circulation_rules.yaml b/api/v1/swagger/definitions/circulation_rules.yaml index 13160f30f4d..62f89fe4849 100644 --- a/api/v1/swagger/definitions/circulation_rules.yaml +++ b/api/v1/swagger/definitions/circulation_rules.yaml @@ -16,4 +16,4 @@ properties: description: Context of the ruleset additionalProperties: true required: - - context \ No newline at end of file + - context diff --git a/api/v1/swagger/definitions/edifact_file.yaml b/api/v1/swagger/definitions/edifact_file.yaml index 46ff9c8f4f9..de74f020934 100644 --- a/api/v1/swagger/definitions/edifact_file.yaml +++ b/api/v1/swagger/definitions/edifact_file.yaml @@ -57,4 +57,4 @@ properties: description: EDIFACT file name errors: type: array -additionalProperties: false \ No newline at end of file +additionalProperties: false diff --git a/api/v1/swagger/definitions/erm_counter_file.yaml b/api/v1/swagger/definitions/erm_counter_file.yaml index 17eea906c14..5f9e4344929 100644 --- a/api/v1/swagger/definitions/erm_counter_file.yaml +++ b/api/v1/swagger/definitions/erm_counter_file.yaml @@ -33,4 +33,4 @@ additionalProperties: false required: - usage_data_provider_id - filename - - file_content \ No newline at end of file + - file_content diff --git a/api/v1/swagger/definitions/erm_counter_log.yaml b/api/v1/swagger/definitions/erm_counter_log.yaml index 22af4f6c6cb..a1b830c8c4e 100644 --- a/api/v1/swagger/definitions/erm_counter_log.yaml +++ b/api/v1/swagger/definitions/erm_counter_log.yaml @@ -44,4 +44,4 @@ additionalProperties: false required: - filename - patron_id - - counter_files_id \ No newline at end of file + - counter_files_id diff --git a/api/v1/swagger/definitions/erm_custom_report.yaml b/api/v1/swagger/definitions/erm_custom_report.yaml index 8193f74d82b..7f0f9ac46be 100644 --- a/api/v1/swagger/definitions/erm_custom_report.yaml +++ b/api/v1/swagger/definitions/erm_custom_report.yaml @@ -61,4 +61,4 @@ properties: type: array description: usage yus items: - $ref: erm_usage_yus.yaml \ No newline at end of file + $ref: erm_usage_yus.yaml diff --git a/api/v1/swagger/definitions/erm_default_usage_report.yaml b/api/v1/swagger/definitions/erm_default_usage_report.yaml index 657421e8273..347961c4ea8 100644 --- a/api/v1/swagger/definitions/erm_default_usage_report.yaml +++ b/api/v1/swagger/definitions/erm_default_usage_report.yaml @@ -15,4 +15,4 @@ properties: additionalProperties: false required: - report_name - - report_url_params \ No newline at end of file + - report_url_params diff --git a/api/v1/swagger/definitions/erm_license.yaml b/api/v1/swagger/definitions/erm_license.yaml index 0bb1222ab57..625021f0f10 100644 --- a/api/v1/swagger/definitions/erm_license.yaml +++ b/api/v1/swagger/definitions/erm_license.yaml @@ -67,4 +67,4 @@ required: - license_id - name - status - - type \ No newline at end of file + - type diff --git a/api/v1/swagger/definitions/erm_usage_mus.yaml b/api/v1/swagger/definitions/erm_usage_mus.yaml index 6b80649e186..9bdd87fa118 100644 --- a/api/v1/swagger/definitions/erm_usage_mus.yaml +++ b/api/v1/swagger/definitions/erm_usage_mus.yaml @@ -69,4 +69,4 @@ properties: additionalProperties: false required: - title_id - - usage_data_provider_id \ No newline at end of file + - usage_data_provider_id diff --git a/api/v1/swagger/definitions/erm_usage_yus.yaml b/api/v1/swagger/definitions/erm_usage_yus.yaml index 8056a29be82..8bb2d8b6683 100644 --- a/api/v1/swagger/definitions/erm_usage_yus.yaml +++ b/api/v1/swagger/definitions/erm_usage_yus.yaml @@ -65,4 +65,4 @@ properties: additionalProperties: false required: - title_id - - usage_data_provider_id \ No newline at end of file + - usage_data_provider_id diff --git a/api/v1/swagger/definitions/extended_attribute_value.yaml b/api/v1/swagger/definitions/extended_attribute_value.yaml index 3bdfb1acbc4..1c1f67cc023 100644 --- a/api/v1/swagger/definitions/extended_attribute_value.yaml +++ b/api/v1/swagger/definitions/extended_attribute_value.yaml @@ -15,4 +15,4 @@ properties: description: value of the additional field type: string -additionalProperties: false \ No newline at end of file +additionalProperties: false diff --git a/api/v1/swagger/paths/acquisitions_baskets.yaml b/api/v1/swagger/paths/acquisitions_baskets.yaml index eab24251181..30a6c6e2e6f 100644 --- a/api/v1/swagger/paths/acquisitions_baskets.yaml +++ b/api/v1/swagger/paths/acquisitions_baskets.yaml @@ -107,4 +107,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - acquisition: order_manage \ No newline at end of file + acquisition: order_manage diff --git a/api/v1/swagger/paths/acquisitions_edifiles.yaml b/api/v1/swagger/paths/acquisitions_edifiles.yaml index a03f4b9e146..5f317217261 100644 --- a/api/v1/swagger/paths/acquisitions_edifiles.yaml +++ b/api/v1/swagger/paths/acquisitions_edifiles.yaml @@ -68,4 +68,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - acquisition: edi_manage \ No newline at end of file + acquisition: edi_manage diff --git a/api/v1/swagger/paths/article_requests.yaml b/api/v1/swagger/paths/article_requests.yaml index 12196f84565..d3413243f12 100644 --- a/api/v1/swagger/paths/article_requests.yaml +++ b/api/v1/swagger/paths/article_requests.yaml @@ -112,4 +112,4 @@ "503": description: Under maintenance schema: - $ref: "../swagger.yaml#/definitions/error" \ No newline at end of file + $ref: "../swagger.yaml#/definitions/error" diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index ab9f8ebd454..18120c5dd98 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -919,4 +919,4 @@ "503": description: Under maintenance schema: - $ref: "../swagger.yaml#/definitions/error" \ No newline at end of file + $ref: "../swagger.yaml#/definitions/error" diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml index a6d63ff1adc..9f464eef671 100644 --- a/api/v1/swagger/paths/checkouts.yaml +++ b/api/v1/swagger/paths/checkouts.yaml @@ -454,4 +454,4 @@ "503": description: Under maintenance schema: - $ref: "../swagger.yaml#/definitions/error" \ No newline at end of file + $ref: "../swagger.yaml#/definitions/error" diff --git a/api/v1/swagger/paths/circulation_rules.yaml b/api/v1/swagger/paths/circulation_rules.yaml index c89b44dbbf5..4b7e5e1cd65 100644 --- a/api/v1/swagger/paths/circulation_rules.yaml +++ b/api/v1/swagger/paths/circulation_rules.yaml @@ -158,4 +158,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - - circulate: circulate_remaining_permissions \ No newline at end of file + - circulate: circulate_remaining_permissions diff --git a/installer/data/mysql/en/mandatory/account_credit_types.yml b/installer/data/mysql/en/mandatory/account_credit_types.yml index b5e95ac1085..f73ef651765 100644 --- a/installer/data/mysql/en/mandatory/account_credit_types.yml +++ b/installer/data/mysql/en/mandatory/account_credit_types.yml @@ -78,4 +78,4 @@ tables: - code: "PROCESSING_FOUND" description: "Lost item processing fee refund" can_be_added_manually: "0" - is_system: "1" \ No newline at end of file + is_system: "1" diff --git a/installer/data/mysql/en/mandatory/account_debit_types.yml b/installer/data/mysql/en/mandatory/account_debit_types.yml index 0c3ed6b2771..e2479faa245 100644 --- a/installer/data/mysql/en/mandatory/account_debit_types.yml +++ b/installer/data/mysql/en/mandatory/account_debit_types.yml @@ -135,4 +135,4 @@ tables: can_be_invoiced: "0" can_be_sold: "0" default_amount: ~ - is_system: "1" \ No newline at end of file + is_system: "1" diff --git a/installer/data/mysql/en/mandatory/illbatch_statuses.yml b/installer/data/mysql/en/mandatory/illbatch_statuses.yml index 0d6c2c41879..7f507fdfcaa 100644 --- a/installer/data/mysql/en/mandatory/illbatch_statuses.yml +++ b/installer/data/mysql/en/mandatory/illbatch_statuses.yml @@ -39,4 +39,4 @@ tables: - code: "UNKNOWN" name: "Unknown" - is_system: "1" \ No newline at end of file + is_system: "1" diff --git a/installer/data/mysql/en/marcflavour/marc21/optional/marc21_sample_fastadd_framework.yml b/installer/data/mysql/en/marcflavour/marc21/optional/marc21_sample_fastadd_framework.yml index 23862b6cbf4..74d4bb3a683 100644 --- a/installer/data/mysql/en/marcflavour/marc21/optional/marc21_sample_fastadd_framework.yml +++ b/installer/data/mysql/en/marcflavour/marc21/optional/marc21_sample_fastadd_framework.yml @@ -97,4 +97,4 @@ sql_statements: - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '952' AND tagsubfield = 'j' AND frameworkcode = 'FA';" - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 't' AND frameworkcode = 'FA';" - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'u' AND frameworkcode = 'FA';" - - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'w' AND frameworkcode = 'FA';" \ No newline at end of file + - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'w' AND frameworkcode = 'FA';" diff --git a/installer/data/mysql/en/optional/marc21_relatorterms.yml b/installer/data/mysql/en/optional/marc21_relatorterms.yml index d97df6beda4..273a3b0e0db 100644 --- a/installer/data/mysql/en/optional/marc21_relatorterms.yml +++ b/installer/data/mysql/en/optional/marc21_relatorterms.yml @@ -1220,4 +1220,4 @@ tables: - category: "RELTERMS" authorised_value: "wts" - lib: "Writer of television story" \ No newline at end of file + lib: "Writer of television story" diff --git a/koha-tmpl/intranet-tmpl/prog/css/hierarchy.css b/koha-tmpl/intranet-tmpl/prog/css/hierarchy.css index d661bb3fabf..4208ce53b88 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/hierarchy.css +++ b/koha-tmpl/intranet-tmpl/prog/css/hierarchy.css @@ -102,4 +102,4 @@ .parents{ display:inline; cursor:crosshair; -} \ No newline at end of file +} diff --git a/koha-tmpl/intranet-tmpl/prog/css/print.css b/koha-tmpl/intranet-tmpl/prog/css/print.css index b57ffade6a5..748e6324d25 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/print.css +++ b/koha-tmpl/intranet-tmpl/prog/css/print.css @@ -381,4 +381,4 @@ p#upload_image { #catalog_detail .col-sm-push-2 { left: 0; -} \ No newline at end of file +} diff --git a/koha-tmpl/intranet-tmpl/prog/css/spinelabel.css b/koha-tmpl/intranet-tmpl/prog/css/spinelabel.css index b62e8de688f..7c169102538 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/spinelabel.css +++ b/koha-tmpl/intranet-tmpl/prog/css/spinelabel.css @@ -32,4 +32,4 @@ body { width: 100%; border-top: 1px solid #b9d8d9; background-color: #e6f0f2; -} \ No newline at end of file +} diff --git a/koha-tmpl/intranet-tmpl/prog/css/tinymce.css b/koha-tmpl/intranet-tmpl/prog/css/tinymce.css index 57fec753e70..34ccd2b8568 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/tinymce.css +++ b/koha-tmpl/intranet-tmpl/prog/css/tinymce.css @@ -1,4 +1,4 @@ body, td, pre { font-family: Arial,Helvetica,sans-serif; font-size: 13px; -} \ No newline at end of file +} diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/hierarchy.css b/koha-tmpl/opac-tmpl/bootstrap/css/hierarchy.css index d661bb3fabf..4208ce53b88 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/hierarchy.css +++ b/koha-tmpl/opac-tmpl/bootstrap/css/hierarchy.css @@ -102,4 +102,4 @@ .parents{ display:inline; cursor:crosshair; -} \ No newline at end of file +} diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/oai.css b/koha-tmpl/opac-tmpl/bootstrap/css/oai.css index 30198f25bc5..2fe7e17a5dd 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/oai.css +++ b/koha-tmpl/opac-tmpl/bootstrap/css/oai.css @@ -19,4 +19,4 @@ pre { .xmlverb-text { color: #000000; font-weight: bold } .xmlverb-comment { color: #006600; font-style: italic } .xmlverb-pi-name { color: #006600; font-style: italic } -.xmlverb-pi-content { color: #006666; font-style: italic } \ No newline at end of file +.xmlverb-pi-content { color: #006666; font-style: italic } diff --git a/xt/find-missing-new-lines-at-the-end-of-file.t b/xt/find-missing-new-lines-at-the-end-of-file.t new file mode 100755 index 00000000000..591269c7901 --- /dev/null +++ b/xt/find-missing-new-lines-at-the-end-of-file.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use Modern::Perl; +use Test::PerlTidy; +use Test::More; +use Test::NoWarnings; + +use Koha::Devel::Files; + +my $dev_files = Koha::Devel::Files->new( { context => 'all' } ); +my @files; +push @files, $dev_files->ls_perl_files; +push @files, $dev_files->ls_tt_files; +push @files, $dev_files->ls_js_files; +push @files, $dev_files->ls_yml_files; +push @files, $dev_files->ls_css_files; + +plan tests => scalar @files + 1; + +for my $file (@files) { + if ( -z $file ) { + + # File is empty + ok(1); + next; + } + open my $fh, '<', $file or die "Can't open file ($file): $!"; + seek $fh, -1, 2 or die "Can't seek ($file): $!"; + read $fh, my $char, 1; + close $fh; + is( $char, "\n", "$file should end with a new line" ); +} -- 2.39.5