Skip to content

Commit

Permalink
🏗 Remove lint and presubmit checks for AMP copyright notice (ampproje…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha authored Aug 18, 2021
1 parent 7881599 commit d75c2ba
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 115 deletions.
11 changes: 0 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module.exports = {
'jsdoc',
'local',
'module-resolver',
'notice',
'prettier',
'react',
'react-hooks',
Expand Down Expand Up @@ -271,16 +270,6 @@ module.exports = {
'no-useless-concat': 2,
'no-undef': 2,
'no-var': 2,
'notice/notice': [
2,
{
'mustMatch': 'Copyright 20\\d{2} The AMP HTML Authors\\.',
'templateFile': 'build-system/common/LICENSE-TEMPLATE.txt',
'messages': {
'whenFailedToMatch': 'Missing or incorrect license header',
},
},
],
'object-shorthand': [
2,
'properties',
Expand Down
15 changes: 0 additions & 15 deletions build-system/common/LICENSE-TEMPLATE.txt

This file was deleted.

65 changes: 3 additions & 62 deletions build-system/tasks/presubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ const {log} = require('../common/logging');
* build-system/test-configs/forbidden-terms.js
*/

const dedicatedCopyrightNoteSources = /(\.css|\.go)$/;

// Terms that must appear in a source file.
const requiredTerms = {
'Copyright 20(15|16|17|18|19|2\\d) The AMP HTML Authors\\.':
dedicatedCopyrightNoteSources,
'Licensed under the Apache License, Version 2\\.0':
dedicatedCopyrightNoteSources,
'http\\://www\\.apache\\.org/licenses/LICENSE-2\\.0':
dedicatedCopyrightNoteSources,
};
// Exclude extension generator templates
const requiredTermsExcluded = new RegExp('/make-extension(/.+)?/template/');

/**
* Test if a file's contents match any of the forbidden terms
* @param {string} srcFile
Expand All @@ -70,72 +56,27 @@ function hasForbiddenTerms(srcFile) {
return terms.length > 0;
}

/**
* Test if a file's contents fail to match any of the required terms and log
* any missing terms
*
* @param {string} srcFile
* @return {boolean} true if any of the terms are not matched in the file
* content, false otherwise
*/
function isMissingTerms(srcFile) {
const contents = fs.readFileSync(srcFile, 'utf-8');
return Object.keys(requiredTerms)
.map(function (term) {
const filter = requiredTerms[term];
if (!filter.test(srcFile) || requiredTermsExcluded.test(srcFile)) {
return false;
}

const matches = contents.match(new RegExp(term));
if (!matches) {
log(
red('ERROR:'),
'Did not find required',
cyan(`"${term}"`),
'in',
cyan(srcFile)
);
return true;
}
return false;
})
.some(function (hasMissingTerm) {
return hasMissingTerm;
});
}

/**
* Entry point for amp presubmit.
* @return {Promise<void>}
*/
async function presubmit() {
let forbiddenFound = false;
let missingRequirements = false;
const srcFiles = await globby(srcGlobs);
for (const srcFile of srcFiles) {
forbiddenFound = hasForbiddenTerms(srcFile) || forbiddenFound;
missingRequirements = isMissingTerms(srcFile) || missingRequirements;
}
if (forbiddenFound) {
log(
yellow('NOTE:'),
'Please remove these usages or consult with the AMP team.'
);
}
if (missingRequirements) {
log(
yellow('NOTE:'),
'Please add these terms (e.g. a required LICENSE) to the files.'
'Please remove these terms or consult with the AMP team.'
);
}
if (forbiddenFound || missingRequirements) {
process.exitCode = 1;
throw new Error('Found forbidden terms');
}
}

module.exports = {
presubmit,
};

presubmit.description = 'Check source files for forbidden and required terms';
presubmit.description = 'Check source files for forbidden terms';
5 changes: 2 additions & 3 deletions build-system/test-configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ const lintGlobs = [
];

/**
* This should not include .js files, since those are handled by eslint:
* - required terms: notice/notice
* - forbidden terms: local/no-forbidden-terms
* This should not include .js files, since those are handled by eslint via the
* local/no-forbidden-terms rule.
*/
const presubmitGlobs = [
'**/*.{css,go,md}',
Expand Down
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"eslint-plugin-jsdoc": "35.4.0",
"eslint-plugin-local": "1.0.0",
"eslint-plugin-module-resolver": "1.4.0",
"eslint-plugin-notice": "0.9.10",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
Expand Down

0 comments on commit d75c2ba

Please sign in to comment.