Skip to content

Enforce BSD copyright headers in dart_skills_lint Dart files#161

Merged
reidbaker merged 2 commits into
mainfrom
enforce-copyright-headers
Jun 12, 2026
Merged

Enforce BSD copyright headers in dart_skills_lint Dart files#161
reidbaker merged 2 commits into
mainfrom
enforce-copyright-headers

Conversation

@reidbaker-agent

@reidbaker-agent reidbaker-agent commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds test/copyright_header_test.dart which scans every .dart file under bin/, lib/, and test/ and fails if any is missing the three-line BSD copyright block (year is not pinned; shebang files are handled correctly)
  • Backfills the 15 Dart source files that were missing the header

Closes #160.

@google-cla

google-cla Bot commented Jun 12, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces native binary distribution for dart_skills_lint on macOS and Linux, including a new install.sh script, updated documentation, and a test to ensure all Dart files contain the standard BSD copyright header. Feedback focuses on improving cross-platform compatibility, specifically by handling Windows-style line endings (\r\n) in the copyright header test and the checksum verification script, as well as refining the install.sh script to correctly determine if sudo is needed when installing to nested directories.

Comment thread tool/dart_skills_lint/test/copyright_header_test.dart
Comment on lines +102 to +108
needs_sudo=0
if [ -d "$INSTALL_DIR" ]; then
[ -w "$INSTALL_DIR" ] || needs_sudo=1
else
parent="$(dirname "$INSTALL_DIR")"
[ -d "$parent" ] && [ -w "$parent" ] || needs_sudo=1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If INSTALL_DIR is a nested directory that does not exist yet (e.g., ~/my-tools/bin), checking only the immediate parent directory dirname "$INSTALL_DIR" will fail if that parent also doesn't exist. This incorrectly sets needs_sudo=1 even if the user has full write permissions to create the nested directory structure under their home directory, leading to unnecessary sudo prompts and root-owned directories in user space. Finding the closest existing parent directory and checking its writability resolves this issue.

Suggested change
needs_sudo=0
if [ -d "$INSTALL_DIR" ]; then
[ -w "$INSTALL_DIR" ] || needs_sudo=1
else
parent="$(dirname "$INSTALL_DIR")"
[ -d "$parent" ] && [ -w "$parent" ] || needs_sudo=1
fi
needs_sudo=0
target_dir="$INSTALL_DIR"
while [ ! -d "$target_dir" ] && [ "$target_dir" != "/" ] && [ "$target_dir" != "." ]; do
target_dir="$(dirname "$target_dir")"
done
[ -w "$target_dir" ] || needs_sudo=1

Adds test/copyright_header_test.dart which scans every .dart file
in bin/, lib/, and test/ and fails if any is missing the BSD
copyright block. Bacfills the 15 files that were missing it, closing #160.
@reidbaker reidbaker force-pushed the enforce-copyright-headers branch from da4678a to aa05580 Compare June 12, 2026 19:34
final String packageRoot = p.normalize(p.absolute('.'));
final List<String> missing = [];

for (final dir in ['bin', 'lib', 'test']) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make this a set of directories and document the relative path they are defined from.

'The following Dart files are missing the BSD copyright header:\n'
' ${missing.join('\n ')}\n\n'
'Add the following block as the first three lines of each file:\n'
' // Copyright (c) <year>, the Dart project authors. Please see the AUTHORS file\n'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put the year we are using in the exiting headers instead of using so that the copyright is copy pasteable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and extract the copyright that is pasted into a constant variable.

- Normalize \r\n -> \n in _hasCopyrightHeader so the test passes on
  Windows checkouts with core.autocrlf enabled.
- Extract the canonical copyright text into a _copyrightHeader constant
  and use it in the error message (with 2026 instead of <year> so the
  block is copy-pasteable).
- Convert source directories to a const Set<String> with a doc comment
  naming the path base.
- Revert bin/cli.dart's shebang/copyright spacing to match main; the
  blank line came from a dev-channel formatter and is rejected by CI's
  stable formatter (and by pana).
@flutter flutter deleted a comment from gemini-code-assist Bot Jun 12, 2026
@reidbaker reidbaker merged commit 384da05 into main Jun 12, 2026
13 checks passed
@reidbaker reidbaker deleted the enforce-copyright-headers branch June 12, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce copyright headers with test code

2 participants