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

chore: Check copyright and license as one joined substring #8815

Merged
merged 3 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- `[jest-core]` Add `getVersion` (moved from `jest-cli`) ([#8706](https://github.com/facebook/jest/pull/8706))
- `[docs]` Fix MockFunctions example that was using toContain instead of toContainEqual ([#8765](https://github.com/facebook/jest/pull/8765))
- `[*]` Make sure copyright header comment includes license ([#8783](https://github.com/facebook/jest/pull/8783))
- `[*]` Check copyright and license as one joined substring ([#8815](https://github.com/facebook/jest/pull/8815))
- `[docs]` Fix WatchPlugins `jestHooks.shouldRunTestSuite` example that receives an object ([#8784](https://github.com/facebook/jest/pull/8784))
- `[*]` Enforce LF line endings ([#8809](https://github.com/facebook/jest/pull/8809))

Expand Down
18 changes: 7 additions & 11 deletions scripts/checkCopyrightHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,20 @@ const INCLUDED_PATTERNS = [
/\.[^/]+$/,
];

const COPYRIGHT_HEADER =
'Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.';
const LICENSE1 =
'This source code is licensed under the MIT license found in the';
const LICENSE2 = 'LICENSE file in the root directory of this source tree.';
const COPYRIGHT_LICENSE = [
' * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.',
' *',
' * This source code is licensed under the MIT license found in the',
' * LICENSE file in the root directory of this source tree.',
].join('\n');

function needsCopyrightHeader(file) {
const contents = getFileContents(file);

// Match lines individually to avoid false positive for:
Copy link
Contributor

Choose a reason for hiding this comment

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

@pedrottimark Yes the line endings now shouldn't be a problem as they're required to be LF. But this comment says another reason why lines are checked individually is the ability to use line comments instead of a block comment. Looks like this possibility is never used (CI is green) but wondering if these line substrings are the standard license header check for FB or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry to make you do the proof reading that I should have done, because I wrote that comment in the previous PR and that sentence was a step in the wrong direction.

// comment block versus lines
// line ending LF versus CRLF
return (
contents.trim().length > 0 &&
(!contents.includes(COPYRIGHT_HEADER) ||
!contents.includes(LICENSE1) ||
!contents.includes(LICENSE2))
);
return contents.trim().length > 0 && !contents.includes(COPYRIGHT_LICENSE);
}

function check() {
Expand Down