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 <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit e9eb20249e)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-07-29 11:53:22 +02:00 committed by Paul Derscheid
parent 1ef30cc10c
commit cb504d5cc7
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
30 changed files with 111 additions and 28 deletions

View File

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

View File

@ -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
additionalProperties: false

View File

@ -16,4 +16,4 @@ properties:
description: Context of the ruleset
additionalProperties: true
required:
- context
- context

View File

@ -57,4 +57,4 @@ properties:
description: EDIFACT file name
errors:
type: array
additionalProperties: false
additionalProperties: false

View File

@ -33,4 +33,4 @@ additionalProperties: false
required:
- usage_data_provider_id
- filename
- file_content
- file_content

View File

@ -44,4 +44,4 @@ additionalProperties: false
required:
- filename
- patron_id
- counter_files_id
- counter_files_id

View File

@ -61,4 +61,4 @@ properties:
type: array
description: usage yus
items:
$ref: erm_usage_yus.yaml
$ref: erm_usage_yus.yaml

View File

@ -15,4 +15,4 @@ properties:
additionalProperties: false
required:
- report_name
- report_url_params
- report_url_params

View File

@ -67,4 +67,4 @@ required:
- license_id
- name
- status
- type
- type

View File

@ -69,4 +69,4 @@ properties:
additionalProperties: false
required:
- title_id
- usage_data_provider_id
- usage_data_provider_id

View File

@ -65,4 +65,4 @@ properties:
additionalProperties: false
required:
- title_id
- usage_data_provider_id
- usage_data_provider_id

View File

@ -15,4 +15,4 @@ properties:
description: value of the additional field
type: string
additionalProperties: false
additionalProperties: false

View File

@ -107,4 +107,4 @@
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
acquisition: order_manage
acquisition: order_manage

View File

@ -68,4 +68,4 @@
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
acquisition: edi_manage
acquisition: edi_manage

View File

@ -112,4 +112,4 @@
"503":
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
$ref: "../swagger.yaml#/definitions/error"

View File

@ -919,4 +919,4 @@
"503":
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
$ref: "../swagger.yaml#/definitions/error"

View File

@ -454,4 +454,4 @@
"503":
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
$ref: "../swagger.yaml#/definitions/error"

View File

@ -158,4 +158,4 @@
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
permissions:
- circulate: circulate_remaining_permissions
- circulate: circulate_remaining_permissions

View File

@ -78,4 +78,4 @@ tables:
- code: "PROCESSING_FOUND"
description: "Lost item processing fee refund"
can_be_added_manually: "0"
is_system: "1"
is_system: "1"

View File

@ -135,4 +135,4 @@ tables:
can_be_invoiced: "0"
can_be_sold: "0"
default_amount: ~
is_system: "1"
is_system: "1"

View File

@ -39,4 +39,4 @@ tables:
- code: "UNKNOWN"
name: "Unknown"
is_system: "1"
is_system: "1"

View File

@ -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';"
- "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'w' AND frameworkcode = 'FA';"

View File

@ -1220,4 +1220,4 @@ tables:
- category: "RELTERMS"
authorised_value: "wts"
lib: "Writer of television story"
lib: "Writer of television story"

View File

@ -102,4 +102,4 @@
.parents{
display:inline;
cursor:crosshair;
}
}

View File

@ -381,4 +381,4 @@ p#upload_image {
#catalog_detail .col-sm-push-2 {
left: 0;
}
}

View File

@ -32,4 +32,4 @@ body {
width: 100%;
border-top: 1px solid #b9d8d9;
background-color: #e6f0f2;
}
}

View File

@ -1,4 +1,4 @@
body, td, pre {
font-family: Arial,Helvetica,sans-serif;
font-size: 13px;
}
}

View File

@ -102,4 +102,4 @@
.parents{
display:inline;
cursor:crosshair;
}
}

View File

@ -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 }
.xmlverb-pi-content { color: #006666; font-style: italic }

View File

@ -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" );
}