Check license headers for CSS files during PRESUBMIT
This mirrors the license header checks we perform for
Python-like files and apply the same logic for CSS.
To do so, we modify the relevant regexes and patch
function to use the correct version of comment structure
for CSS files (which use `/*` rather than `#` as delimiters).
[email protected]
Bug: 1106746
Change-Id: I51d51e9b793a1015aeb20a3b3a55e075c2ee748f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3014756
Commit-Queue: Tim van der Lippe <[email protected]>
Auto-Submit: Tim van der Lippe <[email protected]>
Reviewed-by: Jack Franklin <[email protected]>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d9cf8c2..bcbf54b 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -324,14 +324,14 @@
return results
-def _CheckDevToolsPythonLikeFileLicenseHeaders(input_api, output_api):
+def _CheckDevToolsNonJSFileLicenseHeaders(input_api, output_api):
results = [
output_api.PresubmitNotifyResult(
'Python-like file license header check:')
]
- lint_path = input_api.os_path.join(
- input_api.PresubmitLocalPath(), 'scripts', 'test',
- 'run_header_check_python_like_files.js')
+ lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
+ 'scripts', 'test',
+ 'run_header_check_non_js_files.js')
front_end_directory = input_api.os_path.join(
input_api.PresubmitLocalPath(), 'front_end')
@@ -356,7 +356,7 @@
should_bail_out, files_to_lint = _getFilesToLint(
input_api, output_api, lint_config_files, default_linted_directories,
- ['BUILD.gn', '.gni'], results)
+ ['BUILD.gn', '.gni', '.css'], results)
if should_bail_out:
return results
@@ -516,8 +516,8 @@
results.extend(_CheckJSON(input_api, output_api))
results.extend(_CheckDevToolsStyleJS(input_api, output_api))
results.extend(_CheckDevToolsStyleCSS(input_api, output_api))
- results.extend(
- _CheckDevToolsPythonLikeFileLicenseHeaders(input_api, output_api))
+ results.extend(_CheckDevToolsNonJSFileLicenseHeaders(
+ input_api, output_api))
results.extend(_CheckFormat(input_api, output_api))
results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api))
diff --git a/front_end/panels/application/backgroundServiceView.css b/front_end/panels/application/backgroundServiceView.css
index a54bb05..dc75014 100644
--- a/front_end/panels/application/backgroundServiceView.css
+++ b/front_end/panels/application/backgroundServiceView.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.background-service-toolbar {
background-color: var(--color-background-elevation-1);
border-bottom: var(--legacy-divider-border);
diff --git a/front_end/panels/changes/changesSidebar.css b/front_end/panels/changes/changesSidebar.css
index f219884..d7ad3cc 100644
--- a/front_end/panels/changes/changesSidebar.css
+++ b/front_end/panels/changes/changesSidebar.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.tree-outline {
/**
* These variables (and the dark mode variants) are duplicated from
diff --git a/front_end/panels/coverage/coverageListView.css b/front_end/panels/coverage/coverageListView.css
index 3357944..437d1b0 100644
--- a/front_end/panels/coverage/coverageListView.css
+++ b/front_end/panels/coverage/coverageListView.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.data-grid {
border: none;
}
diff --git a/front_end/panels/elements/components/cssQuery.css b/front_end/panels/elements/components/cssQuery.css
index aaeba22..e0152a8 100644
--- a/front_end/panels/elements/components/cssQuery.css
+++ b/front_end/panels/elements/components/cssQuery.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.query:not(.editing-query) {
overflow: hidden;
}
diff --git a/front_end/panels/elements/components/elementsPanelLink.css b/front_end/panels/elements/components/elementsPanelLink.css
index 6b24afe..924711a 100644
--- a/front_end/panels/elements/components/elementsPanelLink.css
+++ b/front_end/panels/elements/components/elementsPanelLink.css
@@ -1,4 +1,5 @@
-/* Copyright 2021 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/panels/elements/components/queryContainer.css b/front_end/panels/elements/components/queryContainer.css
index 0fed1de..9902f70 100644
--- a/front_end/panels/elements/components/queryContainer.css
+++ b/front_end/panels/elements/components/queryContainer.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.container-link {
color: var(--color-text-primary);
}
diff --git a/front_end/panels/elements/layoutPane.css b/front_end/panels/elements/layoutPane.css
index 81235c34..70777c3 100644
--- a/front_end/panels/elements/layoutPane.css
+++ b/front_end/panels/elements/layoutPane.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
* {
box-sizing: border-box;
font-size: 12px;
diff --git a/front_end/panels/network/networkWaterfallColumn.css b/front_end/panels/network/networkWaterfallColumn.css
index 573de3c..6a0a3c6 100644
--- a/front_end/panels/network/networkWaterfallColumn.css
+++ b/front_end/panels/network/networkWaterfallColumn.css
@@ -1,4 +1,5 @@
-/* Copyright 2016 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2016 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/panels/security/lockIcon.css b/front_end/panels/security/lockIcon.css
index 20e24cf..0b5daa4 100644
--- a/front_end/panels/security/lockIcon.css
+++ b/front_end/panels/security/lockIcon.css
@@ -1,4 +1,5 @@
-/* Copyright (c) 2015 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/panels/security/mainView.css b/front_end/panels/security/mainView.css
index 1a5b7ee..01807ab 100644
--- a/front_end/panels/security/mainView.css
+++ b/front_end/panels/security/mainView.css
@@ -1,4 +1,5 @@
-/* Copyright (c) 2015 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/panels/security/originView.css b/front_end/panels/security/originView.css
index 3627513..9308f7f 100644
--- a/front_end/panels/security/originView.css
+++ b/front_end/panels/security/originView.css
@@ -1,4 +1,5 @@
-/* Copyright (c) 2015 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/panels/security/sidebar.css b/front_end/panels/security/sidebar.css
index dcf7b2c..607487e 100644
--- a/front_end/panels/security/sidebar.css
+++ b/front_end/panels/security/sidebar.css
@@ -1,4 +1,5 @@
-/* Copyright (c) 2015 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2015 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
diff --git a/front_end/ui/components/icon_button/icon.css b/front_end/ui/components/icon_button/icon.css
index 4eba1ed..093361f 100644
--- a/front_end/ui/components/icon_button/icon.css
+++ b/front_end/ui/components/icon_button/icon.css
@@ -1,6 +1,8 @@
-/* Copyright 2021 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file. */
+ * found in the LICENSE file.
+ */
:host {
display: inline-block;
diff --git a/front_end/ui/components/icon_button/iconButton.css b/front_end/ui/components/icon_button/iconButton.css
index f4f7a993..9ab954a 100644
--- a/front_end/ui/components/icon_button/iconButton.css
+++ b/front_end/ui/components/icon_button/iconButton.css
@@ -1,6 +1,8 @@
-/* Copyright 2021 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file. */
+ * found in the LICENSE file.
+ */
:host {
white-space: normal;
diff --git a/front_end/ui/legacy/components/color_picker/spectrum.css b/front_end/ui/legacy/components/color_picker/spectrum.css
index 8249c44..e3353b8 100644
--- a/front_end/ui/legacy/components/color_picker/spectrum.css
+++ b/front_end/ui/legacy/components/color_picker/spectrum.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
/* https://github.com/bgrins/spectrum */
:host {
diff --git a/front_end/ui/legacy/components/data_grid/dataGrid.css b/front_end/ui/legacy/components/data_grid/dataGrid.css
index 3fc3170..0966c72 100644
--- a/front_end/ui/legacy/components/data_grid/dataGrid.css
+++ b/front_end/ui/legacy/components/data_grid/dataGrid.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.data-grid {
position: relative;
border: 1px solid var(--color-details-hairline-light) !important; /* stylelint-disable-line declaration-no-important */
diff --git a/front_end/ui/legacy/components/source_frame/jsonView.css b/front_end/ui/legacy/components/source_frame/jsonView.css
index 80d8f45c..6c02704 100644
--- a/front_end/ui/legacy/components/source_frame/jsonView.css
+++ b/front_end/ui/legacy/components/source_frame/jsonView.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
.json-view {
padding: 2px 6px;
overflow: auto;
diff --git a/front_end/ui/legacy/components/text_editor/cmdevtools.css b/front_end/ui/legacy/components/text_editor/cmdevtools.css
index 4f7142f..03b59ed 100644
--- a/front_end/ui/legacy/components/text_editor/cmdevtools.css
+++ b/front_end/ui/legacy/components/text_editor/cmdevtools.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
/* stylelint-disable no-descending-specificity */
/**
diff --git a/front_end/ui/legacy/inspectorScrollbars.css b/front_end/ui/legacy/inspectorScrollbars.css
index 093f86a..4467317 100644
--- a/front_end/ui/legacy/inspectorScrollbars.css
+++ b/front_end/ui/legacy/inspectorScrollbars.css
@@ -1,7 +1,9 @@
-/* Copyright 2020 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2020 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
/* Dark mode scrollbar styling overrides */
:not(.platform-mac).-theme-with-dark-background ::-webkit-scrollbar {
diff --git a/front_end/ui/legacy/themeColors.css b/front_end/ui/legacy/themeColors.css
index 6a443b4..0f8fc46 100644
--- a/front_end/ui/legacy/themeColors.css
+++ b/front_end/ui/legacy/themeColors.css
@@ -1,7 +1,9 @@
-/* Copyright 2020 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2020 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
/**
* These are the new set of colors for the new Light/Dark themes. See
* https://crbug.com/1122511 and
diff --git a/inspector_overlay/tool_grid.css b/inspector_overlay/tool_grid.css
index 78d3d50..b808a31 100644
--- a/inspector_overlay/tool_grid.css
+++ b/inspector_overlay/tool_grid.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
@media (forced-colors: active) {
:root,
body {
diff --git a/inspector_overlay/tool_highlight.css b/inspector_overlay/tool_highlight.css
index 5d24766..22adfc1 100644
--- a/inspector_overlay/tool_highlight.css
+++ b/inspector_overlay/tool_highlight.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
body {
--arrow-width: 15px;
--arrow-height: 8px;
diff --git a/inspector_overlay/tool_paused.css b/inspector_overlay/tool_paused.css
index 9eecf64..46122a7 100644
--- a/inspector_overlay/tool_paused.css
+++ b/inspector_overlay/tool_paused.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
body {
background-color: rgb(0 0 0 / 31%);
}
diff --git a/inspector_overlay/tool_screenshot.css b/inspector_overlay/tool_screenshot.css
index 144b545..1de9867 100644
--- a/inspector_overlay/tool_screenshot.css
+++ b/inspector_overlay/tool_screenshot.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
body {
cursor: crosshair;
}
diff --git a/inspector_overlay/tool_source_order.css b/inspector_overlay/tool_source_order.css
index bf0e38b..6ef5727 100644
--- a/inspector_overlay/tool_source_order.css
+++ b/inspector_overlay/tool_source_order.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
:root {
--border-radius: 4px;
}
diff --git a/scripts/eslint_rules/tests/check_css_import_test_file.css b/scripts/eslint_rules/tests/check_css_import_test_file.css
index 81bd9ad..d005faf 100644
--- a/scripts/eslint_rules/tests/check_css_import_test_file.css
+++ b/scripts/eslint_rules/tests/check_css_import_test_file.css
@@ -1,3 +1,5 @@
-/* Copyright 2021 The Chromium Authors. All rights reserved.
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file. */
+ * found in the LICENSE file.
+ */
diff --git a/scripts/test/run_header_check_non_js_files.js b/scripts/test/run_header_check_non_js_files.js
new file mode 100644
index 0000000..7713e30
--- /dev/null
+++ b/scripts/test/run_header_check_non_js_files.js
@@ -0,0 +1,147 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Script that can automatically add missing license headers to non-JS
+// files, including `.gn`, `.py`, `.gni`, `.css` files.
+
+// @ts-check
+
+const readline = require('readline');
+const path = require('path');
+const fs = require('fs');
+const glob = require('glob');
+
+const ROOT_DIRECTORY = path.join(__dirname, '..', '..');
+const FRONT_END_DIRECTORY = path.join(ROOT_DIRECTORY, 'front_end');
+const TEST_DIRECTORY = path.join(ROOT_DIRECTORY, 'test');
+const SCRIPTS_DIRECTORY = path.join(ROOT_DIRECTORY, 'scripts');
+const INSPECTOR_OVERLAY_DIRECTORY = path.join(ROOT_DIRECTORY, 'inspector_overlay');
+const CONFIG_DIRECTORY = path.join(ROOT_DIRECTORY, 'config');
+
+const CURRENT_YEAR = new Date().getFullYear();
+const LINE_LICENSE_HEADER = [
+ `Copyright ${CURRENT_YEAR} The Chromium Authors. All rights reserved.`,
+ 'Use of this source code is governed by a BSD-style license that can be',
+ 'found in the LICENSE file.',
+];
+const LINE_REGEXES = LINE_LICENSE_HEADER.map(line => line.replace(String(CURRENT_YEAR), '(\\(c\\) )?\\d{4}') + '$');
+
+const PYTHON_LIKE_LINE_REGEXES = LINE_REGEXES.map(line => new RegExp('# ' + line));
+
+/** @type {!Array<!RegExp>} */
+const CSS_LIKE_LINE_REGEXES = [];
+CSS_LIKE_LINE_REGEXES.push(new RegExp('\\/\\*'));
+for (const line of LINE_REGEXES) {
+ CSS_LIKE_LINE_REGEXES.push(new RegExp(` \\* ${line}`));
+}
+CSS_LIKE_LINE_REGEXES.push(new RegExp(' \\*\\/'));
+
+const EXEMPTED_FILES = new Set([
+ ['front_end', 'panels', 'application', 'indexedDBViews.css'],
+ ['front_end', 'panels', 'application', 'resourcesPanel.css'],
+ ['front_end', 'panels', 'console', 'consoleView.css'],
+ ['front_end', 'panels', 'elements', 'elementsPanel.css'],
+ ['front_end', 'panels', 'network', 'networkLogView.css'],
+ ['front_end', 'panels', 'network', 'networkPanel.css'],
+ ['front_end', 'panels', 'profiler', 'heapProfiler.css'],
+ ['front_end', 'panels', 'profiler', 'profilesPanel.css'],
+ ['front_end', 'panels', 'screencast', 'screencastView.css'],
+ ['front_end', 'panels', 'sources', 'navigatorTree.css'],
+ ['front_end', 'panels', 'sources', 'sourcesPanel.css'],
+ ['front_end', 'panels', 'sources', 'sourcesView.css'],
+ ['front_end', 'panels', 'timeline', 'timelinePanel.css'],
+ ['front_end', 'ui', 'legacy', 'filter.css'],
+ ['front_end', 'ui', 'legacy', 'inspectorSyntaxHighlight.css'],
+ ['front_end', 'ui', 'legacy', 'splitWidget.css'],
+ ['front_end', 'ui', 'legacy', 'suggestBox.css'],
+ ['front_end', 'ui', 'legacy', 'tabbedPane.css'],
+ ['front_end', 'ui', 'legacy', 'viewContainers.css'],
+].map(fileLocation => fileLocation.join('/')));
+
+/**
+ * @param {string} fileLocation
+ * @returns {boolean}
+ */
+function isPythonLikeFile(fileLocation) {
+ return ['.gn', '.gni'].includes(path.extname(fileLocation));
+}
+
+/**
+ * @param {string} fileLocation
+ */
+async function checkAndMaybeAddLicenseHeader(fileLocation) {
+ const fileStream = fs.createReadStream(fileLocation);
+ const fileReader = readline.createInterface({input: fileStream});
+
+ const lineRegexes = isPythonLikeFile(fileLocation) ? PYTHON_LIKE_LINE_REGEXES : CSS_LIKE_LINE_REGEXES;
+
+ try {
+ await new Promise((resolve, reject) => {
+ let i = 0;
+ fileReader.on('line', line => {
+ if (lineRegexes[i].exec(line)) {
+ i++;
+
+ if (i === lineRegexes.length) {
+ fileReader.close();
+ fileReader.removeAllListeners();
+ resolve();
+ }
+ } else {
+ reject(`Invalid license header for file ${fileLocation}`);
+ }
+ });
+ });
+ } catch (checkError) {
+ try {
+ fixLicenseHeaderForFile(fileLocation);
+ } catch (writeError) {
+ console.error('Unable to automatically fix license header for file');
+ console.error(`Error when checking: ${checkError}`);
+ console.error(`Error when writing: ${writeError}`);
+ process.exit(1);
+ }
+ } finally {
+ fileStream.close();
+ }
+}
+
+/**
+ * @param {string} fileLocation
+ */
+function fixLicenseHeaderForFile(fileLocation) {
+ /** @type {!Array<string>} */
+ let newLicenseHeaderLines;
+ if (isPythonLikeFile(fileLocation)) {
+ newLicenseHeaderLines = LINE_LICENSE_HEADER.map(line => `# ${line}`);
+ } else {
+ newLicenseHeaderLines = ['/*'];
+ for (const line of LINE_LICENSE_HEADER) {
+ newLicenseHeaderLines.push(` * ${line}`);
+ }
+ newLicenseHeaderLines.push(' */');
+ }
+ fs.writeFileSync(
+ fileLocation,
+ Buffer.concat([Buffer.from(newLicenseHeaderLines.join('\n') + '\n\n'), fs.readFileSync(fileLocation)]));
+}
+
+let filesToLint = process.argv.slice(2);
+
+if (filesToLint.length === 0) {
+ const topLevelDirectories =
+ [FRONT_END_DIRECTORY, SCRIPTS_DIRECTORY, TEST_DIRECTORY, INSPECTOR_OVERLAY_DIRECTORY, CONFIG_DIRECTORY].join(',');
+ filesToLint = glob.sync(`{${topLevelDirectories}}/**/{BUILD.gn,*.gni,*.css}`);
+}
+
+for (const fileLocation of filesToLint) {
+ const relativeFileLocation = path.relative(ROOT_DIRECTORY, fileLocation).replace(/\\/g, '/');
+ if (relativeFileLocation.startsWith('front_end/third_party')) {
+ continue;
+ }
+ if (EXEMPTED_FILES.has(relativeFileLocation)) {
+ continue;
+ }
+ checkAndMaybeAddLicenseHeader(fileLocation);
+}
diff --git a/scripts/test/run_header_check_python_like_files.js b/scripts/test/run_header_check_python_like_files.js
deleted file mode 100644
index 0fc343f..0000000
--- a/scripts/test/run_header_check_python_like_files.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2021 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Script that can automatically add missing license headers to Python-like
-// files, including `.gn`, `.py`, `.gni` files.
-
-const readline = require('readline');
-const path = require('path');
-const fs = require('fs');
-const glob = require('glob');
-
-const ROOT_DIRECTORY = path.join(__dirname, '..', '..');
-const FRONT_END_DIRECTORY = path.join(ROOT_DIRECTORY, 'front_end');
-const TEST_DIRECTORY = path.join(ROOT_DIRECTORY, 'test');
-const SCRIPTS_DIRECTORY = path.join(ROOT_DIRECTORY, 'scripts');
-const INSPECTOR_OVERLAY_DIRECTORY = path.join(ROOT_DIRECTORY, 'inspector_overlay');
-const CONFIG_DIRECTORY = path.join(ROOT_DIRECTORY, 'config');
-
-const CURRENT_YEAR = new Date().getFullYear();
-const LINE_LICENSE_HEADER = [
- `# Copyright ${CURRENT_YEAR} The Chromium Authors. All rights reserved.`,
- '# Use of this source code is governed by a BSD-style license that can be',
- '# found in the LICENSE file.',
-];
-const LINE_REGEXES =
- LINE_LICENSE_HEADER.map(line => new RegExp(line.replace(String(CURRENT_YEAR), '(\\(c\\) )?\\d{4}') + '$'));
-
-/**
- * @param {string} fileLocation
- */
-async function checkAndMaybeAddLicenseHeader(fileLocation) {
- const fileStream = fs.createReadStream(fileLocation);
- const fileReader = readline.createInterface({input: fileStream});
-
- try {
- await new Promise((resolve, reject) => {
- let i = 0;
- fileReader.on('line', line => {
- if (LINE_REGEXES[i].exec(line)) {
- i++;
-
- if (i === LINE_REGEXES.length) {
- fileReader.close();
- fileReader.removeAllListeners();
- resolve();
- }
- } else {
- reject(`Invalid license header for file ${fileLocation}`);
- }
- });
- });
- } catch (checkError) {
- try {
- fixLicenseHeaderForFile(fileLocation);
- } catch (writeError) {
- console.error('Unable to automatically fix license header for file');
- console.error(`Error when checking: ${checkError}`);
- console.error(`Error when writing: ${writeError}`);
- process.exit(1);
- }
- } finally {
- fileStream.close();
- }
-}
-
-/**
- * @param {string} fileLocation
- */
-function fixLicenseHeaderForFile(fileLocation) {
- fs.writeFileSync(
- fileLocation,
- Buffer.concat([Buffer.from(LINE_LICENSE_HEADER.join('\n') + '\n\n'), fs.readFileSync(fileLocation)]));
-}
-
-let filesToLint = process.argv.slice(2);
-
-if (filesToLint.length === 0) {
- const topLevelDirectories =
- [FRONT_END_DIRECTORY, SCRIPTS_DIRECTORY, TEST_DIRECTORY, INSPECTOR_OVERLAY_DIRECTORY, CONFIG_DIRECTORY].join(',');
- filesToLint = glob.sync(`{${topLevelDirectories}}/**/{BUILD.gn,*.gni}`);
-}
-
-for (const fileLocation of filesToLint) {
- checkAndMaybeAddLicenseHeader(fileLocation);
-}
diff --git a/test/e2e/resources/elements/css-module.css b/test/e2e/resources/elements/css-module.css
index 3fada03..e69d8fc 100644
--- a/test/e2e/resources/elements/css-module.css
+++ b/test/e2e/resources/elements/css-module.css
@@ -1 +1,7 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#properties-to-inspect { height: 20% ; }
diff --git a/test/webtests/http/tests/devtools/lighthouse/resources/lighthouse-basic.css b/test/webtests/http/tests/devtools/lighthouse/resources/lighthouse-basic.css
index fb6a572..b6cae13 100644
--- a/test/webtests/http/tests/devtools/lighthouse/resources/lighthouse-basic.css
+++ b/test/webtests/http/tests/devtools/lighthouse/resources/lighthouse-basic.css
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2021 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
body {
font-size: 10px;
}