-
Notifications
You must be signed in to change notification settings - Fork 918
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
Add pre-commit hook for including the MPLv2 in all source code files #10617
Conversation
3c57485
to
aa1cc65
Compare
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the webpack config already had the MPL in it (see the final file in this changeset), I'm assuming that literally everything in the repo needs the MPL, including configuration files like this. Makes sense that it would, I think.
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
#} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might look like an uncessary change, but we needed to make sure the existing comments matche the format that the pre-commit hook was expecting and generating, else we'd end up with the MPL double-included
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
#} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shoudn't mess with the beast, I think
(Self-reviewing from the top-down) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still test driving this but here's a few issues I encountered so far:
- For JS files, the license block inserted by pre-commit differs from the comment formatting expected by Prettier. When I delete a comment and then try to make a commit, the hook fails twice (once for this check and a second time for Prettier) before it will accept the comment formatting.
- When I run
pre-commit run --all-files
it still finds some changes:
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/fr/brands.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/fr/mozorg/fluent.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/en/brands.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/en-US/mozorg/fluent.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/en/mozorg/fluent.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
Some sources were modified by the hook ['lib/l10n_utils/tests/test_files/l10n/de/mozorg/fluent.ftl']
Now aborting the commit.
You should check the changes made. Then simply "git add --update ." and re-commit
We should also make sure this commit gets added to |
aa1cc65
to
a1c8270
Compare
FTL omissions now included/fixed @alexgibson. Will DM re prettier vs this hook |
a1c8270
to
8a18a40
Compare
@alexgibson Thanks for the feedback. Fixed the prettier issue by re-ordering the execution of the hooks - works fine that we add the missing text before running the style checkers, so that any styling mismatches (eg prettier's take on comments formatting) happens in the same single pre-commit pass. Basically, if someone forgets a licence, they will have to re-stage the relevant file(s), but now at least only once, including any formatting fixes
|
8a18a40
to
47a26a0
Compare
@@ -1,6 +1,8 @@ | |||
{# This Source Code Form is subject to the terms of the Mozilla Public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another special file because it contains the MPL as a comment and as content/examples for people to use
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
#} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another special file which uses the licence text in different ways - for the file itself, and for its content
Thinking about this @alexgibson -- maybe it's a change we do want to reflect in the changelog, as it's basically additive or corrective in very specific places, that won't obliterate significant history, rather than - say - |
Good point. This does seem like an okay thing to keep in the history. |
6eb48fc
to
b13efc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+ (reviewing this PR has caused my tab in Firefox to freeze twice!) 😬
@@ -2,7 +2,7 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some test fixups were needed here for things which parsed templates
@alexgibson Following our DMs, I've removed the MPL added in error to the four JS lib files we have and also amended the pre-commit hook to not do that in the future. The isolated commit for that is: dd5d766 I looked into adding RST support but a) we don't have any gaps at the mo, so the manual process is decent and b) the hook doesn't seem to pick up changes to .rst, so am drawing a line under this The only other file type that we could include because we have the MPL in some files but not all is I've eyeballed literally all of the diff, so if you're happy with the commit above, I think we're good. (Will quickly rebase on master now) |
Adds to Python, JS, SCSS, Jinja HTML, Fluent templates and shell scripts Note that the order of application of the hooks is important - we want to add a missing license before we check the formatting of files
…t produced by pre-commit hook * Updates existing MPLv2 text to use a https URL * Amend a handful of Fluent templates that used a token instead of the string "Mozilla" - this standardised things; translation was not used or needed * Add missing MPLv2 where needed * Update three tests that regressed with these changes, above
…e MPL from the four files which should not have had it
dd5d766
to
a5e48d3
Compare
@stevejalim thanks! I think this looks great overall. As to adding comments to svg files, that's something we certainly could do, although I'm also a bit concious as to how far it really makes sense to go with this, as doing this with assets loaded as images likely also has a (small but incremental) performance impact, unless we then go to the effort of optimising them again in the build process. For now, I think this is fine to merge and iterate on in the future, if we think it makes sense. r+ 🍡 |
Adds to Python, JS, SCSS, Jinja HTML, Fluent files and shell scripts
Description
This changeset adds a pre-commit hook that can automatically insert a licence in a file. It is configured to insert the MPLv2 into Python, JS, SCSS, Jinja HTML and shell files.
Issue / Bugzilla link
Resolves #10614
Testing
git commit
to trigger the pre-commit hookspre-commit run --all-files
and confirm there are no changes