// Needs to start and end with new line const licenseHeader = ` /** * @license * Copyright ${currentYear} Google Inc. * SPDX-License-Identifier: Apache-2.0
*/
`;
const enforceLicenseRule = createRule<[], 'licenseRule'>({
name: 'check-license',
meta: {
type: 'layout',
docs: {
description: 'Validate existence of license header',
requiresTypeChecking: false,
},
fixable: 'code',
schema: [],
messages: {
licenseRule: 'Add license header.',
},
},
defaultOptions: [],
create(context) { const sourceCode = context.sourceCode; const comments = sourceCode.getAllComments();
let insertAfter = [0, 0] as TSESTree.Range;
let header: TSESTree.Comment | null = null; // Check only the first 2 comments for (let index = 0; index < 2; index++) { const comment = comments[index]; if (!comment) { break;
} // Shebang comments should be at the top if ( // Types don't have it debugger showed it...
(comment.type as string) === 'Shebang' ||
(comment.type === 'Line' && comment.value.startsWith('#!'))
) {
insertAfter = comment.range; continue;
} if (comment.type === 'Block') {
header = comment; break;
}
}
return {
Program(node) { if (context.filename.endsWith('.json')) { return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.