Skip to content

Commit 82bc44b

Browse files
committed
check_license: accept Triple Slash Directive
run-tests.sh checks that Licenses are OK for some files. This scripts fails when JS files use a Triple Slash Directive. This commit change this. * Improves check_license method to include Triple-Slash directives for .js files (Cf. https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) * Avoids checking screenshots directory in Cypress * Adds a triple slash directive on 2 JS files (from Cypress). Co-Authored-by: Olivier DOSSMANN <[email protected]>
1 parent 7a8d502 commit 82bc44b

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

check_license_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ directories:
3636
js:
3737
- tests/e2e/cypress/cypress/support
3838
- tests/e2e/cypress/cypress/plugins
39+
- tests/e2e/cypress/cypress/screenshots
3940
- tests/e2e/cypress/node_modules
4041
d.ts:
4142
- tests/e2e/cypress/cypress/support

rero_ils/modules/cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import logging
2727
import multiprocessing
2828
import os
29+
import re
2930
import shutil
3031
import sys
3132
import traceback
@@ -448,6 +449,12 @@ def test_file(file_name, extensions, extension, license_lines,
448449
# No error found
449450
return 0
450451

452+
def is_slash_directive(file, line):
453+
is_js_file = file.name.split('.')[-1] == 'js'
454+
if is_js_file and re.search(triple_slash, line):
455+
return True
456+
return False
457+
451458
def test_license(file, extension, license_lines, verbose):
452459
"""Test the license in file."""
453460
lines_with_errors = []
@@ -456,7 +463,10 @@ def test_license(file, extension, license_lines, verbose):
456463
linemaxnbr = len(lines)
457464
prefix = extension.get('prefix')
458465
line, linenbr = get_line(lines, linenbr, prefix)
459-
while lines[linenbr-1].startswith('#!'):
466+
# Get over Shebang lines or Triple-Slash Directives (for Javascript
467+
# files)
468+
while lines[linenbr-1].startswith('#!') or \
469+
is_slash_directive(file, lines[linenbr-1]):
460470
# get over Shebang
461471
line, linenbr = get_line(lines, linenbr, prefix)
462472
if extension.get('top'):
@@ -512,6 +522,9 @@ def test_license(file, extension, license_lines, verbose):
512522
)
513523
files_list = list(set(files_list) - set(exclude_list))
514524

525+
# set regexp expression for Triple-Slash directives
526+
triple_slash = r'^/// <reference \w*=\"\w*\" />$'
527+
515528
license_lines = config['license_text'].split('\n')
516529
tot_error_cnt = 0
517530
for file_name in files_list:

tests/e2e/cypress/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cypress/screenshots

tests/e2e/cypress/cypress/integration/circulation/checkout-checkin.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="Cypress" />
12
/*
23
34
RERO ILS

tests/e2e/cypress/cypress/support/commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="Cypress" />
12
// ***********************************************
23
// This example commands.js shows you how to
34
// create various custom commands and overwrite

0 commit comments

Comments
 (0)