Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_license: accept Triple Slash Directive #1098

Merged
merged 1 commit into from
Jul 20, 2020
Merged
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
1 change: 1 addition & 0 deletions check_license_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ directories:
js:
- tests/e2e/cypress/cypress/support
- tests/e2e/cypress/cypress/plugins
- tests/e2e/cypress/cypress/screenshots
- tests/e2e/cypress/node_modules
d.ts:
- tests/e2e/cypress/cypress/support
Expand Down
15 changes: 14 additions & 1 deletion rero_ils/modules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import multiprocessing
import os
import re
import shutil
import sys
import traceback
Expand Down Expand Up @@ -448,6 +449,12 @@ def test_file(file_name, extensions, extension, license_lines,
# No error found
return 0

def is_slash_directive(file, line):
is_js_file = file.name.split('.')[-1] == 'js'
if is_js_file and re.search(triple_slash, line):
return True
return False
Comment on lines +453 to +456
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic: can be replaced by:

if file.name.split('.')[-1] == 'js' and re.search(triple_slash, line):
   return True


def test_license(file, extension, license_lines, verbose):
"""Test the license in file."""
lines_with_errors = []
Expand All @@ -456,7 +463,10 @@ def test_license(file, extension, license_lines, verbose):
linemaxnbr = len(lines)
prefix = extension.get('prefix')
line, linenbr = get_line(lines, linenbr, prefix)
while lines[linenbr-1].startswith('#!'):
# Get over Shebang lines or Triple-Slash Directives (for Javascript
# files)
while lines[linenbr-1].startswith('#!') or \
is_slash_directive(file, lines[linenbr-1]):
# get over Shebang
line, linenbr = get_line(lines, linenbr, prefix)
if extension.get('top'):
Expand Down Expand Up @@ -512,6 +522,9 @@ def test_license(file, extension, license_lines, verbose):
)
files_list = list(set(files_list) - set(exclude_list))

# set regexp expression for Triple-Slash directives
triple_slash = r'^/// <reference \w*=\"\w*\" />$'

license_lines = config['license_text'].split('\n')
tot_error_cnt = 0
for file_name in files_list:
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cypress/screenshots
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="Cypress" />
/*

RERO ILS
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cypress/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="Cypress" />
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
Expand Down