Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"LICENSE"
],
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
},
"scripts": {
"dev": "tsup --watch",
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin/src/constants/copyright.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export const DEFAULT_START_YEAR = 2017;

export const COPYRIGHT_TEXT = `
/*
* Copyright {startYear}-{currentYear} Commencis. All Rights Reserved.
*
* Save to the extent permitted by law, you may not use, copy, modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of Commencis.
* Any reproduction of this material must contain this notice.
*/
`.trim();
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/rules/copyright-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export default createRule<[RuleOptions], MessageIds>({

create(context, [options]) {
const startYear = options.startYear ?? DEFAULT_START_YEAR;
const expectedCopyrightText = getCopyrightText(startYear);
const isHtml = context.filename.endsWith('.vue');

const expectedCopyrightText = getCopyrightText(startYear, isHtml);

return {
Program(node: TSESTree.Program) {
Expand Down
16 changes: 11 additions & 5 deletions packages/eslint-plugin/src/utils/getCopyrightText.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { COPYRIGHT_TEXT } from '@/constants/copyright';

export function getCopyrightText(startYear: number): string {
export function getCopyrightText(startYear: number, isHtml: boolean): string {
const currentYear = new Date().getFullYear();
return COPYRIGHT_TEXT.replace(/{startYear}/g, startYear.toString()).replace(
/{currentYear}/g,
currentYear.toString()
);

const formattedText = COPYRIGHT_TEXT.replace(
/{startYear}/g,
startYear.toString()
).replace(/{currentYear}/g, currentYear.toString());

if (isHtml) {
return `<!--\n ${formattedText}\n-->`;
}
return `/*\n ${formattedText}\n */`;
}