Skip to content

Commit

Permalink
[INTERNAL] JSDoc: Add check for copyright notice
Browse files Browse the repository at this point in the history
Checks for a copyright notice at the beginning of each file.
The comment doesn't need to be the first comment but it must be placed
before any code starts.

This implements the same check as the internal validation rule
DOCUMENTATION__COPYRIGHT_NOTICE_MISSING.

JIRA: CPOUI5FOUNDATION-329

Cherry picked from SAP/openui5@bcb5110
  • Loading branch information
matz3 committed Jun 16, 2021
1 parent b86f0fa commit 0580905
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/processors/jsdoc/lib/ui5/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,27 @@ exports.astNodeVisitor = {
processPotentialEnum(node.expression.right, comment);
}

} else if ( node.type === Syntax.File ) {
// Check for copyright notice

let programBodyStart;
if ( node.program.body.length >= 1 ) {
programBodyStart = node.program.body[0].start
} else {
// File has no code at all
programBodyStart = Infinity;
}

const hasCopyrightComment = ( node.comments || [] ).some(function(commentBlock) {
return (
// Copyright comments must be at the top of the file, not between some code or at the end
commentBlock.end <= programBodyStart &&
/copyright|\(c\)|released under|license|\u00a9/.test(commentBlock.value)
);
});
if ( !hasCopyrightComment ) {
error(`document doesn't contain a copyright notice: ${currentSourceName}`);
}
}
}

Expand Down

0 comments on commit 0580905

Please sign in to comment.